From 6d3a76f894052209cad136ec9bff6ddcd43fc4e7 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 20 四月 2026 17:55:48 +0800
Subject: [PATCH] feat: 扫码时做限制,若采购台账已全部质检入库,APP扫码 入库时提示已入库。并且联动质检

---
 src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
index 5208f92..8baa113 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -58,13 +58,15 @@
     @Transactional(rollbackFor = Exception.class)
     public Boolean addstockInventory(StockInventoryDto stockInventoryDto) {
         //鏂板鍏ュ簱璁板綍鍐嶆坊鍔犲簱瀛�
-        //  鏇存柊浜у搧鍏ュ簱鐘舵��
-        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(stockInventoryDto.getSalesLedgerProductId());
-        if (salesLedgerProduct == null) {
-            throw new ServiceException("鍏ュ簱澶辫触,閿�鍞骇鍝佷笉瀛樺湪");
+        //  鏇存柊璁㈠崟浜у搧鍏ュ簱鐘舵�侊紙浠呭綋浼犲叆浜嗕骇鍝佽ID鏃讹級
+        if (stockInventoryDto.getSalesLedgerProductId() != null) {
+            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(stockInventoryDto.getSalesLedgerProductId());
+            if (salesLedgerProduct == null) {
+                throw new ServiceException("鍏ュ簱澶辫触,閿�鍞骇鍝佷笉瀛樺湪");
+            }
+            salesLedgerProduct.setProductStockStatus(1);
+            salesLedgerProductMapper.updateById(salesLedgerProduct);
         }
-        salesLedgerProduct.setProductStockStatus(1);
-        salesLedgerProductMapper.updateById(salesLedgerProduct);
 
         StockInRecordDto stockInRecordDto = new StockInRecordDto();
         stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());
@@ -77,7 +79,10 @@
         stockInRecordService.add(stockInRecordDto);
         //鍐嶈繘琛屾柊澧炲簱瀛樻暟閲忓簱瀛�
         //鍏堟煡璇㈠簱瀛樿〃涓殑浜у搧鏄惁瀛樺湪锛屼笉瀛樺湪鏂板锛屽瓨鍦ㄦ洿鏂�
-        StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()));
+        List<StockInventory> stockInventories = stockInventoryMapper.selectList(new QueryWrapper<StockInventory>().lambda()
+                .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())
+                .orderByDesc(StockInventory::getId));
+        StockInventory oldStockInventory = (stockInventories == null || stockInventories.isEmpty()) ? null : stockInventories.get(0);
         if (ObjectUtils.isEmpty(oldStockInventory)) {
             StockInventory newStockInventory = new StockInventory();
             newStockInventory.setProductModelId(stockInventoryDto.getProductModelId());
@@ -107,7 +112,10 @@
         stockOutRecordDto.setSalesLedgerId(stockInventoryDto.getSalesLedgerId());
         stockOutRecordDto.setSalesLedgerProductId(stockInventoryDto.getSalesLedgerProductId());
         stockOutRecordService.add(stockOutRecordDto);
-        StockInventory oldStockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId()));
+        List<StockInventory> stockInventories = stockInventoryMapper.selectList(new QueryWrapper<StockInventory>().lambda()
+                .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())
+                .orderByDesc(StockInventory::getId));
+        StockInventory oldStockInventory = (stockInventories == null || stockInventories.isEmpty()) ? null : stockInventories.get(0);
         if (ObjectUtils.isEmpty(oldStockInventory)) {
             throw new RuntimeException("浜у搧搴撳瓨涓嶅瓨鍦�");
         }

--
Gitblit v1.9.3