From 9171db8f5ddd91b4619bf6a928dcbe98b82f33a0 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 09 九月 2026 15:34:14 +0800
Subject: [PATCH] feat:工业泵收款推送 bip收款单与收款确认分离 开票前校验产品是否维护税收分类信息
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java | 537 +++++++++++++++-------------------------------------------
1 files changed, 143 insertions(+), 394 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 1bb9245..13a4196 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
@@ -19,6 +19,7 @@
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -44,19 +45,35 @@
if (ObjUtil.isNull(schedule)) {
return R.failed("灞ョ害闃舵涓庡悎鍚屼笉涓�鑷达紝璇疯仈绯绘妧鏈汉鍛�");
}
- if (schedule.getStageName().equals("璐у埌绛炬敹") && CollUtil.isEmpty(addDTO.getContractOutBoundIds())) {
- return R.failed("璇烽�夋嫨鍒拌揣鐨勫嚭搴撲俊鎭�");
- }
//鍚堝悓
Contract contract = contractMapper.selectById(schedule.getContractId());
- List<ContractSubjectMatter> subjectMatterList = subjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, contract.getId()));
- if (CollUtil.isEmpty(subjectMatterList)) {
- return R.failed("璇ュ悎鍚屾爣鐨勭墿寮傚父锛岃鑱旂郴鎶�鏈汉鍛�");
+ if (ObjUtil.isNull(contract)) {
+ return R.failed("鍚堝悓淇℃伅寮傚父");
}
-// if (!subjectMatterList.stream().allMatch(item -> item.getDeliveryStatus() == 2)) {
-// return R.failed("鍑哄簱鏁伴噺灏忎簬褰撳墠鍚堝悓鏍囩殑鐗╂暟閲忥紝鏃犳硶杩涜褰撳墠鎿嶄綔");
-// }
+ return handleSchedule(addDTO, schedule, contract);
+
+ }
+
+ public void saveScheduleProcess(Date date, ContractPaymentSchedule schedule) {
+ //鏇存柊灞ョ害
+ ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess();
+ contractPaymentScheduleProcess.setContractId(schedule.getContractId());
+ contractPaymentScheduleProcess.setContractName(schedule.getContractName());
+ contractPaymentScheduleProcess.setScheduleId(schedule.getId());
+ contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
+ contractPaymentScheduleProcess.setProcessDate(date);
+ ContractPaymentScheduleProcess lastProcess = baseMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
+ .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
+ if (ObjUtil.isNull(lastProcess)) {
+ baseMapper.insert(contractPaymentScheduleProcess);
+ }
+ }
+
+ private R handleSchedule(ContractPaymentScheduleProcessAddDTO addDTO, ContractPaymentSchedule schedule, Contract contract) {
if (schedule.getStageName().equals("璐у埌绛炬敹")) {
+ if (CollUtil.isEmpty(addDTO.getContractOutBoundIds())) {
+ return R.failed("绛炬敹淇℃伅涓嶈兘涓虹┖");
+ }
//鏇存柊鍚堝悓鍑哄簱鍒拌揣鏃堕棿
addDTO.getContractOutBoundIds().forEach(contractOutBoundId -> {
ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundId);
@@ -66,403 +83,135 @@
contractOutBoundMapper.updateById(contractOutBound);
});
}
- //灞ョ害
- ContractPaymentScheduleProcess contractPaymentScheduleProcess = BeanUtil.copyProperties(addDTO, ContractPaymentScheduleProcess.class);
- contractPaymentScheduleProcess.setContractId(schedule.getContractId());
- contractPaymentScheduleProcess.setContractName(schedule.getContractName());
- contractPaymentScheduleProcess.setScheduleId(schedule.getId());
- contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
- ContractPaymentScheduleProcess lastProcess = baseMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
- .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
- if (ObjUtil.isNull(lastProcess)) {
- baseMapper.insert(contractPaymentScheduleProcess);
+ //浠樻姣斾緥涓嶄负0 淇濆瓨鏀舵鏄庣粏
+ if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
+ savePaymentConfirm(addDTO, contract, schedule);
}
- //鏇存柊褰撳墠闃舵
- if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) {
- 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);
-// }
-
- List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery().eq(ContractOutBound::getContractId, contract.getId())
- .isNotNull(ContractOutBound::getArrivalTime));
- if (schedule.getStageName().equals("璐у埌绛炬敹")) {
- if (CollUtil.isNotEmpty(contractOutBoundList)
- && CollUtil.isNotEmpty(subjectMatterList)) {
- Map<String, BigDecimal> sumMap = contractOutBoundList.stream()
- .collect(Collectors.groupingBy(
- ContractOutBound::getSubjectMatterCode,
- Collectors.reducing(
- BigDecimal.ZERO,
- ContractOutBound::getOutBoundNum,
- BigDecimal::add
- )
- ));
- Boolean outFlag = checkQuantityEquality(subjectMatterList, sumMap);
- //鍑哄簱鍒拌揣涓庡悎鍚屾爣鐨勭墿绉嶇被鏁伴噺涓�鑷�
- if (outFlag) {
- //鏂板褰撳墠闃舵搴旀敹
- 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.getProcessDate());
- currentConfim.setTransationAmount(schedule.getPlannedAmount());
- currentConfim.setReceivableAmount(schedule.getPlannedAmount());
- PaymentConfirm lastConfirm = paymentConfirmMapper.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 {
- //瀹㈡埛浠樻瀹屾垚鍚堝悓
- 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&&
- contract.getContractNo().startsWith("ZB-")){
- //鏂板瀹屾垚浠樻鍚堝悓 璧勯噾杞嚭
- 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 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")));
- }
- if (contract.getContractNo().startsWith("ZB-")) {
- paymentConfirmMapper.insert(inConfirm);
- }
- }
- }
- }
- }
- currentConfim.setTotalAmount(lastTotal.subtract(currentConfim.getReceivableAmount()));
- if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0&&
- contract.getContractNo().startsWith("ZB-")) {
- 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()));
- if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) {
- //鏈�鍚庨樁娈电敓鏁堟椂闂�
- ContractPaymentSchedule endSchedule = afterSchedule.get(0);
- 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&&contract.getContractNo().startsWith("ZB-")){
- paymentConfirmMapper.insert(newConfim);
-
- }
-
- }
- //鏇存柊鍚堝悓涓嬩釜闃舵
- contract.setNextScheduleName(endSchedule.getStageName());
- contractMapper.updateById(contract);
- }
- if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) {
- //鏇存柊鍚堝悓涓嬩釜闃舵
- contract.setNextScheduleName(afterSchedule.get(0).getStageName());
- contractMapper.updateById(contract);
- }
- if (CollUtil.isEmpty(afterSchedule)) {
-// schedule.setEffectiveEndDate(contract.getExpirationDate());
-// contractPaymentScheduleMapper.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);
- }
- }
- }
- }
- } else if (schedule.getStageName().equals("璋冭瘯瀹屾垚鎴栭獙鏀�")){
- //鏂板褰撳墠闃舵搴旀敹
- 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.getProcessDate());
- currentConfim.setTransationAmount(schedule.getPlannedAmount());
- currentConfim.setReceivableAmount(schedule.getPlannedAmount());
- PaymentConfirm lastConfirm = paymentConfirmMapper.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();
- }
- currentConfim.setTotalAmount(lastTotal.subtract(currentConfim.getReceivableAmount()));
- if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0&&contract.getContractNo().startsWith("ZB-")){
- 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::getPaymentRatio,"0"));
- if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) {
- //鏈�鍚庨樁娈电敓鏁堟椂闂�
- ContractPaymentSchedule endSchedule = afterSchedule.get(0);
-// 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);
- }
- if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) {
- //鏇存柊鍚堝悓涓嬩釜闃舵
- contract.setNextScheduleName(afterSchedule.get(0).getStageName());
- contractMapper.updateById(contract);
- }
- if (CollUtil.isEmpty(afterSchedule)) {
-// schedule.setEffectiveEndDate(contract.getExpirationDate());
-// contractPaymentScheduleMapper.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);
- }
- }
- }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&&contract.getContractNo().startsWith("ZB-")) {
- 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);
- }
-
-
+ updateCurrentSchedule(addDTO.getProcessDate(), schedule, contract);
+ //淇濆瓨灞ョ害璁板綍
+ saveScheduleProcess(addDTO.getProcessDate(), schedule);
return R.ok();
}
- public boolean checkQuantityEquality(List<ContractSubjectMatter> subjectMatterList, Map<String, BigDecimal> materialCodeMap) {
- // 1. 鍩烘湰鏍¢獙
- if (subjectMatterList == null || materialCodeMap == null) {
- return false;
+ private void savePaymentConfirm(ContractPaymentScheduleProcessAddDTO addDTO, Contract contract, ContractPaymentSchedule schedule) {
+ BigDecimal amount = schedule.getPlannedAmount();
+ if (schedule.getStageName().equals("璐у埌绛炬敹")) {
+ amount = new BigDecimal("0");
+ //璁$畻绛炬敹浠锋牸
+ for (Long contractOutBoundId : addDTO.getContractOutBoundIds()) {
+ ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundId);
+ ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getContractId, contract.getId())
+ .eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode())
+ .eq(ContractSubjectMatter::getLineNo, contractOutBound.getLineNo())
+ .last("limit 1"));
+ amount = amount.add(contractOutBound.getOutBoundNum().multiply(subjectMatter.getUnitPrice()));
+ }
+ //瀹為檯鍒拌揣閲戦鎸夋瘮渚嬭绠�
+ amount = schedule.getPlannedAmount().multiply(amount.divide(contract.getAmount(), 2, RoundingMode.HALF_UP));
}
- // 濡傛灉瑕佹眰涓よ�呭寘鍚殑鐗╂枡浠g爜瀹屽叏涓�鑷翠笖鏁伴噺涓�鑷达紝鍏堟瘮杈� Key 鐨勬暟閲�
- // 鎻愬彇 List 涓潪绌虹殑 materialCode
- List<String> listCodes = subjectMatterList.stream()
- .map(ContractSubjectMatter::getMaterialCode)
- .filter(Objects::nonNull)
- .distinct()
- .sorted()
- .collect(Collectors.toList());
-
- List<String> mapKeys = materialCodeMap.keySet().stream()
- .sorted()
- .collect(Collectors.toList());
-
- // 濡傛灉鐗╂枡缂栫爜闆嗗悎涓嶄竴鑷达紝鐩存帴杩斿洖 false
- if (!listCodes.equals(mapKeys)) {
- return false;
+ //鏂板褰撳墠闃舵搴旀敹
+ 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.getProcessDate());
+ currentConfim.setTransationAmount(amount);
+ currentConfim.setReceivableAmount(amount);
+ 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;
}
+ currentConfim.setTotalAmount(currentConfim.getTransationAmount().multiply(new BigDecimal("-1")));
+ paymentConfirmMapper.insert(currentConfim);
+ handleBeforeRemain(currentConfim, contract);
+ }
- // 2. 閫愪釜姣旇緝鏁伴噺
- // 鍋囪 ContractSubjectMatter 涓湁 getQuantity() 鏂规硶杩斿洖 BigDecimal 鎴� Number
- for (ContractSubjectMatter item : subjectMatterList) {
- String code = item.getMaterialCode();
- if (code == null) continue;
-
- BigDecimal mapValue = materialCodeMap.get(code);
- BigDecimal listValue = item.getQuantity(); // 鍋囪杩欐槸 List 涓唬琛ㄦ暟閲忕殑瀛楁
-
- // 澶勭悊 null 鎯呭喌
- if (mapValue == null && listValue == null) {
- continue; // 閮戒负绌鸿涓虹浉绛夛紝鎴栨牴鎹笟鍔″畾涓轰笉绛�
+ public void handleBeforeRemain(PaymentConfirm currentConfim, Contract contract) {
+ //瀹㈡埛浠樻瀹屾垚鍚堝悓
+ List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId())
+ .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).eq(Contract::getContractStatus, 3));
+ 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 &&
+ contract.getContractNo().startsWith("ZB-")) {
+ //鏂板瀹屾垚浠樻鍚堝悓 璧勯噾杞嚭
+ 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"));
+ if (contract.getContractNo().startsWith("ZB-")) {
+ paymentConfirmMapper.insert(outConfirm);
+ }
+ outAmountList.add(contractLastConfirm.getTotalAmount());
+ }
}
- if (mapValue == null || listValue == null) {
- return false; // 涓�涓负绌轰竴涓笉涓虹┖锛屼笉绛�
- }
-
- // 浣跨敤 compareTo 姣旇緝 BigDecimal 鍊硷紝0 琛ㄧず鐩哥瓑
- if (listValue.compareTo(mapValue) != 0) {
- return false; // 鍙戠幇涓嶇浉绛夛紝绔嬪嵆杩斿洖
+ if (CollUtil.isNotEmpty(outAmountList)) {
+ BigDecimal currentSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+ //鏂板褰撳墠鍚堝悓 璧勯噾杞叆
+ PaymentConfirm inConfirm = BeanUtil.copyProperties(currentConfim, PaymentConfirm.class, "id", "transationAmount",
+ "advanceAmount", "receivableAmount", "overdueAmount", "totalAmount");
+ inConfirm.setBusinessType("璧勯噾杞叆");
+ inConfirm.setConfirmTime(new Date());
+ inConfirm.setTransationAmount(currentSum);
+ inConfirm.setTotalAmount(currentConfim.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")));
+ }
+ if (contract.getContractNo().startsWith("ZB-")) {
+ paymentConfirmMapper.insert(inConfirm);
+ }
+ contract.setPaidAmount(currentSum);
+ contractMapper.updateById(contract);
}
}
+ }
- return true; // 鎵�鏈夊尮閰嶉」鏁伴噺鍧囩浉绛�
+ private void updateCurrentSchedule(Date date, ContractPaymentSchedule schedule, Contract contract) {
+
+ //鏌ヨ鏄惁鏈夊悗缁樁娈�
+ ContractPaymentSchedule afterOneSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery()
+ .eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
+ .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
+ .orderByAsc(ContractPaymentSchedule::getCreateTime)
+ .last("limit 1"));
+ if (ObjUtil.isNotNull(afterOneSchedule)) {
+ //鏇存柊涓嬮樁娈靛悕绉�
+ List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery().eq(ContractOutBound::getContractId, contract.getId())
+ .isNull(ContractOutBound::getArrivalTime));
+ if (CollUtil.isEmpty(contractOutBoundList)) {
+ contract.setNextScheduleName(afterOneSchedule.getStageName());
+ }
+ }
+ if (ObjUtil.isNull(afterOneSchedule)) {
+ contract.setNextScheduleName("");
+ }
+ contractMapper.updateById(contract);
+ //鏇存柊灞ョ害闃舵鏃堕棿
+ if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) {
+ schedule.setEffectiveEndDate(DateUtil.offsetDay(date, schedule.getAgreedDays()));
+ }
+ contractPaymentScheduleMapper.updateById(schedule);
}
@Override
@@ -472,7 +221,7 @@
ContractPaymentSchedule::getPlannedAmount, ContractPaymentSchedule::getPlannedAmount,
ContractPaymentSchedule::getEffectiveEndDate, ContractPaymentSchedule::getPaymentDate,
ContractPaymentSchedule::getPaymentStatus, ContractPaymentSchedule::getActualAmount,
- ContractPaymentSchedule::getAgreedDays,ContractPaymentSchedule::getPaymentRatio)
+ ContractPaymentSchedule::getAgreedDays, ContractPaymentSchedule::getPaymentRatio)
.select(ContractPaymentScheduleProcess::getProcessDate)
.leftJoin(ContractPaymentScheduleProcess.class, ContractPaymentScheduleProcess::getScheduleId, ContractPaymentSchedule::getId)
.eq(ContractPaymentSchedule::getContractId, id)
--
Gitblit v1.9.1