Commit 743fce78290f0b359d3d99b79a6c9c0a2a5a0dee

Authored by RuoYi
1 parent 8b5d2542

优化防重提交唯一标识

ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
... ... @@ -61,6 +61,11 @@ public class Constants
61 61 * 登录用户 redis key
62 62 */
63 63 public static final String LOGIN_TOKEN_KEY = "login_tokens:";
  64 +
  65 + /**
  66 + * 防重提交 redis key
  67 + */
  68 + public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
64 69  
65 70 /**
66 71 * 验证码有效期(分钟)
... ...
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
... ... @@ -5,8 +5,10 @@ import java.util.Map;
5 5 import java.util.concurrent.TimeUnit;
6 6 import javax.servlet.http.HttpServletRequest;
7 7 import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.beans.factory.annotation.Value;
8 9 import org.springframework.stereotype.Component;
9 10 import com.alibaba.fastjson.JSONObject;
  11 +import com.ruoyi.common.constant.Constants;
10 12 import com.ruoyi.common.core.redis.RedisCache;
11 13 import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
12 14 import com.ruoyi.common.utils.StringUtils;
... ... @@ -26,7 +28,9 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
26 28  
27 29 public final String REPEAT_TIME = "repeatTime";
28 30  
29   - public final String CACHE_REPEAT_KEY = "repeatData";
  31 + // 令牌自定义标识
  32 + @Value("${token.header}")
  33 + private String header;
30 34  
31 35 @Autowired
32 36 private RedisCache redisCache;
... ... @@ -62,7 +66,10 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
62 66 // 请求地址(作为存放cache的key值)
63 67 String url = request.getRequestURI();
64 68  
65   - Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY);
  69 + // 唯一标识(指定key + 消息头)
  70 + String cache_repeat_key = Constants.REPEAT_SUBMIT_KEY + request.getHeader(header);
  71 +
  72 + Object sessionObj = redisCache.getCacheObject(cache_repeat_key);
66 73 if (sessionObj != null)
67 74 {
68 75 Map<String, Object> sessionMap = (Map<String, Object>) sessionObj;
... ... @@ -77,7 +84,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
77 84 }
78 85 Map<String, Object> cacheMap = new HashMap<String, Object>();
79 86 cacheMap.put(url, nowDataMap);
80   - redisCache.setCacheObject(CACHE_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS);
  87 + redisCache.setCacheObject(cache_repeat_key, cacheMap, intervalTime, TimeUnit.SECONDS);
81 88 return false;
82 89 }
83 90  
... ...