From 2db76f2066701cbe292f206ad49a7f8523b8aa9f Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期五, 14 八月 2026 16:30:25 +0800
Subject: [PATCH] feat:银行流水关联多个合同,新增预收款开票,所有List校验调整为ColUtil

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java |  204 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 137 insertions(+), 67 deletions(-)

diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java
index f722306..c1a18c9 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java
@@ -1,8 +1,8 @@
 package com.by4cloud.platformx.business.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -12,7 +12,6 @@
 import com.by4cloud.platformx.business.mapper.*;
 import com.by4cloud.platformx.business.service.ContractPaymentScheduleProcessService;
 import com.by4cloud.platformx.business.vo.ContractPaymentScheduleVo;
-import com.by4cloud.platformx.business.vo.ScheduleProcessVo;
 import com.by4cloud.platformx.common.core.util.R;
 import com.by4cloud.platformx.common.security.util.SecurityUtils;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -45,13 +44,13 @@
 		if (ObjUtil.isNull(schedule)) {
 			return R.failed("灞ョ害闃舵涓庡悎鍚屼笉涓�鑷达紝璇疯仈绯绘妧鏈汉鍛�");
 		}
-		if (schedule.getStageName().equals("璐у埌绛炬敹") && ArrayUtil.isEmpty(addDTO.getContractOutBoundIds().toArray())) {
+		if (schedule.getStageName().equals("璐у埌绛炬敹") && CollUtil.isEmpty(addDTO.getContractOutBoundIds())) {
 			return R.failed("璇烽�夋嫨鍒拌揣鐨勫嚭搴撲俊鎭�");
 		}
 		//鍚堝悓
 		Contract contract = contractMapper.selectById(schedule.getContractId());
 		List<ContractSubjectMatter> subjectMatterList = subjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, contract.getId()));
-		if (ArrayUtil.isEmpty(subjectMatterList.toArray())) {
+		if (CollUtil.isEmpty(subjectMatterList)) {
 			return R.failed("璇ュ悎鍚屾爣鐨勭墿寮傚父锛岃鑱旂郴鎶�鏈汉鍛�");
 		}
 //		if (!subjectMatterList.stream().allMatch(item -> item.getDeliveryStatus() == 2)) {
@@ -81,23 +80,23 @@
 
 		//鏇存柊褰撳墠闃舵
 		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));
 		if (schedule.getStageName().equals("璐у埌绛炬敹")) {
-			if (ArrayUtil.isNotEmpty(contractOutBoundList.toArray())
-					&& ArrayUtil.isNotEmpty(subjectMatterList.toArray())) {
+			if (CollUtil.isNotEmpty(contractOutBoundList)
+					&& CollUtil.isNotEmpty(subjectMatterList)) {
 				Map<String, BigDecimal> sumMap = contractOutBoundList.stream()
 						.collect(Collectors.groupingBy(
 								ContractOutBound::getSubjectMatterCode,
@@ -132,7 +131,7 @@
 						//瀹㈡埛浠樻瀹屾垚鍚堝悓
 						List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId())
 								.eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount"));
-						if (ArrayUtil.isNotEmpty(customerCompleteContractList)){
+						if (CollUtil.isNotEmpty(customerCompleteContractList)){
 							List<BigDecimal> outAmountList = new ArrayList<>();
 							for (Contract completeContract:customerCompleteContractList
 							) {
@@ -151,7 +150,7 @@
 									outAmountList.add(outConfirm.getTransationAmount());
 								}
 							}
-							if (ArrayUtil.isNotEmpty(outAmountList.toArray())){
+							if (CollUtil.isNotEmpty(outAmountList)){
 								BigDecimal currentSum = new BigDecimal("0");
 								for (BigDecimal currentAmount:outAmountList
 								) {
@@ -176,23 +175,33 @@
 					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);
+							}
+						}
+
 					}
 
 					//鏌ヨ鏄惁鏈夊悗缁樁娈�
 					List<ContractPaymentSchedule> afterSchedule = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
 							.eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
 							.gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()));
-					if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) {
+					if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) {
 						//鏈�鍚庨樁娈电敓鏁堟椂闂�
 						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 +224,7 @@
 							newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount()));
 							if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
 								paymentConfirmMapper.insert(newConfim);
