🐛 昵称不能修改为空

This commit is contained in:
ronger 2024-03-15 16:34:38 +08:00
parent 6c9996c742
commit 19f47dee0d

View File

@ -188,11 +188,11 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public UserInfoDTO updateUserInfo(UserInfoDTO user) throws ServiceException { public UserInfoDTO updateUserInfo(UserInfoDTO user) throws ServiceException {
user.setNickname(formatNickname(user.getNickname())); boolean number = checkNicknameByIdUser(user.getIdUser(), user.getNickname());
Integer number = userMapper.checkNicknameByIdUser(user.getIdUser(), user.getNickname()); if (number) {
if (number > 0) {
throw new NicknameOccupyException("该昵称已使用!"); throw new NicknameOccupyException("该昵称已使用!");
} }
user.setNickname(formatNickname(user.getNickname()));
if (FileDataType.BASE64.equals(user.getAvatarType())) { if (FileDataType.BASE64.equals(user.getAvatarType())) {
String avatarUrl = UploadController.uploadBase64File(user.getAvatarUrl(), FilePath.AVATAR); String avatarUrl = UploadController.uploadBase64File(user.getAvatarUrl(), FilePath.AVATAR);
user.setAvatarUrl(avatarUrl); user.setAvatarUrl(avatarUrl);
@ -216,11 +216,11 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
} }
public boolean checkNicknameByIdUser(Long idUser, String nickname) { public boolean checkNicknameByIdUser(Long idUser, String nickname) {
Integer number = userMapper.checkNicknameByIdUser(idUser, nickname); if (StringUtils.isBlank(formatNickname(nickname))) {
if (number > 0) { throw new IllegalArgumentException("昵称不能为空!");
return false;
} }
return true; Integer number = userMapper.checkNicknameByIdUser(idUser, nickname);
return number <= 0;
} }
@Override @Override