From d6edc56d0e24f028f7e3d2f9865dff025e694e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 7 Mar 2023 23:49:02 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20userId=20=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/satoken/utils/LoginHelper.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/java/com/ruoyi/common/satoken/utils/LoginHelper.java b/ruoyi-common/ruoyi-common-satoken/src/main/java/com/ruoyi/common/satoken/utils/LoginHelper.java index 2dee11c3..c4cc66e5 100644 --- a/ruoyi-common/ruoyi-common-satoken/src/main/java/com/ruoyi/common/satoken/utils/LoginHelper.java +++ b/ruoyi-common/ruoyi-common-satoken/src/main/java/com/ruoyi/common/satoken/utils/LoginHelper.java @@ -1,6 +1,7 @@ package com.ruoyi.common.satoken.utils; import cn.dev33.satoken.context.SaHolder; +import cn.dev33.satoken.context.model.SaStorage; import cn.dev33.satoken.stp.SaLoginModel; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.convert.Convert; @@ -46,7 +47,9 @@ public class LoginHelper { * @param loginUser 登录用户信息 */ public static void loginByDevice(LoginUser loginUser, DeviceType deviceType) { - SaHolder.getStorage().set(LOGIN_USER_KEY, loginUser); + SaStorage storage = SaHolder.getStorage(); + storage.set(LOGIN_USER_KEY, loginUser); + storage.set(USER_KEY, loginUser.getUserId()); SaLoginModel model = new SaLoginModel(); if (ObjectUtil.isNotNull(deviceType)) { model.setDevice(deviceType.getDevice()); @@ -81,7 +84,11 @@ public class LoginHelper { public static Long getUserId() { Long userId; try { - userId = Convert.toLong(StpUtil.getExtra(USER_KEY)); + userId = Convert.toLong(SaHolder.getStorage().get(USER_KEY)); + if (ObjectUtil.isNull(userId)) { + userId = Convert.toLong(StpUtil.getExtra(USER_KEY).toString()); + SaHolder.getStorage().set(USER_KEY, userId); + } } catch (Exception e) { return null; }