feat(profile): 允许用户修改用户名(loginCode)

- 后端 UpdateUserInfoDTO 新增 loginCode 字段
- 后端 Service 层新增 loginCode 唯一性检查,已被使用则报错
- 前端表单支持编辑用户名
- 前端 DTO 类型同步更新
This commit is contained in:
小蟑螂
2026-03-29 15:21:05 +08:00
parent a4fdac079c
commit f3a0309dbd
4 changed files with 30 additions and 3 deletions
@@ -9,6 +9,11 @@ import lombok.Data;
@Data
public class UpdateUserInfoDTO {
/**
* 登录账号(用户名)
*/
private String loginCode;
/**
* 用户名称
*/
@@ -211,7 +211,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
}
}
// 检查登录账号是否已被其他用户使用
if (StringUtils.hasText(updateUserInfoDTO.getLoginCode()) &&
!updateUserInfoDTO.getLoginCode().equals(user.getLoginCode())) {
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserPO::getLoginCode, updateUserInfoDTO.getLoginCode());
if (this.count(wrapper) > 0) {
throw new BusinessException("登录账号已被其他用户使用");
}
}
// 更新用户信息
if (StringUtils.hasText(updateUserInfoDTO.getLoginCode())) {
user.setLoginCode(updateUserInfoDTO.getLoginCode());
}
if (StringUtils.hasText(updateUserInfoDTO.getRealName())) {
user.setRealName(updateUserInfoDTO.getRealName());
}