From e02812df9217d3e50a368a8234c07c60c64c0ff4 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期三, 05 八月 2026 08:34:26 +0800
Subject: [PATCH] feat:新增石煤机 机械厂模版合同/客户数据主数据同步接口/合同履约进度新增质保结束操作/合同开票状态 修改为待开 可开 已开/出库逻辑完善
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java | 402 ++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 308 insertions(+), 94 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..5f9b207 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
@@ -6,6 +6,7 @@
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;
@@ -17,6 +18,8 @@
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;
@@ -41,6 +44,22 @@
private final ContractPaymentScheduleProcessMapper scheduleProcessMapper;
private final ContractOutBoundMapper contractOutBoundMapper;
private final DeliveryOverdueMapper deliveryOverdueMapper;
+ private final StringRedisTemplate redisTemplate;
+
+ @Value("${dept.smj}")
+ private String smj;
+
+ @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) {
@@ -78,11 +97,25 @@
//褰撳墠鍏ュ簱鏍囩殑鐗�
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)){
+ 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());
@@ -169,12 +202,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);
}
//璁$畻鍙戣揣鍓嶅簲鏀舵洿鏂拌祫閲戞槑缁�
@@ -380,11 +418,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);
@@ -424,17 +463,70 @@
if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) {
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);
+ //鍑哄簱鏁伴噺鏍¢獙
+ 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 (outSubjectMatterAddDTO.getOutBoundNum().compareTo(new BigDecimal("0"))==0){
+ return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"鍑哄簱鏁伴噺涓嶈兘涓�0");
+ }
+ 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()));
@@ -451,15 +543,33 @@
contractSubjectMatterMapper.updateById(subjectMatter);
//
OutBound outBound = new OutBound();
- outBound.setBatchNumber(batchNumber);
+ if (StrUtil.equals(SecurityUtils.getUser().getCompId()+"",smj)){
+ 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.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());
@@ -477,12 +587,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);
}
//璁$畻鍙戣揣鍓嶅簲鏀舵洿鏂拌祫閲戞槑缁�
@@ -496,36 +611,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")));
@@ -582,21 +692,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());
@@ -615,52 +711,16 @@
List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
.eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
.gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
+ .gt(ContractPaymentSchedule::getPaymentRatio, 0)
.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 (ArrayUtil.isNotEmpty(afterSchedule.toArray())&&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);
+ schedule.setEffectiveEndDate(contract.getExpirationDate());
+ scheduleMapper.updateById(schedule);
//鏇存柊鍚堝悓涓嬩釜闃舵
contract.setNextScheduleName("鏃�");
contractMapper.updateById(contract);
@@ -676,4 +736,158 @@
}
return R.ok();
}
+
+ /**
+ * 鐢熸垚鏍煎紡涓�: 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 (ArrayUtil.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 (ArrayUtil.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