From 4295247f77b9ae0c64db3977b5717b68f86c1273 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 09 四月 2026 14:14:05 +0800
Subject: [PATCH] fix: 销售产品开始生产不能删除和编辑
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java | 48 ++++++++++++++++++++++++
src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java | 30 ++++++++++-----
2 files changed, 68 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
index 819ce65..4bb3a84 100644
--- a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
+++ b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -21,7 +21,9 @@
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
@@ -35,12 +37,13 @@
/**
* 涓嶅悎鏍煎叆搴�
+ *
* @param productModelId
* @param quantity
* @param recordType
* @param recordId
*/
- public void addUnStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
+ public void addUnStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
stockUninventoryDto.setRecordId(recordId);
stockUninventoryDto.setRecordType(String.valueOf(recordType));
@@ -51,12 +54,13 @@
/**
* 涓嶅悎鏍煎嚭搴�
+ *
* @param productModelId
* @param quantity
* @param recordType
* @param recordId
*/
- public void subtractUnStock(Long productModelId, BigDecimal quantity, Integer recordType,Long recordId) {
+ public void subtractUnStock(Long productModelId, BigDecimal quantity, Integer recordType, Long recordId) {
StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
stockUninventoryDto.setRecordId(recordId);
stockUninventoryDto.setRecordType(String.valueOf(recordType));
@@ -67,12 +71,13 @@
/**
* 鍚堟牸鍏ュ簱
+ *
* @param productModelId
* @param quantity
* @param recordType
* @param recordId
*/
- public void addStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
+ public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
StockInventoryDto stockInventoryDto = new StockInventoryDto();
stockInventoryDto.setRecordId(recordId);
stockInventoryDto.setRecordType(String.valueOf(recordType));
@@ -83,12 +88,13 @@
/**
* 鍚堟牸鍑哄簱
+ *
* @param productModelId
* @param quantity
* @param recordType
* @param recordId
*/
- public void substractStock(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
+ public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
StockInventoryDto stockInventoryDto = new StockInventoryDto();
stockInventoryDto.setRecordId(recordId);
stockInventoryDto.setRecordType(String.valueOf(recordType));
@@ -99,19 +105,23 @@
//涓嶅悎鏍煎簱瀛樺垹闄�
public void deleteStockInRecord(Long recordId, String recordType) {
- StockInRecord one = stockInRecordService.getOne(new QueryWrapper<StockInRecord>()
+ List<StockInRecord> stockInRecords = stockInRecordService.list(new QueryWrapper<StockInRecord>()
.lambda().eq(StockInRecord::getRecordId, recordId)
.eq(StockInRecord::getRecordType, recordType));
- if (ObjectUtils.isNotEmpty(one)) {
- stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
+ if (ObjectUtils.isNotEmpty(stockInRecords)) {
+ List<Long> collect = stockInRecords.stream().map(StockInRecord::getId).collect(Collectors.toList());
+ stockInRecordService.batchDelete(collect);
}
}
+
public void deleteStockOutRecord(Long recordId, String recordType) {
- StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>()
+ List<StockOutRecord> stockOutRecords = stockOutRecordService.list(new QueryWrapper<StockOutRecord>()
.lambda().eq(StockOutRecord::getRecordId, recordId)
.eq(StockOutRecord::getRecordType, recordType));
- if (ObjectUtils.isNotEmpty(one)) {
- stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
+
+ if (ObjectUtils.isNotEmpty(stockOutRecords)) {
+ List<Long> collect = stockOutRecords.stream().map(StockOutRecord::getId).collect(Collectors.toList());
+ stockOutRecordService.batchDelete(collect);
}
}
}
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
index 68b52cb..2bab798 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -158,6 +158,8 @@
return 0;
}
+ checkProductionDataExist(Arrays.asList(ids));
+
// 1. 鍏堟煡璇㈣鍒犻櫎鐨勫瓙琛ㄨ褰曪紝鑾峰彇瀵瑰簲鐨� salesLedgerId
List<SalesLedgerProduct> deletedProducts = salesLedgerProductMapper.selectBatchIds(Arrays.asList(ids));
if (deletedProducts.isEmpty()) {
@@ -222,6 +224,8 @@
result = salesLedgerProductMapper.insert(salesLedgerProduct);
addProductionData(salesLedgerProduct);
} else {
+ checkProductionDataExist(Collections.singletonList(salesLedgerProduct.getId()));
+
//鏌ヨ鍘熸湰鐨勪骇鍝佸瀷鍙穒d
salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity());
result = salesLedgerProductMapper.updateById(salesLedgerProduct);
@@ -334,6 +338,50 @@
}
/**
+ * 妫�鏌ユ槸鍚︽湁鎶ュ伐鏁版嵁
+ */
+ public void checkProductionDataExist(List<Long> productIds) {
+ if (org.springframework.util.CollectionUtils.isEmpty(productIds)) {
+ return;
+ }
+ // 鏌ヨproductOrder
+ List<ProductOrder> productOrders = productOrderMapper.selectList(new LambdaQueryWrapper<ProductOrder>()
+ .in(ProductOrder::getSaleLedgerProductId, productIds));
+ if (!CollectionUtils.isEmpty(productOrders)) {
+ List<Long> orderIds = productOrders.stream()
+ .map(ProductOrder::getId)
+ .collect(Collectors.toList());
+
+ // 鏌ヨprocessRouteItems
+ List<ProductProcessRouteItem> allRouteItems = productProcessRouteItemMapper.selectList(new LambdaQueryWrapper<ProductProcessRouteItem>()
+ .in(ProductProcessRouteItem::getProductOrderId, orderIds));
+
+ if (!CollectionUtils.isEmpty(allRouteItems)) {
+ // 鑾峰彇宸ュ簭椤笽D
+ List<Long> routeItemIds = allRouteItems.stream()
+ .map(ProductProcessRouteItem::getId)
+ .collect(Collectors.toList());
+
+ // 鏌ヨ鍏宠仈鐨勫伐鍗旾D
+ List<ProductWorkOrder> workOrders = productWorkOrderMapper.selectList(new LambdaQueryWrapper<ProductWorkOrder>()
+ .in(ProductWorkOrder::getProductProcessRouteItemId, routeItemIds));
+ if (!CollectionUtils.isEmpty(workOrders)) {
+ List<Long> workOrderIds = workOrders.stream()
+ .map(ProductWorkOrder::getId)
+ .collect(Collectors.toList());
+
+ // 鏌ヨ鍏宠仈鐨勭敓浜т富琛↖D鏄惁鏈夋暟鎹�
+ Long count = productionProductMainMapper.selectCount(new LambdaQueryWrapper<ProductionProductMain>()
+ .in(ProductionProductMain::getWorkOrderId, workOrderIds));
+ if (count != null && count > 0L) {
+ throw new RuntimeException("褰撳墠閿�鍞鍗曞凡鏈夋姤宸ユ暟鎹紝涓嶈兘鍒犻櫎鍜屼慨鏀�");
+ }
+ }
+ }
+ }
+ }
+
+ /**
* 鍒犻櫎鐢熶骇鏁版嵁
*/
public void deleteProductionData(List<Long> productIds) {
--
Gitblit v1.9.3