|
@ -15,6 +15,8 @@ |
|
|
*/ |
|
|
*/ |
|
|
package org.nl.modules.system.service.impl; |
|
|
package org.nl.modules.system.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.secure.SaSecureUtil; |
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import org.nl.modules.common.config.FileProperties; |
|
|
import org.nl.modules.common.config.FileProperties; |
|
@ -89,9 +91,6 @@ public class UserServiceImpl implements UserService { |
|
|
if (userRepository.findByUsername(resources.getUsername()) != null) { |
|
|
if (userRepository.findByUsername(resources.getUsername()) != null) { |
|
|
throw new EntityExistException(User.class, "username", resources.getUsername()); |
|
|
throw new EntityExistException(User.class, "username", resources.getUsername()); |
|
|
} |
|
|
} |
|
|
if (userRepository.findByEmail(resources.getEmail()) != null) { |
|
|
|
|
|
throw new EntityExistException(User.class, "email", resources.getEmail()); |
|
|
|
|
|
} |
|
|
|
|
|
resources.setCreateBy(SecurityUtils.getCurrentUsername()); |
|
|
resources.setCreateBy(SecurityUtils.getCurrentUsername()); |
|
|
userRepository.save(resources); |
|
|
userRepository.save(resources); |
|
|
} |
|
|
} |
|
@ -102,45 +101,36 @@ public class UserServiceImpl implements UserService { |
|
|
User user = userRepository.findById(resources.getId()).orElseGet(User::new); |
|
|
User user = userRepository.findById(resources.getId()).orElseGet(User::new); |
|
|
ValidationUtil.isNull(user.getId(), "User", "id", resources.getId()); |
|
|
ValidationUtil.isNull(user.getId(), "User", "id", resources.getId()); |
|
|
User user1 = userRepository.findByUsername(resources.getUsername()); |
|
|
User user1 = userRepository.findByUsername(resources.getUsername()); |
|
|
User user2 = userRepository.findByEmail(resources.getEmail()); |
|
|
|
|
|
|
|
|
|
|
|
if (user1 != null && !user.getId().equals(user1.getId())) { |
|
|
if (user1 != null && !user.getId().equals(user1.getId())) { |
|
|
throw new EntityExistException(User.class, "username", resources.getUsername()); |
|
|
throw new EntityExistException(User.class, "username", resources.getUsername()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (user2 != null && !user.getId().equals(user2.getId())) { |
|
|
|
|
|
throw new EntityExistException(User.class, "email", resources.getEmail()); |
|
|
|
|
|
} |
|
|
|
|
|
// 如果用户的角色改变
|
|
|
// 如果用户的角色改变
|
|
|
if (!resources.getRoles().equals(user.getRoles())) { |
|
|
if (!resources.getRoles().equals(user.getRoles())) { |
|
|
redisUtils.del(CacheKey.DATA_USER + resources.getId()); |
|
|
redisUtils.del(CacheKey.DATA_USER + resources.getId()); |
|
|
redisUtils.del(CacheKey.MENU_USER + resources.getId()); |
|
|
redisUtils.del(CacheKey.MENU_USER + resources.getId()); |
|
|
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); |
|
|
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); |
|
|
} |
|
|
} |
|
|
// 如果用户名称修改
|
|
|
|
|
|
if(!resources.getUsername().equals(user.getUsername())){ |
|
|
|
|
|
redisUtils.del("user::username:" + user.getUsername()); |
|
|
redisUtils.del("user::username:" + user.getUsername()); |
|
|
} |
|
|
|
|
|
// 如果用户被禁用,则清除用户登录信息
|
|
|
// 如果用户被禁用,则清除用户登录信息
|
|
|
if(!resources.getEnabled()){ |
|
|
if(!resources.getEnabled()){ |
|
|
onlineUserService.kickOutForUsername(resources.getUsername()); |
|
|
onlineUserService.kickOutForUsername(resources.getUsername()); |
|
|
} |
|
|
} |
|
|
User clone = new User(); // jpa 多表问题,需要用新的类来进行修改
|
|
|
user.setId(resources.getId()); |
|
|
clone.setId(resources.getId()); |
|
|
user.setUsername(resources.getUsername()); |
|
|
clone.setUsername(resources.getUsername()); |
|
|
user.setEmail(resources.getEmail()); |
|
|
clone.setEmail(resources.getEmail()); |
|
|
user.setEnabled(resources.getEnabled()); |
|
|
clone.setEnabled(resources.getEnabled()); |
|
|
user.setRoles(resources.getRoles()); |
|
|
clone.setRoles(resources.getRoles()); |
|
|
user.setDept(resources.getDept()); |
|
|
clone.setDept(resources.getDept()); |
|
|
user.setPhone(resources.getPhone()); |
|
|
clone.setPhone(resources.getPhone()); |
|
|
user.setNickName(resources.getNickName()); |
|
|
clone.setNickName(resources.getNickName()); |
|
|
user.setGender(resources.getGender()); |
|
|
clone.setGender(resources.getGender()); |
|
|
if (ObjectUtil.isNotEmpty(resources.getPassword())) |
|
|
|
|
|
user.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt")); |
|
|
userRepository.save(clone); |
|
|
|
|
|
|
|
|
userRepository.save(user); |
|
|
// 清除缓存
|
|
|
// 清除缓存
|
|
|
delCaches(user.getId(), user.getUsername()); |
|
|
delCaches(user.getId(), user.getUsername()); |
|
|
// 修改session
|
|
|
|
|
|
// flushSession(user);
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -153,8 +143,6 @@ public class UserServiceImpl implements UserService { |
|
|
userRepository.save(user); |
|
|
userRepository.save(user); |
|
|
// 清理缓存
|
|
|
// 清理缓存
|
|
|
delCaches(user.getId(), user.getUsername()); |
|
|
delCaches(user.getId(), user.getUsername()); |
|
|
// 修改session
|
|
|
|
|
|
// flushSession(user);
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -184,7 +172,6 @@ public class UserServiceImpl implements UserService { |
|
|
public void updatePass(String username, String pass) { |
|
|
public void updatePass(String username, String pass) { |
|
|
userRepository.updatePass(username, pass, new Date()); |
|
|
userRepository.updatePass(username, pass, new Date()); |
|
|
redisUtils.del("user::username:" + username); |
|
|
redisUtils.del("user::username:" + username); |
|
|
// flushSession(userRepository.findByUsername(username));
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -200,7 +187,6 @@ public class UserServiceImpl implements UserService { |
|
|
FileUtil.del(oldPath); |
|
|
FileUtil.del(oldPath); |
|
|
} |
|
|
} |
|
|
@NotBlank String username = user.getUsername(); |
|
|
@NotBlank String username = user.getUsername(); |
|
|
// flushSession(user);
|
|
|
|
|
|
return new HashMap<String, String>(1) {{ |
|
|
return new HashMap<String, String>(1) {{ |
|
|
put("avatar", file.getName()); |
|
|
put("avatar", file.getName()); |
|
|
}}; |
|
|
}}; |
|
@ -210,7 +196,6 @@ public class UserServiceImpl implements UserService { |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void updateEmail(String username, String email) { |
|
|
public void updateEmail(String username, String email) { |
|
|
userRepository.updateEmail(username, email); |
|
|
userRepository.updateEmail(username, email); |
|
|
// flushSession(userRepository.findByUsername(username));
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -239,17 +224,6 @@ public class UserServiceImpl implements UserService { |
|
|
*/ |
|
|
*/ |
|
|
public void delCaches(Long id, String username) { |
|
|
public void delCaches(Long id, String username) { |
|
|
redisUtils.del(CacheKey.USER_ID + id); |
|
|
redisUtils.del(CacheKey.USER_ID + id); |
|
|
// flushCache(username);
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 清理 登陆时 用户缓存信息 |
|
|
|
|
|
* |
|
|
|
|
|
* @param user / |
|
|
|
|
|
*/ |
|
|
|
|
|
// private void flushSession(User user) {
|
|
|
|
|
|
// UserDto userDto = this.findByName(user.getUsername());
|
|
|
|
|
|
// List<String> permissionList = roleService.getPermissionList(userDto.getId().toString());
|
|
|
|
|
|
// flushSessionUtil.flushSessionInfo(userDto, permissionList);
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
} |
|
|