From 32bf2bed7dc2a14afeb50b72723570eaf295e316 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 28 五月 2026 09:53:35 +0800
Subject: [PATCH] feat(purchase): 新增采购草稿简易新增功能并完善生产订单库存数量显示

---
 src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java
index 598ae6b..3d9a515 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java
@@ -189,6 +189,7 @@
             return Collections.emptyList();
         }
         List<ProductionOrderPickVo> detailList = baseMapper.listPickedDetailByOrderId(productionOrderId);
+        fillStockQuantity(detailList);
         fillBatchNoList(detailList);
         fillSelectableBatchNoList(detailList);
         return detailList;
@@ -430,7 +431,7 @@
         BigDecimal totalReturnQty = oldReturnQty.add(currentReturnQty);
         if (currentReturnQty.compareTo(BigDecimal.ZERO) > 0) {
             String returnBatchNo = resolveInventoryBatchNoFromStored(oldPick.getBatchNo());
-            addInventory(oldPick.getId(), oldPick.getProductModelId(), returnBatchNo, currentReturnQty, FEED_RETURN_IN_RECORD_TYPE);
+            addInventoryRecordOnly(oldPick.getId(), oldPick.getProductModelId(), returnBatchNo, currentReturnQty, FEED_RETURN_IN_RECORD_TYPE);
         }
 
         BigDecimal actualQty = defaultDecimal(oldPick.getQuantity())
@@ -734,6 +735,31 @@
             throw ex;
         } catch (Exception ex) {
             throw new ServiceException("鍥炶ˉ搴撳瓨澶辫触锛�" + ex.getMessage());
+        }
+    }
+
+    private void addInventoryRecordOnly(Long recordId,
+                                        Long productModelId,
+                                        String batchNo,
+                                        BigDecimal quantity,
+                                        String stockInRecordType) {
+        // 浠呰褰曞叆搴撶敵璇凤紝涓嶅仛瀹℃牳閫氳繃銆�
+        BigDecimal addQuantity = defaultDecimal(quantity);
+        if (addQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+            return;
+        }
+        try {
+            StockInventoryDto stockInventoryDto = new StockInventoryDto();
+            stockInventoryDto.setProductModelId(productModelId);
+            stockInventoryDto.setBatchNo(batchNo);
+            stockInventoryDto.setQualitity(addQuantity);
+            stockInventoryDto.setRecordType(stockInRecordType);
+            stockInventoryDto.setRecordId(recordId == null ? 0L : recordId);
+            stockInventoryService.addStockInRecordOnly(stockInventoryDto);
+        } catch (ServiceException ex) {
+            throw ex;
+        } catch (Exception ex) {
+            throw new ServiceException("閫�鏂欏叆搴撹褰曚繚瀛樺け璐ワ細" + ex.getMessage());
         }
     }
 
@@ -1096,6 +1122,34 @@
         }
     }
 
+    private void fillStockQuantity(List<ProductionOrderPickVo> detailList) {
+        if (detailList == null || detailList.isEmpty()) {
+            return;
+        }
+        Set<Long> productModelIdSet = detailList.stream()
+                .map(ProductionOrderPickVo::getProductModelId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        if (productModelIdSet.isEmpty()) {
+            return;
+        }
+        List<StockInventory> stockList = stockInventoryMapper.selectList(
+                Wrappers.<StockInventory>lambdaQuery()
+                        .in(StockInventory::getProductModelId, productModelIdSet));
+        Map<Long, BigDecimal> stockQuantityMap = new HashMap<>();
+        for (StockInventory stockInventory : stockList) {
+            if (stockInventory == null || stockInventory.getProductModelId() == null) {
+                continue;
+            }
+            stockQuantityMap.merge(stockInventory.getProductModelId(),
+                    defaultDecimal(stockInventory.getQualitity()),
+                    BigDecimal::add);
+        }
+        for (ProductionOrderPickVo detail : detailList) {
+            detail.setStockQuantity(stockQuantityMap.getOrDefault(detail.getProductModelId(), BigDecimal.ZERO));
+        }
+    }
+
     private String buildBatchNoGroupKey(ProductionOrderPickVo detail) {
         // 鏋勫缓鎵规鑱氬悎鍒嗙粍閿��
         return detail.getProductionOrderId() + "|"

--
Gitblit v1.9.3