+
 							}
 
 						}
@@ -222,14 +232,14 @@
 						contract.setNextScheduleName(endSchedule.getStageName());
 						contractMapper.updateById(contract);
 					}
-					if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) {
+					if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) {
 						//鏇存柊鍚堝悓涓嬩釜闃舵
 						contract.setNextScheduleName(afterSchedule.get(0).getStageName());
 						contractMapper.updateById(contract);
 					}
-					if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
-						schedule.setEffectiveEndDate(contract.getExpirationDate());
-						contractPaymentScheduleMapper.updateById(schedule);
+					if (CollUtil.isEmpty(afterSchedule)) {
+//						schedule.setEffectiveEndDate(contract.getExpirationDate());
+//						contractPaymentScheduleMapper.updateById(schedule);
 						//鏇存柊鍚堝悓涓嬩釜闃舵
 						contract.setNextScheduleName("鏃�");
 						contractMapper.updateById(contract);
@@ -244,7 +254,7 @@
 					}
 				}
 			}
-		} else {
+		} else if (schedule.getStageName().equals("璋冭瘯瀹屾垚鎴栭獙鏀�")){
 			//鏂板褰撳墠闃舵搴旀敹
 			PaymentConfirm currentConfim = new PaymentConfirm();
 			currentConfim.setBusinessType(schedule.getStageName() + "搴旀敹");
@@ -267,60 +277,81 @@
 			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);
+					}
+				}
 			}
 
 			//鏌ヨ鏄惁鏈夊悗缁樁娈�
 			List<ContractPaymentSchedule> afterSchedule = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
 					.eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
-					.gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()));
-			if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) {
+					.gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
+					.gt(ContractPaymentSchedule::getPaymentRatio,"0"));
+			if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) {
 				//鏈�鍚庨樁娈电敓鏁堟椂闂�
 				ContractPaymentSchedule endSchedule = afterSchedule.get(0);
-				if (StrUtil.equals(endSchedule.getStageName(), "璐ㄤ繚閲�")) {
-					endSchedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
-					endSchedule.setEffectiveEndDate(contract.getExpirationDate());
-					contractPaymentScheduleMapper.updateById(endSchedule);
-					//褰撳墠闃舵鐢熸晥鏃堕棿
-					schedule.setEffectiveDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
-					schedule.setEffectiveEndDate(endSchedule.getEffectiveDate());
-					contractPaymentScheduleMapper.updateById(schedule);
-					//鏈�鍚庨樁娈靛簲鏀�
-					PaymentConfirm newConfim = new PaymentConfirm();
-					newConfim.setBusinessType(endSchedule.getStageName() + "搴旀敹");
-					newConfim.setBusGuestId(contract.getPartyAId());
-					newConfim.setBusGuestName(contract.getPartyA());
-					newConfim.setContractId(contract.getId());
-					newConfim.setContractName(contract.getContractName());
-					newConfim.setContractNo(contract.getContractNo());
-					newConfim.setScheduleId(endSchedule.getId());
-					newConfim.setScheduleName(schedule.getStageName());
-					newConfim.setConfirmTime(addDTO.getProcessDate());
-					newConfim.setTransationAmount(endSchedule.getPlannedAmount());
-					newConfim.setReceivableAmount(endSchedule.getPlannedAmount());
-					PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
-							.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
-					BigDecimal lastNewTotal = new BigDecimal("0");
-					if (ObjUtil.isNotNull(lastNewConfirm)) {
-						lastNewTotal = lastNewConfirm.getTotalAmount();
-					}
-					newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount()));
-					if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
-						paymentConfirmMapper.insert(newConfim);
-					}
-
-				}
+//				if (StrUtil.equals(endSchedule.getStageName(), "璐ㄤ繚閲�")) {
+//					endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), endSchedule.getAgreedDays()));
+//					contractPaymentScheduleMapper.updateById(endSchedule);
+//					//褰撳墠闃舵鐢熸晥鏃堕棿
+//					schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(), schedule.getAgreedDays()));
+//					contractPaymentScheduleMapper.updateById(schedule);
+//					//鏈�鍚庨樁娈靛簲鏀�
+//					PaymentConfirm newConfim = new PaymentConfirm();
+//					newConfim.setBusinessType(endSchedule.getStageName() + "搴旀敹");
+//					newConfim.setBusGuestId(contract.getPartyAId());
+//					newConfim.setBusGuestName(contract.getPartyA());
+//					newConfim.setContractId(contract.getId());
+//					newConfim.setContractName(contract.getContractName());
+//					newConfim.setContractNo(contract.getContractNo());
+//					newConfim.setScheduleId(endSchedule.getId());
+//					newConfim.setScheduleName(schedule.getStageName());
+//					newConfim.setConfirmTime(addDTO.getProcessDate());
+//					newConfim.setTransationAmount(endSchedule.getPlannedAmount());
+//					newConfim.setReceivableAmount(endSchedule.getPlannedAmount());
+//					PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
+//							.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
+//					BigDecimal lastNewTotal = new BigDecimal("0");
+//					if (ObjUtil.isNotNull(lastNewConfirm)) {
+//						lastNewTotal = lastNewConfirm.getTotalAmount();
+//					}
+//					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);
+//							}
+//						}
+//					}
+//
+//				}
 				//鏇存柊鍚堝悓涓嬩釜闃舵
 				contract.setNextScheduleName(endSchedule.getStageName());
 				contractMapper.updateById(contract);
 			}
