|
|
@@ -91,42 +91,51 @@ public class UserInfoManage { |
|
|
|
entity.setRealName(req.getRealName()); |
|
|
|
entity.setUsername(req.getUserName()); |
|
|
|
entity.setAvatarFileId(req.getAvatarFileId()); |
|
|
|
entity.setAccountStatus(AccountStatus.ENABLE); |
|
|
|
userInfoService.saveOrUpdate(entity); |
|
|
|
if (userId == null) { |
|
|
|
String password = passwordEncoder.encode(req.getPassword()); |
|
|
|
List<UserAuth> auths = new ArrayList<>(); |
|
|
|
UserAuth accountAuth = new UserAuth(); |
|
|
|
accountAuth.setAuthType(AuthTypeEnum.ACCOUNT_PASSWORD.name()); |
|
|
|
accountAuth.setUserId(entity.getId()); |
|
|
|
accountAuth.setIdentifier(entity.getUsername()); |
|
|
|
accountAuth.setCredential(password); |
|
|
|
auths.add(accountAuth); |
|
|
|
UserAuth phoneAuth = new UserAuth(); |
|
|
|
phoneAuth.setAuthType(AuthTypeEnum.PHONE_PASSWORD.name()); |
|
|
|
phoneAuth.setUserId(entity.getId()); |
|
|
|
phoneAuth.setIdentifier(entity.getMobile()); |
|
|
|
phoneAuth.setCredential(password); |
|
|
|
auths.add(phoneAuth); |
|
|
|
userAuthService.saveBatch(auths); |
|
|
|
saveUserAuth(req, entity); |
|
|
|
} else { |
|
|
|
// 用户ID不为空时修改账号 |
|
|
|
if (!oldUser.getMobile().equals(req.getPhoneNo())) { |
|
|
|
LambdaUpdateWrapper<UserAuth> phoneAuth = Wrappers.lambdaUpdate(UserAuth.class) |
|
|
|
.set(UserAuth::getIdentifier, req.getPhoneNo()) |
|
|
|
.eq(UserAuth::getUserId, userId) |
|
|
|
.eq(UserAuth::getAuthType, AuthTypeEnum.PHONE_PASSWORD); |
|
|
|
userAuthService.update(phoneAuth); |
|
|
|
} |
|
|
|
if (!oldUser.getUsername().equals(req.getUserName())) { |
|
|
|
LambdaUpdateWrapper<UserAuth> accountAuth = Wrappers.lambdaUpdate(UserAuth.class) |
|
|
|
.set(UserAuth::getIdentifier, req.getUserName()) |
|
|
|
.eq(UserAuth::getUserId, userId) |
|
|
|
.eq(UserAuth::getAuthType, AuthTypeEnum.ACCOUNT_PASSWORD); |
|
|
|
userAuthService.update(accountAuth); |
|
|
|
} |
|
|
|
modifyAccount(req, oldUser, userId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void modifyAccount(SaveUserReq req, UserInfo oldUser, Long userId) { |
|
|
|
// 用户ID不为空时修改账号 |
|
|
|
if (!oldUser.getMobile().equals(req.getPhoneNo())) { |
|
|
|
Wrapper<UserAuth> phoneAuth = Wrappers.lambdaUpdate(UserAuth.class) |
|
|
|
.set(UserAuth::getIdentifier, req.getPhoneNo()) |
|
|
|
.eq(UserAuth::getUserId, userId) |
|
|
|
.eq(UserAuth::getAuthType, AuthTypeEnum.PHONE_PASSWORD); |
|
|
|
userAuthService.update(phoneAuth); |
|
|
|
} |
|
|
|
if (!oldUser.getUsername().equals(req.getUserName())) { |
|
|
|
Wrapper<UserAuth> accountAuth = Wrappers.lambdaUpdate(UserAuth.class) |
|
|
|
.set(UserAuth::getIdentifier, req.getUserName()) |
|
|
|
.eq(UserAuth::getUserId, userId) |
|
|
|
.eq(UserAuth::getAuthType, AuthTypeEnum.ACCOUNT_PASSWORD); |
|
|
|
userAuthService.update(accountAuth); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void saveUserAuth(SaveUserReq req, UserInfo entity) { |
|
|
|
String password = passwordEncoder.encode(req.getPassword()); |
|
|
|
List<UserAuth> auths = new ArrayList<>(); |
|
|
|
UserAuth accountAuth = new UserAuth(); |
|
|
|
accountAuth.setAuthType(AuthTypeEnum.ACCOUNT_PASSWORD.name()); |
|
|
|
accountAuth.setUserId(entity.getId()); |
|
|
|
accountAuth.setIdentifier(entity.getUsername()); |
|
|
|
accountAuth.setCredential(password); |
|
|
|
auths.add(accountAuth); |
|
|
|
UserAuth phoneAuth = new UserAuth(); |
|
|
|
phoneAuth.setAuthType(AuthTypeEnum.PHONE_PASSWORD.name()); |
|
|
|
phoneAuth.setUserId(entity.getId()); |
|
|
|
phoneAuth.setIdentifier(entity.getMobile()); |
|
|
|
phoneAuth.setCredential(password); |
|
|
|
auths.add(phoneAuth); |
|
|
|
userAuthService.saveBatch(auths); |
|
|
|
} |
|
|
|
|
|
|
|
public UserDetailVO getUserDetail(Long userId) { |
|
|
|
UserInfo info = userInfoService.getById(userId); |
|
|
|
Assert.notNull(info, "用户不存在"); |
|
|
|