From 2917d335bc3fd1f6dfb57cbad6d73ba48bc5f9d7 Mon Sep 17 00:00:00 2001
From: konbai <1527468660@qq.com>
Date: 星期六, 19 二月 2022 16:15:44 +0800
Subject: [PATCH] update 优化 是否为管理员的判断

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java |   35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java
index 05cff03..54f373b 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java
@@ -5,25 +5,30 @@
 import cn.dev33.satoken.jwt.StpLogicJwtForStyle;
 import cn.dev33.satoken.router.SaRouter;
 import cn.dev33.satoken.stp.StpLogic;
+import cn.hutool.core.util.ObjectUtil;
+import com.ruoyi.common.helper.LoginHelper;
 import com.ruoyi.framework.config.properties.SecurityProperties;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * sa-token 閰嶇疆
  *
  * @author Lion Li
  */
+@RequiredArgsConstructor
 @Slf4j
 @Configuration
 public class SaTokenConfig implements WebMvcConfigurer {
 
-    @Autowired
-    private SecurityProperties securityProperties;
+    private final SecurityProperties securityProperties;
 
     /**
      * 娉ㄥ唽sa-token鐨勬嫤鎴櫒
@@ -39,16 +44,22 @@
                 // 鎺掗櫎涓嬩笉闇�瑕佹嫤鎴殑
                 .notMatch(securityProperties.getExcludes())
                 .check(() -> {
-                    // 鍋氫竴浜涜闂鏌�
-//                    if (log.isDebugEnabled()) {
-//                        Long userId = LoginUtils.getUserId();
-//                        if (StringUtils.isNotNull(userId)) {
-//                             log.debug("鍓╀綑鏈夋晥鏃堕棿: {}", StpUtil.getTokenTimeout());
-//                             log.debug("涓存椂鏈夋晥鏃堕棿: {}", StpUtil.getTokenActivityTimeout());
-//                        }
-//                    }
+                    Long userId = LoginHelper.getUserId();
+                    if (ObjectUtil.isNotNull(userId)) {
+                        // 鏈夋晥鐜囧奖鍝� 鐢ㄤ簬涓存椂娴嬭瘯
+                        // if (log.isDebugEnabled()) {
+                        //     log.debug("鍓╀綑鏈夋晥鏃堕棿: {}", StpUtil.getTokenTimeout());
+                        //     log.debug("涓存椂鏈夋晥鏃堕棿: {}", StpUtil.getTokenActivityTimeout());
+                        // }
+                    }
                 });
-        })).addPathPatterns("/**");
+        }) {
+            @SuppressWarnings("all")
+            @Override
+            public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+                LoginHelper.clearCache();
+            }
+        }).addPathPatterns("/**");
         registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
     }
 

--
Gitblit v1.9.3