|
|
@@ -77,7 +77,11 @@ public class UserServiceImpl implements UserService {
|
|
|
// TODO 密码修改后是否应该清除用户 session?
|
|
|
@Override
|
|
|
public void modifyUserPassword(Integer userId, String newPassword) {
|
|
|
- User userEntity = userRepository.getOne(userId);
|
|
|
+ User userEntity = userRepository.findById(userId).orElse(null);
|
|
|
+ if (userEntity == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
userEntity.setPassword(newPassword);
|
|
|
setEncryptPassword(userEntity);
|
|
|
userRepository.save(userEntity);
|
|
|
@@ -85,7 +89,11 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
@Override
|
|
|
public void modifyUserInfo(UserInfo userInfo) {
|
|
|
- User userEntity = userRepository.getOne(userInfo.getUserId());
|
|
|
+ User userEntity = userRepository.findById(userInfo.getUserId()).orElse(null);
|
|
|
+ if (userEntity == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
userEntity.setNickname(userInfo.getNickname());
|
|
|
userEntity.setMobilePhone(userInfo.getMobilePhone());
|
|
|
userEntity.setEmail(userInfo.getEmail());
|
|
|
@@ -94,7 +102,10 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
@Override
|
|
|
public void setUserRoles(UserRole userRole) {
|
|
|
- User userEntity = userRepository.getOne(userRole.getUserId());
|
|
|
+ User userEntity = userRepository.findById(userRole.getUserId()).orElse(null);
|
|
|
+ if (userEntity == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
/*Set<UserAuthority> authorities = userRole.getRoles().stream()
|
|
|
.map(role -> new UserAuthority(role.getTitle()))
|
|
|
.collect(Collectors.toSet());
|
|
|
@@ -109,7 +120,11 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
@Override
|
|
|
public void setUserStatus(Integer userId, Boolean enable) {
|
|
|
- User userEntity = userRepository.getOne(userId);
|
|
|
+ User userEntity = userRepository.findById(userId).orElse(null);
|
|
|
+ if (userEntity == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
userEntity.setIsEnabled(enable);
|
|
|
userRepository.save(userEntity);
|
|
|
}
|
|
|
@@ -117,7 +132,11 @@ public class UserServiceImpl implements UserService {
|
|
|
// TODO 删除用户后还需清除用户 session
|
|
|
@Override
|
|
|
public void deleteUser(Integer userId) {
|
|
|
- User userEntity = userRepository.getOne(userId);
|
|
|
+ User userEntity = userRepository.findById(userId).orElse(null);
|
|
|
+ if (userEntity == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (userEntity.getId() == 1) {
|
|
|
log.error("不能删除管理员帐号");
|
|
|
} else {
|