From d29080af4e965ba341cb85a5bc45ecd183c06783 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 14 八月 2026 17:45:45 +0800
Subject: [PATCH] Merge branch 'dev_New_pro' into dev_pro_山西_晋和园
---
src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java | 64 +++++++++++++++++++++++++++++--
1 files changed, 59 insertions(+), 5 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 5c103b8..95c7344 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -439,9 +439,54 @@
productionOrderBomMapper.insert(orderBom);
Map<Long, Long> idMap = new HashMap<>();
- BigDecimal lastProcessDemandedQuantity = orderQuantity;
+ // 鏋勫缓 sourceId 鈫� sourceNode 鏄犲皠 鍜� parentId 鈫� children 鏄犲皠
+ Map<Long, TechnologyBomStructure> sourceById = new HashMap<>();
+ Map<Long, List<TechnologyBomStructure>> childrenMap = new LinkedHashMap<>();
for (TechnologyBomStructure source : structureList) {
- // 瀛愯妭鐐� parentId 闇�瑕佹槧灏勬垚鏂板揩鐓ц妭鐐� id锛屾墠鑳戒繚鐣欏師濮� BOM 灞傜骇銆�
+ if (source == null || source.getId() == null) {
+ continue;
+ }
+ sourceById.put(source.getId(), source);
+ Long parentId = source.getParentId();
+ childrenMap.computeIfAbsent(parentId, k -> new ArrayList<>()).add(source);
+ }
+
+ // BFS 浠庢牴鑺傜偣寮�濮嬶紝鐖惰妭鐐瑰厛浜庡瓙鑺傜偣澶勭悊
+ Deque<TechnologyBomStructure> queue = new ArrayDeque<>();
+ List<TechnologyBomStructure> rootNodes = childrenMap.get(null);
+ if (rootNodes != null) {
+ queue.addAll(rootNodes);
+ }
+ // parentId=0 鐨勪篃瑙嗕负鏍硅妭鐐�
+ List<TechnologyBomStructure> zeroParentNodes = childrenMap.get(0L);
+ if (zeroParentNodes != null) {
+ for (TechnologyBomStructure node : zeroParentNodes) {
+ if (!queue.contains(node)) {
+ queue.add(node);
+ }
+ }
+ }
+
+ while (!queue.isEmpty()) {
+ TechnologyBomStructure source = queue.poll();
+ if (source == null || source.getId() == null) {
+ continue;
+ }
+ // 璁$畻闇�姹傞噺 = 鐖惰妭鐐归渶姹傞噺 脳 鑷韩 unitQuantity
+ BigDecimal parentDemandedQuantity = orderQuantity;
+ Long sourceParentId = source.getParentId();
+ if (sourceParentId != null && sourceParentId != 0L) {
+ Long parentTargetId = idMap.get(sourceParentId);
+ if (parentTargetId != null) {
+ // 鐖惰妭鐐瑰凡缁忔彃鍏ワ紝鐢ㄧ埗鑺傜偣鐨� targetId 浠庡凡鎻掑叆鍒楄〃鎵�
+ // 杩欓噷鎴戜滑鐩存帴鐢ㄥ瓨涓嬫潵鐨勭埗鑺傜偣闇�姹傞噺
+ TechnologyBomStructure parentSource = sourceById.get(sourceParentId);
+ if (parentSource != null && parentSource.getDemandedQuantity() != null) {
+ parentDemandedQuantity = parentSource.getDemandedQuantity();
+ }
+ }
+ }
+
ProductionBomStructure target = new ProductionBomStructure();
target.setProductionOrderId(productionOrder.getId());
target.setProductionOrderBomId(orderBom.getId());
@@ -449,11 +494,20 @@
target.setProductModelId(source.getProductModelId());
target.setTechnologyOperationId(source.getOperationId());
target.setUnitQuantity(source.getUnitQuantity());
- target.setDemandedQuantity(lastProcessDemandedQuantity.multiply(source.getUnitQuantity()));
+ target.setDemandedQuantity(parentDemandedQuantity.multiply(defaultDecimal(source.getUnitQuantity())));
target.setUnit(source.getUnit());
productionBomStructureMapper.insert(target);
idMap.put(source.getId(), target.getId());
- lastProcessDemandedQuantity = target.getDemandedQuantity();
+ // 灏嗗綋鍓嶈妭鐐圭殑 demandedQuantity 鍥炲啓鍒� source 瀵硅薄涓婏紝渚涘瓙鑺傜偣璁$畻浣跨敤
+ source.setDemandedQuantity(target.getDemandedQuantity());
+
+ // 灏嗗瓙鑺傜偣鍔犲叆闃熷垪
+ List<TechnologyBomStructure> children = childrenMap.get(source.getId());
+ if (children != null) {
+ for (TechnologyBomStructure child : children) {
+ queue.add(child);
+ }
+ }
}
return orderBom;
}
@@ -1134,7 +1188,7 @@
@Override
public int updateOrder(ProductionOrderDto productionOrderDto) {
// 鏇存柊鐢熶骇璁㈠崟涓绘暟鎹�
- productionOrderDto.setStatus(5);
+ productionOrderDto.setStatus(ProductOrderStatusEnum.END.getCode());
return baseMapper.updateById(productionOrderDto);
}
}
--
Gitblit v1.9.3