From ca019747743a76f9348fcac99385c91736a36638 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期四, 17 九月 2026 16:44:15 +0800
Subject: [PATCH] feat:标的物变更 合同审核流程改为推送合同中心通过后上传盖章签字件 履约进度新增合同补录按钮

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java |  400 +++++++++++++++++++++++----------------------------------
 1 files changed, 162 insertions(+), 238 deletions(-)

diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java
index b624244..57f2256 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java
@@ -12,6 +12,7 @@
 import com.by4cloud.platformx.business.dto.OutSubjectMatterAddDTO;
 import com.by4cloud.platformx.business.entity.*;
 import com.by4cloud.platformx.business.mapper.*;
+import com.by4cloud.platformx.business.service.ContractPaymentScheduleProcessService;
 import com.by4cloud.platformx.business.service.OutBoundService;
 import com.by4cloud.platformx.common.core.util.R;
 import com.by4cloud.platformx.common.security.util.SecurityUtils;
@@ -46,6 +47,7 @@
 	private final ContractOutBoundMapper contractOutBoundMapper;
 	private final DeliveryOverdueMapper deliveryOverdueMapper;
 	private final StringRedisTemplate redisTemplate;
+	private final ContractPaymentScheduleProcessService processService;
 
 	@Value("${dept.smj}")
 	private String smj;
@@ -335,18 +337,6 @@
 //							beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
 //							scheduleMapper.updateById(beforeSchedule);
 //						}
-						//鏇存柊灞ョ害
-						ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess();
-						contractPaymentScheduleProcess.setContractId(schedule.getContractId());
-						contractPaymentScheduleProcess.setContractName(schedule.getContractName());
-						contractPaymentScheduleProcess.setScheduleId(schedule.getId());
-						contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
-						contractPaymentScheduleProcess.setProcessDate(addDTO.getOutBoundTime());
-						ContractPaymentScheduleProcess lastProcess = scheduleProcessMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
-								.eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
-						if (ObjUtil.isNull(lastProcess)) {
-							scheduleProcessMapper.insert(contractPaymentScheduleProcess);
-						}
 					}
 
 					//鏌ヨ鏄惁鏈夊悗缁樁娈�
