From 280261219bafff383fe37dfc24f148baca4672e1 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 28 八月 2026 20:40:17 +0800
Subject: [PATCH] fix: 操作日志根据操作时间倒序

---
 src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java |   17 ++++++++++++-----
 1 files changed, 12 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..acad3ef 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionBomStructureServiceImpl.java
@@ -217,13 +217,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 +232,6 @@
             update.setDemandedQuantity(demandedQuantity);
             updateList.add(update);
             structure.setDemandedQuantity(demandedQuantity);
-            lastProcessDemandedQuantity = demandedQuantity;
         }
         if (!updateList.isEmpty()) {
             this.updateBatchById(updateList);
@@ -823,14 +822,22 @@
         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,
                                              Long rootProductModelId) {
         if (outputNode == null) {

--
Gitblit v1.9.3