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 | 143 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 123 insertions(+), 20 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 47e7fcd..4808e75 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;
@@ -37,7 +40,6 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
-import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -53,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;
@@ -99,6 +103,10 @@
BigDecimal reportQty = dto.getQuantity();
BigDecimal scrapQty = dto.getScrapQty() == null ? BigDecimal.ZERO : dto.getScrapQty();
+ BigDecimal bomInputQty = dto.getInputWeight();
+ if (bomInputQty == null) {
+ bomInputQty = resolveInputWeight(dto.getOtherData());
+ }
if (reportQty == null || reportQty.compareTo(BigDecimal.ZERO) <= 0) {
throw new ServiceException("鎶ュ伐鏁伴噺蹇呴』澶т簬0");
}
@@ -107,6 +115,9 @@
}
if (scrapQty.compareTo(reportQty) > 0) {
throw new ServiceException("鎶ュ簾鏁伴噺涓嶈兘澶т簬鎶ュ伐鏁伴噺");
+ }
+ if (bomInputQty == null || bomInputQty.compareTo(BigDecimal.ZERO) < 0) {
+ throw new ServiceException("浜у搧缁撴瀯鎶曞叆鏁伴噺涓嶈兘灏忎簬0");
}
// 绗簩姝ワ細鍔犺浇褰撳墠宸ュ簭銆佸伐鍗曘�佸伐鑹鸿矾绾垮拰璁㈠崟鏁版嵁锛屽苟鏍¢獙鍩虹鍏宠仈鍏崇郴
@@ -193,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()
@@ -239,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;
@@ -313,6 +324,14 @@
.collect(Collectors.toMap(ProductStructureDto::getId, Function.identity(), (a, b) -> a));
}
+ // 绗竷姝�-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("鎶曞叆鐗╂枡浜у搧鍨嬪彿涓嶈兘涓虹┖");
@@ -335,23 +354,24 @@
throw new ServiceException("鐖剁骇鐗╂枡鐢ㄩ噺蹇呴』澶т簬0");
}
- BigDecimal needQty = childQty
- .divide(parentQty, 6, RoundingMode.HALF_UP)
- .multiply(reportQty);
+ BigDecimal needQty = inputBaseQty;
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);
- stockUtils.substractStock(
- productStructureDto.getProductModelId(),
- needQty,
- StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(),
- productionProductMain.getId(),
- null
- );
+ if (!shouldSkipStockDeduction) {
+ stockUtils.substractStock(
+ productStructureDto.getProductModelId(),
+ needQty,
+ StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(),
+ productionProductMain.getId(),
+ null,
+ null
+ );
+ }
}
// 绗叓姝ワ細鍐欎骇鍑鸿褰曞苟璁$畻鏈鍚堟牸鏁伴噺
@@ -756,4 +776,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;
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3