From 6256daf29f4c44944fa71a7dbd211b06bf1a495d Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 25 五月 2026 09:46:20 +0800
Subject: [PATCH] feat: 报工投入用“投入重量/数量”

---
 src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java |   95 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 93 insertions(+), 2 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 5b1177c..e5b5843 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -1,5 +1,8 @@
 package com.ruoyi.production.service.impl;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -52,6 +55,8 @@
     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_FIELD = "inputWeight";
     private static final Object PRODUCT_MAIN_NO_LOCK = new Object();
 
     private IQualityInspectService qualityInspectService;
@@ -98,7 +103,10 @@
 
         BigDecimal reportQty = dto.getQuantity();
         BigDecimal scrapQty = dto.getScrapQty() == null ? BigDecimal.ZERO : dto.getScrapQty();
-        BigDecimal bomInputQty = dto.getBomInputQty();
+        BigDecimal bomInputQty = dto.getInputWeight();
+        if (bomInputQty == null) {
+            bomInputQty = resolveInputWeight(dto.getOtherData());
+        }
         if (reportQty == null || reportQty.compareTo(BigDecimal.ZERO) <= 0) {
             throw new ServiceException("鎶ュ伐鏁伴噺蹇呴』澶т簬0");
         }
@@ -345,7 +353,7 @@
 
             ProductionProductInput productionProductInput = new ProductionProductInput();
             productionProductInput.setProductModelId(productStructureDto.getProductModelId());
-            productionProductInput.setQuantity(needQty);
+            productionProductInput.setQuantity(needQty == null ? BigDecimal.ZERO : needQty);
             productionProductInput.setProductMainId(productionProductMain.getId());
             productionProductInputMapper.insert(productionProductInput);
 
@@ -761,4 +769,87 @@
 
         return productionProductMainDtos;
     }
+
+    private BigDecimal resolveInputWeight(String otherData) {
+        if (StringUtils.isBlank(otherData)) {
+            return null;
+        }
+        Object parsed;
+        try {
+            parsed = JSON.parse(otherData);
+        } catch (Exception ex) {
+            throw new ServiceException("鎶ュ伐鍙傛暟鏍煎紡閿欒锛屾棤娉曡В鏋愭姇鍏ラ噸閲�/鏁伴噺");
+        }
+        String inputWeight = StringUtils.trim(findParameterValue(parsed, INPUT_WEIGHT_PARAMETER));
+        if (StringUtils.isBlank(inputWeight)) {
+            inputWeight = StringUtils.trim(findFieldValue(parsed, INPUT_WEIGHT_FIELD));
+        }
+        if (StringUtils.isBlank(inputWeight)) {
+            return null;
+        }
+        try {
+            return new BigDecimal(inputWeight);
+        } catch (NumberFormatException ex) {
+            throw new ServiceException("鎶ュ伐鍙傛暟涓殑鎶曞叆閲嶉噺/鏁伴噺鏍煎紡閿欒");
+        }
+    }
+
+    private String findParameterValue(Object node, String parameterItem) {
+        if (node instanceof JSONArray) {
+            JSONArray array = (JSONArray) node;
+            for (Object item : array) {
+                String value = findParameterValue(item, parameterItem);
+                if (StringUtils.isNotBlank(value)) {
+                    return value;
+                }
+            }
+            return null;
+        }
+        if (node instanceof JSONObject) {
+            JSONObject object = (JSONObject) node;
+            if (parameterItem.equals(StringUtils.trim(object.getString("parameterItem")))) {
+                String value = StringUtils.trim(object.getString("value"));
+                if (StringUtils.isNotBlank(value)) {
+                    return value;
+                }
+            }
+            for (Object value : object.values()) {
+                String matched = findParameterValue(value, parameterItem);
+                if (StringUtils.isNotBlank(matched)) {
+                    return matched;
+                }
+            }
+        }
+        return null;
+    }
+
+    private String findFieldValue(Object node, String fieldName) {
+        if (node instanceof JSONArray) {
+            JSONArray array = (JSONArray) node;
+            for (Object item : array) {
+                String value = findFieldValue(item, fieldName);
+                if (StringUtils.isNotBlank(value)) {
+                    return value;
+                }
+            }
+            return null;
+        }
+        if (node instanceof JSONObject) {
+            JSONObject object = (JSONObject) node;
+            Object fieldValue = object.get(fieldName);
+            if (fieldValue != null) {
+                String value = StringUtils.trim(String.valueOf(fieldValue));
+                if (StringUtils.isNotBlank(value)) {
+                    return value;
+                }
+            }
+            for (Object value : object.values()) {
+                String matched = findFieldValue(value, fieldName);
+                if (StringUtils.isNotBlank(matched)) {
+                    return matched;
+                }
+            }
+        }
+        return null;
+    }
 }

--
Gitblit v1.9.3