From 346d463346701e8714b3a3a3ebb21e21960b5484 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 20 三月 2026 15:06:47 +0800
Subject: [PATCH] feat: 查看生产订单对应的生产计划来源

---
 src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java
index 22f248e..f694dad 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java
@@ -25,13 +25,14 @@
 
     @Override
     @Transactional
-    public Boolean addProductStructureDto(ProductStructureDto dto) {
+    public Boolean addProductStructureDto(Integer bomId, List<ProductStructureDto> list) {
 
-        Integer bomId = dto.getBomId();
-
-        //  灏嗘爲鎵佸钩鍖�
+        // 鎵佸钩鍖栦紶鍏ョ殑鏍�
         List<ProductStructureDto> flatDtoList = new ArrayList<>();
-        flattenTree(dto.getChildren(), flatDtoList);
+        for (ProductStructureDto root : list) {
+            flatDtoList.add(root);
+            flattenTree(root.getChildren(), flatDtoList);
+        }
 
         //  鏌ヨ鏁版嵁搴撲腑宸叉湁鐨� BOM 鏁版嵁
         List<ProductStructure> dbList = this.list(new LambdaQueryWrapper<ProductStructure>().eq(ProductStructure::getBomId, bomId));
@@ -65,13 +66,13 @@
             entity.setBomId(bomId);
 
             if (psDto.getId() == null) {
-                // 鏂板
                 entity.setId(null);
                 entity.setParentId(null);
                 insertList.add(entity);
-                tempEntityMap.put(psDto.getTempId(), entity);
+                if (psDto.getTempId() != null) {
+                    tempEntityMap.put(psDto.getTempId(), entity);
+                }
             } else {
-                // 鏇存柊
                 updateList.add(entity);
             }
         }
@@ -83,32 +84,27 @@
 
         //  鍥炲啓鏂板鑺傜偣 parentId
         List<ProductStructure> parentFixList = new ArrayList<>();
-        //  鐪熷疄鐨勭埗鑺傜偣 ID
         Long realParentId;
         for (ProductStructureDto psDto : flatDtoList) {
+            if (psDto.getId() != null) continue;
+            ProductStructure child = tempEntityMap.get(psDto.getTempId());
+            if (child == null) continue;
             String parentTempId = psDto.getParentTempId();
-            if (psDto.getId() == null && parentTempId != null && !parentTempId.isEmpty()) {
-                ProductStructure child = tempEntityMap.get(psDto.getTempId());
+            if (parentTempId != null && !parentTempId.isEmpty()) {
                 if (tempEntityMap.containsKey(parentTempId)) {
-                    // 鐖惰妭鐐规槸鏂拌妭鐐�
                     realParentId = tempEntityMap.get(parentTempId).getId();
                 } else {
-                    // 鐖惰妭鐐规槸鑰佽妭鐐�
                     try {
                         realParentId = Long.valueOf(parentTempId);
                     } catch (NumberFormatException e) {
                         realParentId = 0L;
                     }
                 }
-
                 child.setParentId(realParentId);
-                parentFixList.add(child);
-            } else if (psDto.getId() == null) {
-                // 濡傛灉 parentTempId 涓虹┖锛屽垯鏄《绾ц妭鐐�
-                ProductStructure child = tempEntityMap.get(psDto.getTempId());
+            } else {
                 child.setParentId(0L);
-                parentFixList.add(child);
             }
+            parentFixList.add(child);
         }
 
         if (!parentFixList.isEmpty()) {

--
Gitblit v1.9.3