From 8beb176e14312b8e7ca43a25f8ec1386157502f9 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 28 五月 2026 14:40:42 +0800
Subject: [PATCH] feat:采购批量审核-质检-入库

---
 src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java |   71 ++++++++++++++++++++++++++---------
 1 files changed, 53 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
index b7e0478..9b8735f 100644
--- a/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
+++ b/src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -3,11 +3,11 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.ruoyi.common.enums.ReviewStatusEnum;
 import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper;
 import com.ruoyi.procurementrecord.mapper.ProcurementRecordOutMapper;
 import com.ruoyi.stock.dto.StockInventoryDto;
 import com.ruoyi.stock.dto.StockUninventoryDto;
-import com.ruoyi.stock.mapper.StockInventoryMapper;
 import com.ruoyi.stock.pojo.StockInRecord;
 import com.ruoyi.stock.pojo.StockOutRecord;
 import com.ruoyi.stock.service.StockInRecordService;
@@ -18,6 +18,7 @@
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.Collections;
 
 @Component
@@ -29,7 +30,6 @@
     private final StockInventoryService stockInventoryService;
     private final StockInRecordService stockInRecordService;
     private final StockOutRecordService stockOutRecordService;
-    private final StockInventoryMapper stockInventoryMapper;
 
     /**
      * 涓嶅悎鏍煎叆搴�
@@ -45,6 +45,24 @@
         stockUninventoryDto.setRecordType(String.valueOf(recordType));
         stockUninventoryDto.setQualitity(quantity);
         stockUninventoryDto.setProductModelId(productModelId);
+        stockUninventoryService.addStockInRecordOnly(stockUninventoryDto);
+    }
+
+    /**
+     * 涓嶅悎鏍煎叆搴撳甫鎵规鍙�
+     *
+     * @param productModelId
+     * @param quantity
+     * @param recordType
+     * @param recordId
+     */
+    public void addUnStockWithBatchNo(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo) {
+        StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
+        stockUninventoryDto.setRecordId(recordId);
+        stockUninventoryDto.setRecordType(String.valueOf(recordType));
+        stockUninventoryDto.setQualitity(quantity);
+        stockUninventoryDto.setProductModelId(productModelId);
+        stockUninventoryDto.setBatchNo(batchNo);
         stockUninventoryService.addStockInRecordOnly(stockUninventoryDto);
     }
 
@@ -71,11 +89,21 @@
      * @param recordId
      */
     public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId) {
+        addStock(productModelId, quantity, recordType, recordId, null);
+    }
+
+    /**
+     * 鍚堟牸鍏ュ簱
+     * @param recordType
+     * @param recordId
+     */
+    public void addStock(Long productModelId, BigDecimal quantity, String recordType, Long recordId, LocalDateTime createTime) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
         stockInventoryDto.setQualitity(quantity);
         stockInventoryDto.setProductModelId(productModelId);
+        stockInventoryDto.setCreateTime(createTime);
         stockInventoryService.addStockInRecordOnly(stockInventoryDto);
     }
 
@@ -87,12 +115,22 @@
      * @param recordId
      */
     public void addStockWithBatchNo(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo) {
+        addStockWithBatchNo(productModelId, quantity, recordType, recordId, batchNo, null);
+    }
+
+    /**
+     * 鍚堟牸鍏ュ簱甯︽壒娆″彿
+     * @param recordType
+     * @param recordId
+     */
+    public void addStockWithBatchNo(Long productModelId, BigDecimal quantity, String recordType, Long recordId, String batchNo, LocalDateTime createTime) {
         StockInventoryDto stockInventoryDto = new StockInventoryDto();
         stockInventoryDto.setRecordId(recordId);
         stockInventoryDto.setRecordType(String.valueOf(recordType));
         stockInventoryDto.setQualitity(quantity);
         stockInventoryDto.setProductModelId(productModelId);
         stockInventoryDto.setBatchNo(batchNo);
+        stockInventoryDto.setCreateTime(createTime);
         stockInventoryService.addStockInRecordOnly(stockInventoryDto);
     }
 
@@ -132,31 +170,28 @@
     public void deleteStockInRecord(Long recordId, String recordType) {
         StockInRecord one = stockInRecordService.getOne(new QueryWrapper<StockInRecord>()
                 .lambda().eq(StockInRecord::getRecordId, recordId)
-                .eq(StockInRecord::getRecordType, recordType));
+                .eq(StockInRecord::getRecordType, recordType), false);
         if (ObjectUtils.isNotEmpty(one)) {
-            stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
-            //灏嗗簱瀛樺噺鍥炴潵
-            StockInventoryDto stockInventoryDto = new StockInventoryDto();
-            stockInventoryDto.setRecordId(recordId);
-            stockInventoryDto.setRecordType(recordType);
-            stockInventoryDto.setQualitity(one.getStockInNum());
-            stockInventoryMapper.updateSubtractStockInventory((stockInventoryDto));
+            if (ReviewStatusEnum.APPROVED.getCode().equals(one.getApprovalStatus())) {
+                stockInRecordService.batchDelete(Collections.singletonList(one.getId()));
+            } else {
+                stockInRecordService.removeById(one.getId());
+            }
         }
 
     }
 
+    //鍒犻櫎鍑哄簱璁板綍
     public void deleteStockOutRecord(Long recordId, String recordType) {
         StockOutRecord one = stockOutRecordService.getOne(new QueryWrapper<StockOutRecord>()
                 .lambda().eq(StockOutRecord::getRecordId, recordId)
-                .eq(StockOutRecord::getRecordType, recordType));
+                .eq(StockOutRecord::getRecordType, recordType), false);
         if (ObjectUtils.isNotEmpty(one)) {
-            stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
-            //灏嗗簱瀛樺姞鍥炴潵
-            StockInventoryDto stockInventoryDto = new StockInventoryDto();
-            stockInventoryDto.setRecordId(recordId);
-            stockInventoryDto.setRecordType(recordType);
-            stockInventoryDto.setQualitity(one.getStockOutNum());
-            stockInventoryMapper.updateAddStockInventory((stockInventoryDto));
+            if (ReviewStatusEnum.APPROVED.getCode().equals(one.getApprovalStatus())) {
+                stockOutRecordService.batchDelete(Collections.singletonList(one.getId()));
+            } else {
+                stockOutRecordService.removeById(one.getId());
+            }
         }
 
     }

--
Gitblit v1.9.3