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 |   51 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 38 insertions(+), 13 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 5cb6dda..8baa113 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -7,6 +7,7 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
 import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.web.domain.R;
 import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
@@ -42,10 +43,11 @@
 @AllArgsConstructor
 public class StockInventoryServiceImpl extends ServiceImpl<StockInventoryMapper, StockInventory> implements StockInventoryService {
 
-    private  StockInventoryMapper stockInventoryMapper;
+    private StockInventoryMapper stockInventoryMapper;
     private StockInRecordService stockInRecordService;
     private StockOutRecordService stockOutRecordService;
     private SalesLedgerProductMapper salesLedgerProductMapper;
+
     @Override
     public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) {
         return stockInventoryMapper.pagestockInventory(page, stockInventoryDto);
@@ -56,16 +58,31 @@
     @Transactional(rollbackFor = Exception.class)
     public Boolean addstockInventory(StockInventoryDto stockInventoryDto) {
         //鏂板鍏ュ簱璁板綍鍐嶆坊鍔犲簱瀛�
+        //  鏇存柊璁㈠崟浜у搧鍏ュ簱鐘舵�侊紙浠呭綋浼犲叆浜嗕骇鍝佽ID鏃讹級
+        if (stockInventoryDto.getSalesLedgerProductId() != null) {
+            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(stockInventoryDto.getSalesLedgerProductId());
+            if (salesLedgerProduct == null) {
+                throw new ServiceException("鍏ュ簱澶辫触,閿�鍞骇鍝佷笉瀛樺湪");
+            }
+            salesLedgerProduct.setProductStockStatus(1);
+            salesLedgerProductMapper.updateById(salesLedgerProduct);
+        }
+
         StockInRecordDto stockInRecordDto = new StockInRecordDto();
         stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());
         stockInRecordDto.setRecordType(stockInventoryDto.getRecordType());
         stockInRecordDto.setStockInNum(stockInventoryDto.getQualitity());
         stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
         stockInRecordDto.setType("0");
+        stockInRecordDto.setSalesLedgerId(stockInventoryDto.getSalesLedgerId());
+        stockInRecordDto.setSalesLedgerProductId(stockInventoryDto.getSalesLedgerProductId());
         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());
@@ -75,8 +92,8 @@
             newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
             newStockInventory.setWarnNum(stockInventoryDto.getWarnNum());
             stockInventoryMapper.insert(newStockInventory);
-        }else {
-             stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
+        } else {
+            stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
         }
         return true;
     }
@@ -92,8 +109,13 @@
         stockOutRecordDto.setStockOutNum(stockInventoryDto.getQualitity());
         stockOutRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
         stockOutRecordDto.setType("0");
+        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("浜у搧搴撳瓨涓嶅瓨鍦�");
         }
@@ -105,7 +127,10 @@
             throw new RuntimeException("搴撳瓨涓嶈冻鏃犳硶鍑哄簱");
         }
 
-        stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
+        int affectRows = stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
+        if (affectRows <= 0) {
+            throw new RuntimeException("搴撳瓨涓嶈冻鏃犳硶鍑哄簱");
+        }
         return true;
     }
 
@@ -132,7 +157,7 @@
                         stockInventoryDto.setQualitity(dto.getQualitity());
                         stockInventoryDto.setRemark(dto.getRemark());
                         stockInventoryDto.setWarnNum(dto.getWarnNum());
-                        if (ObjectUtils.isNotEmpty(dto.getLockedQuantity())&&dto.getLockedQuantity().compareTo(dto.getQualitity())>0) {
+                        if (ObjectUtils.isNotEmpty(dto.getLockedQuantity()) && dto.getLockedQuantity().compareTo(dto.getQualitity()) > 0) {
                             throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃鏈瀵煎叆鐨勫簱瀛樻暟閲�");
                         }
                         stockInventoryDto.setLockedQuantity(dto.getLockedQuantity());
@@ -171,28 +196,28 @@
 
         List<StockInventoryExportData> list = stockInventoryMapper.listStockInventoryExportData(stockInventoryDto);
         ExcelUtil<StockInventoryExportData> util = new ExcelUtil<>(StockInventoryExportData.class);
-        util.exportExcel(response,list, "搴撳瓨淇℃伅");
+        util.exportExcel(response, list, "搴撳瓨淇℃伅");
     }
 
     @Override
     public IPage<StockInRecordDto> stockInventoryPage(StockInventoryDto stockInventoryDto, Page page) {
-        return stockInventoryMapper.stockInventoryPage(stockInventoryDto,page);
+        return stockInventoryMapper.stockInventoryPage(stockInventoryDto, page);
     }
 
     @Override
     public IPage<StockInventoryDto> stockInAndOutRecord(StockInventoryDto stockInventoryDto, Page page) {
-        return stockInventoryMapper.stockInAndOutRecord(stockInventoryDto,page);
+        return stockInventoryMapper.stockInAndOutRecord(stockInventoryDto, page);
     }
 
     @Override
     public Boolean frozenStock(StockInventoryDto stockInventoryDto) {
         StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
-        if (stockInventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+        if (stockInventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) {
             throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃搴撳瓨鏁伴噺");
         }
         if (ObjectUtils.isEmpty(stockInventory.getLockedQuantity())) {
             stockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
-        }else {
+        } else {
             stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().add(stockInventoryDto.getLockedQuantity()));
         }
         return this.updateById(stockInventory);
@@ -201,7 +226,7 @@
     @Override
     public Boolean thawStock(StockInventoryDto stockInventoryDto) {
         StockInventory stockInventory = stockInventoryMapper.selectById(stockInventoryDto.getId());
-        if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+        if (stockInventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity()) < 0) {
             throw new RuntimeException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
         }
         stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity()));

--
Gitblit v1.9.3