public static String discountDetailListJson(List<UnitDiscountDetail> detailList) {

    if (CommonUtils.isCollectionEmpty(detailList)) {

      return "[]";
    }

    List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
    Map<String, String> map = null;

    for (UnitDiscountDetail detail : detailList) {

      map = new HashMap<String, String>();

      map.put("typeId", detail.getDiscountType());
      map.put("percent", detail.getDiscountPercent().toString());
      map.put("remark", detail.getRemark());

      listMap.add(map);
    }

    String out = CommonUtils.getListMapJsonAnd(listMap);

    return out;
  }
  /**
   * 根据单元折扣id获取项目折扣的显示名称
   *
   * @param unitDiscountId
   * @return
   */
  public static String getProjectDiscountShowByUnitDiscountId(int unitDiscountId) {

    StringBuffer sb = new StringBuffer();

    UnitDiscount unitDiscount = unitDiscountServices.findUnitDiscountById(unitDiscountId);

    try {

      List<UnitDiscountDetail> detailList =
          unitDiscountDetailServices.findDetailByDiscountId(unitDiscountId);

      if (!CommonUtils.isCollectionEmpty(detailList)) {
        for (UnitDiscountDetail detail : detailList) {

          sb.append(detail.getDiscountPercent()).append("*");
        }
      }

      List<ProjectDiscount> proList =
          projectDiscountServices.findProjectDiscountByUnitDiscountId(unitDiscountId);

      if (!CommonUtils.isCollectionEmpty(proList)) {
        for (ProjectDiscount pro : proList) {

          sb.append(pro.getDiscountPercent()).append("*");
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
      sb.delete(0, sb.length());
      sb.append(unitDiscount.getDiscountName());
    }

    String ret = sb.toString();
    if (ret.endsWith("*")) {

      ret = ret.substring(0, ret.length() - 1);

      // 增加折扣对应的说明
      String computeWay = unitDiscount.getComputeWay();
      String wayValue = computeWayMap.get(computeWay);
      if (!CommonUtils.isStrEmpty(wayValue)) {

        ret += wayValue;
      }
    }

    if (CommonUtils.isStrEmpty(ret)) {
      ret = "查看折扣";
    }

    return ret;
  }
  /**
   * 根据折扣id获取其显示及折扣乘积
   *
   * @param discountId
   * @return
   */
  public static Map<String, String> getDiscountDetailShowAndMultiplyByDiscountId(
      HttpServletRequest request) {

    int discountId = Integer.parseInt(request.getParameter("unitDiscountId"));

    Map<String, String> retMap = new HashMap<String, String>();

    StringBuffer sb = new StringBuffer();
    BigDecimal multiply = new BigDecimal(1); // 具体的折扣

    UnitDiscount unitDiscount = unitDiscountServices.findUnitDiscountById(discountId);

    try {

      List<UnitDiscountDetail> detailList =
          unitDiscountDetailServices.findDetailByDiscountId(discountId);

      if (!CommonUtils.isCollectionEmpty(detailList)) {
        for (UnitDiscountDetail detail : detailList) {

          sb.append(detail.getDiscountPercent()).append("*");
          multiply = multiply.multiply(detail.getDiscountPercent().divide(new BigDecimal(100)));
        }
      } else {

        sb.append(unitDiscount.getDiscountName());
      }

      retMap = initSumMoneyAndContractMoney(request, discountId, multiply, retMap); // 设置其他的相关金额

    } catch (Exception e) {
      e.printStackTrace();
    }

    String detail = sb.toString();
    if (detail.endsWith("*")) {
      detail = detail.substring(0, detail.length() - 1);
    }

    // 增加折扣对应的说明
    String computeWay = unitDiscount.getComputeWay();
    String wayValue = computeWayMap.get(computeWay);
    if (!CommonUtils.isStrEmpty(wayValue)) {

      detail += wayValue;
    }

    retMap.put("detail", detail); // 折扣显示
    retMap.put("multiply", multiply.toString()); // 具体的折扣

    return retMap;
  }
  /**
   * 根据请求参数及单元折扣id,获取单元折扣详细列表
   *
   * @param someDetail
   * @param discountId
   * @return
   * @throws Exception
   */
  public static List<UnitDiscountDetail> initForAddDiscountDetail(String someDetail, int discountId)
      throws Exception {
    // typeId1=3&percent1=99&remark1=&typeId2=4&percent2=97&remark2=&detailCount=2

    Map<String, String> map = new HashMap<String, String>();

    String[] details = someDetail.split("&");
    for (String detail : details) {

      String[] tmp = detail.split("=");
      try {

        map.put(tmp[0], tmp[1]);
      } catch (Exception e) {

        map.put(tmp[0], "");
      }
    }

    List<UnitDiscountDetail> retList = new ArrayList<UnitDiscountDetail>();
    int beanCount = Integer.parseInt(map.get("detailCount"));

    for (int i = 1; i <= beanCount; i++) {

      UnitDiscountDetail tmpDetail = new UnitDiscountDetail();

      String typeId = map.get("typeId" + i);
      String percent = map.get("percent" + i);
      String remark = map.get("remark" + i);

      if (CommonUtils.isStrEmpty(typeId)
          && CommonUtils.isStrEmpty(percent)
          && CommonUtils.isStrEmpty(remark)) continue;

      tmpDetail.setDiscountId(discountId);
      tmpDetail.setDiscountType(typeId);
      tmpDetail.setDiscountPercent(CommonUtils.exceptionToZero(percent));
      tmpDetail.setRemark(remark);

      CommonPojoUtils.initPojoCommonFiled(tmpDetail);

      retList.add(tmpDetail);
    }

    return retList;
  }