fix 修复 修改用户信息 校验用户名未排除当前用户问题

feature/model
疯狂的狮子li 2 years ago
parent 02f4fdb2e5
commit 98bb1f00ee

@ -136,7 +136,7 @@ public class SysUserController extends BaseController {
@Log(title = "用户管理", businessType = BusinessType.INSERT) @Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public R<Void> add(@Validated @RequestBody SysUser user) { public R<Void> add(@Validated @RequestBody SysUser user) {
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) { if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) {
return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) } else if (StringUtils.isNotEmpty(user.getPhonenumber())
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
@ -158,7 +158,7 @@ public class SysUserController extends BaseController {
public R<Void> edit(@Validated @RequestBody SysUser user) { public R<Void> edit(@Validated @RequestBody SysUser user) {
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId()); userService.checkUserDataScope(user.getUserId());
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) { if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) {
return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) } else if (StringUtils.isNotEmpty(user.getPhonenumber())
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {

@ -86,7 +86,7 @@ public interface ISysUserService {
* @param user * @param user
* @return * @return
*/ */
String checkUserNameUnique(String userName); String checkUserNameUnique(SysUser user);
/** /**
* *

@ -48,15 +48,15 @@ public class SysRegisterService {
if (captchaEnabled) { if (captchaEnabled) {
validateCaptcha(username, registerBody.getCode(), registerBody.getUuid(), request); validateCaptcha(username, registerBody.getCode(), registerBody.getUuid(), request);
} }
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) {
throw new UserException("user.register.save.error", username);
}
SysUser sysUser = new SysUser(); SysUser sysUser = new SysUser();
sysUser.setUserName(username); sysUser.setUserName(username);
sysUser.setNickName(username); sysUser.setNickName(username);
sysUser.setPassword(BCrypt.hashpw(password)); sysUser.setPassword(BCrypt.hashpw(password));
sysUser.setUserType(userType); sysUser.setUserType(userType);
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(sysUser))) {
throw new UserException("user.register.save.error", username);
}
boolean regFlag = userService.registerUser(sysUser); boolean regFlag = userService.registerUser(sysUser);
if (!regFlag) { if (!regFlag) {
throw new UserException("user.register.error"); throw new UserException("user.register.error");

@ -193,12 +193,14 @@ public class SysUserServiceImpl implements ISysUserService {
/** /**
* *
* *
* @param userName * @param user
* @return * @return
*/ */
@Override @Override
public String checkUserNameUnique(String userName) { public String checkUserNameUnique(SysUser user) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, userName)); boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getUserName, user.getUserName())
.ne(ObjectUtil.isNotNull(user.getUserId()), SysUser::getUserId, user.getUserId()));
if (exist) { if (exist) {
return UserConstants.NOT_UNIQUE; return UserConstants.NOT_UNIQUE;
} }

Loading…
Cancel
Save