From 260dd6fe156265832544715192ce1491e9c2afd6 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 26 六月 2026 13:41:13 +0800
Subject: [PATCH] fix(stock): 解决库存管理中的重复键异常问题 - 在采购台账服务中添加净合同金额字段设置 - 在销售台账服务中添加净合同金额字段设置 - 在入库记录服务中为库存插入操作添加重复键异常处理 - 在入库记录服务中为非库存插入操作添加重复键异常处理 - 在库存服务中为库存插入操作添加重复键异常处理 - 统一处理数据库唯一键约束冲突,避免系统错误
---
src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java | 39 ++++++++++++++++++++++++++++++++++-----
1 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
index 5e31cfa..4503e4d 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
@@ -104,9 +104,19 @@
}).collect(Collectors.toList());
salesQuotationProductService.saveBatch(products);
// 鎶ヤ环瀹℃壒
+ ApprovalTemplate approvalTemplate = approvalTemplateMapper.selectOne(
+ new LambdaQueryWrapper<ApprovalTemplate>()
+ .eq(ApprovalTemplate::getBusinessType, 6L)
+ .eq(ApprovalTemplate::getDeleted, 0)
+ .orderByDesc(ApprovalTemplate::getId)
+ .last("LIMIT 1")
+ );
+ if (approvalTemplate == null) {
+ throw new RuntimeException("璇峰厛閰嶇疆鎶ヤ环瀹℃壒妯℃澘");
+ }
ApprovalInstanceDto approvalInstance = new ApprovalInstanceDto();
- approvalInstance.setTemplateId(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getId());
- approvalInstance.setTemplateName(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getTemplateName());
+ approvalInstance.setTemplateId(approvalTemplate.getId());
+ approvalInstance.setTemplateName(approvalTemplate.getTemplateName());
approvalInstance.setBusinessId(salesQuotation.getId());
approvalInstance.setBusinessType(6L);
approvalInstance.setCurrentLevel(1);
@@ -150,9 +160,19 @@
// 鍏堢粨鏉熶箣鍓嶆湭缁撴潫鐨勬姤浠峰鎵�
approvalInstanceService.lambdaUpdate().set(ApprovalInstance::getStatus,"REJECTED").eq(ApprovalInstance::getBusinessId,salesQuotation.getId()).eq(ApprovalInstance::getBusinessType,6L).update();
+ ApprovalTemplate approvalTemplate = approvalTemplateMapper.selectOne(
+ new LambdaQueryWrapper<ApprovalTemplate>()
+ .eq(ApprovalTemplate::getBusinessType, 6L)
+ .eq(ApprovalTemplate::getDeleted, 0)
+ .orderByDesc(ApprovalTemplate::getId)
+ .last("LIMIT 1")
+ );
+ if (approvalTemplate == null) {
+ throw new RuntimeException("璇峰厛閰嶇疆鎶ヤ环瀹℃壒妯℃澘");
+ }
ApprovalInstanceDto approvalInstance = new ApprovalInstanceDto();
- approvalInstance.setTemplateId(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getId());
- approvalInstance.setTemplateName(approvalTemplateMapper.selectOne(new LambdaQueryWrapper<ApprovalTemplate>().eq(ApprovalTemplate::getBusinessType,6L).orderByDesc(ApprovalTemplate::getId).last("LIMIT 1")).getTemplateName());
+ approvalInstance.setTemplateId(approvalTemplate.getId());
+ approvalInstance.setTemplateName(approvalTemplate.getTemplateName());
approvalInstance.setBusinessId(salesQuotation.getId());
approvalInstance.setBusinessType(6L);
approvalInstance.setCurrentLevel(1);
@@ -174,7 +194,16 @@
if(salesQuotation==null) return false;
salesQuotationMapper.deleteById(id);
salesQuotationProductMapper.delete(new LambdaQueryWrapper<SalesQuotationProduct>().eq(SalesQuotationProduct::getSalesQuotationId, id));
- // 鍒犻櫎鎶ヤ环瀹℃壒
+ // 鍒犻櫎鎶ヤ环瀹℃壒瀹炰緥锛圓pprovalInstance锛�
+ ApprovalInstance approvalInstance = approvalInstanceService.getOne(new LambdaQueryWrapper<ApprovalInstance>()
+ .eq(ApprovalInstance::getBusinessId, id)
+ .eq(ApprovalInstance::getBusinessType, 6L)
+ .eq(ApprovalInstance::getDeleted, 0)
+ .last("LIMIT 1"));
+ if(approvalInstance != null){
+ approvalInstanceService.delete(Collections.singletonList(approvalInstance.getId()));
+ }
+ // 鍒犻櫎鎶ヤ环瀹℃壒娴佺▼锛圓pproveProcess锛�
ApproveProcess one = approveProcessService.getOne(new LambdaQueryWrapper<ApproveProcess>()
.eq(ApproveProcess::getApproveType, 6)
.eq(ApproveProcess::getApproveDelete, IsDeleteEnum.NOT_DELETED)
--
Gitblit v1.9.3