|
|
@@ -402,6 +402,26 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private AdminUserDO validateUserForImport(String id, String username, String mobile, String email,
|
|
|
+ String deptId, Set<String> postIds) {
|
|
|
+ // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
+ return DataPermissionUtils.executeIgnore(() -> {
|
|
|
+ // 校验用户存在
|
|
|
+ AdminUserDO user = validateUserExists(id);
|
|
|
+ // 校验用户名唯一
|
|
|
+ validateUsernameUnique(id, username);
|
|
|
+ // 校验手机号唯一
|
|
|
+ validateMobileUnique(id, mobile);
|
|
|
+ // 校验邮箱唯一
|
|
|
+ validateEmailUnique(id, email);
|
|
|
+ // 校验部门处于开启状态
|
|
|
+ deptService.validateDeptListByCodes(CollectionUtils.singleton(deptId));
|
|
|
+ // 校验岗位处于开启状态
|
|
|
+ postService.validatePostList(postIds);
|
|
|
+ return user;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@VisibleForTesting
|
|
|
AdminUserDO validateUserExists(String id) {
|
|
|
if (id == null) {
|
|
|
@@ -510,7 +530,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
}
|
|
|
// 2.1.2 校验,判断是否有不符合的原因
|
|
|
try {
|
|
|
- validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
|
|
|
+ validateUserForImport(null, null, importUser.getMobile(), importUser.getEmail(),
|
|
|
importUser.getDeptId(), null);
|
|
|
} catch (ServiceException ex) {
|
|
|
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
|
|
|
@@ -520,6 +540,13 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
// 2.2.1 判断如果不存在,在进行插入
|
|
|
AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername());
|
|
|
if (existUser == null) {
|
|
|
+
|
|
|
+ DeptDO dept = deptService.getDeptByCode(importUser.getDeptId());
|
|
|
+ if (dept == null) {
|
|
|
+ respVO.getFailureUsernames().put(importUser.getUsername(), DEPT_NOT_FOUND.getMsg());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ importUser.setDeptId(dept.getId());
|
|
|
userMapper.insert(BeanUtils.toBean(importUser, AdminUserDO.class)
|
|
|
.setPassword(encodePassword(initPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组
|
|
|
respVO.getCreateUsernames().add(importUser.getUsername());
|