-			if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) {
+			if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) {
 				//鏇存柊鍚堝悓涓嬩釜闃舵
 				contract.setNextScheduleName(afterSchedule.get(0).getStageName());
 				contractMapper.updateById(contract);
 			}
-			if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
-				schedule.setEffectiveEndDate(contract.getExpirationDate());
-				contractPaymentScheduleMapper.updateById(schedule);
+			if (CollUtil.isEmpty(afterSchedule)) {
+//				schedule.setEffectiveEndDate(contract.getExpirationDate());
+//				contractPaymentScheduleMapper.updateById(schedule);
 				//鏇存柊鍚堝悓涓嬩釜闃舵
 				contract.setNextScheduleName("鏃�");
 				contractMapper.updateById(contract);
@@ -333,6 +364,45 @@
 					contractMapper.updateById(contract);
 				}
 			}
+		}else {
+
+			//鏈�鍚庨樁娈靛簲鏀�
+			PaymentConfirm newConfim = new PaymentConfirm();
+			newConfim.setBusinessType(schedule.getStageName() + "搴旀敹");
+			newConfim.setBusGuestId(contract.getPartyAId());
+			newConfim.setBusGuestName(contract.getPartyA());
+			newConfim.setContractId(contract.getId());
+			newConfim.setContractName(contract.getContractName());
+			newConfim.setContractNo(contract.getContractNo());
+			newConfim.setScheduleId(schedule.getId());
+			newConfim.setScheduleName(schedule.getStageName());
+			newConfim.setConfirmTime(addDTO.getProcessDate());
+			newConfim.setTransationAmount(schedule.getPlannedAmount());
+			newConfim.setReceivableAmount(schedule.getPlannedAmount());
+			PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
+					.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
+			BigDecimal lastNewTotal = new BigDecimal("0");
+			if (ObjUtil.isNotNull(lastNewConfirm)) {
+				lastNewTotal = lastNewConfirm.getTotalAmount();
+			}
+			newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount()));
+			if (schedule.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());
+					}else {
+						schedule.setPaymentStatus(1);
+						schedule.setPlannedAmount(lastNewTotal);
+					}
+					contractPaymentScheduleMapper.updateById(schedule);
+				}
+			}
+			//鏇存柊鍚堝悓涓嬩釜闃舵
+			contract.setNextScheduleName("");
+			contractMapper.updateById(contract);
 		}
 
 
@@ -396,7 +466,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)

--
Gitblit v1.9.1