用户管理:已有认证密码账户不允许修改手机号账号

This commit is contained in:
gaoqr
2025-03-10 16:10:47 +08:00
parent 0f5c00281c
commit 9e2e91eca1
3 changed files with 8 additions and 7 deletions
@@ -59,7 +59,7 @@ public class ErrorCodeConstants {
public static final ErrorCode INSUFFICIENT_PERMISSIONS = new ErrorCode(1_002_003_014, "当前用户权限不足,无法修改开料状态");
public static final ErrorCode USERNAME_MULTIPLE_ERROR = new ErrorCode(1_002_003_015,"存在【{}】重复用户,请联系系统管理员");
public static final ErrorCode USER_OPERATE_SELF_STATUS_ERROR = new ErrorCode(1_002_003_016, "不允许操作用户自身状态");
public static final ErrorCode THE_PASSWORD_MUST_CONTAIN_AT_LEAST_ONE_UPPER_LETTER = new ErrorCode(1_002_003_017, "密码必须包含至少一个大写字母");
public static final ErrorCode USER_MOBILE_UPDATE_NOT_ALLOW_ERROR = new ErrorCode(1_002_003_017, "该用户已通过手机号认证设置密码,不允许在用户管理修改手机号,如需修改请前往个人中心");
// ========== 部门模块 1-002-004-000 ==========
public static final ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "已经存在该名字的部门");
@@ -171,7 +171,7 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
* @param id
* @return
*/
@Select("SELECT username FROM system_users WHERE id = #{id} FOR UPDATE")
@Select("SELECT username, password FROM system_users WHERE id = #{id} FOR UPDATE")
AdminUserDO selectByIdForUpdate(@Param("id") Long id);
/**
@@ -78,6 +78,7 @@ import static com.cf.imes.framework.common.util.collection.CollectionUtils.conve
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
import static com.cf.imes.module.system.dal.redis.RedisKeyConstants.OAUTH2_ACCESS_TOKEN;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.USER_ME_ERROR;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.USER_MOBILE_UPDATE_NOT_ALLOW_ERROR;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.USER_OPERATE_SELF_STATUS_ERROR;
/**
@@ -200,11 +201,11 @@ public class AdminUserServiceImpl implements AdminUserService {
Long id = updateObj.getId();
if (ObjectUtil.isNotNull(id)) {
AdminUserDO adminUserDO = userMapper.selectByIdForUpdate(id);
// 当手机号(账号)发生改变时,清空密码
if (ObjectUtil.isNotNull(adminUserDO) && !Objects.equals(adminUserDO.getUsername(), mobile)) {
// 清空密码
updateObj.setPassword("");
updateObj.setUsername(mobile);
// 当手机号(账号)发生改变时,只允许密码为空的通过(还没有使用验证码来设置过密码
if (ObjectUtil.isNotNull(adminUserDO) && !StringUtils.equals(adminUserDO.getUsername(), mobile)) {
if(StringUtils.isNotEmpty(adminUserDO.getPassword())) {
throw ServiceExceptionUtil.exception(USER_MOBILE_UPDATE_NOT_ALLOW_ERROR);
}
}
}
userMapper.updateById(updateObj);