mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-11-04 10:57:10 +08:00 
			
		
		
		
	重构:重构获取登录用户信息的代码逻辑
1.用户基本信息调整为实时获取 2.登录用户不再保存基本信息,降低维护成本 3.移除冗余的维护登录用户基本信息的代码
This commit is contained in:
		@@ -25,7 +25,6 @@ import lombok.Data;
 | 
			
		||||
import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
 | 
			
		||||
import top.charles7c.cnadmin.common.constant.SysConsts;
 | 
			
		||||
import top.charles7c.cnadmin.common.enums.GenderEnum;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 登录用户信息
 | 
			
		||||
@@ -48,55 +47,25 @@ public class LoginUser implements Serializable {
 | 
			
		||||
     */
 | 
			
		||||
    private String username;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 昵称
 | 
			
		||||
     */
 | 
			
		||||
    private String nickname;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 性别(0未知 1男 2女)
 | 
			
		||||
     */
 | 
			
		||||
    private GenderEnum gender;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 手机号码
 | 
			
		||||
     */
 | 
			
		||||
    private String phone;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 邮箱
 | 
			
		||||
     */
 | 
			
		||||
    private String email;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 头像地址
 | 
			
		||||
     */
 | 
			
		||||
    private String avatar;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 描述
 | 
			
		||||
     */
 | 
			
		||||
    private String description;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 最后一次修改密码时间
 | 
			
		||||
     */
 | 
			
		||||
    private LocalDateTime pwdResetTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 部门 ID
 | 
			
		||||
     */
 | 
			
		||||
    private Long deptId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 部门名称
 | 
			
		||||
     * 权限码集合
 | 
			
		||||
     */
 | 
			
		||||
    private String deptName;
 | 
			
		||||
    private Set<String> permissions;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建时间
 | 
			
		||||
     * 角色编码集合
 | 
			
		||||
     */
 | 
			
		||||
    private LocalDateTime createTime;
 | 
			
		||||
    private Set<String> roles;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 角色集合
 | 
			
		||||
     */
 | 
			
		||||
    private Set<RoleDTO> roleSet;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 令牌
 | 
			
		||||
@@ -123,21 +92,6 @@ public class LoginUser implements Serializable {
 | 
			
		||||
     */
 | 
			
		||||
    private LocalDateTime loginTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 权限码集合
 | 
			
		||||
     */
 | 
			
		||||
    private Set<String> permissions;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 角色编码集合
 | 
			
		||||
     */
 | 
			
		||||
    private Set<String> roles;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 角色集合
 | 
			
		||||
     */
 | 
			
		||||
    private Set<RoleDTO> roleSet;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 是否为管理员
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -26,10 +26,12 @@ import lombok.NoArgsConstructor;
 | 
			
		||||
import cn.dev33.satoken.context.SaHolder;
 | 
			
		||||
import cn.dev33.satoken.stp.StpUtil;
 | 
			
		||||
import cn.hutool.extra.servlet.ServletUtil;
 | 
			
		||||
import cn.hutool.extra.spring.SpringUtil;
 | 
			
		||||
 | 
			
		||||
import top.charles7c.cnadmin.common.constant.CacheConsts;
 | 
			
		||||
import top.charles7c.cnadmin.common.model.dto.LogContext;
 | 
			
		||||
import top.charles7c.cnadmin.common.model.dto.LoginUser;
 | 
			
		||||
import top.charles7c.cnadmin.common.service.CommonUserService;
 | 
			
		||||
import top.charles7c.cnadmin.common.util.ExceptionUtils;
 | 
			
		||||
import top.charles7c.cnadmin.common.util.IpUtils;
 | 
			
		||||
import top.charles7c.cnadmin.common.util.ServletUtils;
 | 
			
		||||
@@ -110,7 +112,7 @@ public class LoginHelper {
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取登录用户 ID
 | 
			
		||||
     *
 | 
			
		||||
     * @return /
 | 
			
		||||
     * @return 登录用户 ID
 | 
			
		||||
     */
 | 
			
		||||
    public static Long getUserId() {
 | 
			
		||||
        return ExceptionUtils.exToNull(() -> getLoginUser().getId());
 | 
			
		||||
@@ -119,7 +121,7 @@ public class LoginHelper {
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取登录用户名
 | 
			
		||||
     *
 | 
			
		||||
     * @return /
 | 
			
		||||
     * @return 登录用户名
 | 
			
		||||
     */
 | 
			
		||||
    public static String getUsername() {
 | 
			
		||||
        return ExceptionUtils.exToNull(() -> getLoginUser().getUsername());
 | 
			
		||||
@@ -128,9 +130,20 @@ public class LoginHelper {
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取登录用户昵称
 | 
			
		||||
     *
 | 
			
		||||
     * @return /
 | 
			
		||||
     * @return 登录用户昵称
 | 
			
		||||
     */
 | 
			
		||||
    public static String getNickname() {
 | 
			
		||||
        return ExceptionUtils.exToNull(() -> getLoginUser().getNickname());
 | 
			
		||||
        return getNickname(getUserId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取登录用户昵称
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId
 | 
			
		||||
     *            登录用户 ID
 | 
			
		||||
     * @return 登录用户昵称
 | 
			
		||||
     */
 | 
			
		||||
    public static String getNickname(Long userId) {
 | 
			
		||||
        return ExceptionUtils.exToNull(() -> SpringUtil.getBean(CommonUserService.class).getNicknameById(userId));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user