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/ProductionOrderServiceImpl.java | 65 ++++++++++++++++++++------------
1 files changed, 40 insertions(+), 25 deletions(-)
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 9543cad..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;
}
@@ -1066,8 +1075,19 @@
}
// 杩囨护鍑洪潪鏍硅妭鐐癸紙瀹為檯棰嗘枡椤癸級
+ // 鎺掗櫎鎶曞叆鍝佷笌浜у嚭鍝佺浉鍚屼笖姣斾緥涓�1鐨勬儏鍐碉紙鑷韩鍔犲伐锛屼笉闇�瑕侀鏂欙級
List<ProductionBomStructureVo> childStructureList = bomStructureList.stream()
.filter(s -> s != null && s.getParentId() != null && s.getParentId() != 0)
+ .filter(s -> {
+ ProductionBomStructureVo parent = structureByIdMap.get(s.getParentId());
+ if (parent == null) {
+ return true;
+ }
+ // 鎶曞叆鍝佷笌浜у嚭鍝佺浉鍚屼笖姣斾緥涓�1鏃讹紝涓嶉渶瑕侀鏂�
+ boolean sameProduct = Objects.equals(s.getProductModelId(), parent.getProductModelId());
+ boolean unitRatio = BigDecimal.ONE.compareTo(defaultDecimal(s.getUnitQuantity())) == 0;
+ return !(sameProduct && unitRatio);
+ })
.collect(Collectors.toList());
// 閬嶅巻澶勭悊鏁版嵁骞剁粍瑁呯粨鏋�
@@ -1095,34 +1115,29 @@
}
}
- Map<String, ProductionOrderPickVo> mergedPickMap = new LinkedHashMap<>();
+ List<ProductionOrderPickVo> pickList = new ArrayList<>();
for (ProductionBomStructureVo structure : childStructureList) {
if (structure == null || structure.getProductModelId() == null) {
continue;
}
Long productModelId = structure.getProductModelId();
- String mergeKey = String.valueOf(structure.getTechnologyOperationId()) + "#" + productModelId;
- ProductionOrderPickVo vo = mergedPickMap.get(mergeKey);
- if (vo == null) {
- vo = new ProductionOrderPickVo();
- vo.setProductModelId(productModelId);
- vo.setOperationName(structure.getOperationName());
- vo.setTechnologyOperationId(structure.getTechnologyOperationId());
- vo.setProductName(structure.getProductName());
- vo.setModel(structure.getModel());
- vo.setDemandedQuantity(BigDecimal.ZERO);
- vo.setUnit(structure.getUnit());
- List<String> batchNoList = stockBatchNoMap.get(productModelId) == null
- ? Collections.emptyList()
- : new ArrayList<>(stockBatchNoMap.get(productModelId));
- vo.setBatchNoList(batchNoList);
- vo.setStockQuantity(stockQuantityMap.getOrDefault(productModelId, BigDecimal.ZERO));
- vo.setBom(true);
- mergedPickMap.put(mergeKey, vo);
- }
- vo.setDemandedQuantity(defaultDecimal(vo.getDemandedQuantity()).add(defaultDecimal(structure.getDemandedQuantity())));
+ ProductionOrderPickVo vo = new ProductionOrderPickVo();
+ vo.setProductModelId(productModelId);
+ vo.setOperationName(structure.getOperationName());
+ vo.setTechnologyOperationId(structure.getTechnologyOperationId());
+ vo.setProductName(structure.getProductName());
+ vo.setModel(structure.getModel());
+ vo.setDemandedQuantity(defaultDecimal(structure.getDemandedQuantity()));
+ vo.setUnit(structure.getUnit());
+ List<String> batchNoList = stockBatchNoMap.get(productModelId) == null
+ ? Collections.emptyList()
+ : new ArrayList<>(stockBatchNoMap.get(productModelId));
+ vo.setBatchNoList(batchNoList);
+ vo.setStockQuantity(stockQuantityMap.getOrDefault(productModelId, BigDecimal.ZERO));
+ vo.setBom(true);
+ pickList.add(vo);
}
- return new ArrayList<>(mergedPickMap.values());
+ return pickList;
}
@Override
--
Gitblit v1.9.3