platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java
@@ -53,6 +53,7 @@
   private final HistoryOverdueMapper historyOverdueMapper;
   private final PaymentSlipMapper paymentSlipMapper;
   private final BipRequestRecordMapper bipRequestRecordMapper;
   private final ContractExecDateMapper contractExecDateMapper;
   private final RemoteDeptService remoteDeptService;
   private final RedisTemplate redisTemplate;
@@ -73,7 +74,7 @@
      if (StrUtil.isNotBlank(addDTO.getContractNo())) {
         Contract contract = contractService.getOne(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, addDTO.getContractNo()));
         BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery()
               .eq(StrUtil.isNotBlank(addDTO.getBusGuestName()), BusinessCustomer::getCompanyName, addDTO.getBusGuestName())
               .eq(StrUtil.isNotBlank(addDTO.getBusGuestName()), BusinessCustomer::getRegisterName, addDTO.getBusGuestName())
               .eq(StrUtil.isNotBlank(addDTO.getBusGuestId()), BusinessCustomer::getId, addDTO.getBusGuestId()));
         if (ObjUtil.isNull(customer)) {
            return R.failed("客商查询失败,请检查客商");
@@ -98,7 +99,7 @@
               entity.setScheduleName(lastConfirm.getScheduleName());
            }
            entity.setBusGuestId(customer.getId());
            entity.setBusGuestName(customer.getCompanyName());
            entity.setBusGuestName(customer.getRegisterName());
            entity.setBusinessType("客户付款");
            if (newtotal.compareTo(new BigDecimal("0")) > 0) {
               entity.setTransationAmount(addDTO.getTransationAmount());
@@ -120,7 +121,7 @@
            }
            //更新付款阶段付款
            List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                  .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2)
                  .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3)
                  .orderByAsc(ContractPaymentSchedule::getCreateTime));
            if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
               BigDecimal remain = addDTO.getTransationAmount();
@@ -192,7 +193,7 @@
            entity.setContractNo(addDTO.getContractNo());
            entity.setBusGuestId(customer.getId());
            entity.setBusGuestName(customer.getCompanyName());
            entity.setBusGuestName(customer.getRegisterName());
            entity.setBusinessType("");
            entity.setTransationAmount(addDTO.getTransationAmount());
            BigDecimal newtotal = addDTO.getTransationAmount().multiply(new BigDecimal("-1")).add(lastConfirm.getTotalAmount());
@@ -217,18 +218,28 @@
            ;
         }
      }else {
         List<Contract> customerContractList = contractService.list(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, addDTO.getBusGuestId())
               .eq(Contract::getPartyBId,SecurityUtils.getUser().getCompId()).orderByAsc(Contract::getCreateTime).apply(" amount != paid_amount"));
         if (ArrayUtil.isEmpty(customerContractList.toArray())) {
            return R.failed("为查询到未付款合同");
         }
         BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery()
               .eq(StrUtil.isNotBlank(addDTO.getBusGuestName()), BusinessCustomer::getCompanyName, addDTO.getBusGuestName())
               .eq(StrUtil.isNotBlank(addDTO.getBusGuestName()), BusinessCustomer::getRegisterName, addDTO.getBusGuestName())
               .eq(ObjUtil.isNotNull(addDTO.getBusGuestId()), BusinessCustomer::getId, addDTO.getBusGuestId())
               .last("limit 1"));
         if (ObjUtil.isNull(customer)) {
            return  R.failed("客商查询失败");
         }
         //新增付款单
         PaymentSlip slip = new PaymentSlip();
         slip.setBusGuestId(customer.getId());
         slip.setBusGuestName(customer.getRegisterName());
         slip.setPayeeCompId(SecurityUtils.getUser().getCompId());
         slip.setPaymentTime(addDTO.getConfirmTime());
         slip.setPaymentAmount(addDTO.getTransationAmount());
         slip.setPayType(addDTO.getPayType());
         paymentSlipMapper.insert(slip);
         BigDecimal transtionAmount = addDTO.getTransationAmount();
         //剩余付款
