mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 优化 getLoginUser 方法 支持返回多种类型登陆实体
This commit is contained in:
		@@ -17,6 +17,7 @@ import org.dromara.common.core.constant.TenantConstants;
 | 
			
		||||
import org.dromara.common.core.domain.dto.PostDTO;
 | 
			
		||||
import org.dromara.common.core.domain.dto.RoleDTO;
 | 
			
		||||
import org.dromara.common.core.domain.model.LoginUser;
 | 
			
		||||
import org.dromara.common.core.domain.model.XcxLoginUser;
 | 
			
		||||
import org.dromara.common.core.enums.LoginType;
 | 
			
		||||
import org.dromara.common.core.exception.ServiceException;
 | 
			
		||||
import org.dromara.common.core.exception.user.UserException;
 | 
			
		||||
@@ -109,7 +110,7 @@ public class SysLoginService {
 | 
			
		||||
     */
 | 
			
		||||
    public void logout() {
 | 
			
		||||
        try {
 | 
			
		||||
            LoginUser loginUser = LoginHelper.getLoginUser();
 | 
			
		||||
            XcxLoginUser loginUser = LoginHelper.getLoginUser();
 | 
			
		||||
            if (ObjectUtil.isNull(loginUser)) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -63,23 +63,25 @@ public class LoginHelper {
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取用户(多级缓存)
 | 
			
		||||
     */
 | 
			
		||||
    public static LoginUser getLoginUser() {
 | 
			
		||||
    @SuppressWarnings("unchecked cast")
 | 
			
		||||
    public static <T> T getLoginUser() {
 | 
			
		||||
        SaSession session = StpUtil.getTokenSession();
 | 
			
		||||
        if (ObjectUtil.isNull(session)) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        return (LoginUser) session.get(LOGIN_USER_KEY);
 | 
			
		||||
        return (T) session.get(LOGIN_USER_KEY);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取用户基于token
 | 
			
		||||
     */
 | 
			
		||||
    public static LoginUser getLoginUser(String token) {
 | 
			
		||||
    @SuppressWarnings("unchecked cast")
 | 
			
		||||
    public static <T> T getLoginUser(String token) {
 | 
			
		||||
        SaSession session = StpUtil.getTokenSessionByToken(token);
 | 
			
		||||
        if (ObjectUtil.isNull(session)) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        return (LoginUser) session.get(LOGIN_USER_KEY);
 | 
			
		||||
        return (T) session.get(LOGIN_USER_KEY);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -191,7 +193,11 @@ public class LoginHelper {
 | 
			
		||||
     * @return 结果
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isTenantAdmin() {
 | 
			
		||||
        return Convert.toBool(isTenantAdmin(getLoginUser().getRolePermission()));
 | 
			
		||||
        LoginUser loginUser = getLoginUser();
 | 
			
		||||
        if (loginUser == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        return Convert.toBool(isTenantAdmin(loginUser.getRolePermission()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user