From 6d5ce70c3e2b536c8e4b74269be70029a57cb1cc Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 11 五月 2026 15:36:32 +0800
Subject: [PATCH] feat(approve): 使用通用工具类优化审批流程ID生成逻辑

---
 src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
index d22f0f4..7a24e0e 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -16,6 +16,7 @@
 import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum;
 import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.procurementrecord.utils.StockUtils;
 import com.ruoyi.production.dto.ProductStructureDto;
@@ -169,8 +170,14 @@
         }
         String productNo = String.format("%s%03d", datePrefix, sequenceNumber);
         productionProductMain.setProductNo(productNo);
-        productionProductMain.setUserId(dto.getUserId());
-        productionProductMain.setUserName(dto.getUserName());
+        Long userId = dto.getUserId();
+        String userName = dto.getUserName();
+        if (userId == null) {
+            userId = SecurityUtils.getLoginUser().getUserId();
+            userName = SecurityUtils.getLoginUser().getNickName();
+        }
+        productionProductMain.setUserId(userId);
+        productionProductMain.setUserName(userName);
         productionProductMain.setProductProcessRouteItemId(dto.getProductProcessRouteItemId());
         productionProductMain.setWorkOrderId(dto.getWorkOrderId());
         productionProductMain.setStatus(0);
@@ -188,13 +195,15 @@
                 .map(ProductStructureDto::getParentId)
                 .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
-        Map<Long, ProductStructureDto> parentMap =
-                productStructureMapper.selectByIds(parentIds)
-                        .stream()
-                        .collect(Collectors.toMap(
-                                ProductStructureDto::getId,
-                                Function.identity()
-                        ));
+        Map<Long, ProductStructureDto> parentMap = new HashMap<>();
+        if (!parentIds.isEmpty()) {
+            parentMap = productStructureMapper.selectByIds(parentIds)
+                    .stream()
+                    .collect(Collectors.toMap(
+                            ProductStructureDto::getId,
+                            Function.identity()
+                    ));
+        }
         for (ProductStructureDto productStructureDto : productStructureDtos) {
             ProductionProductInput productionProductInput = new ProductionProductInput();
             productionProductInput.setProductModelId(productStructureDto.getProductModelId());
@@ -474,4 +483,4 @@
         
         return productionProductMainDtos;
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3