|
|
@@ -37,21 +37,23 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
/**
|
|
|
- * 间隔时间,单位:秒 默认10秒
|
|
|
+ * 默认间隔时间,单位:毫秒 默认10秒(10000毫秒)
|
|
|
*
|
|
|
* 两次相同参数的请求,如果间隔时间大于该参数,系统不会认定为重复提交的数据
|
|
|
*/
|
|
|
- private int intervalTime = 10;
|
|
|
+ private int defaultIntervalTime = 10000;
|
|
|
|
|
|
- public void setIntervalTime(int intervalTime)
|
|
|
+ public void setDefaultIntervalTime(int defaultIntervalTime)
|
|
|
{
|
|
|
- this.intervalTime = intervalTime;
|
|
|
+ this.defaultIntervalTime = defaultIntervalTime;
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
- public boolean isRepeatSubmit(HttpServletRequest request)
|
|
|
+ public boolean isRepeatSubmit(HttpServletRequest request, int interval)
|
|
|
{
|
|
|
+ int intervalMs = interval > 0 ? interval : defaultIntervalTime;
|
|
|
+
|
|
|
String nowParams = "";
|
|
|
if (request instanceof RepeatedlyRequestWrapper)
|
|
|
{
|
|
|
@@ -88,7 +90,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
|
|
|
if (sessionMap.containsKey(url))
|
|
|
{
|
|
|
Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url);
|
|
|
- if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap))
|
|
|
+ if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap, intervalMs))
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
@@ -96,7 +98,8 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
|
|
|
}
|
|
|
Map<String, Object> cacheMap = new HashMap<String, Object>();
|
|
|
cacheMap.put(url, nowDataMap);
|
|
|
- redisCache.setCacheObject(cacheRepeatKey, cacheMap, intervalTime, TimeUnit.SECONDS);
|
|
|
+ int intervalSeconds = (intervalMs + 999) / 1000;
|
|
|
+ redisCache.setCacheObject(cacheRepeatKey, cacheMap, intervalSeconds, TimeUnit.SECONDS);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -112,12 +115,15 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
|
|
|
|
|
|
/**
|
|
|
* 判断两次间隔时间
|
|
|
+ * @param nowMap 当前请求数据
|
|
|
+ * @param preMap 上次请求数据
|
|
|
+ * @param intervalMs 间隔时间(毫秒)
|
|
|
*/
|
|
|
- private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap)
|
|
|
+ private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap, int intervalMs)
|
|
|
{
|
|
|
long time1 = (Long) nowMap.get(REPEAT_TIME);
|
|
|
long time2 = (Long) preMap.get(REPEAT_TIME);
|
|
|
- if ((time1 - time2) < (this.intervalTime * 1000))
|
|
|
+ if ((time1 - time2) < intervalMs)
|
|
|
{
|
|
|
return true;
|
|
|
}
|