From 17ce55a3b038ed61d332bb54916de4fa55ba19c6 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期二, 27 十月 2026 09:10:23 +0800
Subject: [PATCH] fix: 修复导出表头缺失、权限码不一致及生产链路断点

---
 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
index 9f46412..dd46571 100644
--- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
+++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
@@ -55,7 +55,7 @@
 /**
  * 鍚庡彴鐢ㄦ埛 Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service("adminUserService")
 @Slf4j
@@ -512,11 +512,8 @@
         if (CollUtil.isEmpty(importUsers)) {
             throw exception(USER_IMPORT_LIST_IS_EMPTY);
         }
-        // 1.2 鍒濆鍖栧瘑鐮佷笉鑳戒负绌�
+        // 1.2 绯荤粺鍙傛暟涓殑鍒濆瀵嗙爜锛屼綔涓� Excel 鏈~鍐欏瘑鐮佹椂鐨勫厹搴�
         String initPassword = configApi.getConfigValueByKey(USER_INIT_PASSWORD_KEY);
-        if (StrUtil.isEmpty(initPassword)) {
-            throw exception(USER_IMPORT_INIT_PASSWORD);
-        }
 
         // 2. 閬嶅巻锛岄�愪釜鍒涘缓 or 鏇存柊
         UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>())
@@ -524,11 +521,20 @@
         AtomicInteger index = new AtomicInteger(1);
         importUsers.forEach(importUser -> {
             int currentIndex = index.getAndIncrement();
+            String key = StrUtil.blankToDefault(importUser.getUsername(), "绗� " + currentIndex + " 琛�");
+            // 2.1.0 瑙f瀽璇ヨ鍒濆瀵嗙爜锛欵xcel 濉啓浜嗗氨鐢ㄥ~鍐欑殑锛屽惁鍒欒鍙栫郴缁熷弬鏁�
+            String effectivePassword = StrUtil.isNotBlank(importUser.getPassword())
+                    ? importUser.getPassword() : initPassword;
+            if (StrUtil.isBlank(effectivePassword)) {
+                respVO.getFailureUsernames().put(key,
+                        "鏈~鍐欏垵濮嬪瘑鐮侊紝涓旂郴缁熷弬鏁� system.user.init-password 鏈厤缃��"
+                                + "璇峰湪 Excel 涓~鍐欒琛屽垵濮嬪瘑鐮侊紝鎴栧厛鍦ㄥ弬鏁拌缃腑閰嶇疆 system.user.init-password");
+                return;
+            }
             // 2.1.1 鏍¢獙瀛楁鏄惁绗﹀悎瑕佹眰
             try {
-                ValidationUtils.validate(BeanUtils.toBean(importUser, UserSaveReqVO.class).setPassword(initPassword));
+                ValidationUtils.validate(BeanUtils.toBean(importUser, UserSaveReqVO.class).setPassword(effectivePassword));
             } catch (ConstraintViolationException ex) {
-                String key = StrUtil.blankToDefault(importUser.getUsername(), "绗� " + currentIndex + " 琛�");
                 respVO.getFailureUsernames().put(key, ex.getMessage());
                 return;
             }
@@ -545,7 +551,7 @@
             AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername());
             if (existUser == null) {
                 userMapper.insert(BeanUtils.toBean(importUser, AdminUserDO.class)
-                        .setPassword(encodePassword(initPassword)).setPostIds(new HashSet<>())); // 璁剧疆榛樿瀵嗙爜鍙婄┖宀椾綅缂栧彿鏁扮粍
+                        .setPassword(encodePassword(effectivePassword)).setPostIds(new HashSet<>())); // 璁剧疆鍒濆瀵嗙爜鍙婄┖宀椾綅缂栧彿鏁扮粍
                 respVO.getCreateUsernames().add(importUser.getUsername());
                 return;
             }
@@ -556,6 +562,9 @@
             }
             AdminUserDO updateUser = BeanUtils.toBean(importUser, AdminUserDO.class);
             updateUser.setId(existUser.getId());
+            // 瀵嗙爜鍗曠嫭澶勭悊锛欵xcel 濉啓浜嗘墠鏇存柊锛涙湭濉啓鍒欑疆绌猴紝淇濇寔鍘熷瘑鐮佷笉鍙橈紙閬垮厤鎶婃槑鏂囧啓杩涘簱锛�
+            updateUser.setPassword(StrUtil.isNotBlank(importUser.getPassword())
+                    ? encodePassword(importUser.getPassword()) : null);
             userMapper.updateById(updateUser);
             respVO.getUpdateUsernames().add(importUser.getUsername());
         });

--
Gitblit v1.9.3