From 5b9f87937feb53890138dbcd3a94cd883997e950 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期四, 26 十二月 2024 16:32:44 +0800
Subject: [PATCH] 修改菜单报错bug

---
 iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/user/AdminUserServiceImpl.java |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/user/AdminUserServiceImpl.java b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/user/AdminUserServiceImpl.java
index f954f50..cfa0743 100644
--- a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/user/AdminUserServiceImpl.java
+++ b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/user/AdminUserServiceImpl.java
@@ -4,12 +4,14 @@
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.iailab.framework.common.enums.CommonStatusEnum;
 import com.iailab.framework.common.exception.ServiceException;
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.util.collection.CollectionUtils;
 import com.iailab.framework.common.util.object.BeanUtils;
 import com.iailab.framework.datapermission.core.util.DataPermissionUtils;
+import com.iailab.module.infra.api.config.ConfigApi;
 import com.iailab.module.infra.api.file.FileApi;
 import com.iailab.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
 import com.iailab.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
@@ -57,8 +59,7 @@
 @Slf4j
 public class AdminUserServiceImpl implements AdminUserService {
 
-    @Value("${sys.user.init-password:iailabyuanma}")
-    private String userInitPassword;
+    static final String USER_INIT_PASSWORD_KEY = "system.user.init-password";
 
     @Resource
     private AdminUserMapper userMapper;
@@ -81,8 +82,11 @@
     @Resource
     private FileApi fileApi;
 
+    @Resource
+    private ConfigApi configApi;
+
     @Override
-    @Transactional(rollbackFor = Exception.class)
+    @DSTransactional
     @LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_CREATE_SUB_TYPE, bizNo = "{{#user.id}}",
             success = SYSTEM_USER_CREATE_SUCCESS)
     public Long createUser(UserSaveReqVO createReqVO) {
@@ -113,7 +117,7 @@
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
+    @DSTransactional
     @LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
             success = SYSTEM_USER_UPDATE_SUCCESS)
     public void updateUser(UserSaveReqVO updateReqVO) {
@@ -428,9 +432,17 @@
     @Override
     @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
     public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) {
+        // 1.1 参数校验
         if (CollUtil.isEmpty(importUsers)) {
             throw exception(USER_IMPORT_LIST_IS_EMPTY);
         }
+        // 1.2 初始化密码不能为空
+        String initPassword = configApi.getConfigValueByKey(USER_INIT_PASSWORD_KEY).getCheckedData();
+        if (StrUtil.isEmpty(initPassword)) {
+            throw exception(USER_IMPORT_INIT_PASSWORD);
+        }
+
+        // 2. 遍历,逐个创建 or 更新
         UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>())
                 .updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
         importUsers.forEach(importUser -> {
@@ -446,7 +458,7 @@
             AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername());
             if (existUser == null) {
                 userMapper.insert(BeanUtils.toBean(importUser, AdminUserDO.class)
-                        .setPassword(encodePassword(userInitPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组
+                        .setPassword(encodePassword(initPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组
                 respVO.getCreateUsernames().add(importUser.getUsername());
                 return;
             }

--
Gitblit v1.9.3