From 6b969ca247b98e5a793e61ec5b0d89f4fccb3318 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 10 六月 2026 16:25:18 +0800
Subject: [PATCH] feat:抵抹账条件新增付款金额小于开票金额,红票审核拒绝后蓝票可重新开红票

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java |   71 ++++++++++++++++++++++-------------
 1 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
index fa9c7b6..675e5aa 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
@@ -25,10 +25,7 @@
 import com.by4cloud.platformx.business.mapper.*;
 import com.by4cloud.platformx.business.service.ContractInvoiceService;
 import com.by4cloud.platformx.business.service.PaymentConfirmService;
-import com.by4cloud.platformx.business.vo.ContractInvoiceOutBoundVo;
-import com.by4cloud.platformx.business.vo.ContractOutBoundMergeVo;
-import com.by4cloud.platformx.business.vo.GenInvoiceInfoVo;
-import com.by4cloud.platformx.business.vo.InvoiceItemVo;
+import com.by4cloud.platformx.business.vo.*;
 import com.by4cloud.platformx.common.core.util.R;
 import com.by4cloud.platformx.common.data.mybatis.BaseModel;
 import com.by4cloud.platformx.common.security.util.SecurityUtils;
@@ -88,15 +85,21 @@
 				.selectAll(ContractOutBound.class)
 				.eq(ContractOutBound::getContractId, contractId);
 		List<ContractInvoiceOutBoundVo> invoiceOutBoundVoList = contractOutBoundMapper.selectJoinList(ContractInvoiceOutBoundVo.class, wrapper);
+		if (ArrayUtil.isNotEmpty(invoiceOutBoundVoList.toArray())){
+			invoiceOutBoundVoList.stream().forEach(contractInvoiceOutBoundVo -> {
+				contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(contractInvoiceOutBoundVo.getInvoiceNum()));
+				contractInvoiceOutBoundVo.setToInvoiceNum(contractInvoiceOutBoundVo.getInvoiceNum());
+			});
+		}
 		return R.ok(invoiceOutBoundVoList);
 	}
 
 	@Override
 	public R genInvoiceInfo(GenInvoiceInfoDTO genInvoiceInfoDTO) {
-		if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getContractOutBoundIds())) {
+		if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) {
 			return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庡啀鎿嶄綔");
 		}
-		ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getContractOutBoundIds().get(0));
+		ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
 		Contract contract = contractMapper.selectById(outBound.getContractId());
 		if (ObjUtil.isNull(contract)) {
 			return R.failed("鍚堝悓淇℃伅寮傚父锛岃鑱旂郴鎶�鏈汉鍛�");
@@ -114,7 +117,7 @@
 	private GenInvoiceInfoVo genInvoiceInfoVo(GenInvoiceInfoDTO genInvoiceInfoDTO, Contract contract, SysDept b) {
 		GenInvoiceInfoVo vo = new GenInvoiceInfoVo();
 		BusinessCustomer a = businessCustomerMapper.selectById(contract.getPartyAId());
-		vo.setPartyA(a.getCompanyName());
+		vo.setPartyA(a.getRegisterName());
 		vo.setPartyAOrgCode(a.getCreditCode());
 		vo.setPartyAOpenBank(a.getBankName());
 		vo.setPartyABankAccount(a.getBankAccount());
@@ -125,16 +128,18 @@
 		List<InvoiceItemVo> invoiceItemVoList = new ArrayList<>();
 		List<String> erpCode = new ArrayList<>();
 		List<ContractOutBoundMergeVo> mergeOutBounds = new ArrayList<>();
-		List<ContractOutBound> outBounds = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
-				.in(ContractOutBound::getId, genInvoiceInfoDTO.getContractOutBoundIds()));
-		if (ArrayUtil.isNotEmpty(outBounds.toArray())) {
-			outBounds.stream().forEach(contractOutBound -> {
+//		List<ContractOutBound> outBounds = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
+//				.in(ContractOutBound::getId, genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getContractOutBoundId()).collect(Collectors.toList())));
+		if (ArrayUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) {
+			genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
+				ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+
 				if (!ArrayUtil.contains(erpCode.toArray(), contractOutBound.getSubjectMatterCode())) {
 					erpCode.add(contractOutBound.getSubjectMatterCode());
 					ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo();
 					mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode());
 					mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName());
-					mergeVo.setQuantity(contractOutBound.getOutBoundNum());
+					mergeVo.setQuantity(contractOutBoundInvoiceVo.getInvoiceNum());
 					Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
 							.eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1"));
 					if (ObjUtil.isNotNull(product)) {
@@ -183,10 +188,10 @@
 
 	@Override
 	public R toInvoice(GenInvoiceInfoDTO genInvoiceInfoDTO) {
-		if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getContractOutBoundIds().toArray())) {
+		if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) {
 			return R.failed("璇烽�夋嫨寮�绁ㄥ嚭搴撳崟鍚庡啀鎿嶄綔");
 		}
-		ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getContractOutBoundIds().get(0));
+		ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
 		Contract contract = contractMapper.selectById(outBound.getContractId());
 		if (ObjUtil.isNull(contract)) {
 			return R.failed("鍚堝悓淇℃伅寮傚父锛岃鑱旂郴鎶�鏈汉鍛�");
@@ -198,7 +203,7 @@
 		SysDept b = r.getData();
 		GenInvoiceInfoVo vo = genInvoiceInfoVo(genInvoiceInfoDTO, contract, b);
 		//鍙戠エ淇濆瓨
-		ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getContractOutBoundIds(), DateUtil.current() + "");
+		ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "");
 		//鍚姩娴佺▼
 		ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
 		Map<String, Object> map = BeanUtil.beanToMap(invoice);
@@ -209,9 +214,10 @@
 			return R.failed("娴佺▼鍚姩澶辫触");
 		}
 		//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
-		genInvoiceInfoDTO.getContractOutBoundIds().stream().forEach(outBoundId -> {
-			ContractOutBound bound = contractOutBoundMapper.selectById(outBoundId);
+		genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> {
+			ContractOutBound bound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
 			bound.setInvoiceStatus("1");
+			bound.setInvoiceNum(bound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum()));
 			contractOutBoundMapper.updateById(bound);
 		});
 		return R.ok();
@@ -271,7 +277,7 @@
 		return jsonObject;
 	}
 
