|
|
|
|
@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
|
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
|
|
|
|
|
@ -101,7 +102,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
});
|
|
|
|
|
// 1.2 校验正确性
|
|
|
|
|
validateUserForCreateOrUpdate(null, createReqVO.getUsername(),
|
|
|
|
|
createReqVO.getMobile(), createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds());
|
|
|
|
|
createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds());
|
|
|
|
|
// 2.1 插入用户
|
|
|
|
|
AdminUserDO user = BeanUtils.toBean(createReqVO, AdminUserDO.class);
|
|
|
|
|
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
|
|
|
|
|
@ -132,7 +133,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 1.3 校验正确性
|
|
|
|
|
validateUserForCreateOrUpdate(null, registerReqVO.getUsername(), null, null, null, null);
|
|
|
|
|
validateUserForCreateOrUpdate(null, registerReqVO.getUsername(), null, null, null);
|
|
|
|
|
|
|
|
|
|
// 2. 插入用户
|
|
|
|
|
AdminUserDO user = BeanUtils.toBean(registerReqVO, AdminUserDO.class);
|
|
|
|
|
@ -150,7 +151,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
updateReqVO.setPassword(null); // 特殊:此处不更新密码
|
|
|
|
|
// 1. 校验正确性
|
|
|
|
|
AdminUserDO oldUser = validateUserForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getUsername(),
|
|
|
|
|
updateReqVO.getMobile(), updateReqVO.getEmail(), updateReqVO.getDeptId(), updateReqVO.getPostIds());
|
|
|
|
|
updateReqVO.getEmail(), updateReqVO.getDeptId(), updateReqVO.getPostIds());
|
|
|
|
|
|
|
|
|
|
// 2.1 更新用户
|
|
|
|
|
AdminUserDO updateObj = BeanUtils.toBean(updateReqVO, AdminUserDO.class);
|
|
|
|
|
@ -190,7 +191,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
// 校验正确性
|
|
|
|
|
validateUserExists(id);
|
|
|
|
|
validateEmailUnique(id, reqVO.getEmail());
|
|
|
|
|
validateMobileUnique(id, reqVO.getMobile());
|
|
|
|
|
validateUsernameUnique(id, reqVO.getUsername());
|
|
|
|
|
// 执行更新
|
|
|
|
|
userMapper.updateById(BeanUtils.toBean(reqVO, AdminUserDO.class).setId(id));
|
|
|
|
|
}
|
|
|
|
|
@ -276,11 +277,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
return userMapper.selectByUsername(username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public AdminUserDO getUserByMobile(String mobile) {
|
|
|
|
|
return userMapper.selectByMobile(mobile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<AdminUserDO> getUserPage(UserPageReqVO reqVO) {
|
|
|
|
|
// 如果有角色编号,查询角色对应的用户编号
|
|
|
|
|
@ -366,7 +362,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
return deptIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AdminUserDO validateUserForCreateOrUpdate(Long id, String username, String mobile, String email,
|
|
|
|
|
private AdminUserDO validateUserForCreateOrUpdate(Long id, String username, String email,
|
|
|
|
|
Long deptId, Set<Long> postIds) {
|
|
|
|
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
|
|
return DataPermissionUtils.executeIgnore(() -> {
|
|
|
|
|
@ -374,8 +370,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
AdminUserDO user = validateUserExists(id);
|
|
|
|
|
// 校验用户名唯一
|
|
|
|
|
validateUsernameUnique(id, username);
|
|
|
|
|
// 校验手机号唯一
|
|
|
|
|
validateMobileUnique(id, mobile);
|
|
|
|
|
// 校验邮箱唯一
|
|
|
|
|
validateEmailUnique(id, email);
|
|
|
|
|
// 校验部门处于开启状态
|
|
|
|
|
@ -400,56 +394,62 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
void validateUsernameUnique(Long id, String username) {
|
|
|
|
|
if (StrUtil.isBlank(username)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AdminUserDO user = userMapper.selectByUsername(username);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
|
|
|
|
if (id == null) {
|
|
|
|
|
throw exception(USER_USERNAME_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
if (!user.getId().equals(id)) {
|
|
|
|
|
throw exception(USER_USERNAME_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
TenantUtils.executeIgnore(() -> {
|
|
|
|
|
if (StrUtil.isBlank(username)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AdminUserDO user = userMapper.selectByUsername(username);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
|
|
|
|
if (id == null) {
|
|
|
|
|
throw exception(USER_USERNAME_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
if (!user.getId().equals(id)) {
|
|
|
|
|
throw exception(USER_USERNAME_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
void validateEmailUnique(Long id, String email) {
|
|
|
|
|
if (StrUtil.isBlank(email)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AdminUserDO user = userMapper.selectByEmail(email);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
|
|
|
|
if (id == null) {
|
|
|
|
|
throw exception(USER_EMAIL_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
if (!user.getId().equals(id)) {
|
|
|
|
|
throw exception(USER_EMAIL_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
TenantUtils.executeIgnore(() -> {
|
|
|
|
|
if (StrUtil.isBlank(email)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AdminUserDO user = userMapper.selectByEmail(email);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
|
|
|
|
if (id == null) {
|
|
|
|
|
throw exception(USER_EMAIL_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
if (!user.getId().equals(id)) {
|
|
|
|
|
throw exception(USER_EMAIL_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
void validateMobileUnique(Long id, String mobile) {
|
|
|
|
|
if (StrUtil.isBlank(mobile)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AdminUserDO user = userMapper.selectByMobile(mobile);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
|
|
|
|
if (id == null) {
|
|
|
|
|
throw exception(USER_MOBILE_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
if (!user.getId().equals(id)) {
|
|
|
|
|
throw exception(USER_MOBILE_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
TenantUtils.executeIgnore(() ->{
|
|
|
|
|
if (StrUtil.isBlank(mobile)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AdminUserDO user = userMapper.selectByUsername(mobile);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
|
|
|
|
if (id == null) {
|
|
|
|
|
throw exception(USER_MOBILE_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
if (!user.getId().equals(id)) {
|
|
|
|
|
throw exception(USER_MOBILE_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -494,7 +494,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
}
|
|
|
|
|
// 2.1.2 校验,判断是否有不符合的原因
|
|
|
|
|
try {
|
|
|
|
|
validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
|
|
|
|
|
validateUserForCreateOrUpdate(null, importUser.getUsername(), importUser.getEmail(),
|
|
|
|
|
importUser.getDeptId(), null);
|
|
|
|
|
} catch (ServiceException ex) {
|
|
|
|
|
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
|
|
|
|
|
|