From a8188d1675594d7756eddccc3eda60601325942a Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 20 十月 2026 15:22:35 +0800
Subject: [PATCH] feat: 工序添加是否领料,用于后续生产订单领料

---
 src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java |   42 +++++++++++++++++++++++++++++++++++++-----
 1 files changed, 37 insertions(+), 5 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..eca8cb3 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
@@ -131,10 +131,15 @@
         List<ProductionBomStructure> updateList = new ArrayList<>();
         Map<String, ProductionBomStructure> tempEntityMap = new HashMap<>();
 
+        Map<Long, Boolean> operationPickMap = loadOperationPickMap(flatDtoList.stream()
+                .map(ProductionBomStructureDto::getTechnologyOperationId)
+                .collect(Collectors.toList()));
+
         for (ProductionBomStructureDto item : flatDtoList) {
             ProductionBomStructure entity = new ProductionBomStructure();
             BeanUtils.copyProperties(item, entity);
             entity.setProductionOrderBomId(orderBomId);
+            entity.setIsPick(operationPickMap.getOrDefault(item.getTechnologyOperationId(), Boolean.FALSE));
             if (item.getId() == null) {
                 entity.setParentId(null);
                 insertList.add(entity);
@@ -217,13 +222,13 @@
             return;
         }
         List<ProductionBomStructure> updateList = new ArrayList<>();
-        BigDecimal lastProcessDemandedQuantity = orderQuantity;
         for (ProductionBomStructure structure : structureList) {
             if (structure == null || structure.getId() == null) {
                 continue;
             }
 
-            BigDecimal demandedQuantity = lastProcessDemandedQuantity.multiply(defaultDecimal(structure.getUnitQuantity()));
+            BigDecimal demandedQuantity = defaultDecimal(orderQuantity)
+                    .multiply(defaultDecimal(structure.getUnitQuantity()));
 //            if (compareDecimal(structure.getDemandedQuantity(), demandedQuantity) == 0) {
 //                continue;
 //            }
@@ -232,7 +237,6 @@
             update.setDemandedQuantity(demandedQuantity);
             updateList.add(update);
             structure.setDemandedQuantity(demandedQuantity);
-            lastProcessDemandedQuantity = demandedQuantity;
         }
         if (!updateList.isEmpty()) {
             this.updateBatchById(updateList);
@@ -823,12 +827,20 @@
         if (bomStructure == null) {
             return null;
         }
-        // The root node is the first output node; other rows use their direct parent as the current operation output.
-        if (bomStructure.getParentId() == null) {
+        if (bomStructure.getParentId() == null || hasChildren(bomStructure, structureById)) {
             return bomStructure;
         }
         ProductionBomStructure parent = structureById.get(bomStructure.getParentId());
         return parent != null ? parent : bomStructure;
+    }
+
+    private boolean hasChildren(ProductionBomStructure bomStructure,
+                                Map<Long, ProductionBomStructure> structureById) {
+        if (bomStructure == null || bomStructure.getId() == null || structureById == null) {
+            return false;
+        }
+        return structureById.values().stream()
+                .anyMatch(child -> child != null && Objects.equals(child.getParentId(), bomStructure.getId()));
     }
 
     private Long resolveOutputProductModelId(ProductionBomStructure outputNode,
@@ -846,6 +858,26 @@
         return technologyOperationMapper.selectById(technologyOperationId);
     }
 
+    /**
+     * 鎵归噺璇诲彇宸ュ簭鐨勨�滄槸鍚﹂鏂欌�濇爣璁帮紝淇濊瘉鐢熶骇BOM缁撴瀯涓殑棰嗘枡鏍囪涓庡伐搴忎富鏁版嵁涓�鑷淬��
+     */
+    private Map<Long, Boolean> loadOperationPickMap(List<Long> technologyOperationIds) {
+        if (technologyOperationIds == null || technologyOperationIds.isEmpty()) {
+            return Collections.emptyMap();
+        }
+        Set<Long> operationIdSet = technologyOperationIds.stream()
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        if (operationIdSet.isEmpty()) {
+            return Collections.emptyMap();
+        }
+        return technologyOperationMapper.selectBatchIds(operationIdSet).stream()
+                .filter(item -> item != null && item.getId() != null)
+                .collect(Collectors.toMap(TechnologyOperation::getId,
+                        item -> Boolean.TRUE.equals(item.getIsPick()),
+                        (left, right) -> left));
+    }
+
     private String generateNextTaskNo() {
         String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
         ProductionOperationTask latestTask = productionOperationTaskMapper.selectOne(

--
Gitblit v1.9.3