-	private ContractInvoice saveContractInvoice(GenInvoiceInfoVo genInvoiceInfoVo, Contract contract, List<Long> outBoundIds, String serialNo) {
+	private ContractInvoice saveContractInvoice(GenInvoiceInfoVo genInvoiceInfoVo, Contract contract, List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList, String serialNo) {
 		ContractInvoice invoice = new ContractInvoice();
 		invoice.setContractId(contract.getId());
 		invoice.setInvoiceCategory("1");
@@ -286,9 +292,10 @@
 		invoice.setInvoicePreview(JSONObject.toJSONString(genInvoiceInfoVo));
 		invoice.setInvoiceStatus("1");
 		invoice.setApprovalStatus("0");
-		invoice.setOutBoundId(outBoundIds.stream()
-				.map(String::valueOf) // 鎴栬�� .map(Object::toString)
+		invoice.setOutBoundId(outBoundInvoiceVoList.stream()
+				.map(item-> String.valueOf(item.getContractOutBoundId())) // 鎴栬�� .map(Object::toString)
 				.collect(Collectors.joining(",")));
+		invoice.setInvoicePreviewParam(JSONObject.toJSONString(outBoundInvoiceVoList));
 		baseMapper.insert(invoice);
 		return invoice;
 	}
@@ -327,6 +334,7 @@
 		invoice.setSerialNo(DateUtil.current() + "");
 		invoice.setBlueInvoiceId(invoiceId);
 		invoice.setApprovalStatus("0");
+		invoice.setInvoicePreviewParam(blueInvoice.getInvoicePreviewParam());
 		baseMapper.insert(invoice);
 		//鍚姩娴佺▼
 		ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
@@ -621,16 +629,21 @@
 			}
 			//鏇存柊鍚堝悓寮�绁ㄧ姸鎬�
 			contract.setBillingStatus("2");
-			contract.setBillingAmout(contract.getAmount().subtract(invoice.getInvoiceTotalPriceTax()));
+			contract.setBillingAmout(contract.getBillingAmout().subtract(invoice.getInvoiceTotalPriceTax()));
 			contractMapper.updateById(contract);
 
+			blueInvoice.setRedReversal("1");
+			baseMapper.updateById(blueInvoice);
+
 			//鏇存柊鍚堝悓鍑哄簱鍗曠姸鎬�
-			String[] outBoundIds = blueInvoice.getOutBoundId().split(",");
-			Arrays.stream(outBoundIds).forEach(outBoundId -> {
-				ContractOutBound bound = contractOutBoundMapper.selectById(outBoundId);
-				bound.setInvoiceStatus("0");
-				contractOutBoundMapper.updateById(bound);
-			});
+			List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()),ContractOutBoundInvoiceVo.class);
+			if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())){
+				outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> {
+					ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
+					contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum()));
+					contractOutBoundMapper.updateById(contractOutBound);
+				});
+			}
 		}
 		invoice.setApprovalStatus("1");
 		baseMapper.updateById(invoice);
@@ -648,5 +661,9 @@
 		});
 		invoice.setApprovalStatus("2");
 		baseMapper.updateById(invoice);
+
+		ContractInvoice blueInvoice = baseMapper.selectById(invoice.getBlueInvoiceId());
+		blueInvoice.setRedReversal("0");
+		baseMapper.updateById(blueInvoice);
 	}
 }

--
Gitblit v1.9.1