shiyunteng
2026-05-26 5b1c84423d590c7240209fa9a68d33c0116457af
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java
@@ -81,17 +81,17 @@
      //更新当前阶段
      if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) {
         schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
         schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
         contractPaymentScheduleMapper.updateById(schedule);
      }
      //查询是否有之前阶段
      ContractPaymentSchedule beforeSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
            .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
      if (ObjUtil.isNotNull(beforeSchedule) && ObjUtil.isNull(beforeSchedule.getEffectiveEndDate())) {
         beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
         contractPaymentScheduleMapper.updateById(beforeSchedule);
      }
//      //查询是否有之前阶段
//      ContractPaymentSchedule beforeSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
//            .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
//      if (ObjUtil.isNotNull(beforeSchedule) && ObjUtil.isNull(beforeSchedule.getEffectiveEndDate())) {
//         beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
//         contractPaymentScheduleMapper.updateById(beforeSchedule);
//      }
      List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery().eq(ContractOutBound::getContractId, contract.getId())
            .isNotNull(ContractOutBound::getArrivalTime));
@@ -176,6 +176,18 @@
               currentConfim.setTotalAmount(lastTotal.subtract(currentConfim.getReceivableAmount()));
               if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
                  paymentConfirmMapper.insert(currentConfim);
                  //更新当前阶段付款情况
                  if (lastTotal.compareTo(new BigDecimal("0"))>0){
                     if (currentConfim.getTotalAmount().compareTo(new BigDecimal("0"))>=0) {
                        schedule.setPaymentStatus(2);
                        schedule.setPlannedAmount(schedule.getPlannedAmount());
                        contractPaymentScheduleMapper.updateById(schedule);
                     }else {
                        schedule.setPaymentStatus(1);
                        schedule.setPlannedAmount(lastTotal);
                     }
                  }
               }
               //查询是否有后续阶段
@@ -186,13 +198,11 @@
                  //最后阶段生效时间
                  ContractPaymentSchedule endSchedule = afterSchedule.get(0);
                  if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
                     endSchedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
                     endSchedule.setEffectiveEndDate(contract.getExpirationDate());
                     endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
                     contractPaymentScheduleMapper.updateById(endSchedule);
                     //当前阶段生效时间
                     schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
                     schedule.setEffectiveEndDate(endSchedule.getEffectiveDate());
                     contractPaymentScheduleMapper.updateById(schedule);
//                     schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
//                     contractPaymentScheduleMapper.updateById(schedule);
                     //最后阶段应收
                     PaymentConfirm newConfim = new PaymentConfirm();
                     newConfim.setBusinessType(endSchedule.getStageName() + "应收");
@@ -215,6 +225,7 @@
                     newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount()));
                     if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
                        paymentConfirmMapper.insert(newConfim);
                     }
                  }
@@ -228,8 +239,8 @@
                  contractMapper.updateById(contract);
               }
               if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
                  schedule.setEffectiveEndDate(contract.getExpirationDate());
                  contractPaymentScheduleMapper.updateById(schedule);
//                  schedule.setEffectiveEndDate(contract.getExpirationDate());
//                  contractPaymentScheduleMapper.updateById(schedule);
                  //更新合同下个阶段
                  contract.setNextScheduleName("无");
                  contractMapper.updateById(contract);
@@ -267,6 +278,17 @@
         currentConfim.setTotalAmount(lastTotal.subtract(currentConfim.getReceivableAmount()));
         if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
            paymentConfirmMapper.insert(currentConfim);
            //更新当前阶段付款情况
            if (lastTotal.compareTo(new BigDecimal("0"))>0){
               if (currentConfim.getTotalAmount().compareTo(new BigDecimal("0"))>=0) {
                  schedule.setPaymentStatus(2);
                  schedule.setPlannedAmount(schedule.getPlannedAmount());
                  contractPaymentScheduleMapper.updateById(schedule);
               }else {
                  schedule.setPaymentStatus(1);
                  schedule.setPlannedAmount(lastTotal);
               }
            }
         }
         //查询是否有后续阶段
@@ -277,12 +299,10 @@
            //最后阶段生效时间
            ContractPaymentSchedule endSchedule = afterSchedule.get(0);
            if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
               endSchedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
               endSchedule.setEffectiveEndDate(contract.getExpirationDate());
               endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
               contractPaymentScheduleMapper.updateById(endSchedule);
               //当前阶段生效时间
               schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
               schedule.setEffectiveEndDate(endSchedule.getEffectiveDate());
               schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
               contractPaymentScheduleMapper.updateById(schedule);
               //最后阶段应收
               PaymentConfirm newConfim = new PaymentConfirm();
@@ -306,6 +326,17 @@
               newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount()));
               if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
                  paymentConfirmMapper.insert(newConfim);
                  //更新当前阶段付款情况
                  if (lastNewTotal.compareTo(new BigDecimal("0"))>0){
                     if (newConfim.getTotalAmount().compareTo(new BigDecimal("0"))>=0) {
                        schedule.setPaymentStatus(2);
                        schedule.setPlannedAmount(schedule.getPlannedAmount());
                        contractPaymentScheduleMapper.updateById(schedule);
                     }else {
                        schedule.setPaymentStatus(1);
                        schedule.setPlannedAmount(lastNewTotal);
                     }
                  }
               }
            }
@@ -319,8 +350,8 @@
            contractMapper.updateById(contract);
         }
         if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
            schedule.setEffectiveEndDate(contract.getExpirationDate());
            contractPaymentScheduleMapper.updateById(schedule);
//            schedule.setEffectiveEndDate(contract.getExpirationDate());
//            contractPaymentScheduleMapper.updateById(schedule);
            //更新合同下个阶段
            contract.setNextScheduleName("无");
            contractMapper.updateById(contract);
@@ -396,7 +427,7 @@
                  ContractPaymentSchedule::getPlannedAmount, ContractPaymentSchedule::getPlannedAmount,
                  ContractPaymentSchedule::getEffectiveEndDate, ContractPaymentSchedule::getPaymentDate,
                  ContractPaymentSchedule::getPaymentStatus, ContractPaymentSchedule::getActualAmount,
                  ContractPaymentSchedule::getAgreedDays)
                  ContractPaymentSchedule::getAgreedDays,ContractPaymentSchedule::getPaymentRatio)
            .select(ContractPaymentScheduleProcess::getProcessDate)
            .leftJoin(ContractPaymentScheduleProcess.class, ContractPaymentScheduleProcess::getScheduleId, ContractPaymentSchedule::getId)
            .eq(ContractPaymentSchedule::getContractId, id)