public void save(FiDeliverycost entity) {
   if (entity.getId() == null) {
     if (entity.getFlightMainNo() != null) {
       List<FiDeliverycost> list =
           find(
               "from FiDeliverycost  fi where fi.flightMainNo=? and fi.customerId=? ",
               entity.getFlightMainNo(),
               entity.getCustomerId());
       if (list.size() > 0) {
         throw new ServiceException("此黄单号已录入,不能重复录入");
       }
     } else {
       throw new ServiceException("录入的黄单号不能为空");
     }
   }
   fiDeliverycostDao.save(entity);
 }
  /*
   * 取消成本审核
   */
  @ModuleName(value = "提货成本管理取消成本审核", logType = LogType.fi)
  public void saveQxFiAudit(List<FiDeliverycost> aa) throws Exception {
    List<Long> fiDelivAll = new ArrayList<Long>(); // 取消审核的ID集合
    for (FiDeliverycost fd : aa) {
      fiDelivAll.add(fd.getId());
    }

    List<FiDeliverycost> listAa = new ArrayList<FiDeliverycost>();
    for (FiDeliverycost fiDeliverycost : aa) { // 验证时间戳
      FiDeliverycost fiDeli = fiDeliverycostDao.get(fiDeliverycost.getId());
      List<Long> faxIdList = getPksByIds(fiDeli.getFaxId());
      for (Long faxIdLong : faxIdList) {
        OprFaxMain fiMain = oprFaxMainService.get(faxIdLong);
        fiMain.setCostAuditStatus(0l);
        oprFaxMainService.save(fiMain);

        //			fiCostService.sumCostBySourceDataId("提货成本", fiDeliverycost.getId());   //总
        List<OprFaxIn> listFax =
            oprFaxInDao.find(
                "from OprFaxIn oi where oi.faxMainId=? and oi.status=1  ",
                fiMain.getId()); // 找到配送单号
        for (OprFaxIn oin : listFax) {
          double totalCost =
              fiCostService.sumCostBySourceDataId("提货成本", oin.getDno()); // 所有配送单号提货成本
          FiCost fiCostNew = new FiCost();
          fiCostNew.setCostType("提货成本");
          fiCostNew.setCostTypeDetail("撤销审核");
          fiCostNew.setCostAmount(-totalCost);
          fiCostNew.setDataSource("提货成本");
          fiCostNew.setDno(oin.getDno());
          fiCostNew.setSourceSignNo(fiDeliverycost.getId() + "");
          fiCostNew.setStatus(1l);
          fiCostService.save(fiCostNew); // 重新

          oprHistoryService.saveLog(
              oin.getDno(), "提货成本审核撤销,撤销金额:" + totalCost, log_qxAuditCost); // 操作日志
        }
      }
      if (faxIdList.size() == 1) {
        List<FiDeliverycost> lisd =
            find(
                "from FiDeliverycost  fd where fd.departId=? and fd.faxId=? and  fd.id<> ? ",
                fiDeli.getDepartId(),
                fiDeli.getFaxId(),
                fiDeli.getId());
        List<Long> idsLongList = new ArrayList<Long>();
        for (FiDeliverycost fiDt2 : lisd) {
          idsLongList.add(fiDt2.getId());
        }
        if (!fiDelivAll.containsAll(idsLongList)) {
          throw new ServiceException("存在多条黄单记录匹配一条主单号的记录,请一起取消审核");
        }
      }
      if (fiDeli.getPayStatus() == 1l) {
        throw new ServiceException("不能撤销会计审核,存在已支付的数据");
      }
      fiDeli.setTs(fiDeliverycost.getTs());
      fiDeliverycostDao.save(fiDeli);
      listAa.add(fiDeli);
    }

    List<FiDeliverycost> list =
        fiDeliverycostDao.find(
            "from FiDeliverycost f where f.batchNo=? ", listAa.get(0).getBatchNo());
    if (list.size() == listAa.size()) { // 如果是一个批次的数据全部撤销
      for (FiDeliverycost fiDeliverycost : listAa) {
        // 财务接口
        List<FiInterfaceProDto> listfiInterfaceDto = new ArrayList<FiInterfaceProDto>();
        FiInterfaceProDto fiIn = new FiInterfaceProDto();
        fiIn.setSourceData("提货成本");
        fiIn.setSourceNo(fiDeliverycost.getBatchNo());
        fiIn.setAmount(fiDeliverycost.getAmount());
        listfiInterfaceDto.add(fiIn);
        fiInterfaceImpl.changePaymentAmount(listfiInterfaceDto);

        fiDeliverycost.setReviewDept(null);
        fiDeliverycost.setReviewDate(null);
        fiDeliverycost.setBatchNo(null);
        fiDeliverycost.setReviewUser(null);
        fiDeliverycost.setBatchNo(null);
        fiDeliverycost.setStatus(0l);
        save(fiDeliverycost); // 更新会计审核信息
      }
    } else { // 如果只撤销一部分

      double totalChange = 0.0;
      for (int i = 0; i < listAa.size(); i++) {
        totalChange = DoubleUtil.add(listAa.get(i).getAmount(), totalChange); // 修改的总金额
      }

      // 财务接口   撤销部分应收应入
      List<FiInterfaceProDto> listfiInterfaceDto = new ArrayList<FiInterfaceProDto>();
      FiInterfaceProDto fiIn = new FiInterfaceProDto();
      fiIn.setSourceData("提货成本");
      fiIn.setSourceNo(listAa.get(0).getBatchNo());
      fiIn.setAmount(totalChange);
      listfiInterfaceDto.add(fiIn);
      fiInterfaceImpl.revocationFiDeliveryCost(listfiInterfaceDto);

      //		throw new ServiceException("正在开发中...");
      for (FiDeliverycost fiDeliverycost : listAa) {

        fiDeliverycost.setReviewDept(null);
        fiDeliverycost.setReviewDate(null);
        fiDeliverycost.setReviewUser(null);
        fiDeliverycost.setBatchNo(null);
        fiDeliverycost.setStatus(0l);
        save(fiDeliverycost); // 更新会计审核信息
      }
    }
  }
  // 取消匹配
  @ModuleName(value = "提货成本管理取消匹配", logType = LogType.fi)
  public String qxAudit(List<FiDeliverycost> aa) throws Exception {
    List<Long> fiDelivAll = new ArrayList<Long>(); // 取消匹配的ID集合
    for (FiDeliverycost fd : aa) {
      fiDelivAll.add(fd.getId());
    }

    for (FiDeliverycost fiDeliv : aa) {
      FiDeliverycost fiDeliverycost = fiDeliverycostDao.get(fiDeliv.getId());
      fiDeliverycost.setTs(fiDeliv.getTs());

      if (fiDeliverycost.getStatus() == 1l) {
        throw new ServiceException("已审核数据不能进行取消匹配操作");
      }

      if (fiDeliverycost.getMatStatus() == null || fiDeliverycost.getMatStatus() == 0l) {
        throw new ServiceException("未匹配的数据不能进行取消匹配操作");
      }
      List<Long> list = getPksByIds(fiDeliverycost.getFaxId());
      for (Long faxIdLong : list) {
        OprFaxMain fiMain = oprFaxMainService.get(faxIdLong);
        fiMain.setMatchStatus(0l);
        oprFaxMainService.save(fiMain);

        // 超重删除
        List<OprOverweight> list2 =
            cusOverWeightService.find(
                "from OprOverweight oo where oo.departId=? and oo.flightMainNo=?  and oo.status=1 ",
                fiDeliverycost.getDepartId(),
                fiMain.getFlightMainNo());
        for (OprOverweight oprOverweight : list2) {
          oprOverweight.setStatus(0l);
          cusOverWeightService.save(oprOverweight);
        }
      }

      if (list.size() == 1) { // 保存黄单多对一的ID集合,用来判断是否一次全部取消匹配
        List<FiDeliverycost> lisd =
            find(
                "from FiDeliverycost  fd where fd.departId=? and fd.faxId=? and  fd.id<> ? ",
                fiDeliverycost.getDepartId(),
                fiDeliverycost.getFaxId(),
                fiDeliverycost.getId());
        List<Long> idsLongList = new ArrayList<Long>();
        for (FiDeliverycost fiDt2 : lisd) {
          idsLongList.add(fiDt2.getId());
        }
        if (!fiDelivAll.containsAll(idsLongList)) {
          throw new ServiceException("存在多条黄单记录匹配一条主单号的记录,请全部取消匹配");
        }
      }

      if (fiDeliverycost.getStatus() != null && fiDeliverycost.getStatus() == 1l) {
        throw new ServiceException("数据已审核,不能撤销手工匹配");
      }

      fiDeliverycost.setMatStatus(0l);
      fiDeliverycost.setFaxMainNo(null);
      fiDeliverycost.setFaxPiece(0l);
      fiDeliverycost.setFaxWeight(0.0);
      fiDeliverycost.setDiffAmount(0.0);
      fiDeliverycost.setDiffWeight(0.0);
      fiDeliverycost.setFaxId(null);
      fiDeliverycostDao.save(fiDeliverycost); // 撤销手工匹配
    }
    return null;
  }