hexiao 2 gadi atpakaļ
vecāks
revīzija
2f1fe97635

+ 9 - 12
purchase-admin/src/main/java/com/ozs/web/filter/LogOutFilter.java

@@ -3,28 +3,25 @@ package com.ozs.web.filter;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.filter.Filter;
 import ch.qos.logback.core.spi.FilterReply;
-import com.ozs.common.constant.Constants;
 import com.ozs.common.utils.SecurityUtils;
-import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
 import org.springframework.util.ObjectUtils;
 
-@Slf4j
+import javax.annotation.PostConstruct;
+
 public class LogOutFilter extends Filter<ILoggingEvent> {
 
 
     @Override
     public FilterReply decide(ILoggingEvent event) {
-        String s = Constants.localVar.get();
-        if (!ObjectUtils.isEmpty(s)) {
-            Long userId = SecurityUtils.getUserId();
-            if (!ObjectUtils.isEmpty(userId)) {
-                if (userId.equals(Long.parseLong("-1"))) {
-                    return FilterReply.DENY;
-                }
-            }
-
+        if (getFlay()) {
+            return FilterReply.DENY;
         }
         return FilterReply.ACCEPT;
     }
 
+    private boolean getFlay() {
+        return LogOutUtil.getFlay();
+    }
+
 }

+ 24 - 0
purchase-admin/src/main/java/com/ozs/web/filter/LogOutUtil.java

@@ -0,0 +1,24 @@
+package com.ozs.web.filter;
+
+import com.ozs.common.constant.Constants;
+import com.ozs.common.utils.SecurityUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.util.ObjectUtils;
+
+
+@Slf4j
+public class LogOutUtil {
+
+    public static boolean getFlay() {
+        if (!ObjectUtils.isEmpty(Constants.map.keySet())) {
+            Long userId = SecurityUtils.getUserId();
+            if (!ObjectUtils.isEmpty(userId)) {
+                if (userId.equals(Long.parseLong("-1"))) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+}

+ 6 - 7
purchase-common/src/main/java/com/ozs/common/constant/Constants.java

@@ -12,11 +12,11 @@ import java.util.Map;
  * @author ruoyi
  */
 public class Constants {
- public static ThreadLocal<String> localVar = new ThreadLocal<String>();
- /**
-  * UTF-8 字符集
-  */
- public static final String UTF8 = "UTF-8";
+    /**
+     * UTF-8 字符集
+     */
+    public static final String UTF8 = "UTF-8";
+    public final static Map<String, LoginUser> map = new HashMap<>();
 
     /**
      * GBK 字符集
@@ -167,6 +167,5 @@ public class Constants {
     public static final String PROJECT_WARN_STATUS = "project_warn_status";
     // 单位性质
     public static final String SYS_COMPANY_NATURE = "sys_company_nature";
-
- public static Map<String, LoginUser> map = new HashMap<>();
+    public static ThreadLocal<String> localVar = new ThreadLocal<String>();
 }

+ 0 - 2
purchase-framework/src/main/java/com/ozs/framework/web/service/SysLoginService.java

@@ -75,8 +75,6 @@ public class SysLoginService {
             loginUser.setUserId(-1L);
             // 生成token
             String token = tokenService.createToken(loginUser);
-            Constants.localVar.remove();
-            Constants.localVar.set(token);
             Constants.map.clear();
             Constants.map.put(token, loginUser);
             return token;