public Map<String, Object> billAudit(Map<String, Object> reqMap) {
    Map<String, Object> paraMap = JSONUtil.getMap(reqMap.get(SInvokeKeys.postData.value()) + "");
    // 请求参数
    Long billId = Long.valueOf(StringUtil.objectToString(paraMap.get("billId"))); // 单据ID
    int checkStatus =
        Integer.valueOf(StringUtil.objectToString(paraMap.get("checkStatus"))); // 审核状态
    String op = StringUtil.objectToString(paraMap.get("op")); // 操作类型
    SysUser operator = (SysUser) reqMap.get("operator");

    // 获取将要审核的单据
    JxcBreakage tmpBill = jxcBreakageDao.get(billId);

    if (op.equals("audit")) { // 审核
      if (checkStatus == 1) { // 如果单据审核通过
        // 获取 审核的单据 中包含的 商品信息
        Map<String, Object> argMap = new HashMap<String, Object>();
        argMap.put("billNo", tmpBill.getBillNo());
        List<JxcProfitandlossDetail> billGoodsList =
            jxcProfitandlossDetailDao.getBillGoodsDetailList(argMap);
        // 将单据中的商品信息转化成 仓库库存的变更
        Long storageId = tmpBill.getStorageId(); // 单据 - 仓库ID
        Long brokerId = tmpBill.getBrokerId(); // 单据 - 经手人ID

        Map<String, Object> transMap = new HashMap<String, Object>();
        transMap.put("billGoodsList", billGoodsList);
        transMap.put("storageId", storageId);
        transMap.put("brokerId", brokerId);
        transMap.put("storeOp", StorageKeys.breakage.value());
        Map<String, Object> resMap = jxcStorehouseService.profitAndLossTransStorage(transMap);

        int resultFlag = Integer.valueOf(resMap.get("resultFlag") + "");

        // 设置单据审核状态
        if (resultFlag == 1) { // 通过审核
          tmpBill.setCheckStatus(BillAuditKeys.approved.value());
        } else { // 未通过审核
          tmpBill.setCheckStatus(BillAuditKeys.notapproved.value());
        }

        // 更新单据 审核状态
        jxcBreakageDao.update(tmpBill);

        /** 记录 审核日志* */
        Map<String, Object> auditLogParaMap = new HashMap<String, Object>();
        auditLogParaMap.put("bill", tmpBill);
        auditLogParaMap.put("operator", operator);
        auditLogParaMap.put("auditStage", BillAuditLogKeys.firstAuditStage.value());
        auditLogParaMap.put("auditProcess", BillAuditLogKeys.firstAudit.value());
        jxcAuditLogService.recordBillAuditLog(auditLogParaMap);

        return DataResponseUtil.getResultData(reqMap, resultFlag, resMap.get("resultMsg") + "");
      } else {
        tmpBill.setCheckStatus(checkStatus);
        // 更新单据 审核状态
        jxcBreakageDao.update(tmpBill);

        /** 记录 审核日志* */
        Map<String, Object> auditLogParaMap = new HashMap<String, Object>();
        auditLogParaMap.put("bill", tmpBill);
        auditLogParaMap.put("operator", operator);
        auditLogParaMap.put("auditStage", BillAuditLogKeys.firstAuditStage.value());
        auditLogParaMap.put("auditProcess", BillAuditLogKeys.firstAudit.value());
        jxcAuditLogService.recordBillAuditLog(auditLogParaMap);

        return DataResponseUtil.getResultData(reqMap, 1, "单据审核完成。");
      }
    } else {
      return DataResponseUtil.getResultData(reqMap, 0, "其他操作类型");
    }
  }
  private List<Map<String, Object>> analysesData(Map<String, Object> paraMap, String orderDay) {
    // 结果List
    List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();

    /** 查询符合条件的 单位* */
    List<Map<String, Object>> unitInfoList = orderDao.getOrderAnalysesUnitInfoList(paraMap);

    for (Map<String, Object> tmpInfo : unitInfoList) {
      String shortName = StringUtil.objectToString(tmpInfo.get("shortName")); // 单位简称
      Object idObj = tmpInfo.get("unitID");
      Long unitID = Long.valueOf(idObj == null ? "0" : StringUtil.objectToString(idObj)); // 单位ID

      paraMap.put("unitIdOption", unitID); // 根据单位查询各单位的订单

      /** 查询符合条件的订单数据* */
      List<Order> orderList = orderDao.getOrderAnalysesData(paraMap);

      /** 分析订单数据* */
      if (!orderList.isEmpty()) {
        // 分析数据详情

        // 所有订单
        int orderCount = orderList.size(); // 所有订单量
        double goodsAmount = 0.0; // 商品金额
        double avgAmount = 0.0; // 客单价(商品金额/订单总数)
        double realAmount = 0.0; // 实付金额总数
        double coinAmount = 0.0; // 达人币总数
        double goodsTransportAmount = 0.0; // 订单总运费
        double couponsAmount = 0.0; // 优惠券总额
        // 有效订单
        int orderCount0 = 0; // 所有订单量
        double goodsAmount0 = 0.0; // 商品金额
        double avgAmount0 = 0.0; // 客单价(商品金额/订单总数)
        double realAmount0 = 0.0; // 实付金额总数
        double coinAmount0 = 0.0; // 达人币总数
        double goodsTransportAmount0 = 0.0; // 订单总运费
        double couponsAmount0 = 0.0; // 优惠券总额
        // 拒收订单
        int orderCount4 = 0; // 所有订单量
        double goodsAmount4 = 0.0; // 商品金额
        double avgAmount4 = 0.0; // 客单价(商品金额/订单总数)
        double realAmount4 = 0.0; // 实付金额总数
        double coinAmount4 = 0.0; // 达人币总数
        double goodsTransportAmount4 = 0.0; // 订单总运费
        double couponsAmount4 = 0.0; // 优惠券总额
        // 线下订单
        int orderCount2 = 0; // 所有订单量
        double goodsAmount2 = 0.0; // 商品金额
        double avgAmount2 = 0.0; // 客单价(商品金额/订单总数)
        double realAmount2 = 0.0; // 实付金额总数
        double coinAmount2 = 0.0; // 达人币总数
        double goodsTransportAmount2 = 0.0; // 订单总运费
        double couponsAmount2 = 0.0; // 优惠券总额
        // 线上订单
        int orderCount1 = 0; // 所有订单量
        double goodsAmount1 = 0.0; // 商品金额
        double avgAmount1 = 0.0; // 客单价(商品金额/订单总数)
        double realAmount1 = 0.0; // 实付金额总数
        double coinAmount1 = 0.0; // 达人币总数
        double goodsTransportAmount1 = 0.0; // 订单总运费
        double couponsAmount1 = 0.0; // 优惠券总额

        for (Order tmpOrder : orderList) {

          // 所有订单
          goodsAmount = Arith.add(goodsAmount, tmpOrder.getGoodsAmount());
          realAmount = Arith.add(realAmount, tmpOrder.getRealAmount());
          coinAmount = Arith.add(coinAmount, tmpOrder.getVipCoin());
          goodsTransportAmount =
              Arith.add(goodsTransportAmount, tmpOrder.getGoodsTransportAmount());
          couponsAmount = Arith.add(couponsAmount, tmpOrder.getCouponsAmount());

          // 有效订单
          if (tmpOrder.getDeliveryerStatus() == 12) {

            orderCount0++;
            goodsAmount0 = Arith.add(goodsAmount0, tmpOrder.getGoodsAmount());
            realAmount0 = Arith.add(realAmount0, tmpOrder.getRealAmount());
            coinAmount0 = Arith.add(coinAmount0, tmpOrder.getVipCoin());
            goodsTransportAmount0 =
                Arith.add(goodsTransportAmount0, tmpOrder.getGoodsTransportAmount());
            couponsAmount0 = Arith.add(couponsAmount0, tmpOrder.getCouponsAmount());
          }

          // 拒收订单
          if (tmpOrder.getDeliveryerStatus() == -11) {

            orderCount4++;
            goodsAmount4 = Arith.add(goodsAmount4, tmpOrder.getGoodsAmount());
            realAmount4 = Arith.add(realAmount4, tmpOrder.getRealAmount());
            coinAmount4 = Arith.add(coinAmount4, tmpOrder.getVipCoin());
            goodsTransportAmount4 =
                Arith.add(goodsTransportAmount4, tmpOrder.getGoodsTransportAmount());
            couponsAmount4 = Arith.add(couponsAmount4, tmpOrder.getCouponsAmount());
          }

          // 线下订单
          if (tmpOrder.getPayType() == 0) {

            orderCount2++;
            goodsAmount2 = Arith.add(goodsAmount2, tmpOrder.getGoodsAmount());
            realAmount2 = Arith.add(realAmount2, tmpOrder.getRealAmount());
            coinAmount2 = Arith.add(coinAmount2, tmpOrder.getVipCoin());
            goodsTransportAmount2 =
                Arith.add(goodsTransportAmount2, tmpOrder.getGoodsTransportAmount());
            couponsAmount2 = Arith.add(couponsAmount2, tmpOrder.getCouponsAmount());
          }

          // 线上订单
          if (tmpOrder.getPayType() == 1) {

            orderCount1++;
            goodsAmount1 = Arith.add(goodsAmount1, tmpOrder.getGoodsAmount());
            realAmount1 = Arith.add(realAmount1, tmpOrder.getRealAmount());
            coinAmount1 = Arith.add(coinAmount1, tmpOrder.getVipCoin());
            goodsTransportAmount1 =
                Arith.add(goodsTransportAmount1, tmpOrder.getGoodsTransportAmount());
            couponsAmount1 = Arith.add(couponsAmount1, tmpOrder.getCouponsAmount());
          }
        }

        if (orderCount != 0) {
          avgAmount = Arith.div(goodsAmount, orderCount + 0.0, 2);
        } else {
          avgAmount = 0;
        }
        if (orderCount0 != 0) {
          avgAmount0 = Arith.div(goodsAmount0, orderCount0 + 0.0, 2);
        } else {
          avgAmount0 = 0;
        }
        if (orderCount4 != 0) {
          avgAmount4 = Arith.div(goodsAmount4, orderCount4 + 0.0, 2);
        } else {
          avgAmount4 = 0;
        }
        if (orderCount2 != 0) {
          avgAmount2 = Arith.div(goodsAmount2, orderCount2 + 0.0, 2);
        } else {
          avgAmount2 = 0;
        }
        if (orderCount1 != 0) {
          avgAmount1 = Arith.div(goodsAmount1, orderCount1 + 0.0, 2);
        } else {
          avgAmount1 = 0;
        }

        Map<String, Object> analysisData = new HashMap<String, Object>();

        // 基本数据
        analysisData.put("ORDER_DAY", orderDay); // 数据统计的时间
        analysisData.put("UNIT_SHORT_NAME", shortName); // 单位简称
        // 所有订单
        analysisData.put("ORDER_COUNT", orderCount); // 所有订单量
        analysisData.put("GOODS_AMOUNT", goodsAmount); // 商品总金额
        analysisData.put("REAL_AMOUNT", realAmount); // 实付总金额
        analysisData.put("COIN_AMOUNT", coinAmount); // 达人币总量
        analysisData.put("GOODS_TRANSPORT_AMOUNT", goodsTransportAmount); // 总配送费
        analysisData.put("COUPONS_AMOUNT", couponsAmount); // 优惠券总额
        analysisData.put("AVG_AMOUNT", avgAmount); // 客单价
        // 有效订单
        analysisData.put("ORDER_COUNT_0", orderCount0); // 所有订单量
        analysisData.put("GOODS_AMOUNT_0", goodsAmount0); // 商品总金额
        analysisData.put("REAL_AMOUNT_0", realAmount0); // 实付总金额
        analysisData.put("COIN_AMOUNT_0", coinAmount0); // 达人币总量
        analysisData.put("GOODS_TRANSPORT_AMOUNT_0", goodsTransportAmount0); // 总配送费
        analysisData.put("COUPONS_AMOUNT_0", couponsAmount0); // 优惠券总额
        analysisData.put("AVG_AMOUNT_0", avgAmount0); // 客单价
        // 拒收订单
        analysisData.put("ORDER_COUNT_4", orderCount4); // 所有订单量
        analysisData.put("GOODS_AMOUNT_4", goodsAmount4); // 商品总金额
        analysisData.put("REAL_AMOUNT_4", realAmount4); // 实付总金额
        analysisData.put("COIN_AMOUNT_4", coinAmount4); // 达人币总量
        analysisData.put("GOODS_TRANSPORT_AMOUNT_4", goodsTransportAmount4); // 总配送费
        analysisData.put("COUPONS_AMOUNT_4", couponsAmount4); // 优惠券总额
        analysisData.put("AVG_AMOUNT_4", avgAmount4); // 客单价
        // 线下订单
        analysisData.put("ORDER_COUNT_2", orderCount2); // 所有订单量
        analysisData.put("GOODS_AMOUNT_2", goodsAmount2); // 商品总金额
        analysisData.put("REAL_AMOUNT_2", realAmount2); // 实付总金额
        analysisData.put("COIN_AMOUNT_2", coinAmount2); // 达人币总量
        analysisData.put("GOODS_TRANSPORT_AMOUNT_2", goodsTransportAmount2); // 总配送费
        analysisData.put("COUPONS_AMOUNT_2", couponsAmount2); // 优惠券总额
        analysisData.put("AVG_AMOUNT_2", avgAmount2); // 客单价
        // 线上订单
        analysisData.put("ORDER_COUNT_1", orderCount1); // 所有订单量
        analysisData.put("GOODS_AMOUNT_1", goodsAmount1); // 商品总金额
        analysisData.put("REAL_AMOUNT_1", realAmount1); // 实付总金额
        analysisData.put("COIN_AMOUNT_1", coinAmount1); // 达人币总量
        analysisData.put("GOODS_TRANSPORT_AMOUNT_1", goodsTransportAmount1); // 总配送费
        analysisData.put("COUPONS_AMOUNT_1", couponsAmount1); // 优惠券总额
        analysisData.put("AVG_AMOUNT_1", avgAmount1); // 客单价

        resultList.add(analysisData);
      }
    }

    return resultList;
  }
  public JxcBillCheckParams billCheck(Map<String, Object> reqMap) {
    // 单据审核返回对象
    JxcBillCheckParams checkParams = new JxcBillCheckParams();
    checkParams.setResultFlag(0);
    checkParams.setResultMsg("单据参数有误,请修改后再保存!");

    // 验证通过返回的单据对象
    JxcAllocation allocateBill = new JxcAllocation();

    // 调拨单参数map
    Map<String, Object> paraMap = JSONUtil.getMap(reqMap.get(SInvokeKeys.postData.value()) + "");

    String billNo = StringUtil.objectToString(paraMap.get("billNo"));
    String billCustomNo = StringUtil.objectToString(paraMap.get("billCustomNo"));

    String exStorageId = StringUtil.objectToString(paraMap.get("exStorageId"));
    String inStorageId = StringUtil.objectToString(paraMap.get("inStorageId"));
    String brokerId = StringUtil.objectToString(paraMap.get("brokerId"));

    String allocateDate = StringUtil.objectToString(paraMap.get("allocateDate"));
    String notes = StringUtil.objectToString(paraMap.get("notes"));
    String reviseMark = StringUtil.objectToString(paraMap.get("reviseMark"));

    // 单据编号
    allocateBill.setBillNo(billNo);

    // 自定义单据编号
    allocateBill.setBillCustomNo(billCustomNo);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    try {
      // 调拨日期
      if (allocateDate != null && !"".equals(allocateDate)) {
        Date allocateTime = sdf.parse(allocateDate);
        allocateBill.setAllocateDate(allocateTime);
      }
    } catch (ParseException e) {
      System.err.println("字符串 转 日期出错");
      e.printStackTrace();
    }

    // 调出仓库
    if (exStorageId == null || "".equals(exStorageId)) {
      checkParams.setResultMsg("单据保存失败,原因:调出仓库ID不能为空!");
      return checkParams;
    }

    Long exStorageIdL = Long.valueOf(exStorageId);

    Storehouse exStorehouse = jxcStorehouseDao.get(exStorageIdL);
    if (exStorehouse == null) {
      checkParams.setResultMsg("单据保存失败,原因:调出仓库信息错误!");
      return checkParams;
    } else {
      allocateBill.setExportStorageId(exStorageIdL);
      allocateBill.setStorageExport(exStorehouse.getStoreName());
    }

    // 调入仓库
    if (inStorageId == null || "".equals(inStorageId)) {
      checkParams.setResultMsg("单据保存失败,原因:调入仓库ID不能为空!");
      return checkParams;
    }

    Long inStorageIdL = Long.valueOf(inStorageId);

    Storehouse inStorehouse = jxcStorehouseDao.get(inStorageIdL);
    if (inStorehouse == null) {
      checkParams.setResultMsg("单据保存失败,原因:调入仓库信息错误!");
      return checkParams;
    } else {
      allocateBill.setImportStorageId(inStorageIdL);
      allocateBill.setStorageImport(inStorehouse.getStoreName());
    }

    // 经手人
    if (brokerId != null && !"".equals(brokerId)) {
      Long brokerIdL = Long.valueOf(brokerId);

      SysUser broker = jxcSysUserDao.get(brokerIdL);
      if (broker == null) {
        checkParams.setResultMsg("单据保存失败,原因:经手人信息错误!");
        return checkParams;
      } else {
        allocateBill.setBrokerId(brokerIdL);
        allocateBill.setBroker(broker.getUserName());
      }
    }

    // 备注
    allocateBill.setNotes(notes);

    // 补单标记
    if (reviseMark == "1") {
      allocateBill.setReviseMark(1);
    } else {
      allocateBill.setReviseMark(0);
    }

    // 整单合计金额
    Double billTotalAmount = 0.00;

    // 整单合计差额
    Double billTotalDifference = 0.00;

    /** 调拨单明细处理* */
    // 调拨单据 明细对象
    JxcAllocationbillDetail billDetail;
    // 获取单据明细(商品)列表
    String billGoodsDetailJson = StringUtil.objectToString(paraMap.get("billGoodsList"));

    if (billGoodsDetailJson == null || "".equals(billGoodsDetailJson)) {
      checkParams.setResultMsg("单据保存失败,原因:商品信息为空!");
      return checkParams;
    }

    List<Map<String, Object>> billGoodsList = JSONUtil.jsonToListMap(billGoodsDetailJson);
    if (billGoodsList == null || billGoodsList.isEmpty()) {
      checkParams.setResultMsg("单据保存失败,原因:商品明细为空!");
      return checkParams;
    } else {
      for (Map<String, Object> goodsMap : billGoodsList) {
        // init 单据明细对象
        billDetail = new JxcAllocationbillDetail();
        // 商品信息
        Long goodsId = Long.valueOf(goodsMap.get("goodsId") + "");
        GoodsPrice goodsDetail = goodsPriceDao.get(goodsId);
        if (goodsDetail == null) {
          checkParams.setResultMsg("单据保存失败,原因:商品不存在!");
          return checkParams;
        } else {
          // 单据编号
          billDetail.setBillNo(billNo);

          // 调出仓库信息
          billDetail.setExportStorageId(exStorageIdL);
          billDetail.setExportStorage(exStorehouse.getStoreName());

          // 调入仓库信息
          billDetail.setImportStorageId(inStorageIdL);
          billDetail.setImportStorage(inStorehouse.getStoreName());

          // 商品信息
          billDetail.setGoodsId(goodsId);
          billDetail.setGoodsNickname(goodsDetail.getGoodsNickName());
          billDetail.setGoodsNumber(goodsDetail.getGoodsNumber());

          // 商品 成本原价
          String costSinglePrice = StringUtil.objectToString(goodsMap.get("costSinglePrice"));
          if (costSinglePrice == null || "".equals(costSinglePrice)) {
            billDetail.setCostSinglePrice(0.00);
          } else {
            Double singlePriceD = Double.valueOf(costSinglePrice);
            billDetail.setCostSinglePrice(singlePriceD);
          }

          // 商品 调拨单价
          String allocateSinglePrice =
              StringUtil.objectToString(goodsMap.get("allocateSinglePrice"));
          if (allocateSinglePrice == null || "".equals(allocateSinglePrice)) {
            billDetail.setCostSinglePrice(0.00);
          } else {
            Double allocateSinglePriceD = Double.valueOf(allocateSinglePrice);
            billDetail.setAllocateSinglePrice(allocateSinglePriceD);
          }

          // 商品数量
          String goodsCount = StringUtil.objectToString(goodsMap.get("goodsCount"));
          if (goodsCount == null || "".equals(goodsCount)) {
            billDetail.setGoodsCount(0);
          } else {
            Integer goodsCountI = Integer.valueOf(goodsCount);
            billDetail.setGoodsCount(goodsCountI);
          }

          // 该类商品 总差额
          Double totalDifference =
              Arith.mul(
                  Arith.sub(billDetail.getAllocateSinglePrice(), billDetail.getCostSinglePrice()),
                  Double.valueOf(billDetail.getGoodsCount()));
          billDetail.setTotalDifference(totalDifference);

          // 该类商品 总额
          Double totalAmount =
              Arith.mul(
                  billDetail.getAllocateSinglePrice(), Double.valueOf(billDetail.getGoodsCount()));
          billDetail.setTotalAmount(totalAmount);

          // 明细创建时间
          billDetail.setCreateDate(DateUtil.getSystemTime());

          // 备注信息
          billDetail.setNotes(goodsMap.get("goodsNotes") + "");

          // 保存明细
          jxcAllocationbillDetailDao.add(billDetail);

          // 整单总金额累加
          billTotalAmount = Arith.add(billTotalAmount, totalAmount);

          // 整单总差额累加
          billTotalDifference = Arith.add(billTotalDifference, totalDifference);
        }
      }
    }
    /** 单据明细处理完毕* */

    // 整单合计金额
    allocateBill.setTotalAmount(billTotalAmount);

    // 整单 合计差额
    allocateBill.setTotalDifference(billTotalDifference);

    // 制单人
    String billMakerId = StringUtil.objectToString(paraMap.get("billMakerId"));
    if (billMakerId != null && !"".equals(billMakerId)) {
      SysUser billMaker = jxcSysUserDao.get(Long.valueOf(billMakerId));
      allocateBill.setBillMaker(billMaker.getUserName());
    }

    // 制单日期
    allocateBill.setCreateDate(DateUtil.getSystemTime());

    // 单据校验通过
    checkParams.setResultFlag(1);
    checkParams.setResultMsg("单据校验通过");
    checkParams.setBill(allocateBill);
    return checkParams;
  }