From eaf6548902e9472fc9b876d531db8508e16c4f2f Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 20 三月 2026 13:49:43 +0800
Subject: [PATCH] feat: 生产订单的撤回、删除;BOM的子集新增/修改统一使用临时ID处理

---
 src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 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 2dfd0f3..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,28 +84,32 @@
 
         //  鍥炲啓鏂板鑺傜偣 parentId
         List<ProductStructure> parentFixList = new ArrayList<>();
-        //  鐪熷疄鐨勭埗鑺傜偣 ID
         Long realParentId;
         for (ProductStructureDto psDto : flatDtoList) {
-            if (psDto.getId() == null && psDto.getParentTempId() != null) {
-                ProductStructure child = tempEntityMap.get(psDto.getTempId());
-                if (tempEntityMap.containsKey(psDto.getParentTempId())) {
-                    // 鐖惰妭鐐规槸鏂拌妭鐐�
-                    realParentId = tempEntityMap.get(psDto.getParentTempId()).getId();
+            if (psDto.getId() != null) continue;
+            ProductStructure child = tempEntityMap.get(psDto.getTempId());
+            if (child == null) continue;
+            String parentTempId = psDto.getParentTempId();
+            if (parentTempId != null && !parentTempId.isEmpty()) {
+                if (tempEntityMap.containsKey(parentTempId)) {
+                    realParentId = tempEntityMap.get(parentTempId).getId();
                 } else {
-                    // 鐖惰妭鐐规槸鑰佽妭鐐�
-                    realParentId = Long.valueOf(psDto.getParentTempId());
+                    try {
+                        realParentId = Long.valueOf(parentTempId);
+                    } catch (NumberFormatException e) {
+                        realParentId = 0L;
+                    }
                 }
-
                 child.setParentId(realParentId);
-                parentFixList.add(child);
+            } else {
+                child.setParentId(0L);
             }
+            parentFixList.add(child);
         }
 
         if (!parentFixList.isEmpty()) {
             this.updateBatchById(parentFixList);
         }
-
         if (!updateList.isEmpty()) {
             this.updateBatchById(updateList);
         }

--
Gitblit v1.9.3