From 9cdcbbccbf4b8752504d11e3379a7156492b07f9 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期一, 11 十一月 2024 10:26:34 +0800 Subject: [PATCH] update 重构 将UserConstants改为SystemConstants 统一常量使用 降低使用难度避免误解 --- ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java | 44 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 10 deletions(-) diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java index 8e5af46..cdc5684 100644 --- a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java +++ b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/utils/LoginHelper.java @@ -3,12 +3,13 @@ import cn.dev33.satoken.session.SaSession; import cn.dev33.satoken.stp.SaLoginModel; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.dromara.common.core.constant.SystemConstants; import org.dromara.common.core.constant.TenantConstants; -import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.enums.UserType; @@ -35,6 +36,7 @@ public static final String USER_NAME_KEY = "userName"; public static final String DEPT_KEY = "deptId"; public static final String DEPT_NAME_KEY = "deptName"; + public static final String DEPT_CATEGORY_KEY = "deptCategory"; public static final String CLIENT_KEY = "clientid"; /** @@ -52,6 +54,7 @@ .setExtra(USER_NAME_KEY, loginUser.getUsername()) .setExtra(DEPT_KEY, loginUser.getDeptId()) .setExtra(DEPT_NAME_KEY, loginUser.getDeptName()) + .setExtra(DEPT_CATEGORY_KEY, loginUser.getDeptCategory()) ); StpUtil.getTokenSession().set(LOGIN_USER_KEY, loginUser); } @@ -86,6 +89,13 @@ } /** + * 鑾峰彇鐢ㄦ埛璐︽埛 + */ + public static String getUsername() { + return Convert.toStr(getExtra(USER_NAME_KEY)); + } + + /** * 鑾峰彇绉熸埛ID */ public static String getTenantId() { @@ -97,6 +107,20 @@ */ public static Long getDeptId() { return Convert.toLong(getExtra(DEPT_KEY)); + } + + /** + * 鑾峰彇閮ㄩ棬鍚� + */ + public static String getDeptName() { + return Convert.toStr(getExtra(DEPT_NAME_KEY)); + } + + /** + * 鑾峰彇閮ㄩ棬绫诲埆缂栫爜 + */ + public static String getDeptCategory() { + return Convert.toStr(getExtra(DEPT_CATEGORY_KEY)); } /** @@ -114,13 +138,6 @@ } /** - * 鑾峰彇鐢ㄦ埛璐︽埛 - */ - public static String getUsername() { - return getLoginUser().getUsername(); - } - - /** * 鑾峰彇鐢ㄦ埛绫诲瀷 */ public static UserType getUserType() { @@ -135,7 +152,7 @@ * @return 缁撴灉 */ public static boolean isSuperAdmin(Long userId) { - return UserConstants.SUPER_ADMIN_ID.equals(userId); + return SystemConstants.SUPER_ADMIN_ID.equals(userId); } /** @@ -154,6 +171,9 @@ * @return 缁撴灉 */ public static boolean isTenantAdmin(Set<String> rolePermission) { + if (CollUtil.isEmpty(rolePermission)) { + return false; + } return rolePermission.contains(TenantConstants.TENANT_ADMIN_ROLE_KEY); } @@ -172,7 +192,11 @@ * @return 缁撴灉 */ public static boolean isLogin() { - return getLoginUser() != null; + try { + return getLoginUser() != null; + } catch (Exception e) { + return false; + } } } -- Gitblit v1.9.3