From 5b1c84423d590c7240209fa9a68d33c0116457af Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期二, 26 五月 2026 17:27:03 +0800
Subject: [PATCH] feat:测试调整

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java |  140 ++++++++++++++++++++++++++++------------------
 1 files changed, 84 insertions(+), 56 deletions(-)

diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java
index 851c239..9846cf2 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java
@@ -253,19 +253,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);
@@ -281,9 +287,16 @@
 				entity.setBusGuestName(customer.getCompanyName());
 				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) {
@@ -371,10 +384,10 @@
 //					if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) {
 //						contract.setContractStatus(3);
 //					}
-					contractService.updateById(contract);
 					if (contract.getAmount().compareTo(contract.getPaidAmount()) == 0) {
 						contract.setBillingStatus("2");
 						contract.setContractStatus(3);
+						contractService.updateById(contract);
 						payCompleteContractList.add(contract);
 					}
 					//浠樻 涓� 浠樻鏈叏浠�
@@ -385,28 +398,28 @@
 			});
 
 			//瀹㈡埛棰勪粯鏈夊墿浣� 涓� 鏈夐浠樻鐨勫悎鍚�
-			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();
 	}
@@ -569,7 +582,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");
@@ -601,9 +616,16 @@
 			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")));
@@ -683,11 +705,17 @@
 				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);
+					contractService.updateById(contract);
 					payCompleteContractList.add(contract);
 				}
 				//浠樻 涓� 浠樻鏈叏浠�
@@ -698,28 +726,28 @@
 		});
 
 		//瀹㈡埛棰勪粯鏈夊墿浣� 涓� 鏈夐浠樻鐨勫悎鍚�
-		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,SysDept dept) {

--
Gitblit v1.9.1