@@ -469,6 +459,165 @@
 
 	@Override
 	public R addContractOut(OutBoundAddDTO addDTO) {
+		//鏍¢獙鍙傛暟
+		R<Contract> r = vailParam(addDTO);
+		if (!r.isOk()) {
+			return r;
+		}
+		Contract contract = r.getData();
+		//鍑哄簱
+		handleOutBound(contract, addDTO);
+
+		//淇濆瓨璧勯噾鏄庣粏
+		BigDecimal outBoundAmount = savePaymentConfirm(contract, addDTO);
+		//鏇存柊鍚堝悓鐘舵�佸強闃舵
+		contract.setOutBoundAmout(outBoundAmount);
+		updateContractSchedule(contract);
+
+		return R.ok();
+	}
+
+	private void updateContractSchedule(Contract contract) {
+		List<ContractSubjectMatter> unComOutList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
+				.eq(ContractSubjectMatter::getContractId, contract.getId())
+				.ne(ContractSubjectMatter::getDeliveryStatus, 2));
+		if (CollUtil.isEmpty(unComOutList)) {
+			contract.setNextScheduleName("璐у埌绛炬敹");
+		}
+		contract.setBillingStatus("2");
+		contractMapper.updateById(contract);
+	}
+
+	private BigDecimal savePaymentConfirm(Contract contract, OutBoundAddDTO addDTO) {
+		//鏌ヨ鍚堝悓鏄惁鏈夊嚭搴撻樁娈�
+		ContractPaymentSchedule schedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())
+				.eq(ContractPaymentSchedule::getStageName, "鍙戣揣鍓�").last("limit 1"));
+		if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) {
+			schedule.setEffectiveDate(addDTO.getOutBoundTime());
+			schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
+			scheduleMapper.updateById(schedule);
+		}
+		//灞ョ害鍑犵巼
+		processService.saveScheduleProcess(addDTO.getOutBoundTime(),schedule);
+
+		//璁$畻鍑哄簱浠锋牸
+		BigDecimal outAmount = new BigDecimal("0");
+		for (OutSubjectMatterAddDTO outSubjectMatterAddDTO : addDTO.getSubjectMatterList()) {
+			ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+					.eq(ContractSubjectMatter::getContractId, contract.getId())
+					.eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode())
+					.eq(StrUtil.isNotBlank(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo())
+					.last("limit 1"));
+			outAmount = outAmount.add(outSubjectMatterAddDTO.getOutBoundNum().multiply(subjectMatter.getUnitPrice()));
+		}
+		//瀛樺湪鍙戣揣鍓嶆敹娆鹃樁娈�
+		if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
+			//鏂板褰撳墠闃舵搴旀敹
+			PaymentConfirm currentConfim = new PaymentConfirm();
+			currentConfim.setBusinessType(schedule.getStageName() + "搴旀敹");
+			currentConfim.setBusGuestId(contract.getPartyAId());
+			currentConfim.setBusGuestName(contract.getPartyA());
+			currentConfim.setContractId(contract.getId());
+			currentConfim.setContractName(contract.getContractName());
+			currentConfim.setContractNo(contract.getContractNo());
+			currentConfim.setScheduleId(schedule.getId());
+			currentConfim.setScheduleName(schedule.getStageName());
+			currentConfim.setConfirmTime(addDTO.getOutBoundTime());
+			//鎸夊嚭搴撴瘮渚嬭绠楀簲鏀�
+			currentConfim.setTransationAmount(schedule.getPlannedAmount().multiply(outAmount.divide(contract.getAmount(), 2, RoundingMode.HALF_UP)));
+			currentConfim.setReceivableAmount(currentConfim.getTransationAmount());
+			PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
+					.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
+			if (ObjUtil.isNotNull(lastConfirm)) {
+				currentConfim.setTotalAmount(lastConfirm.getTotalAmount().subtract(currentConfim.getTransationAmount()));
+				if (contract.getContractNo().startsWith("ZB-")) {
+					paymentConfirmMapper.insert(currentConfim);
+				}
+				return outAmount;
+			}
+			currentConfim.setTotalAmount(currentConfim.getTransationAmount().multiply(new BigDecimal("-1")));
+			paymentConfirmMapper.insert(currentConfim);
+			//鍘嗗彶璧勯噾浣欓
+			processService.handleBeforeRemain(currentConfim, contract);
+		}
+		return outAmount;
+	}
+
+	private void handleOutBound(Contract contract, OutBoundAddDTO addDTO) {
+		addDTO.getSubjectMatterList().stream().forEach(outSubjectMatterAddDTO -> {
+			ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+					.eq(ContractSubjectMatter::getContractId, contract.getId())
+					.eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode())
+					.ne(ContractSubjectMatter::getDeliveryStatus, 2)
+					.eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo())
+					.last("limit 1"));
+			if (ObjUtil.isNull(subjectMatter)) {
+				return;
+			}
+			subjectMatter.setLastDeliveredQuantity(outSubjectMatterAddDTO.getOutBoundNum());
+			outSubjectMatterAddDTO.setUnitPrice(subjectMatter.getUnitPrice());
+			if (subjectMatter.getDeliveryStatus() == 0) {
+				subjectMatter.setDeliveredQuantity(outSubjectMatterAddDTO.getOutBoundNum());
+				subjectMatter.setRemainingQuantity(subjectMatter.getQuantity().subtract(outSubjectMatterAddDTO.getOutBoundNum()));
+			}
+			if (subjectMatter.getDeliveryStatus() == 1) {
+				subjectMatter.setDeliveredQuantity(subjectMatter.getDeliveredQuantity().add(outSubjectMatterAddDTO.getOutBoundNum()));
+				subjectMatter.setRemainingQuantity(subjectMatter.getRemainingQuantity().subtract(outSubjectMatterAddDTO.getOutBoundNum()));
+			}
+			subjectMatter.setDeliveryStatus(1);
+			if (subjectMatter.getRemainingQuantity().compareTo(new BigDecimal("0")) == 0) {
+				subjectMatter.setDeliveryStatus(2);
+			}
+			subjectMatter.setActualDeliveryDate(addDTO.getOutBoundTime());
+			contractSubjectMatterMapper.updateById(subjectMatter);
+			//淇濆瓨erp鍑哄簱
+			String batchNumber = genBatchNumber();
+			Long outBoundId = saveErpOutBound(contract, addDTO, outSubjectMatterAddDTO, batchNumber);
+			//淇濆瓨鍚堝悓鍑哄簱璁板綍
+			saveContractOutBound(contract, addDTO, subjectMatter, outBoundId);
+		});
+	}
+
+	private String genBatchNumber() {
+		if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) ||
+				StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) {
+			return generateSMJContractCKNo();
+		}
+		if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) {
+			return generateGYBContractCKNo();
+		}
+		if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", ymj)) {
+			return generateYMJContractCKNo();
+		}
+		if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", tfgs)) {
+			return generateTFContractCKNo();
+		}
+		if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", jxc)) {
+			return generateJXCContractCKNo();
+		}
+		return "";
+	}
+
+	private Long saveErpOutBound(Contract contract, OutBoundAddDTO addDTO, OutSubjectMatterAddDTO outSubjectMatterAddDTO, String batchNumber) {
+		OutBound outBound = new OutBound();
+		outBound.setBatchNumber(batchNumber);
+		outBound.setOutBoundNum(outSubjectMatterAddDTO.getOutBoundNum());
+		outBound.setOutBoundAttNames(addDTO.getOutBoundAttNames());
+		outBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths());
+		outBound.setBusGuestName(contract.getPartyA());
+		outBound.setBusGuestId(contract.getPartyAId());
+		outBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime()) ? addDTO.getOutBoundTime() : new Date());
+		outBound.setSubjectMatterCode(outSubjectMatterAddDTO.getSubjectMatterCode());
+		outBound.setSubjectMatterName(outSubjectMatterAddDTO.getSubjectMatterName());
+		outBound.setOutBoundType("1");
+		if (StrUtil.isEmpty(addDTO.getOutBoundType())) {
+			outBound.setOutBoundType("0");
+		}
+		baseMapper.insert(outBound);
+		return outBound.getId();
+	}
+
+	private R<Contract> vailParam(OutBoundAddDTO addDTO) {
 		if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) {
 			return R.failed("鍑哄簱鏍囩殑鐗╀笉鑳戒负绌�");
 		}
