1
0

2 Commits 3f86b8fc6b ... 3656881960

Autor SHA1 Mensaje Fecha
  openHj 3656881960 Merge remote-tracking branch 'origin/master' hace 11 meses
  openHj a2379f4d78 浏览记录 hace 11 meses
Se han modificado 1 ficheros con 0 adiciones y 86 borrados
  1. 0 86
      hx-xmhjc/src/main/java/com/fjhx/xmhjc/filter/BrowsingFilter.java

+ 0 - 86
hx-xmhjc/src/main/java/com/fjhx/xmhjc/filter/BrowsingFilter.java

@@ -1,86 +0,0 @@
-package com.fjhx.xmhjc.filter;
-
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.StrUtil;
-import cn.hutool.extra.spring.SpringUtil;
-import com.fjhx.xmhjc.utils.NetUtils;
-import com.ruoyi.common.core.redis.RedisCache;
-import org.springframework.core.Ordered;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-import org.springframework.util.AntPathMatcher;
-import org.springframework.util.PathMatcher;
-
-import javax.servlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-/**
- * 浏览记录过滤器
- * @author hj
- * @date 2024年03月12日 9:47
- */
-@Component
-public class BrowsingFilter implements Filter {
-    private static final RedisCache redisCache = SpringUtil.getBean(RedisCache.class);
-
-    private static final String[] FILTER_URL = {"/open/**"};
-
-
-
-
-    @Override
-    public void init(FilterConfig filterConfig) throws ServletException {
-        Filter.super.init(filterConfig);
-    }
-
-    @Override
-    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
-        HttpServletRequest request = (HttpServletRequest) servletRequest;
-        String requestUrl = request.getRequestURI();
-
-        PathMatcher matcher = new AntPathMatcher();
-        boolean match = false;
-
-        filterChain.doFilter(servletRequest, servletResponse);
-        for(String url : FILTER_URL){
-            match = matcher.match(url, requestUrl);
-            if (match){
-                String ip = NetUtils.getIpAddress(request);
-                String key = "browsing:" + ip + "#" + DateUtil.today();
-                //判断redis中是否存在key,存在则不记录
-                if(validRedisKey(key)){
-                    filterChain.doFilter(servletRequest, servletResponse);
-                    return;
-                }
-                //TODO 记录浏览记录入库
-
-
-                break;
-            }
-        }
-    }
-
-    @Override
-    public void destroy() {
-        Filter.super.destroy();
-    }
-
-
-    /**
-     * 判断redis中是否存在key
-     * @param key
-     * @return true 存在 false 不存在
-     */
-    private synchronized boolean validRedisKey(String key){
-        String cacheObject = redisCache.getCacheObject(key);
-        if(StrUtil.isNotBlank(cacheObject)){
-            return true;
-        }
-        //不存在则记录
-        redisCache.setCacheObject(key, key, 1, TimeUnit.DAYS);
-        return false;
-    }
-}