From 64e7b891a3b0c2e16a43819ccba61c9ab5d0927d Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 26 五月 2026 09:28:43 +0800
Subject: [PATCH] 领料台账需求数量按照父子层级计算
---
src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java | 40 +++++++++++++++++++++++++++++++++++++---
1 files changed, 37 insertions(+), 3 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 ecdb37c..8562b01 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -59,6 +59,7 @@
private final ProductionOperationTaskMapper productionOperationTaskMapper;
private final ProductionOrderBomMapper productionOrderBomMapper;
private final ProductionBomStructureMapper productionBomStructureMapper;
+ private final ProductionOrderMapper productionOrderMapper;
private final ProductionProductMainMapper productionProductMainMapper;
private final ProductionProductOutputMapper productionProductOutputMapper;
private final ProductionOrderPickMapper productionOrderPickMapper;
@@ -1029,13 +1030,46 @@
return Collections.emptyList();
}
- List<ProductionBomStructureVo> bomStructureList = productionBomStructureMapper.pickByBomId(orderBom.getId());
+ // 鏌ヨ瀹屾暣鐨凚OM缁撴瀯锛堝寘鎷牴鑺傜偣锛夛紝鐢ㄤ簬璁$畻灞傜骇闇�姹傛暟閲�
+ List<ProductionBomStructureVo> bomStructureList = productionBomStructureMapper.listByBomId(orderBom.getId());
if (bomStructureList == null || bomStructureList.isEmpty()) {
return Collections.emptyList();
}
+ // 鏌ヨ鐢熶骇璁㈠崟鑾峰彇璁㈠崟鏁伴噺
+ ProductionOrder productionOrder = productionOrderMapper.selectById(productionOrderId);
+ BigDecimal orderQuantity = productionOrder != null ? defaultDecimal(productionOrder.getQuantity()) : BigDecimal.ZERO;
+
+ // 鏋勫缓鏍戝舰缁撴瀯骞惰绠楀眰绾ч渶姹傛暟閲�
+ Map<Long, ProductionBomStructureVo> structureByIdMap = bomStructureList.stream()
+ .filter(s -> s != null && s.getId() != null)
+ .collect(Collectors.toMap(ProductionBomStructureVo::getId, s -> s));
+
+ // 鎸夊眰绾ц绠楅渶姹傛暟閲忥細瀛愮骇闇�姹傛暟閲� = 鐖剁骇闇�姹傛暟閲� 脳 瀛愮骇鍗曚綅浜у嚭鎵�闇�鏁伴噺
+ for (ProductionBomStructureVo structure : bomStructureList) {
+ if (structure == null) continue;
+
+ if (structure.getParentId() == null || structure.getParentId() == 0) {
+ // 鏍硅妭鐐癸細闇�姹傛暟閲� = 璁㈠崟鏁伴噺
+ structure.setDemandedQuantity(orderQuantity);
+ } else {
+ // 瀛愯妭鐐癸細闇�姹傛暟閲� = 鐖剁骇闇�姹傛暟閲� 脳 瀛愮骇鍗曚綅浜у嚭鎵�闇�鏁伴噺
+ ProductionBomStructureVo parent = structureByIdMap.get(structure.getParentId());
+ if (parent != null) {
+ BigDecimal parentDemandedQty = defaultDecimal(parent.getDemandedQuantity());
+ BigDecimal unitQuantity = defaultDecimal(structure.getUnitQuantity());
+ structure.setDemandedQuantity(parentDemandedQty.multiply(unitQuantity));
+ }
+ }
+ }
+
+ // 杩囨护鍑洪潪鏍硅妭鐐癸紙瀹為檯棰嗘枡椤癸級
+ List<ProductionBomStructureVo> childStructureList = bomStructureList.stream()
+ .filter(s -> s != null && s.getParentId() != null && s.getParentId() != 0)
+ .collect(Collectors.toList());
+
// 閬嶅巻澶勭悊鏁版嵁骞剁粍瑁呯粨鏋�
- List<Long> productModelIds = bomStructureList.stream()
+ List<Long> productModelIds = childStructureList.stream()
.map(ProductionBomStructureVo::getProductModelId)
.filter(Objects::nonNull)
.distinct()
@@ -1060,7 +1094,7 @@
}
Map<String, ProductionOrderPickVo> mergedPickMap = new LinkedHashMap<>();
- for (ProductionBomStructureVo structure : bomStructureList) {
+ for (ProductionBomStructureVo structure : childStructureList) {
if (structure == null || structure.getProductModelId() == null) {
continue;
}
--
Gitblit v1.9.3