@@ -243,19 +254,25 @@
         List<Contract> advanceContractList = new ArrayList<>();
         //付款时间
         Date payDate = addDTO.getConfirmTime();
         for (Contract contract : customerContractList) {
         Iterator<Contract> iterator = customerContractList.iterator();
         while (iterator.hasNext()) {
            Contract contract = iterator.next();
            PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
                  .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
            BigDecimal lastTotal = new BigDecimal("0");
            if (ObjUtil.isNotNull(lastConfirm)) {
               lastTotal = lastConfirm.getTotalAmount();
            }else {
            }
            //合同最近明细总额为0 或 > 0 情况下
            if (lastTotal.compareTo(new BigDecimal("0")) >= 0) {
               log.info("当前合同号:{},明细总额无应收款", contract.getContractNo());
               advanceContractList.add(contract);
               continue;
               if (iterator.hasNext()) {
                  continue;
               }
            }
            transtionRemainAmount = transtionRemainAmount.add(lastTotal);
@@ -268,12 +285,19 @@
               entity.setScheduleName(lastConfirm.getScheduleName());
            }
            entity.setBusGuestId(customer.getId());
            entity.setBusGuestName(customer.getCompanyName());
            entity.setBusGuestName(customer.getRegisterName());
            entity.setBusinessType("客户付款");
            if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) {
               entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1")));
               entity.setTotalAmount(new BigDecimal("0"));
               entity.setConfirmTime(payDate);
               // 判断是否是最后一个
               if (!iterator.hasNext()) {
                  entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal));
                  entity.setAdvanceAmount(transtionRemainAmount);
                  entity.setTotalAmount(transtionRemainAmount);
               }else {
                  entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1")));
                  entity.setTotalAmount(new BigDecimal("0"));
               }
               baseMapper.insert(entity);
               payContractList.add(contract);
            } else if (transtionRemainAmount.compareTo(new BigDecimal("0")) == 0) {
@@ -285,7 +309,8 @@
               break;
            } else {
               entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal));
               entity.setTotalAmount(transtionAmount);
               entity.setReceivableAmount(transtionRemainAmount.multiply(new BigDecimal("-1")));
               entity.setTotalAmount(transtionRemainAmount);
               entity.setConfirmTime(payDate);
               baseMapper.insert(entity);
               payContractList.add(contract);
@@ -297,6 +322,7 @@
            //更新付款阶段付款
            List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                  .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2)
                  .ne(ContractPaymentSchedule::getPaymentStatus, 3)
                  .orderByAsc(ContractPaymentSchedule::getCreateTime));
            if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
               BigDecimal remain = transtionAmount;
@@ -351,48 +377,64 @@
            //合同所有付款阶段
            List<ContractPaymentSchedule> payComScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                  .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0)
                  );
                  .ne(ContractPaymentSchedule::getPaymentStatus, 3));
            if (ArrayUtil.isNotEmpty(payComScheduleList.toArray())){
               BigDecimal payTotal = payComScheduleList.stream().map(item->StrUtil.equals(item.getPaymentStatus() + "", "0") ? item.getPlannedAmount() :
               BigDecimal payTotal = payComScheduleList.stream().map(item->StrUtil.equals(item.getPaymentStatus() + "", "2") ? item.getPlannedAmount() :
                     item.getActualAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
               contract.setPaidAmount(payTotal);
               if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
                  contract.setContractStatus(3);
               }
               contractService.updateById(contract);
//               if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
//                  contract.setContractStatus(3);
//               }
               if (contract.getAmount().compareTo(contract.getPaidAmount()) == 0) {
                  contract.setBillingStatus("2");
                  contract.setContractStatus(3);
                  payCompleteContractList.add(contract);
               }
               //付款 且 付款未全付
               if (contract.getAmount().compareTo(contract.getPaidAmount()) > 0) {
                  payNoCompleteContractList.add(contract);
               }
               if (StrUtil.isNotEmpty(contract.getContractCategory())&&StrUtil.equals(contract.getContractCategory(),"water_house")){
                  List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery()
                        .eq(ContractExecDate::getContractId,contract.getId()).eq(ContractExecDate::getGenFlag,"0"));
                  if (ArrayUtil.isEmpty(execDateList.toArray())){
                     List<ContractPaymentSchedule> contractPaymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                           .eq(ContractPaymentSchedule::getContractId, contract.getId()));
                     if (ArrayUtil.isNotEmpty(contractPaymentScheduleList.toArray())&&contractPaymentScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
                        contract.setContractStatus(3);
                        contractService.updateById(contract);
                     }
                  }
               }else {
                  contractService.updateById(contract);
               }
            }
         });
         //客户预付有剩余 且 有预付款的合同
         if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) {
            if (ArrayUtil.isNotEmpty(payNoCompleteContractList.toArray())){
               //余额 放到付款未完成合同 预收
               Contract lastContract = payNoCompleteContractList.get(0);
               //保存明细
               saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate);
            }
            if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isNotEmpty(advanceContractList.toArray())){
               //客户预付有剩余 没有预付款的合同
               Contract lastContract = advanceContractList.get(0);
               //保存明细
               saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate);
            }
            if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isEmpty(advanceContractList.toArray())
                  &&ArrayUtil.isNotEmpty(payCompleteContractList.toArray())) {
               //客户预付有剩余 没有预付款的合同
               Contract lastContract = payCompleteContractList.get(payCompleteContractList.size() - 1);
               //保存明细
               saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate);
            }
         }
