From ca019747743a76f9348fcac99385c91736a36638 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期四, 17 九月 2026 16:44:15 +0800
Subject: [PATCH] feat:标的物变更 合同审核流程改为推送合同中心通过后上传盖章签字件 履约进度新增合同补录按钮
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java | 668 ++++++++++++++++++++++++++++++++++---------------------
1 files changed, 410 insertions(+), 258 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 954cc14..57f2256 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,28 +1,33 @@
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;
import com.by4cloud.platformx.business.dto.OutSubjectMatterAddDTO;
import com.by4cloud.platformx.business.entity.*;
import com.by4cloud.platformx.business.mapper.*;
+import com.by4cloud.platformx.business.service.ContractPaymentScheduleProcessService;
import com.by4cloud.platformx.business.service.OutBoundService;
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.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
+
+;
/**
* EPR鍑哄簱璁板綍
@@ -41,10 +46,33 @@
private final ContractPaymentScheduleProcessMapper scheduleProcessMapper;
private final ContractOutBoundMapper contractOutBoundMapper;
private final DeliveryOverdueMapper deliveryOverdueMapper;
+ private final StringRedisTemplate redisTemplate;
+ private final ContractPaymentScheduleProcessService processService;
+
+ @Value("${dept.smj}")
+ private String smj;
+
+ @Value("${dept.smjsc}")
+ private String smjsc;
+
+ @Value("${dept.smjzt}")
+ private String smjzt;
+
+ @Value("${dept.sgb}")
+ private String sgb;
+
+ @Value("${dept.jxc}")
+ private String jxc;
+
+ @Value("${dept.tfgs}")
+ private String tfgs;
+
+ @Value("${dept.ymj}")
+ private String ymj;
@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>()
@@ -60,7 +88,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());
@@ -78,11 +106,26 @@
//褰撳墠鍏ュ簱鏍囩殑鐗�
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);
- outBound.setBatchNumber(batchNumber);
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) ||
+ StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) {
+ outBound.setBatchNumber(generateSMJContractCKNo());
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) {
+ outBound.setBatchNumber(generateGYBContractCKNo());
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", ymj)) {
+ outBound.setBatchNumber(generateYMJContractCKNo());
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", tfgs)) {
+ outBound.setBatchNumber(generateTFContractCKNo());
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", jxc)) {
+ outBound.setBatchNumber(generateJXCContractCKNo());
+ }
outBound.setBusGuestName(addDTO.getBusGuestName());
outBound.setBusGuestId(addDTO.getBusGuestId());
outBound.setOutBoundTime(addDTO.getOutBoundTime());
@@ -152,7 +195,7 @@
});
//鍑哄簱搴旀敹娆炬槑缁�
- if (ArrayUtil.isNotEmpty(currentOutMap.keySet())) {
+ if (CollUtil.isNotEmpty(currentOutMap.keySet())) {
for (Long contractId : currentOutMap.keySet()) {
//褰撳墠鍑哄簱鍚堝悓鍑哄簱鏍囩殑鐗�
List<ContractSubjectMatter> contractSubjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
@@ -169,12 +212,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);
}
//璁$畻鍙戣揣鍓嶅簲鏀舵洿鏂拌祫閲戞槑缁�
@@ -226,7 +274,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
) {
@@ -245,7 +293,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",
@@ -278,7 +326,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);
@@ -289,18 +337,6 @@
// beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
// scheduleMapper.updateById(beforeSchedule);
// }
- //鏇存柊灞ョ害
- ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess();
- contractPaymentScheduleProcess.setContractId(schedule.getContractId());
- contractPaymentScheduleProcess.setContractName(schedule.getContractName());
- contractPaymentScheduleProcess.setScheduleId(schedule.getId());
- contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
- contractPaymentScheduleProcess.setProcessDate(addDTO.getOutBoundTime());
- ContractPaymentScheduleProcess lastProcess = scheduleProcessMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
- .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
- if (ObjUtil.isNull(lastProcess)) {
- scheduleProcessMapper.insert(contractPaymentScheduleProcess);
- }
}
//鏌ヨ鏄惁鏈夊悗缁樁娈�
@@ -308,7 +344,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(), "璐ㄤ繚閲�")) {
@@ -345,12 +381,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);
//鏇存柊鍚堝悓涓嬩釜闃舵
@@ -359,7 +395,8 @@
//褰撳墠涓哄悎鍚屾渶鍚庨樁娈�
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) {
+ if (lastNewConfirm.getTotalAmount().compareTo(new BigDecimal("0")) >= 0
+ && contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
//鏈夐浠樹笖瓒呰繃搴旀敹 鍏抽棴鍚堝悓鐘舵��
contract.setContractStatus(3);
contractMapper.updateById(contract);
@@ -380,15 +417,16 @@
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);
- if (!StrUtil.equals(contract.getContractCategory(),"water_house")) {
+ if (!StrUtil.equals(contract.getContractCategory(), "water_house")) {
// 1. 纭畾鐢ㄤ簬姣旇緝鐨勫熀鍑嗘棩鏈燂紙浼樺厛绾э細璁″垝浜よ揣鏃ユ湡 > 鍚堝悓鍒版湡鏃ユ湡锛�
Date deadline = subjectMatter.getPlannedDeliveryDate();
if (ObjUtil.isNull(deadline)) {
@@ -421,20 +459,103 @@
@Override
public R addContractOut(OutBoundAddDTO addDTO) {
- if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) {
- return R.failed("鍑哄簱鏍囩殑鐗╀笉鑳戒负绌�");
+ //鏍¢獙鍙傛暟
+ R<Contract> r = vailParam(addDTO);
+ if (!r.isOk()) {
+ return r;
}
- Contract contract = contractMapper.selectOne(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractNo, addDTO.getContractNo()).eq(Contract::getContractStatus, 2)
- .last("limit 1"));
- if (ObjUtil.isNull(contract)) {
- return R.failed("鍚堝悓淇℃伅鏌ヨ澶辫触");
- }
- //鍑哄簱鎵规
- String batchNumber = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
+ Contract contract = r.getData();
+ //鍑哄簱
+ handleOutBound(contract, addDTO);
+ //淇濆瓨璧勯噾鏄庣粏
+ BigDecimal outBoundAmount = savePaymentConfirm(contract, addDTO);
+ //鏇存柊鍚堝悓鐘舵�佸強闃舵
+ contract.setOutBoundAmout(outBoundAmount);
+ updateContractSchedule(contract);
+
+ return R.ok();
+ }
+
+ private void updateContractSchedule(Contract contract) {
+ List<ContractSubjectMatter> unComOutList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getContractId, contract.getId())
+ .ne(ContractSubjectMatter::getDeliveryStatus, 2));
+ if (CollUtil.isEmpty(unComOutList)) {
+ contract.setNextScheduleName("璐у埌绛炬敹");
+ }
+ contract.setBillingStatus("2");
+ contractMapper.updateById(contract);
+ }
+
+ private BigDecimal savePaymentConfirm(Contract contract, OutBoundAddDTO addDTO) {
+ //鏌ヨ鍚堝悓鏄惁鏈夊嚭搴撻樁娈�
+ ContractPaymentSchedule schedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())
+ .eq(ContractPaymentSchedule::getStageName, "鍙戣揣鍓�").last("limit 1"));
+ if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) {
+ schedule.setEffectiveDate(addDTO.getOutBoundTime());
+ schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays()));
+ scheduleMapper.updateById(schedule);
+ }
+ //灞ョ害鍑犵巼
+ processService.saveScheduleProcess(addDTO.getOutBoundTime(),schedule);
+
+ //璁$畻鍑哄簱浠锋牸
+ BigDecimal outAmount = new BigDecimal("0");
+ for (OutSubjectMatterAddDTO outSubjectMatterAddDTO : addDTO.getSubjectMatterList()) {
+ ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
+ .eq(ContractSubjectMatter::getContractId, contract.getId())
+ .eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode())
+ .eq(StrUtil.isNotBlank(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo())
+ .last("limit 1"));
+ outAmount = outAmount.add(outSubjectMatterAddDTO.getOutBoundNum().multiply(subjectMatter.getUnitPrice()));
+ }
+ //瀛樺湪鍙戣揣鍓嶆敹娆鹃樁娈�
+ if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
+ //鏂板褰撳墠闃舵搴旀敹
+ 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.getOutBoundTime());
+ //鎸夊嚭搴撴瘮渚嬭绠楀簲鏀�
+ currentConfim.setTransationAmount(schedule.getPlannedAmount().multiply(outAmount.divide(contract.getAmount(), 2, RoundingMode.HALF_UP)));
+ currentConfim.setReceivableAmount(currentConfim.getTransationAmount());
+ 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 outAmount;
+ }
+ currentConfim.setTotalAmount(currentConfim.getTransationAmount().multiply(new BigDecimal("-1")));
+ paymentConfirmMapper.insert(currentConfim);
+ //鍘嗗彶璧勯噾浣欓
+ processService.handleBeforeRemain(currentConfim, contract);
+ }
+ return outAmount;
+ }
+
+ private void handleOutBound(Contract contract, OutBoundAddDTO addDTO) {
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()));
@@ -449,231 +570,262 @@
}
subjectMatter.setActualDeliveryDate(addDTO.getOutBoundTime());
contractSubjectMatterMapper.updateById(subjectMatter);
- //
- OutBound outBound = new OutBound();
- outBound.setBatchNumber(batchNumber);
- 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.setSubjectMatterCode(outSubjectMatterAddDTO.getSubjectMatterCode());
- outBound.setSubjectMatterName(outSubjectMatterAddDTO.getSubjectMatterName());
- baseMapper.insert(outBound);
- //
- saveContractOutBound(contract, addDTO, subjectMatter, outBound.getId());
+ //淇濆瓨erp鍑哄簱
+ String batchNumber = genBatchNumber();
+ Long outBoundId = saveErpOutBound(contract, addDTO, outSubjectMatterAddDTO, batchNumber);
+ //淇濆瓨鍚堝悓鍑哄簱璁板綍
+ saveContractOutBound(contract, addDTO, subjectMatter, outBoundId);
});
- //褰撳墠鍑哄簱鍚堝悓鍑哄簱鏍囩殑鐗�
- List<ContractSubjectMatter> contractSubjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
- .eq(ContractSubjectMatter::getContractId, contract.getId()).ne(ContractSubjectMatter::getDeliveryStatus, 0));
- //鏌ヨ鍚堝悓鏄惁鏈夊嚭搴撻樁娈�
- ContractPaymentSchedule schedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())
- .eq(ContractPaymentSchedule::getStageName, "鍙戣揣鍓�"));
- //瀛樺湪鍑哄簱闃舵
- if (ObjUtil.isNotNull(schedule)) {
- //褰撳墠鍑哄簱閲戦
- BigDecimal outPirce = contractSubjectMatterList.stream()
- .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) {
- contract.setBillingStatus("1");
- contractMapper.updateById(contract);
+ }
+
+ private String genBatchNumber() {
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) ||
+ StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) {
+ return generateSMJContractCKNo();
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) {
+ return generateGYBContractCKNo();
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", ymj)) {
+ return generateYMJContractCKNo();
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", tfgs)) {
+ return generateTFContractCKNo();
+ }
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", jxc)) {
+ return generateJXCContractCKNo();
+ }
+ return "";
+ }
+
+ private Long saveErpOutBound(Contract contract, OutBoundAddDTO addDTO, OutSubjectMatterAddDTO outSubjectMatterAddDTO, String batchNumber) {
+ OutBound outBound = new OutBound();
+ outBound.setBatchNumber(batchNumber);
+ outBound.setOutBoundNum(outSubjectMatterAddDTO.getOutBoundNum());
+ outBound.setOutBoundAttNames(addDTO.getOutBoundAttNames());
+ outBound.setOutBoundAttPaths(addDTO.getOutBoundAttPaths());
+ outBound.setBusGuestName(contract.getPartyA());
+ outBound.setBusGuestId(contract.getPartyAId());
+ 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);
+ return outBound.getId();
+ }
+
+ private R<Contract> vailParam(OutBoundAddDTO addDTO) {
+ if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) {
+ return R.failed("鍑哄簱鏍囩殑鐗╀笉鑳戒负绌�");
+ }
+ // 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("鍚堝悓淇℃伅鏌ヨ澶辫触");
+ }
+ 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 (outPirce.compareTo(contract.getAmount()) == 0) {
- contract.setBillingStatus("2");
- contractMapper.updateById(contract);
- }
- //璁$畻鍙戣揣鍓嶅簲鏀舵洿鏂拌祫閲戞槑缁�
- PaymentConfirm paymentConfirm = new PaymentConfirm();
- paymentConfirm.setBusinessType("鍙戣揣鍓嶅簲鏀�");
- paymentConfirm.setBusGuestId(contract.getPartyAId());
- paymentConfirm.setBusGuestName(contract.getPartyA());
- paymentConfirm.setContractId(contract.getId());
- paymentConfirm.setContractName(contract.getContractName());
- paymentConfirm.setContractNo(contract.getContractNo());
- 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());
-
- //鏈�杩戝簲鏀�
- 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 (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
- paymentConfirmMapper.insert(paymentConfirm);
- }
- }
- } else {
- //鏃犱箣鍓嶉樁娈靛簲鏀�
- paymentConfirm.setTotalAmount(paymentConfirm.getTransationAmount().multiply(new BigDecimal("-1")));
- if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) {
- paymentConfirmMapper.insert(paymentConfirm);
- //瀹㈡埛浠樻瀹屾垚鍚堝悓
- 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 currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
- //鏂板褰撳墠鍚堝悓 璧勯噾杞叆
- PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
- "advanceAmount", "receivableAmount", "overdueAmount", "totalAmount");
- inConfirm.setBusinessType("璧勯噾杞叆");
- inConfirm.setConfirmTime(new Date());
- inConfirm.setTransationAmount(currentInSum);
- inConfirm.setTotalAmount(paymentConfirm.getTotalAmount().add(currentInSum));
- //鏇存柊褰撳墠闃舵瀹為檯鏀舵 鍜� 鏀舵鐘舵��
- schedule.setActualAmount(inConfirm.getTransationAmount());
- schedule.setPaymentStatus(2);
- 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")));
- schedule.setActualAmount(paymentConfirm.getTotalAmount().subtract(currentInSum));
- schedule.setPaymentStatus(1);
- }
- paymentConfirmMapper.insert(inConfirm);
- //鏇存柊褰撳墠闃舵瀹為檯鏀舵 鍜� 鏀舵鐘舵��
- scheduleMapper.updateById(schedule);
- }
- }
+ if (subjectMatter.getDeliveryStatus() == 0) {
+ if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getQuantity()) > 0) {
+ return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode() + "鍑哄簱鏁颁笉鑳借秴杩囧悎鍚屼腑鏁伴噺");
}
}
-
- //鏇存柊鍙戣揣鍓嶆敹娆剧敓鏁堟椂闂�
- 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());
- contractPaymentScheduleProcess.setContractName(schedule.getContractName());
- contractPaymentScheduleProcess.setScheduleId(schedule.getId());
- contractPaymentScheduleProcess.setScheduleName(schedule.getStageName());
- contractPaymentScheduleProcess.setProcessDate(addDTO.getOutBoundTime());
- ContractPaymentScheduleProcess lastProcess = scheduleProcessMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId())
- .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1"));
- if (ObjUtil.isNull(lastProcess)) {
- scheduleProcessMapper.insert(contractPaymentScheduleProcess);
+ if (subjectMatter.getDeliveryStatus() == 1) {
+ if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getRemainingQuantity()) > 0) {
+ return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode() + "鍑哄簱鏁颁笉鑳借秴杩囨湭鍑哄簱鏁伴噺");
}
}
-
- //鏌ヨ鏄惁鏈夊悗缁樁娈�
- List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
- .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) {
- //鏇存柊鍚堝悓涓嬩釜闃舵
- contract.setNextScheduleName(afterSchedule.get(0).getStageName());
- contractMapper.updateById(contract);
- }
- if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
-// schedule.setEffectiveEndDate(contract.getExpirationDate());
-// scheduleMapper.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.setContractStatus(3);
- contractMapper.updateById(contract);
- }
+ if (subjectMatter.getDeliveryStatus() == 2) {
+ return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode() + "宸插嚭搴撳畬鎴愶紝涓嶈兘瓒呴鍑哄簱");
}
}
+ return R.ok(contract);
+ }
+
+ /**
+ * 鐢熸垚鏍煎紡涓�: yyyyMMdd + 4浣嶅簭鍒楀彿 (渚嬪: 20260629000001)
+ */
+ public String generateSMJContractCKNo() {
+ // 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
+ String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
+
+ // 2. 鏋勫缓 Redis Key锛屾寜澶╅殧绂伙紝渚嬪: order:no:20260629
+ String key = "ZB-SMJ-CK:" + dateStr;
+
+ // 3. Redis 鍘熷瓙閫掑锛岃缃繃鏈熸椂闂翠负2澶╋紙闃叉Key鍫嗙Н锛屽悓鏃惰鐩栬法澶╄竟鐣屾儏鍐碉級
+ Long sequence = redisTemplate.opsForValue().increment(key, 1);
+ redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS);
+
+ // 4. 鏍煎紡鍖栧簭鍒楀彿锛屼笉瓒�6浣嶅墠琛�0
+ String seqStr = String.format("%04d", sequence);
+
+ // 5. 鎷兼帴杩斿洖
+ return "ZB-SMJ-CK-" + dateStr + seqStr;
+ }
+
+ public String generateYMJContractCKNo() {
+ // 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
+ String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
+
+ // 2. 鏋勫缓 Redis Key锛屾寜澶╅殧绂伙紝渚嬪: order:no:20260629
+ String key = "ZB-YMJ-CK:" + dateStr;
+
+ // 3. Redis 鍘熷瓙閫掑锛岃缃繃鏈熸椂闂翠负2澶╋紙闃叉Key鍫嗙Н锛屽悓鏃惰鐩栬法澶╄竟鐣屾儏鍐碉級
+ Long sequence = redisTemplate.opsForValue().increment(key, 1);
+ redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS);
+
+ // 4. 鏍煎紡鍖栧簭鍒楀彿锛屼笉瓒�6浣嶅墠琛�0
+ String seqStr = String.format("%04d", sequence);
+
+ // 5. 鎷兼帴杩斿洖
+ return "ZB-YMJ-CK-" + dateStr + seqStr;
+ }
+
+ public String generateJXCContractCKNo() {
+ // 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
+ String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
+
+ // 2. 鏋勫缓 Redis Key锛屾寜澶╅殧绂伙紝渚嬪: order:no:20260629
+ String key = "ZB-JXC-CK:" + dateStr;
+
+ // 3. Redis 鍘熷瓙閫掑锛岃缃繃鏈熸椂闂翠负2澶╋紙闃叉Key鍫嗙Н锛屽悓鏃惰鐩栬法澶╄竟鐣屾儏鍐碉級
+ Long sequence = redisTemplate.opsForValue().increment(key, 1);
+ redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS);
+
+ // 4. 鏍煎紡鍖栧簭鍒楀彿锛屼笉瓒�6浣嶅墠琛�0
+ String seqStr = String.format("%04d", sequence);
+
+ // 5. 鎷兼帴杩斿洖
+ return "ZB-JXC-CK-" + dateStr + seqStr;
+ }
+
+ public String generateTFContractCKNo() {
+ // 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
+ String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
+
+ // 2. 鏋勫缓 Redis Key锛屾寜澶╅殧绂伙紝渚嬪: order:no:20260629
+ String key = "ZB-TF-CK:" + dateStr;
+
+ // 3. Redis 鍘熷瓙閫掑锛岃缃繃鏈熸椂闂翠负2澶╋紙闃叉Key鍫嗙Н锛屽悓鏃惰鐩栬法澶╄竟鐣屾儏鍐碉級
+ Long sequence = redisTemplate.opsForValue().increment(key, 1);
+ redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS);
+
+ // 4. 鏍煎紡鍖栧簭鍒楀彿锛屼笉瓒�6浣嶅墠琛�0
+ String seqStr = String.format("%04d", sequence);
+
+ // 5. 鎷兼帴杩斿洖
+ return "ZB-TF-CK-" + dateStr + seqStr;
+ }
+
+ public String generateGYBContractCKNo() {
+ // 1. 鑾峰彇褰撳墠鏃ユ湡瀛楃涓�
+ String dateStr = DateUtil.format(new Date(), "yyyyMMdd");
+
+ // 2. 鏋勫缓 Redis Key锛屾寜澶╅殧绂伙紝渚嬪: order:no:20260629
+ String key = "ZB-GYB-CK:" + dateStr;
+
+ // 3. Redis 鍘熷瓙閫掑锛岃缃繃鏈熸椂闂翠负2澶╋紙闃叉Key鍫嗙Н锛屽悓鏃惰鐩栬法澶╄竟鐣屾儏鍐碉級
+ Long sequence = redisTemplate.opsForValue().increment(key, 1);
+ redisTemplate.expire(key, 1, java.util.concurrent.TimeUnit.DAYS);
+
+ // 4. 鏍煎紡鍖栧簭鍒楀彿锛屼笉瓒�6浣嶅墠琛�0
+ String seqStr = String.format("%04d", sequence);
+
+ // 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