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 ++++++++++++------
1 files changed, 12 insertions(+), 6 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);
--
Gitblit v1.9.3