//         if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) {
//            if (ArrayUtil.isNotEmpty(payNoCompleteContractList.toArray())){
//               //余额 放到付款未完成合同 预收
//               Contract lastContract = payNoCompleteContractList.get(0);
//               //保存明细
//               saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate);
//            }
//            if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isNotEmpty(advanceContractList.toArray())){
//               //客户预付有剩余 没有预付款的合同
//               Contract lastContract = advanceContractList.get(0);
//               //保存明细
//               saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate);
//            }
//            if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isEmpty(advanceContractList.toArray())
//                  &&ArrayUtil.isNotEmpty(payCompleteContractList.toArray())) {
//               //客户预付有剩余 没有预付款的合同
//               Contract lastContract = payCompleteContractList.get(payCompleteContractList.size() - 1);
//               //保存明细
//               saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate);
//
//            }
//         }
      }
      return R.ok();
   }
@@ -423,7 +465,7 @@
            String result = HttpUtil.post(url + "/yonbip/EFI/collection/list?access_token=" + finalAccessToken, params.toJSONString());
            log.info("SK_CX Response:{}", result);
            //保存请求记录
            saveBipRequestRecord(params, result);
            saveBipRequestRecord(params,"<XSJZ_SK_CX_001>-收款单查询接口", result);
            JSONObject resultJson = JSONObject.parseObject(result);
            if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) {
               handleAndSave(bipCode, resultJson);
@@ -451,7 +493,8 @@
      return params;
   }
   private void getAccessToken(String accessToken) {
   @Override
   public String getAccessToken(String accessToken) {
      long timestamp = System.currentTimeMillis();
      Map<String, Object> paramMap = new HashMap<>();
      paramMap.put("appKey", appKey);
@@ -472,20 +515,22 @@
      JSONObject tokenJson = JSONObject.parseObject(getTokenResult);
      if (!tokenJson.containsKey("code") || !tokenJson.getString("code").equals("200")) {
         log.error("Get access_token ERROR");
         return;
         return "";
      }
      if (ObjUtil.isNull(tokenJson.get("data")) || ObjUtil.isNull(JSONObject.parseObject(tokenJson.getString("data")))) {
         log.error("access_token value exception");
         return;
         return "";
      }
      accessToken = JSONObject.parseObject(tokenJson.getString("data")).getString("access_token");
      log.info("access_token value:", accessToken);
      redisTemplate.opsForValue().set("BIP_TOKEN", accessToken, tokenJson.getIntValue("expire") - 10, TimeUnit.SECONDS);
      return accessToken;
   }
   private void saveBipRequestRecord(JSONObject params, String result) {
   @Override
   public void saveBipRequestRecord(JSONObject params, String methodName, String result) {
      BipRequestRecord record = new BipRequestRecord();
      record.setInterfaceName("<XSJZ_SK_CX_001>-收款单查询接口");
      record.setInterfaceName(methodName);
      record.setRequestParams(params.toJSONString());
      record.setResponseParams(result);
      record.setResponseCode(JSONObject.parseObject(result).getString("code"));
@@ -526,7 +571,7 @@
         return;
      }
      BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery()
            .eq(StrUtil.isNotBlank(record.getString("bodyItemCustomerName")), BusinessCustomer::getCompanyName, record.getString("bodyItemCustomerName"))
            .eq(StrUtil.isNotBlank(record.getString("bodyItemCustomerName")), BusinessCustomer::getRegisterName, record.getString("bodyItemCustomerName"))
      );
      if (ObjUtil.isNull(customer)) {
         log.error("付款单id:{},客商查询失败,请检查客商", record.getString("id"));
@@ -537,7 +582,7 @@
         return;
      }
      //保存付款单
      Boolean codeFlag = savePaymentSlip(customer,record);
      Boolean codeFlag = savePaymentSlip(customer,record,dept);
      if (codeFlag){
         log.error("付款单id:{},付款单已存在");
         return;
@@ -555,7 +600,9 @@
      List<Contract> advanceContractList = new ArrayList<>();
      //付款时间
      Date payDate = DateUtil.parse(record.getString("billDate"), DatePattern.NORM_DATETIME_FORMAT);
      for (Contract contract : contractList) {
      Iterator<Contract> iterator = contractList.iterator();
      while (iterator.hasNext()) {
         Contract contract = iterator.next();
         PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
               .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
         BigDecimal lastTotal = new BigDecimal("0");
@@ -580,16 +627,23 @@
            entity.setScheduleName(lastConfirm.getScheduleName());
         }
         entity.setBusGuestId(customer.getId());
         entity.setBusGuestName(customer.getCompanyName());
         entity.setBusGuestName(customer.getRegisterName());
         entity.setBusinessType("客户付款");
         entity.setIsBip(1);
         entity.setPaymentCode(record.getString("code"));
         entity.setPayType(record.get("bodyItemSettleModeName") != null ? record.getString("bodyItemSettleModeName").contains("承兑汇票") ? 1 : 0 : null);
         entity.setBipId(record.getString("id"));
         if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) {
            entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1")));
            entity.setTotalAmount(new BigDecimal("0"));
            entity.setConfirmTime(payDate);
            // 判断是否是最后一个
            if (!iterator.hasNext()) {
               entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal));
               entity.setAdvanceAmount(transtionRemainAmount);
               entity.setTotalAmount(transtionRemainAmount);
            }else {
               entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1")));
               entity.setTotalAmount(new BigDecimal("0"));
            }
            baseMapper.insert(entity);
         } else if (transtionRemainAmount.compareTo(new BigDecimal("0")) == 0) {
            entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1")));
@@ -609,7 +663,7 @@
      payContractList.stream().forEach(contract -> {
         //更新付款阶段付款
         List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
               .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2)
               .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3)
               .orderByAsc(ContractPaymentSchedule::getCreateTime));
         if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
            BigDecimal remain = transtionAmount;
