From c05ddf57634572b43869e00d426efe05d2df5077 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 10 六月 2026 08:16:23 +0800
Subject: [PATCH] feat:模版合同加备注、水电房屋租赁执行次数改为合同有效期、合同履约列表新增双方履约、开票新增拟开票数量

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 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 3b5e5e9..8782f83 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
@@ -40,6 +40,7 @@
 	private final ContractMapper contractMapper;
 	private final ContractPaymentScheduleProcessMapper scheduleProcessMapper;
 	private final ContractOutBoundMapper contractOutBoundMapper;
+	private final DeliveryOverdueMapper deliveryOverdueMapper;
 
 	@Override
 	public R add(OutBoundAddDTO addDTO) {
@@ -52,6 +53,7 @@
 				.in(ContractSubjectMatter::getMaterialCode, addDTO.getSubjectMatterList().stream().map(item -> item.getSubjectMatterCode()).collect(Collectors.toList()))
 				.exists(Contract.class, contractQuery ->
 						contractQuery.select(ContractSubjectMatter::getId)
+								.eq(Contract::getContractStatus,2)
 								.eq(Contract::getId, ContractSubjectMatter::getContractId)
 								.eq(StrUtil.isNotBlank(addDTO.getBusGuestName()), Contract::getPartyA, addDTO.getBusGuestName())
 								.eq(ObjUtil.isNotNull(addDTO.getBusGuestId()), Contract::getPartyAId, addDTO.getBusGuestId())
@@ -92,7 +94,7 @@
 					if (subjectMatter.getDeliveredQuantity().compareTo(new BigDecimal("0")) > 0) {
 						remainNum = remainNum.subtract(subjectMatter.getRemainingQuantity());
 						//閮ㄥ垎浜や粯鐘舵�佷笅 鍏ㄩ儴鍑哄簱
-						if (remainNum.compareTo(new BigDecimal("0")) >= 0) {
+						if (remainNum.compareTo(new BigDecimal("0")) > 0) {
 							BigDecimal currentOut = subjectMatter.getRemainingQuantity();
 							subjectMatter.setDeliveredQuantity(subjectMatter.getQuantity());
 							subjectMatter.setRemainingQuantity(new BigDecimal("0"));
@@ -120,7 +122,7 @@
 					} else {
 						//鏈氦浠樼姸鎬佷笅
 						remainNum = remainNum.subtract(subjectMatter.getQuantity());
-						if (remainNum.compareTo(new BigDecimal("0")) >= 0) {
+						if (remainNum.compareTo(new BigDecimal("0")) > 0) {
 							subjectMatter.setDeliveredQuantity(subjectMatter.getQuantity());
 							subjectMatter.setRemainingQuantity(new BigDecimal("0"));
 							subjectMatter.setActualDeliveryDate(DateUtil.today());
@@ -383,6 +385,28 @@
 		contractOutBound.setOutBoundAttNames(addDTO.getOutBoundAttNames());
 		contractOutBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths());
 		contractOutBound.setOutBoundId(outBoundId);
+		contractOutBound.setInvoiceStatus("0");
+		contractOutBound.setInvoiceNum(new BigDecimal("0"));
 		contractOutBoundMapper.insert(contractOutBound);
+		if (StrUtil.isEmpty(contract.getContractCategory())){
+			if (DateUtil.compare(addDTO.getOutBoundTime(),contract.getExpirationDate())>0){
+				saveOverdueOutBound(contract, addDTO, subjectMatter);
+			}
+		}
+	}
+
+	private void saveOverdueOutBound(Contract contract, OutBoundAddDTO addDTO, ContractSubjectMatter subjectMatter) {
+		DeliveryOverdue overdue = new DeliveryOverdue();
+		overdue.setContractId(contract.getId());
+		overdue.setContractName(contract.getContractName());
+		overdue.setBusGuestId(contract.getPartyAId());
+		overdue.setBusGuestName(contract.getPartyA());
+		overdue.setMaterialName(subjectMatter.getMaterialName());
+		overdue.setMaterialInternalName(subjectMatter.getMaterialInternalName());
+		overdue.setMaterialCode(subjectMatter.getMaterialCode());
+		overdue.setOverdueNum(subjectMatter.getLastDeliveredQuantity());
+		overdue.setTotalAmount(subjectMatter.getUnitPrice().multiply(subjectMatter.getLastDeliveredQuantity()));
+		overdue.setOverdueDuration(new BigDecimal(DateUtil.betweenDay(addDTO.getOutBoundTime(),contract.getExpirationDate(),true)));
+		deliveryOverdueMapper.insert(overdue);
 	}
 }
\ No newline at end of file

--
Gitblit v1.9.1