From e02812df9217d3e50a368a8234c07c60c64c0ff4 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 05 八月 2026 08:34:26 +0800
Subject: [PATCH] feat:新增石煤机 机械厂模版合同/客户数据主数据同步接口/合同履约进度新增质保结束操作/合同开票状态 修改为待开 可开 已开/出库逻辑完善
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java | 227 ++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 170 insertions(+), 57 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 da08ddc..d653e4e 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
@@ -14,15 +14,13 @@
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;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -83,17 +81,17 @@
//鏇存柊褰撳墠闃舵
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));
@@ -130,10 +128,66 @@
BigDecimal lastTotal = new BigDecimal("0");
if (ObjUtil.isNotNull(lastConfirm)) {
lastTotal = lastConfirm.getTotalAmount();
+ }else {
+ //瀹㈡埛浠樻瀹屾垚鍚堝悓
+ 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)){
+ 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 (ArrayUtil.isNotEmpty(outAmountList.toArray())){
+ BigDecimal currentSum = new BigDecimal("0");
+ for (BigDecimal currentAmount:outAmountList
+ ) {
+ currentSum=currentSum.add(currentAmount);
+ //鏂板褰撳墠鍚堝悓 璧勯噾杞叆
+ PaymentConfirm inConfirm = BeanUtil.copyProperties(lastConfirm,PaymentConfirm.class,"id","transationAmount",
+ "advanceAmount","receivableAmount","overdueAmount","totalAmount");
+ inConfirm.setBusinessType("璧勯噾杞叆");
+ inConfirm.setConfirmTime(new Date());
+ inConfirm.setTransationAmount(currentSum.subtract(currentAmount));
+ inConfirm.setTotalAmount(lastConfirm.getTotalAmount().add(currentSum));
+ 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")));
+ }
+ paymentConfirmMapper.insert(inConfirm);
+ }
+ }
+ }
}
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);
+ }
+ }
+
}
//鏌ヨ鏄惁鏈夊悗缁樁娈�
@@ -144,13 +198,11 @@
//鏈�鍚庨樁娈电敓鏁堟椂闂�
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() + "搴旀敹");
@@ -173,6 +225,7 @@
newConfim.setTotalAmount(lastNewTotal.subtract(newConfim.getReceivableAmount()));
if (endSchedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
paymentConfirmMapper.insert(newConfim);
+
}
}
@@ -186,8 +239,8 @@
contractMapper.updateById(contract);
}
if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
- schedule.setEffectiveEndDate(contract.getExpirationDate());
- contractPaymentScheduleMapper.updateById(schedule);
+// schedule.setEffectiveEndDate(contract.getExpirationDate());
+// contractPaymentScheduleMapper.updateById(schedule);
//鏇存柊鍚堝悓涓嬩釜闃舵
contract.setNextScheduleName("鏃�");
contractMapper.updateById(contract);
@@ -202,7 +255,7 @@
}
}
}
- } else {
+ } else if (schedule.getStageName().equals("璋冭瘯瀹屾垚鎴栭獙鏀�")){
//鏂板褰撳墠闃舵搴旀敹
PaymentConfirm currentConfim = new PaymentConfirm();
currentConfim.setBusinessType(schedule.getStageName() + "搴旀敹");
@@ -225,48 +278,69 @@
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()));
+ .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
+ .gt(ContractPaymentSchedule::getPaymentRatio,"0"));
if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && 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);
@@ -277,8 +351,8 @@
contractMapper.updateById(contract);
}
if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
- schedule.setEffectiveEndDate(contract.getExpirationDate());
- contractPaymentScheduleMapper.updateById(schedule);
+// schedule.setEffectiveEndDate(contract.getExpirationDate());
+// contractPaymentScheduleMapper.updateById(schedule);
//鏇存柊鍚堝悓涓嬩釜闃舵
contract.setNextScheduleName("鏃�");
contractMapper.updateById(contract);
@@ -291,6 +365,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);
}
@@ -354,7 +467,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