From 4336d99906953517399187638925817d969c4e10 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期四, 14 五月 2026 14:18:14 +0800
Subject: [PATCH] refactor(stock): 优化库存管理和产品模型查询功能

---
 src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java |   54 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
index 2fc5eea..2840974 100644
--- a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
+++ b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -34,7 +34,7 @@
     private final StockInventoryMapper stockInventoryMapper;
 
     /**
-     * 涓嶅悎鏍煎叆搴�
+     * 娑撳秴鎮庨弽鐓庡弳鎼�?
      *
      * @param productModelId
      * @param quantity
@@ -47,11 +47,11 @@
         stockUninventoryDto.setRecordType(String.valueOf(recordType));
         stockUninventoryDto.setQualitity(quantity);
         stockUninventoryDto.setProductModelId(productModelId);
-        stockUninventoryService.addStockInRecordOnly(stockUninventoryDto);
+        stockUninventoryService.addStockUninventory(stockUninventoryDto);
     }
 
     /**
-     * 涓嶅悎鏍煎嚭搴�
+     * 娑撳秴鎮庨弽鐓庡毉鎼�?
      *
      * @param productModelId
      * @param quantity
@@ -68,38 +68,49 @@
     }
 
     /**
-     * 鍚堟牸鍏ュ簱
+     * 閸氬牊鐗搁崗銉ョ氨
      * @param recordType
      * @param recordId
      */
     public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+        addStock(productModelId, quantity, recordType, recordId, resolveWarehouseInfoId(null, productModelId, null));
+    }
+
+    public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, Long warehouseInfoId) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
         stockInventoryDto.setQualitity(quantity);
         stockInventoryDto.setProductModelId(productModelId);
+        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
         stockInventoryService.addStockInRecordOnly(stockInventoryDto);
     }
 
     /**
-     * 鍚堟牸鍏ュ簱甯︽壒娆″彿
+     * 閸氬牊鐗搁崗銉ョ氨鐢附澹掑▎鈥冲娇
      * @param productModelId
      * @param quantity
      * @param recordType
      * @param recordId
      */
     public StockInRecordDto addStockWithBatchNo(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo) {
+        return addStockWithBatchNo(productModelId, quantity, recordType, recordId, batchNo,
+                resolveWarehouseInfoId(null, productModelId, batchNo));
+    }
+
+    public StockInRecordDto addStockWithBatchNo(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo, Long warehouseInfoId) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
         stockInventoryDto.setQualitity(quantity);
         stockInventoryDto.setProductModelId(productModelId);
         stockInventoryDto.setBatchNo(batchNo);
-       return stockInventoryService.addStockInRecordOnly(stockInventoryDto);
+        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
+        return stockInventoryService.addStockInRecordOnly(stockInventoryDto);
     }
 
     /**
-     * 鍚堟牸鍑哄簱
+     * 閸氬牊鐗搁崙鍝勭氨
      *
      * @param productModelId
      * @param quantity
@@ -107,26 +118,36 @@
      * @param recordId
      */
     public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+        substractStock(productModelId, quantity, recordType, recordId, resolveWarehouseInfoId(null, productModelId, null));
+    }
+
+    public void substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, Long warehouseInfoId) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
         stockInventoryDto.setQualitity(quantity);
         stockInventoryDto.setProductModelId(productModelId);
+        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
         stockInventoryService.subtractStockInventory(stockInventoryDto);
     }
 
     public StockOutRecordDto substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo) {
+        return substractStock(productModelId, quantity, recordType, recordId, batchNo,
+                resolveWarehouseInfoId(null, productModelId, batchNo));
+    }
+
+    public StockOutRecordDto substractStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo, Long warehouseInfoId) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
         stockInventoryDto.setQualitity(quantity);
         stockInventoryDto.setProductModelId(productModelId);
         stockInventoryDto.setBatchNo(batchNo);
-       return stockInventoryService.addStockOutRecordOnly(stockInventoryDto);
+        stockInventoryDto.setWarehouseInfoId(warehouseInfoId);
+        return stockInventoryService.addStockOutRecordOnly(stockInventoryDto);
     }
 
     /**
-     * 鍙戣揣瀹℃壒鐘舵�佹洿鏀�
      * @param recordType
      * @param recordId
      */
@@ -138,18 +159,18 @@
         stockOutRecordService.updateById(stockOutRecord);
     }
 
-    //涓嶅悎鏍煎簱瀛樺垹闄�
     public void deleteStockInRecord(Long recordId, String recordType) {
         StockInRecord one = stockInRecordService.getOne(new QueryWrapper<StockInRecord>()
                 .lambda().eq(StockInRecord::getRecordId, recordId)
                 .eq(StockInRecord::getRecordType, recordType));
         if (ObjectUtils.isNotEmpty(one)) {
             stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
-            //灏嗗簱瀛樺噺鍥炴潵
             StockInventoryDto stockInventoryDto = new StockInventoryDto();
             stockInventoryDto.setRecordId(recordId);
             stockInventoryDto.setRecordType(recordType);
             stockInventoryDto.setQualitity(one.getStockInNum());
+            stockInventoryDto.setProductModelId(one.getProductModelId());
+            stockInventoryDto.setBatchNo(one.getBatchNo());
             stockInventoryMapper.updateSubtractStockInventory((stockInventoryDto));
         }
 
@@ -161,13 +182,22 @@
                 .eq(StockOutRecord::getRecordType, recordType));
         if (ObjectUtils.isNotEmpty(one)) {
             stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
-            //灏嗗簱瀛樺姞鍥炴潵
             StockInventoryDto stockInventoryDto = new StockInventoryDto();
             stockInventoryDto.setRecordId(recordId);
             stockInventoryDto.setRecordType(recordType);
             stockInventoryDto.setQualitity(one.getStockOutNum());
+            stockInventoryDto.setProductModelId(one.getProductModelId());
+            stockInventoryDto.setBatchNo(one.getBatchNo());
+            stockInventoryDto.setWarehouseInfoId(one.getWarehouseInfoId());
             stockInventoryMapper.updateAddStockInventory((stockInventoryDto));
         }
 
     }
+
+    private Long resolveWarehouseInfoId(Long warehouseInfoId, Long productModelId, String batchNo) {
+        if (warehouseInfoId == null) {
+            throw new IllegalArgumentException("warehouseInfoId涓嶈兘涓虹┖");
+        }
+        return warehouseInfoId;
+    }
 }

--
Gitblit v1.9.3