|
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
8
|
import org.springframework.beans.factory.annotation.Value;
|
8
|
import org.springframework.beans.factory.annotation.Value;
|
|
9
|
import org.springframework.stereotype.Component;
|
9
|
import org.springframework.stereotype.Component;
|
|
10
|
import com.alibaba.fastjson.JSONObject;
|
10
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
11
|
+import com.ruoyi.common.annotation.RepeatSubmit;
|
|
11
|
import com.ruoyi.common.constant.Constants;
|
12
|
import com.ruoyi.common.constant.Constants;
|
|
12
|
import com.ruoyi.common.core.redis.RedisCache;
|
13
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
13
|
import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
|
14
|
import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
|
|
@@ -35,21 +36,9 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
@@ -35,21 +36,9 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
35
|
@Autowired
|
36
|
@Autowired
|
|
36
|
private RedisCache redisCache;
|
37
|
private RedisCache redisCache;
|
|
37
|
|
38
|
|
|
38
|
- /**
|
|
|
|
39
|
- * 间隔时间,单位:秒 默认10秒
|
|
|
|
40
|
- *
|
|
|
|
41
|
- * 两次相同参数的请求,如果间隔时间大于该参数,系统不会认定为重复提交的数据
|
|
|
|
42
|
- */
|
|
|
|
43
|
- private int intervalTime = 10;
|
|
|
|
44
|
-
|
|
|
|
45
|
- public void setIntervalTime(int intervalTime)
|
|
|
|
46
|
- {
|
|
|
|
47
|
- this.intervalTime = intervalTime;
|
|
|
|
48
|
- }
|
|
|
|
49
|
-
|
|
|
|
50
|
@SuppressWarnings("unchecked")
|
39
|
@SuppressWarnings("unchecked")
|
|
51
|
@Override
|
40
|
@Override
|
|
52
|
- public boolean isRepeatSubmit(HttpServletRequest request)
|
41
|
+ public boolean isRepeatSubmit(HttpServletRequest request, RepeatSubmit annotation)
|
|
53
|
{
|
42
|
{
|
|
54
|
String nowParams = "";
|
43
|
String nowParams = "";
|
|
55
|
if (request instanceof RepeatedlyRequestWrapper)
|
44
|
if (request instanceof RepeatedlyRequestWrapper)
|
|
@@ -87,7 +76,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
@@ -87,7 +76,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
87
|
if (sessionMap.containsKey(url))
|
76
|
if (sessionMap.containsKey(url))
|
|
88
|
{
|
77
|
{
|
|
89
|
Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url);
|
78
|
Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url);
|
|
90
|
- if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap))
|
79
|
+ if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap, annotation.interval()))
|
|
91
|
{
|
80
|
{
|
|
92
|
return true;
|
81
|
return true;
|
|
93
|
}
|
82
|
}
|
|
@@ -95,7 +84,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
@@ -95,7 +84,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
95
|
}
|
84
|
}
|
|
96
|
Map<String, Object> cacheMap = new HashMap<String, Object>();
|
85
|
Map<String, Object> cacheMap = new HashMap<String, Object>();
|
|
97
|
cacheMap.put(url, nowDataMap);
|
86
|
cacheMap.put(url, nowDataMap);
|
|
98
|
- redisCache.setCacheObject(cacheRepeatKey, cacheMap, intervalTime, TimeUnit.SECONDS);
|
87
|
+ redisCache.setCacheObject(cacheRepeatKey, cacheMap, annotation.interval(), TimeUnit.MILLISECONDS);
|
|
99
|
return false;
|
88
|
return false;
|
|
100
|
}
|
89
|
}
|
|
101
|
|
90
|
|
|
@@ -112,11 +101,11 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
@@ -112,11 +101,11 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
|
112
|
/**
|
101
|
/**
|
|
113
|
* 判断两次间隔时间
|
102
|
* 判断两次间隔时间
|
|
114
|
*/
|
103
|
*/
|
|
115
|
- private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap)
|
104
|
+ private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap, int interval)
|
|
116
|
{
|
105
|
{
|
|
117
|
long time1 = (Long) nowMap.get(REPEAT_TIME);
|
106
|
long time1 = (Long) nowMap.get(REPEAT_TIME);
|
|
118
|
long time2 = (Long) preMap.get(REPEAT_TIME);
|
107
|
long time2 = (Long) preMap.get(REPEAT_TIME);
|
|
119
|
- if ((time1 - time2) < (this.intervalTime * 1000))
|
108
|
+ if ((time1 - time2) < interval)
|
|
120
|
{
|
109
|
{
|
|
121
|
return true;
|
110
|
return true;
|
|
122
|
}
|
111
|
}
|