@@ -663,55 +717,76 @@
         }
         //合同所有付款阶段
         List<ContractPaymentSchedule> payComScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
               .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0)
               .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0).ne(ContractPaymentSchedule::getPaymentStatus,3)
         );
         if (ArrayUtil.isNotEmpty(payComScheduleList.toArray())){
            BigDecimal payTotal = payComScheduleList.stream().map(item->StrUtil.equals(item.getPaymentStatus() + "", "0") ? item.getPlannedAmount() :
                  item.getActualAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
            contract.setPaidAmount(payTotal);
            if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
               contract.setContractStatus(3);
            }
            contractService.updateById(contract);
//            if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
//               contract.setContractStatus(3);
//            }
//            contractService.updateById(contract);
//            if (contract.getAmount().compareTo(contract.getPaidAmount()) == 0) {
//               payCompleteContractList.add(contract);
//            }
            if (contract.getAmount().compareTo(contract.getPaidAmount()) == 0) {
               contract.setBillingStatus("2");
               contract.setContractStatus(3);
               payCompleteContractList.add(contract);
            }
            //付款 且 付款未全付
            if (contract.getAmount().compareTo(contract.getPaidAmount()) > 0) {
               payNoCompleteContractList.add(contract);
            }
            if (StrUtil.isNotEmpty(contract.getContractCategory())&&StrUtil.equals(contract.getContractCategory(),"water_house")){
               List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery()
                     .eq(ContractExecDate::getContractId,contract.getId()).eq(ContractExecDate::getGenFlag,"0"));
               if (ArrayUtil.isEmpty(execDateList)){
                  List<ContractPaymentSchedule> contractPaymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
                        .eq(ContractPaymentSchedule::getContractId, contract.getId()));
                  if (ArrayUtil.isNotEmpty(contractPaymentScheduleList.toArray())&&contractPaymentScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
                     contract.setContractStatus(3);
                     contractService.updateById(contract);
                  }
               }
            }else {
               contractService.updateById(contract);
            }
         }
      });
      //客户预付有剩余 且 有预付款的合同
      if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) {
         if (ArrayUtil.isNotEmpty(payNoCompleteContractList.toArray())){
            //余额 放到付款未完成合同 预收
            Contract lastContract = payNoCompleteContractList.get(payNoCompleteContractList.size() - 1);
            //保存明细
            saveNewPaymentConfirm(customer,record,lastContract,transtionRemainAmount,payDate);
         }
         if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isNotEmpty(advanceContractList.toArray())){
            //客户预付有剩余 没有预付款的合同
            Contract lastContract = payNoCompleteContractList.get(payNoCompleteContractList.size() - 1);
            //保存明细
            saveNewPaymentConfirm(customer,record,lastContract,transtionRemainAmount,payDate);
         }
         if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isEmpty(advanceContractList.toArray())
               &&ArrayUtil.isNotEmpty(payCompleteContractList.toArray())) {
            //客户预付有剩余 没有预付款的合同
            Contract lastContract = payCompleteContractList.get(payCompleteContractList.size() - 1);
            //保存明细
            saveNewPaymentConfirm(customer,record,lastContract,transtionRemainAmount,payDate);
         }
      }
