From 2db76f2066701cbe292f206ad49a7f8523b8aa9f Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期五, 14 八月 2026 16:30:25 +0800
Subject: [PATCH] feat:银行流水关联多个合同,新增预收款开票,所有List校验调整为ColUtil
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java | 320 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 198 insertions(+), 122 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 05fb704..2a7809e 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
@@ -1,11 +1,11 @@
package com.by4cloud.platformx.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by4cloud.platformx.business.dto.OutBoundAddDTO;
@@ -25,6 +25,8 @@
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
+
+;
/**
* EPR鍑哄簱璁板綍
@@ -62,7 +64,7 @@
@Override
public R add(OutBoundAddDTO addDTO) {
- if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) {
+ if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) {
return R.failed("鍑哄簱鏍囩殑鐗╀笉鑳戒负绌�");
}
MPJLambdaWrapper<ContractSubjectMatter> wrapper = new MPJLambdaWrapper<ContractSubjectMatter>()
@@ -78,7 +80,7 @@
)
.orderByAsc(ContractSubjectMatter::getCreateTime);
List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(wrapper);
- if (ArrayUtil.isEmpty(subjectMatterList.toArray())) {
+ if (CollUtil.isEmpty(subjectMatterList)) {
return R.failed("娌℃湁鏌ヨ鍒扮浉鍏冲悎鍚岃鍗�");
}
List<String> erpCodeList = subjectMatterList.stream().map(ContractSubjectMatter::getMaterialCode).collect(Collectors.toList());
@@ -96,24 +98,24 @@
//褰撳墠鍏ュ簱鏍囩殑鐗�
Map<Long, Object> currentOutMap = new HashMap<>();
//鍑哄簱鎵规
- String batchNumber = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
+// String batchNumber = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
//鍑哄簱
addDTO.getSubjectMatterList().stream().forEach(outSubjectMatterAddDTO -> {
OutBound outBound = BeanUtil.copyProperties(outSubjectMatterAddDTO, OutBound.class);
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)){
- outBound.setBatchNumber(generateSMJContractNo());
+ outBound.setBatchNumber(generateSMJContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",sgb)){
- outBound.setBatchNumber(generateGYBContractNo());
+ outBound.setBatchNumber(generateGYBContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",ymj)){
- outBound.setBatchNumber(generateYMJContractNo());
+ outBound.setBatchNumber(generateYMJContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",tfgs)){
- outBound.setBatchNumber(generateTFContractNo());
+ outBound.setBatchNumber(generateTFContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",jxc)){
- outBound.setBatchNumber(generateJXCContractNo());
+ outBound.setBatchNumber(generateJXCContractCKNo());
}
outBound.setBusGuestName(addDTO.getBusGuestName());
outBound.setBusGuestId(addDTO.getBusGuestId());
@@ -184,7 +186,7 @@
});
//鍑哄簱搴旀敹娆炬槑缁�
- if (ArrayUtil.isNotEmpty(currentOutMap.keySet())) {
+ if (CollUtil.isNotEmpty(currentOutMap.keySet())) {
for (Long contractId : currentOutMap.keySet()) {
//褰撳墠鍑哄簱鍚堝悓鍑哄簱鏍囩殑鐗�
List<ContractSubjectMatter> contractSubjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
@@ -201,12 +203,17 @@
//鍚堝悓閲戦
Contract contract = contractMapper.selectById(contractId);
//鍑哄簱鏄惁瀹屾垚
- if (outPirce.compareTo(contract.getAmount()) < 0) {
+ if (outPirce.compareTo(contract.getBillingAmout())>0) {
+ contract.setBillingStatus("2");
+ contractMapper.updateById(contract);
+ }
+ if (outPirce.compareTo(contract.getBillingAmout())==0) {
contract.setBillingStatus("1");
contractMapper.updateById(contract);
}
- if (outPirce.compareTo(contract.getAmount()) == 0) {
- contract.setBillingStatus("2");
+ if (outPirce.compareTo(contract.getAmount()) == 0&&
+ outPirce.compareTo(contract.getBillingAmout())==0) {
+ contract.setBillingStatus("3");
contractMapper.updateById(contract);
}
//璁$畻鍙戣揣鍓嶅簲鏀舵洿鏂拌祫閲戞槑缁�
@@ -258,7 +265,7 @@
//瀹㈡埛浠樻瀹屾垚鍚堝悓
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)) {
+ if (CollUtil.isNotEmpty(customerCompleteContractList)) {
List<BigDecimal> outAmountList = new ArrayList<>();
for (Contract completeContract : customerCompleteContractList
) {
@@ -277,7 +284,7 @@
outAmountList.add(outConfirm.getTransationAmount());
}
}
- if (ArrayUtil.isNotEmpty(outAmountList.toArray())) {
+ if (CollUtil.isNotEmpty(outAmountList)) {
BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
//鏂板褰撳墠鍚堝悓 璧勯噾杞叆
PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
@@ -310,7 +317,7 @@
//鏌ヨ鏄惁鏈夊悗缁樁娈�
// List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contractId)
// .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()));
-// if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
+// if (.isEmpty(afterSchedule)) {
// schedule.setEffectiveEndDate(contract.getExpirationDate());
// }
scheduleMapper.updateById(schedule);
@@ -340,7 +347,7 @@
.eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
.gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
.orderByAsc(ContractPaymentSchedule::getCreateTime));
- if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) {
+ if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) {
//鏈�鍚庨樁娈电敓鏁堟椂闂�
ContractPaymentSchedule endSchedule = afterSchedule.get(0);
if (StrUtil.equals(endSchedule.getStageName(), "璐ㄤ繚閲�")) {
@@ -377,12 +384,12 @@
contract.setNextScheduleName(endSchedule.getStageName());
contractMapper.updateById(contract);
}
- if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) {
+ if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) {
//鏇存柊鍚堝悓涓嬩釜闃舵
contract.setNextScheduleName(afterSchedule.get(0).getStageName());
contractMapper.updateById(contract);
}
- if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
+ if (CollUtil.isEmpty(afterSchedule)) {
// schedule.setEffectiveEndDate(contract.getExpirationDate());
// scheduleMapper.updateById(schedule);
//鏇存柊鍚堝悓涓嬩釜闃舵
@@ -412,11 +419,12 @@
contractOutBound.setBusGuestName(contract.getPartyA());
contractOutBound.setSubjectMatterCode(subjectMatter.getMaterialCode());
contractOutBound.setSubjectMatterName(subjectMatter.getMaterialInternalName());
- contractOutBound.setOutBoundTime(addDTO.getOutBoundTime());
+ contractOutBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime())?addDTO.getOutBoundTime():new Date());
contractOutBound.setOutBoundNum(subjectMatter.getLastDeliveredQuantity());
contractOutBound.setOutBoundAttNames(addDTO.getOutBoundAttNames());
contractOutBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths());
contractOutBound.setOutBoundId(outBoundId);
+ contractOutBound.setLineNo(subjectMatter.getLineNo());
contractOutBound.setInvoiceStatus("0");
contractOutBound.setInvoiceNum(new BigDecimal("0"));
contractOutBoundMapper.insert(contractOutBound);
@@ -453,20 +461,74 @@
@Override
public R addContractOut(OutBoundAddDTO addDTO) {
- if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) {
+ if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) {
return R.failed("鍑哄簱鏍囩殑鐗╀笉鑳戒负绌�");
}
- Contract contract = contractMapper.selectOne(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, addDTO.getContractNo()).eq(Contract::getContractStatus, 2)
- .last("limit 1"));
+ // 1. 纭畾鏌ヨ鐢ㄧ殑鍚堝悓缂栧彿瀛楁鍊�
+ String targetContractNo = addDTO.getContractNo();
+ boolean isSgbAndEmptyOutbound = StrUtil.isEmpty(addDTO.getOutBoundType())
+ && StrUtil.equals(String.valueOf(SecurityUtils.getUser().getCompId()), sgb);
+
+ // 2. 鏋勫缓鏌ヨ鏉′欢
+ LambdaQueryWrapper<Contract> queryWrapper = Wrappers.lambdaQuery(Contract.class)
+ .eq(Contract::getContractStatus, 2)
+ .last("LIMIT 1"); // 娉ㄦ剰锛歭ast 娉ㄥ叆 SQL 鐗囨锛岄渶纭繚闃叉敞鍏ユ垨涓氬姟鍙帶
+
+ if (isSgbAndEmptyOutbound) {
+ // 鏉′欢 A: 浣跨敤 ERP 鍚堝悓鍙锋煡璇�
+ queryWrapper.eq(Contract::getErpContractNo, targetContractNo);
+ } else {
+ // 鏉′欢 B: 浣跨敤鏅�氬悎鍚屽彿鏌ヨ
+ queryWrapper.eq(Contract::getContractNo, targetContractNo);
+ }
+
+ // 3. 鎵ц鏌ヨ
+ Contract contract = contractMapper.selectOne(queryWrapper);
if (ObjUtil.isNull(contract)) {
return R.failed("鍚堝悓淇℃伅鏌ヨ澶辫触");
}
- //鍑哄簱鎵规
- String batchNumber = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
+ if (addDTO.getSubjectMatterList().stream().allMatch(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))==0)){
+ return R.failed("鍑哄簱鏁伴噺涓嶈兘閮戒负涓�0");
+ }
+ addDTO.setSubjectMatterList(addDTO.getSubjectMatterList().stream().filter(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList()));
+ //鍑哄簱鏁伴噺鏍¢獙
+ for (OutSubjectMatterAddDTO outSubjectMatterAddDTO: addDTO.getSubjectMatterList()) {
+ ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getContractId,contract.getId())
+ .eq(ContractSubjectMatter::getMaterialCode,outSubjectMatterAddDTO.getSubjectMatterCode())
+ .eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()),ContractSubjectMatter::getLineNo,outSubjectMatterAddDTO.getLineNo())
+ .last("limit 1"));
+ if (ObjUtil.isNull(subjectMatter)){
+ continue;
+ }
+ if (subjectMatter.getDeliveryStatus()==0){
+ if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getQuantity())>0){
+ return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"鍑哄簱鏁颁笉鑳借秴杩囧悎鍚屼腑鏁伴噺");
+ }
+ }
+ if (subjectMatter.getDeliveryStatus()==1){
+ if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getRemainingQuantity())>0){
+ return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"鍑哄簱鏁颁笉鑳借秴杩囨湭鍑哄簱鏁伴噺");
+ }
+ }
+ if (subjectMatter.getDeliveryStatus()==2){
+ return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"宸插嚭搴撳畬鎴愶紝涓嶈兘瓒呴鍑哄簱");
+ }
+ }
+
addDTO.getSubjectMatterList().stream().forEach(outSubjectMatterAddDTO -> {
- ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(outSubjectMatterAddDTO.getId());
+ ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getContractId,contract.getId())
+ .eq(ContractSubjectMatter::getMaterialCode,outSubjectMatterAddDTO.getSubjectMatterCode())
+ .ne(ContractSubjectMatter::getDeliveryStatus,2)
+ .eq(StrUtil.isNotEmpty(outSubjectMatterAddDTO.getLineNo()),ContractSubjectMatter::getLineNo,outSubjectMatterAddDTO.getLineNo())
+ .last("limit 1"));
+ if (ObjUtil.isNull(subjectMatter)){
+ return;
+ }
subjectMatter.setLastDeliveredQuantity(outSubjectMatterAddDTO.getOutBoundNum());
+ outSubjectMatterAddDTO.setUnitPrice(subjectMatter.getUnitPrice());
if (subjectMatter.getDeliveryStatus() == 0) {
subjectMatter.setDeliveredQuantity(outSubjectMatterAddDTO.getOutBoundNum());
subjectMatter.setRemainingQuantity(subjectMatter.getQuantity().subtract(outSubjectMatterAddDTO.getOutBoundNum()));
@@ -484,28 +546,32 @@
//
OutBound outBound = new OutBound();
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)){
- outBound.setBatchNumber(generateSMJContractNo());
+ outBound.setBatchNumber(generateSMJContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",sgb)){
- outBound.setBatchNumber(generateGYBContractNo());
+ outBound.setBatchNumber(generateGYBContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",ymj)){
- outBound.setBatchNumber(generateYMJContractNo());
+ outBound.setBatchNumber(generateYMJContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",tfgs)){
- outBound.setBatchNumber(generateTFContractNo());
+ outBound.setBatchNumber(generateTFContractCKNo());
}
if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",jxc)){
- outBound.setBatchNumber(generateJXCContractNo());
+ outBound.setBatchNumber(generateJXCContractCKNo());
}
outBound.setOutBoundNum(outSubjectMatterAddDTO.getOutBoundNum());
outBound.setOutBoundAttNames(addDTO.getOutBoundAttNames());
outBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths());
outBound.setBusGuestName(contract.getPartyA());
outBound.setBusGuestId(contract.getPartyAId());
- outBound.setOutBoundTime(addDTO.getOutBoundTime());
+ outBound.setOutBoundTime(ObjUtil.isNotNull(addDTO.getOutBoundTime())?addDTO.getOutBoundTime():new Date());
outBound.setSubjectMatterCode(outSubjectMatterAddDTO.getSubjectMatterCode());
outBound.setSubjectMatterName(outSubjectMatterAddDTO.getSubjectMatterName());
+ outBound.setOutBoundType("1");
+ if (StrUtil.isEmpty(addDTO.getOutBoundType())){
+ outBound.setOutBoundType("0");
+ }
baseMapper.insert(outBound);
//
saveContractOutBound(contract, addDTO, subjectMatter, outBound.getId());
@@ -523,12 +589,17 @@
.map(item -> (item.getDeliveryStatus() == 1 ? item.getDeliveredQuantity().multiply(item.getUnitPrice()) : item.getQuantity().multiply(item.getUnitPrice())))
.reduce(BigDecimal.ZERO, BigDecimal::add);
//鍑哄簱鏄惁瀹屾垚
- if (outPirce.compareTo(contract.getAmount()) < 0) {
+ if (outPirce.compareTo(contract.getBillingAmout())>0) {
+ contract.setBillingStatus("2");
+ contractMapper.updateById(contract);
+ }
+ if (outPirce.compareTo(contract.getBillingAmout())==0) {
contract.setBillingStatus("1");
contractMapper.updateById(contract);
}
- if (outPirce.compareTo(contract.getAmount()) == 0) {
- contract.setBillingStatus("2");
+ if (outPirce.compareTo(contract.getAmount()) == 0&&
+ outPirce.compareTo(contract.getBillingAmout())==0) {
+ contract.setBillingStatus("3");
contractMapper.updateById(contract);
}
//璁$畻鍙戣揣鍓嶅簲鏀舵洿鏂拌祫閲戞槑缁�
@@ -542,36 +613,31 @@
paymentConfirm.setScheduleId(schedule.getId());
paymentConfirm.setScheduleName(schedule.getStageName());
paymentConfirm.setConfirmTime(addDTO.getOutBoundTime());
- //鎸夊嚭搴撹祫閲戞瘮渚� 璁$畻鍙戣揣鍓嶅簲鏀�
- paymentConfirm.setTransationAmount(outPirce.divide(contract.getAmount(), 10, RoundingMode.HALF_UP).multiply(schedule.getPlannedAmount()));
- paymentConfirm.setReceivableAmount(paymentConfirm.getTransationAmount());
-
- //鏈�杩戝簲鏀�
+ //璁$畻鍑哄簱閲戦
+ BigDecimal outAmount = addDTO.getSubjectMatterList().stream().map(item->item.getUnitPrice().multiply(item.getOutBoundNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
+ paymentConfirm.setTransationAmount(outAmount.divide(new BigDecimal("100")).multiply(schedule.getPaymentRatio()));
+ if (ObjUtil.isNotNull(contract.getOutBoundAmout())){
+ contract.setOutBoundAmout(outAmount.add(contract.getOutBoundAmout()));
+ }else {
+ contract.setOutBoundAmout(outAmount);
+ }
+ contractMapper.updateById(contract);
+ //鏈�杩戞槑缁�
PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
.orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
-
if (ObjUtil.isNotNull(lastConfirm)) {
- //宸插瓨鍦ㄥ彂璐у簲鏀�
- if (StrUtil.equals(lastConfirm.getBusinessType(), paymentConfirm.getBusinessType())) {
-
- //鏌ヨ涔嬪墠鎵�鏈夊彂璐у墠搴旀敹
- List<PaymentConfirm> fhConfirmList = paymentConfirmMapper.selectList(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId())
- .eq(PaymentConfirm::getScheduleId, schedule.getId()).orderByDesc(PaymentConfirm::getCreateTime));
- BigDecimal fhTotalAmount = fhConfirmList.stream().map(item -> item.getTransationAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
- //鏈鍙戣揣鍓嶅簲鏀� 鍑哄簱鎬婚 - 鎵�鏈夊彂璐у墠搴旀敹
- paymentConfirm.setTransationAmount(paymentConfirm.getTransationAmount().subtract(fhTotalAmount));
- paymentConfirm.setReceivableAmount(paymentConfirm.getTransationAmount());
- paymentConfirm.setTotalAmount(lastConfirm.getTotalAmount().subtract(paymentConfirm.getTransationAmount()));
- if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
- paymentConfirmMapper.insert(paymentConfirm);
- }
- } else {
//涓嶅瓨鍦ㄥ彂璐у簲鏀� 鍑哄簱鎬婚
paymentConfirm.setTotalAmount(lastConfirm.getTotalAmount().subtract(paymentConfirm.getTransationAmount()));
+ if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0"))>0){
+ paymentConfirm.setAdvanceAmount(paymentConfirm.getTotalAmount());
+ }
+ if (paymentConfirm.getTotalAmount().compareTo(new BigDecimal("0"))<0){
+ paymentConfirm.setReceivableAmount(paymentConfirm.getTotalAmount().multiply(new BigDecimal("-1")));
+ }
if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
paymentConfirmMapper.insert(paymentConfirm);
}
- }
+// }
} else {
//鏃犱箣鍓嶉樁娈靛簲鏀�
paymentConfirm.setTotalAmount(paymentConfirm.getTransationAmount().multiply(new BigDecimal("-1")));
@@ -580,7 +646,7 @@
//瀹㈡埛浠樻瀹屾垚鍚堝悓
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)) {
+ if (CollUtil.isNotEmpty(customerCompleteContractList)) {
List<BigDecimal> outAmountList = new ArrayList<>();
for (Contract completeContract : customerCompleteContractList
) {
@@ -599,7 +665,7 @@
outAmountList.add(outConfirm.getTransationAmount());
}
}
- if (ArrayUtil.isNotEmpty(outAmountList.toArray())) {
+ if (CollUtil.isNotEmpty(outAmountList)) {
BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
//鏂板褰撳墠鍚堝悓 璧勯噾杞叆
PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
@@ -628,21 +694,7 @@
//鏇存柊鍙戣揣鍓嶆敹娆剧敓鏁堟椂闂�
if (ObjUtil.isNull(schedule.getEffectiveDate())) {
- schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
- //鏌ヨ鏄惁鏈夊悗缁樁娈�
-// List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contractId)
-// .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()));
-// if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
-// schedule.setEffectiveEndDate(contract.getExpirationDate());
-// }
- scheduleMapper.updateById(schedule);
- //鏌ヨ鏄惁鏈変箣鍓嶉樁娈�
-// ContractPaymentSchedule beforeSchedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
-// .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
-// if (ObjUtil.isNotNull(beforeSchedule)) {
-// beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
-// scheduleMapper.updateById(beforeSchedule);
-// }
+
//鏇存柊灞ョ害
ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess();
contractPaymentScheduleProcess.setContractId(schedule.getContractId());
@@ -662,51 +714,14 @@
.eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
.gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
.orderByAsc(ContractPaymentSchedule::getCreateTime));
- if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) {
- //鏈�鍚庨樁娈电敓鏁堟椂闂�
- ContractPaymentSchedule endSchedule = afterSchedule.get(0);
- if (StrUtil.equals(endSchedule.getStageName(), "璐ㄤ繚閲�")) {
-// endSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), endSchedule.getAgreedDays()));
-// scheduleMapper.updateById(endSchedule);
- //褰撳墠闃舵鐢熸晥鏃堕棿
-// schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
-// scheduleMapper.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.getOutBoundTime());
- 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);
- }
- }
- //鏇存柊鍚堝悓涓嬩釜闃舵
- contract.setNextScheduleName(endSchedule.getStageName());
- contractMapper.updateById(contract);
- }
- if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) {
- //鏇存柊鍚堝悓涓嬩釜闃舵
+ if (CollUtil.isNotEmpty(afterSchedule)&&contract.getOutBoundAmout().compareTo(contract.getAmount())==0) {
contract.setNextScheduleName(afterSchedule.get(0).getStageName());
contractMapper.updateById(contract);
}
- if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
-// schedule.setEffectiveEndDate(contract.getExpirationDate());
-// scheduleMapper.updateById(schedule);
+
+ if (CollUtil.isEmpty(afterSchedule)) {
+ schedule.setEffectiveEndDate(contract.getExpirationDate());
+ scheduleMapper.updateById(schedule);
//鏇存柊鍚堝悓涓嬩釜闃舵
contract.setNextScheduleName("鏃�");
contractMapper.updateById(contract);
@@ -726,7 +741,7 @@
/**
* 鐢熸垚鏍煎紡涓�: yyyyMMdd + 4浣嶅簭鍒楀彿 (渚嬪: 20260629000001)
*/
- public String generateSMJContractNo() {
+ public String generateSMJContractCKNo() {
// 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
@@ -744,7 +759,7 @@
return "ZB-SMJ-CK-"+dateStr + seqStr;
}
- public String generateYMJContractNo() {
+ public String generateYMJContractCKNo() {
// 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
@@ -762,7 +777,7 @@
return "ZB-YMJ-CK-"+dateStr + seqStr;
}
- public String generateJXCContractNo() {
+ public String generateJXCContractCKNo() {
// 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
@@ -780,7 +795,7 @@
return "ZB-JXC-CK-"+dateStr + seqStr;
}
- public String generateTFContractNo() {
+ public String generateTFContractCKNo() {
// 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
@@ -798,7 +813,7 @@
return "ZB-TF-CK-"+dateStr + seqStr;
}
- public String generateGYBContractNo() {
+ public String generateGYBContractCKNo() {
// 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
@@ -815,4 +830,65 @@
// 5. 鎷兼帴杩斿洖
return "ZB-GYB-CK-"+dateStr + seqStr;
}
+
+ @Override
+ public R delOutBound(String batchNumber) {
+ List<OutBound> outBoundList = baseMapper.selectList(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber,batchNumber));
+ if (CollUtil.isEmpty(outBoundList)){
+ return R.failed("鍑哄簱淇℃伅寮傚父锛岃鑱旂郴钀ラ攢绯荤粺绠$悊浜哄憳");
+ }
+ List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
+ .in(ContractOutBound::getOutBoundId,outBoundList.stream().map(OutBound::getId).collect(Collectors.toList())));
+ if (CollUtil.isEmpty(contractOutBoundList)){
+ return R.failed("鍑哄簱淇℃伅寮傚父锛岃鑱旂郴钀ラ攢绯荤粺绠$悊浜哄憳");
+ }
+ boolean allZero = true;
+ for (ContractOutBound item : contractOutBoundList) {
+ // 鍋囪 invoiceNum 鏄� Integer 瀵硅薄
+ if (item.getInvoiceNum() == null || item.getInvoiceNum().compareTo(new BigDecimal("0"))!=0) {
+ allZero = false;
+ break; // 鍙戠幇涓�涓笉绗﹀悎鍗抽��鍑�
+ }
+ }
+ if (!allZero){
+ return R.failed("璇峰厛鍐插噺鎵�鏈夎摑鐗屽悗鍦ㄦ搷浣�");
+ }
+ for (ContractOutBound item : contractOutBoundList) {
+ ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getContractId,item.getContractId()).eq(ContractSubjectMatter::getMaterialCode,item.getSubjectMatterCode())
+ .eq(ContractSubjectMatter::getLineNo,item.getLineNo()));
+ if (ObjUtil.isNotNull(subjectMatter)){
+ subjectMatter.setDeliveredQuantity(subjectMatter.getDeliveredQuantity().subtract(item.getOutBoundNum()));
+ subjectMatter.setRemainingQuantity(subjectMatter.getRemainingQuantity().add(item.getOutBoundNum()));
+ if (subjectMatter.getDeliveredQuantity().compareTo(new BigDecimal("0"))==0){
+ subjectMatter.setDeliveryStatus(0);
+ }
+ if (subjectMatter.getDeliveredQuantity().compareTo(new BigDecimal("0"))>0){
+ subjectMatter.setDeliveryStatus(1);
+ }
+ //鏍囩殑鐗╂洿鏂�
+ contractSubjectMatterMapper.updateById(subjectMatter);
+ }
+ //鍚堝悓寮�绁ㄧ姸鎬佹洿鏂�
+// List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
+// .eq(ContractSubjectMatter::getContractId,subjectMatter.getContractId()));
+// if (subjectMatterList.stream().allMatch(matter -> matter.getDeliveryStatus() != null && matter.getDeliveryStatus() == 0)){
+// Contract contract = contractMapper.selectById(subjectMatter.getContractId());
+// if (ObjUtil.isNotNull(contract)){
+// contract.setBillingStatus("1");
+// contractMapper.updateById(contract);
+// }
+// }else {
+// Contract contract = contractMapper.selectById(subjectMatter.getContractId());
+// if (ObjUtil.isNotNull(contract)){
+// contract.setBillingStatus("1");
+// contractMapper.updateById(contract);
+// }
+// }
+ //鍑哄簱璁板綍鍒犻櫎
+ contractOutBoundMapper.deleteById(item);
+ }
+ baseMapper.delete(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber,batchNumber));
+ return R.ok();
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1