From bce524765486d9cb726f37692c8647e1a5e7afcb Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期四, 30 四月 2026 16:32:50 +0800
Subject: [PATCH] fix(stock): 修复出库记录删除功能

---
 src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java |   52 ++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
index 1c6b9f5..3d95c67 100644
--- a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
+++ b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -12,30 +12,38 @@
 import com.ruoyi.stock.service.StockInventoryService;
 import com.ruoyi.stock.service.StockOutRecordService;
 import com.ruoyi.stock.service.StockUninventoryService;
-import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
 import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
 
 @Component
-@RequiredArgsConstructor
 public class StockUtils {
-    private final ProcurementRecordOutMapper procurementRecordOutMapper;
-    private final ProcurementRecordMapper procurementRecordMapper;
-    private final StockUninventoryService stockUninventoryService;
-    private final StockInventoryService stockInventoryService;
-    private final StockInRecordService stockInRecordService;
-    private final StockOutRecordService stockOutRecordService;
+    @Autowired
+    private ProcurementRecordOutMapper procurementRecordOutMapper;
+    @Autowired
+    private ProcurementRecordMapper procurementRecordMapper;
+    @Autowired
+    private StockUninventoryService stockUninventoryService;
+    @Autowired
+    private StockInventoryService stockInventoryService;
+    @Autowired
+    private StockInRecordService stockInRecordService;
+    @Autowired
+    private StockOutRecordService stockOutRecordService;
 
     /**
      * 涓嶅悎鏍煎叆搴擄紙瀹℃牳锛�
+     *
      * @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));
@@ -46,12 +54,13 @@
 
     /**
      * 涓嶅悎鏍煎叆搴擄紙涓嶅鏍革級
+     *
      * @param productModelId
      * @param quantity
      * @param recordType
      * @param recordId
      */
-    public void addUnStockNoReview(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
+    public void addUnStockNoReview(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
         StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
         stockUninventoryDto.setRecordId(recordId);
         stockUninventoryDto.setRecordType(String.valueOf(recordType));
@@ -62,12 +71,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));
@@ -78,12 +88,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));
@@ -94,12 +105,13 @@
 
     /**
      * 鍚堟牸鍏ュ簱锛堜笉瀹℃牳锛�
+     *
      * @param productModelId
      * @param quantity
      * @param recordType
      * @param recordId
      */
-    public void addStockNoReview(Long productModelId, BigDecimal quantity, String recordType,Long recordId) {
+    public void addStockNoReview(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
@@ -110,17 +122,21 @@
 
     /**
      * 鍚堟牸鍑哄簱
+     *
      * @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,String batchNo) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
         stockInventoryDto.setQualitity(quantity);
         stockInventoryDto.setProductModelId(productModelId);
+        if (batchNo !=null && !batchNo.isEmpty()) {
+            stockInventoryDto.setBatchNo(batchNo);
+        }
         stockInventoryService.subtractStockInventory(stockInventoryDto);
     }
 
@@ -133,12 +149,16 @@
             stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
         }
     }
+
     public void deleteStockOutRecord(Long recordId, String recordType) {
-        StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>()
+        List<StockOutRecord> one = stockOutRecordService.list(new QueryWrapper<StockOutRecord>()
                 .lambda().eq(StockOutRecord::getRecordId, recordId)
                 .eq(StockOutRecord::getRecordType, recordType));
         if (ObjectUtils.isNotEmpty(one)) {
-            stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
+            List<Long> idList = one.stream()
+                    .map(StockOutRecord::getId)
+                    .collect(Collectors.toList());
+            stockOutRecordService.batchDelete(idList);
         }
     }
 }

--
Gitblit v1.9.3