//      if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) {
//         if (ArrayUtil.isNotEmpty(payNoCompleteContractList.toArray())){
//            //余额 放到付款未完成合同 预收
//            Contract lastContract = payNoCompleteContractList.get(payNoCompleteContractList.size() - 1);
//            //保存明细
//            saveNewPaymentConfirm(customer,record,lastContract,transtionRemainAmount,payDate);
//         }
//         if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isNotEmpty(advanceContractList.toArray())){
//            //客户预付有剩余 没有预付款的合同
//            Contract lastContract = payNoCompleteContractList.get(payNoCompleteContractList.size() - 1);
//            //保存明细
//            saveNewPaymentConfirm(customer,record,lastContract,transtionRemainAmount,payDate);
//         }
//         if (ArrayUtil.isEmpty(payNoCompleteContractList.toArray())&&ArrayUtil.isEmpty(advanceContractList.toArray())
//               &&ArrayUtil.isNotEmpty(payCompleteContractList.toArray())) {
//            //客户预付有剩余 没有预付款的合同
//            Contract lastContract = payCompleteContractList.get(payCompleteContractList.size() - 1);
//            //保存明细
//            saveNewPaymentConfirm(customer,record,lastContract,transtionRemainAmount,payDate);
//
//         }
//      }
   }
   private Boolean savePaymentSlip(BusinessCustomer customer, JSONObject record) {
   private Boolean savePaymentSlip(BusinessCustomer customer, JSONObject record,SysDept dept) {
      PaymentSlip slip = new PaymentSlip();
      slip.setBusGuestId(customer.getId());
      slip.setBusGuestName(customer.getCompanyName());
      slip.setBusGuestName(customer.getRegisterName());
      slip.setPayee(dept.getName());
      slip.setPayeeCompId(dept.getDeptId());
      slip.setPaymentTime(ObjUtil.isNotNull(record.get("billDate"))?
            DateUtil.parse(record.getString("billDate"), DatePattern.NORM_DATETIME_FORMAT):new Date());
      slip.setPaymentAmount(ObjUtil.isNotNull(record.get("bodyItemOriTaxExcludedAmount"))?record.getBigDecimal("bodyItemOriTaxExcludedAmount"):new BigDecimal("0"));
@@ -746,7 +821,7 @@
      }
      entity.setBusGuestId(customer.getId());
      entity.setBusGuestName(customer.getCompanyName());
      entity.setBusGuestName(customer.getRegisterName());
      entity.setBusinessType("客户付款");
      if (ObjUtil.isNotNull(record)){
         entity.setIsBip(1);