From c0bdce5b5deb0b680534f276d0bb61dbbaa83890 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期日, 13 九月 2026 22:02:36 +0800
Subject: [PATCH] fix: 优化BOM结构需求量计算逻辑,确保子节点以父节点需求量为基数
---
src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java | 18 ++++++++++++------
src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java | 15 ++++++++++++---
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
index 0513bdc..6d275e1 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
@@ -217,22 +217,28 @@
return;
}
List<ProductionBomStructure> updateList = new ArrayList<>();
- BigDecimal lastProcessDemandedQuantity = orderQuantity;
+ // 闇�姹傞噺鎸夆�滅埗鑺傜偣闇�姹傞噺 脳 鏈鍗曡�椻�濋�愬眰璁$畻锛屽厔寮熻妭鐐逛簰涓嶅奖鍝嶏紝缁撴灉涓庡綍鍏ラ『搴忔棤鍏炽��
+ Map<Long, BigDecimal> demandedQuantityById = new HashMap<>();
for (ProductionBomStructure structure : structureList) {
if (structure == null || structure.getId() == null) {
continue;
}
- BigDecimal demandedQuantity = lastProcessDemandedQuantity.multiply(defaultDecimal(structure.getUnitQuantity()));
-// if (compareDecimal(structure.getDemandedQuantity(), demandedQuantity) == 0) {
-// continue;
-// }
+ // 鏍硅妭鐐逛互璁㈠崟鏁伴噺涓哄熀鏁帮紝瀛愯妭鐐逛互鐖惰妭鐐归渶姹傞噺涓哄熀鏁般��
+ boolean rootNode = structure.getParentId() == null || structure.getParentId() == 0L;
+ BigDecimal baseQuantity = rootNode
+ ? orderQuantity
+ : demandedQuantityById.get(structure.getParentId());
+ if (baseQuantity == null) {
+ throw new ServiceException("BOM缁撴瀯鏁版嵁寮傚父锛屽瓨鍦ㄦ壘涓嶅埌鐖惰妭鐐圭殑瀛愯妭鐐�");
+ }
+ BigDecimal demandedQuantity = baseQuantity.multiply(defaultDecimal(structure.getUnitQuantity()));
ProductionBomStructure update = new ProductionBomStructure();
update.setId(structure.getId());
update.setDemandedQuantity(demandedQuantity);
updateList.add(update);
structure.setDemandedQuantity(demandedQuantity);
- lastProcessDemandedQuantity = demandedQuantity;
+ demandedQuantityById.put(structure.getId(), demandedQuantity);
}
if (!updateList.isEmpty()) {
this.updateBatchById(updateList);
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
index 5c103b8..e31fc86 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -439,7 +439,8 @@
productionOrderBomMapper.insert(orderBom);
Map<Long, Long> idMap = new HashMap<>();
- BigDecimal lastProcessDemandedQuantity = orderQuantity;
+ // 闇�姹傞噺鎸夆�滅埗鑺傜偣闇�姹傞噺 脳 鏈鍗曡�椻�濋�愬眰璁$畻锛屽厔寮熻妭鐐逛簰涓嶅奖鍝嶏紝缁撴灉涓庡綍鍏ラ『搴忔棤鍏炽��
+ Map<Long, BigDecimal> demandedQuantityBySourceId = new HashMap<>();
for (TechnologyBomStructure source : structureList) {
// 瀛愯妭鐐� parentId 闇�瑕佹槧灏勬垚鏂板揩鐓ц妭鐐� id锛屾墠鑳戒繚鐣欏師濮� BOM 灞傜骇銆�
ProductionBomStructure target = new ProductionBomStructure();
@@ -449,11 +450,19 @@
target.setProductModelId(source.getProductModelId());
target.setTechnologyOperationId(source.getOperationId());
target.setUnitQuantity(source.getUnitQuantity());
- target.setDemandedQuantity(lastProcessDemandedQuantity.multiply(source.getUnitQuantity()));
+ // 鏍硅妭鐐逛互璁㈠崟鏁伴噺涓哄熀鏁帮紝瀛愯妭鐐逛互鐖惰妭鐐归渶姹傞噺涓哄熀鏁般��
+ boolean rootNode = source.getParentId() == null || source.getParentId() == 0L;
+ BigDecimal baseQuantity = rootNode
+ ? orderQuantity
+ : demandedQuantityBySourceId.get(source.getParentId());
+ if (baseQuantity == null) {
+ throw new ServiceException("BOM缁撴瀯鏁版嵁寮傚父锛屽瓨鍦ㄦ壘涓嶅埌鐖惰妭鐐圭殑瀛愯妭鐐�");
+ }
+ target.setDemandedQuantity(baseQuantity.multiply(defaultDecimal(source.getUnitQuantity())));
target.setUnit(source.getUnit());
productionBomStructureMapper.insert(target);
idMap.put(source.getId(), target.getId());
- lastProcessDemandedQuantity = target.getDemandedQuantity();
+ demandedQuantityBySourceId.put(source.getId(), target.getDemandedQuantity());
}
return orderBom;
}
--
Gitblit v1.9.3