@@ -523,232 +672,7 @@
 				return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode() + "宸插嚭搴撳畬鎴愶紝涓嶈兘瓒呴鍑哄簱");
 			}
 		}
-
-
-		addDTO.getSubjectMatterList().stream().forEach(outSubjectMatterAddDTO -> {
-			ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
-					.eq(ContractSubjectMatter::getContractId, contract.getId())
-					.eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode())
-					.ne(ContractSubjectMatter::getDeliveryStatus, 2)
-					.eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo())
-					.last("limit 1"));
-			if (ObjUtil.isNull(subjectMatter)) {
-				return;
-			}
-			subjectMatter.setLastDeliveredQuantity(outSubjectMatterAddDTO.getOutBoundNum());
-			outSubjectMatterAddDTO.setUnitPrice(subjectMatter.getUnitPrice());
-			if (subjectMatter.getDeliveryStatus() == 0) {
-				subjectMatter.setDeliveredQuantity(outSubjectMatterAddDTO.getOutBoundNum());
-				subjectMatter.setRemainingQuantity(subjectMatter.getQuantity().subtract(outSubjectMatterAddDTO.getOutBoundNum()));
-			}
-			if (subjectMatter.getDeliveryStatus() == 1) {
-				subjectMatter.setDeliveredQuantity(subjectMatter.getDeliveredQuantity().add(outSubjectMatterAddDTO.getOutBoundNum()));
-				subjectMatter.setRemainingQuantity(subjectMatter.getRemainingQuantity().subtract(outSubjectMatterAddDTO.getOutBoundNum()));
-			}
-			subjectMatter.setDeliveryStatus(1);
-			if (subjectMatter.getRemainingQuantity().compareTo(new BigDecimal("0")) == 0) {
-				subjectMatter.setDeliveryStatus(2);
-			}
-			subjectMatter.setActualDeliveryDate(addDTO.getOutBoundTime());
-			contractSubjectMatterMapper.updateById(subjectMatter);
-			//
-			OutBound outBound = new OutBound();
-			if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) ||
-					StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) {
-				outBound.setBatchNumber(generateSMJContractCKNo());
-			}
-			if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) {
-				outBound.setBatchNumber(generateGYBContractCKNo());
-			}
-			if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", ymj)) {
-				outBound.setBatchNumber(generateYMJContractCKNo());
-			}
-			if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", tfgs)) {
-				outBound.setBatchNumber(generateTFContractCKNo());
-			}
-			if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", jxc)) {
-				outBound.setBatchNumber(generateJXCContractCKNo());
-			}
-			outBound.setOutBoundNum(outSubjectMatterAddDTO.getOutBoundNum());
-			outBound.setOutBoundAttNames(addDTO.getOutBoundAttNames());
-			outBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths());
-			outBound.setBusGuestName(contract.getPartyA());
-			outBound.setBusGuestId(contract.getPartyAId());
-			outBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime()) ? addDTO.getOutBoundTime() : new Date());
-			outBound.setSubjectMatterCode(outSubjectMatterAddDTO.getSubjectMatterCode());
-			outBound.setSubjectMatterName(outSubjectMatterAddDTO.getSubjectMatterName());
-			outBound.setOutBoundType("1");
-			if (StrUtil.isEmpty(addDTO.getOutBoundType())) {
-				outBound.setOutBoundType("0");
-			}
-			baseMapper.insert(outBound);
-			//
-			saveContractOutBound(contract, addDTO, subjectMatter, outBound.getId());
-		});
-		//褰撳墠鍑哄簱鍚堝悓鍑哄簱鏍囩殑鐗�
-		List<ContractSubjectMatter> contractSubjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
-				.eq(ContractSubjectMatter::getContractId, contract.getId()).ne(ContractSubjectMatter::getDeliveryStatus, 0));
-		//鏌ヨ鍚堝悓鏄惁鏈夊嚭搴撻樁娈�
-		ContractPaymentSchedule schedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())
-				.eq(ContractPaymentSchedule::getStageName, "鍙戣揣鍓�").gt(ContractPaymentSchedule::getPaymentRatio,0).last("limit 1"));
-		//瀛樺湪鍑哄簱闃舵
-		if (ObjUtil.isNotNull(schedule)) {
-			//褰撳墠鍑哄簱閲戦
-			BigDecimal outPirce = contractSubjectMatterList.stream()
-					.map(item -> (item.getDeliveryStatus() == 1 ? item.getDeliveredQuantity().multiply(item.getUnitPrice()) : item.getQuantity().multiply(item.getUnitPrice())))
-					.reduce(BigDecimal.ZERO, BigDecimal::add);
-			//鍑哄簱鏄惁瀹屾垚
-			if (outPirce.compareTo(contract.getBillingAmout()) > 0) {
-				contract.setBillingStatus("2");
-				contractMapper.updateById(contract);
-			}
-			if (outPirce.compareTo(contract.getBillingAmout()) == 0) {
-				contract.setBillingStatus("1");
-				contractMapper.updateById(contract);
-			}
-			if (outPirce.compareTo(contract.getAmount()) == 0 &&
-					outPirce.compareTo(contract.getBillingAmout()) == 0) {
-				contract.setBillingStatus("3");
-				contractMapper.updateById(contract);
-			}
-			//瀵煎叆鏁版嵁涓嶇敓鎴愬簲鏀�
-			if (targetContractNo.startsWith("ZB-")) {
-				//璁$畻鍙戣揣鍓嶅簲鏀舵洿鏂拌祫閲戞槑缁�
-				PaymentConfirm paymentConfirm = new PaymentConfirm();
-				paymentConfirm.setBusinessType("鍙戣揣鍓嶅簲鏀�");
-				paymentConfirm.setBusGuestId(contract.getPartyAId());
-				paymentConfirm.setBusGuestName(contract.getPartyA());
-				paymentConfirm.setContractId(contract.getId());
-				paymentConfirm.setContractName(contract.getContractName());
-				paymentConfirm.setContractNo(contract.getContractNo());
-				paymentConfirm.setScheduleId(schedule.getId());
-				paymentConfirm.setScheduleName(schedule.getStageName());
-				paymentConfirm.setConfirmTime(addDTO.getOutBoundTime());
-				//璁$畻鍑哄簱閲戦
-				BigDecimal outAmount = addDTO.getSubjectMatterList().stream().map(item -> item.getUnitPrice().multiply(item.getOutBoundNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
-				paymentConfirm.setTransationAmount(outAmount.divide(new BigDecimal("100")).multiply(schedule.getPaymentRatio()));
-				if (ObjUtil.isNotNull(contract.getOutBoundAmout())) {
-					contract.setOutBoundAmout(outAmount.add(contract.getOutBoundAmout()));
-				} else {
-					contract.setOutBoundAmout(outAmount);
-				}
-				contractMapper.updateById(contract);
-				//鏈�杩戞槑缁�
-				PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
-						.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
-				if (ObjUtil.isNotNull(lastConfirm)) {
-					//涓嶅瓨鍦ㄥ彂璐у簲鏀� 鍑哄簱鎬婚
-					paymentConfirm.setTotalAmount(lastConfirm.getTotalAmount().subtract(paymentConfirm.getTransationAmount()));
-					if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) {
-						paymentConfirm.setAdvanceAmount(paymentConfirm.getTotalAmount());
-					}
-					if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) {
-						paymentConfirm.setReceivableAmount(paymentConfirm.getTotalAmount().multiply(new BigDecimal("-1")));
-					}
-					if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
-						paymentConfirmMapper.insert(paymentConfirm);
-					}
-//				}
-				} else {
-					//鏃犱箣鍓嶉樁娈靛簲鏀�
-					paymentConfirm.setTotalAmount(paymentConfirm.getTransationAmount().multiply(new BigDecimal("-1")));
-					if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
-						paymentConfirmMapper.insert(paymentConfirm);
-						//瀹㈡埛浠樻瀹屾垚鍚堝悓
-						List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId())
-								.eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount"));
-						if (CollUtil.isNotEmpty(customerCompleteContractList)) {
-							List<BigDecimal> outAmountList = new ArrayList<>();
-							for (Contract completeContract : customerCompleteContractList
-							) {
-								PaymentConfirm contractLastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, completeContract.getId())
-										.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
-								//鏌ヨ瀹㈡埛浠樻瀹屾垚鍚堝悓涓渶鍚庢槑缁嗛噾棰� 鏈夐鏀惰浆鍏ュ綋鍓嶅悎鍚�
-								if (contractLastConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) {
-									//鏂板瀹屾垚浠樻鍚堝悓 璧勯噾杞嚭
-									PaymentConfirm outConfirm = BeanUtil.copyProperties(contractLastConfirm, PaymentConfirm.class, "id", "transationAmount",
-											"advanceAmount", "receivableAmount", "overdueAmount", "totalAmount");
-									outConfirm.setBusinessType("璧勯噾杞嚭");
-									outConfirm.setConfirmTime(new Date());
-									outConfirm.setTransationAmount(contractLastConfirm.getTotalAmount());
-									outConfirm.setTotalAmount(new BigDecimal("0"));
-									paymentConfirmMapper.insert(outConfirm);
-									outAmountList.add(outConfirm.getTransationAmount());
-								}
-							}
-							if (CollUtil.isNotEmpty(outAmountList)) {
-								BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
-								//鏂板褰撳墠鍚堝悓 璧勯噾杞叆
-								PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
-										"advanceAmount", "receivableAmount", "overdueAmount", "totalAmount");
-								inConfirm.setBusinessType("璧勯噾杞叆");
-								inConfirm.setConfirmTime(new Date());
-								inConfirm.setTransationAmount(currentInSum);
-								inConfirm.setTotalAmount(paymentConfirm.getTotalAmount().add(currentInSum));
-								//鏇存柊褰撳墠闃舵瀹為檯鏀舵 鍜� 鏀舵鐘舵��
-								schedule.setActualAmount(inConfirm.getTransationAmount());
-								schedule.setPaymentStatus(2);
-								if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) > 0) {
-									inConfirm.setAdvanceAmount(inConfirm.getTotalAmount());
-								} else if (inConfirm.getTotalAmount().compareTo(new BigDecimal("0")) < 0) {
-									inConfirm.setReceivableAmount(inConfirm.getTotalAmount().multiply(new BigDecimal("-1")));
-									schedule.setActualAmount(paymentConfirm.getTotalAmount().subtract(currentInSum));
-									schedule.setPaymentStatus(1);
-								}
-								paymentConfirmMapper.insert(inConfirm);
-								//鏇存柊褰撳墠闃舵瀹為檯鏀舵 鍜� 鏀舵鐘舵��
-								scheduleMapper.updateById(schedule);
-							}
-						}
-					}
-				}
-			}
-
-			//鏇存柊鍙戣揣鍓嶆敹娆剧敓鏁堟椂闂�
-			if (ObjUtil.isNull(schedule.getEffectiveDate())) {
-
-				//鏇存柊灞ョ害
-				ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess();
-				contractPaymentScheduleProcess.setContractId(schedule.getContractId());
-				contractPaymentScheduleProcess.setContractName(schedule.getContractName());
-				contractPaymentScheduleProcess.setScheduleId(schedule.getId());
-				contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
-				contractPaymentScheduleProcess.setProcessDate(addDTO.getOutBoundTime());
-				ContractPaymentScheduleProcess lastProcess = scheduleProcessMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
-						.eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
-				if (ObjUtil.isNull(lastProcess)) {
-					scheduleProcessMapper.insert(contractPaymentScheduleProcess);
-				}
-			}
-
-			//鏌ヨ鏄惁鏈夊悗缁樁娈�
-			List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
-					.eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
-					.gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
-					.orderByAsc(ContractPaymentSchedule::getCreateTime));
-			if (CollUtil.isNotEmpty(afterSchedule) && contract.getOutBoundAmout().compareTo(contract.getAmount()) == 0) {
-				contract.setNextScheduleName(afterSchedule.get(0).getStageName());
-				contractMapper.updateById(contract);
-			}
-
-			if (CollUtil.isEmpty(afterSchedule)) {
-				schedule.setEffectiveEndDate(contract.getExpirationDate());
-				scheduleMapper.updateById(schedule);
-				//鏇存柊鍚堝悓涓嬩釜闃舵
-				contract.setNextScheduleName("鏃�");
-				contractMapper.updateById(contract);
-				//褰撳墠涓哄悎鍚屾渶鍚庨樁娈�
-				PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
-						.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
-				if (lastNewConfirm.getTotalAmount().compareTo(new BigDecimal("0")) >= 0
-						&& contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
-					//鏈夐浠樹笖瓒呰繃搴旀敹 鍏抽棴鍚堝悓鐘舵��
-					contract.setContractStatus(3);
-					contractMapper.updateById(contract);
-				}
-			}
-		}
-		return R.ok();
+		return R.ok(contract);
 	}
 
 	/**

--
Gitblit v1.9.1