From 579d785db5254ad64b02eb58cb696c2447821dd3 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 27 五月 2026 11:25:44 +0800
Subject: [PATCH] feat(stock): 完善成品库存维度解析和生产投料扣减逻辑 - 在电压参数解析中增加非成品情况下的空值返回 - 在工艺路线成品类别判断中增加非成品情况下的空值返回 - 添加光检外观和包装工序跳过库存扣减的功能 - 修改生产投料环节仅对非光检包装工序执行库存扣减

---
 src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java |   45 ++++++++++++++++++++++++++-------------------
 1 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
index 989b4e4..4808e75 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -55,7 +55,7 @@
     private static final String PROCESS_VOLTAGE_SORT = "鐢靛帇鍒嗛��";
     private static final String PROCESS_OPTICAL_INSPECTION = "鍏夋澶栬";
     private static final String PROCESS_PACKAGING = "鍖呰";
-    private static final String INPUT_WEIGHT_PARAMETER = "鎶曞叆閲嶉噺";
+    private static final String INPUT_WEIGHT_PARAMETER = "鎶曞叆閲嶉噺/鏁伴噺";
     private static final String INPUT_WEIGHT_FIELD = "inputWeight";
     private static final Object PRODUCT_MAIN_NO_LOCK = new Object();
 
@@ -204,9 +204,9 @@
 
             BigDecimal previousCompleteQty =
                     previousWorkOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : previousWorkOrder.getCompleteQuantity();
-            if (currentReportedQty.add(reportQty).compareTo(previousCompleteQty) > 0) {
-                throw new ServiceException("鏈鎶ュ伐鏁伴噺瓒呰繃涓婇亾宸ュ簭鍙祦杞暟閲�");
-            }
+//            if (currentReportedQty.add(reportQty).compareTo(previousCompleteQty) > 0) {
+//                throw new ServiceException("鏈鎶ュ伐鏁伴噺瓒呰繃涓婇亾宸ュ簭鍙祦杞暟閲�");
+//            }
 
             List<ProductProcessRouteItem> previousItems = productProcessRouteItemMapper.selectList(
                     Wrappers.<ProductProcessRouteItem>lambdaQuery()
@@ -250,10 +250,10 @@
                     .filter(Objects::nonNull)
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
         }
-        if (productWorkOrder.getPlanQuantity() != null
-                && currentWorkOrderReportedQty.add(reportQty).compareTo(productWorkOrder.getPlanQuantity()) > 0) {
-            throw new ServiceException("鏈鎶ュ伐鏁伴噺瓒呰繃宸ュ崟鍙姤鏁伴噺");
-        }
+//        if (productWorkOrder.getPlanQuantity() != null
+//                && currentWorkOrderReportedQty.add(reportQty).compareTo(productWorkOrder.getPlanQuantity()) > 0) {
+//            throw new ServiceException("鏈鎶ュ伐鏁伴噺瓒呰繃宸ュ崟鍙姤鏁伴噺");
+//        }
 
         // 绗簲姝ワ細鐢熸垚鎶ュ伐鍗曞彿骞剁‘瀹氭姤宸ヤ汉淇℃伅
         String productNo;
@@ -327,6 +327,11 @@
         // 绗竷姝�-1锛氭姇鍏ユ暟閲忓己鍒跺彇鍓嶇浼犲叆鐨� bomInputQty
         BigDecimal inputBaseQty = bomInputQty;
 
+        // 绗竷姝�-2锛氬厜妫�澶栬鍜屽寘瑁呭伐搴忎笉鎵e噺搴撳瓨
+        String currentProcessName = productProcess.getName() == null ? "" : productProcess.getName().trim();
+        boolean shouldSkipStockDeduction = PROCESS_OPTICAL_INSPECTION.equals(currentProcessName) 
+                || PROCESS_PACKAGING.equals(currentProcessName);
+
         for (ProductStructureDto productStructureDto : productStructureDtos) {
             if (productStructureDto.getProductModelId() == null) {
                 throw new ServiceException("鎶曞叆鐗╂枡浜у搧鍨嬪彿涓嶈兘涓虹┖");
@@ -357,14 +362,16 @@
             productionProductInput.setProductMainId(productionProductMain.getId());
             productionProductInputMapper.insert(productionProductInput);
 
-            stockUtils.substractStock(
-                    productStructureDto.getProductModelId(),
-                    needQty,
-                    StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(),
-                    productionProductMain.getId(),
-                    null,
-                    null
-            );
+            if (!shouldSkipStockDeduction) {
+                stockUtils.substractStock(
+                        productStructureDto.getProductModelId(),
+                        needQty,
+                        StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(),
+                        productionProductMain.getId(),
+                        null,
+                        null
+                );
+            }
         }
 
         // 绗叓姝ワ細鍐欎骇鍑鸿褰曞苟璁$畻鏈鍚堟牸鏁伴噺
@@ -778,7 +785,7 @@
         try {
             parsed = JSON.parse(otherData);
         } catch (Exception ex) {
-            throw new ServiceException("鎶ュ伐鍙傛暟鏍煎紡閿欒锛屾棤娉曡В鏋愭姇鍏ラ噸閲�");
+            throw new ServiceException("鎶ュ伐鍙傛暟鏍煎紡閿欒锛屾棤娉曡В鏋愭姇鍏ラ噸閲�/鏁伴噺");
         }
         String inputWeight = StringUtils.trim(findParameterValue(parsed, INPUT_WEIGHT_PARAMETER));
         if (StringUtils.isBlank(inputWeight)) {
@@ -790,7 +797,7 @@
         try {
             return new BigDecimal(inputWeight);
         } catch (NumberFormatException ex) {
-            throw new ServiceException("鎶ュ伐鍙傛暟涓殑鎶曞叆閲嶉噺鏍煎紡閿欒");
+            throw new ServiceException("鎶ュ伐鍙傛暟涓殑鎶曞叆閲嶉噺/鏁伴噺鏍煎紡閿欒");
         }
     }
 
@@ -852,4 +859,4 @@
         }
         return null;
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3