| | |
| | | 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; |
| | |
| | | @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; |
| | |
| | | @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) { |
| | |
| | | } |
| | | |
| | | @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) { |
| | |
| | | @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 -> { |
| | |
| | | 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; |
| | | } |