From dcaeb18870ecdf319dbdb03820405a745d4eeb32 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期五, 17 九月 2021 17:22:45 +0800 Subject: [PATCH] add 增加 集群限流功能 --- ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java index 8fc4e79..47b7fbb 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java @@ -2,14 +2,14 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.io.IoUtil; -import cn.hutool.core.lang.Validator; import com.ruoyi.common.annotation.RepeatSubmit; import com.ruoyi.common.constant.Constants; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.filter.RepeatedlyRequestWrapper; import com.ruoyi.common.utils.JsonUtils; +import com.ruoyi.common.utils.RedisUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.config.properties.RepeatSubmitProperties; -import com.ruoyi.framework.config.properties.TokenProperties; +import com.ruoyi.common.properties.TokenProperties; import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -38,7 +38,6 @@ private final TokenProperties tokenProperties; private final RepeatSubmitProperties repeatSubmitProperties; - private final RedisCache redisCache; @SuppressWarnings("unchecked") @@ -60,7 +59,7 @@ } // body鍙傛暟涓虹┖锛岃幏鍙朠arameter鐨勬暟鎹� - if (Validator.isEmpty(nowParams)) { + if (StringUtils.isEmpty(nowParams)) { nowParams = JsonUtils.toJsonString(request.getParameterMap()); } Map<String, Object> nowDataMap = new HashMap<String, Object>(); @@ -72,14 +71,14 @@ // 鍞竴鍊硷紙娌℃湁娑堟伅澶村垯浣跨敤璇锋眰鍦板潃锛� String submitKey = request.getHeader(tokenProperties.getHeader()); - if (Validator.isEmpty(submitKey)) { + if (StringUtils.isEmpty(submitKey)) { submitKey = url; } // 鍞竴鏍囪瘑锛堟寚瀹歬ey + 娑堟伅澶达級 String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + submitKey; - Object sessionObj = redisCache.getCacheObject(cacheRepeatKey); + Object sessionObj = RedisUtils.getCacheObject(cacheRepeatKey); if (sessionObj != null) { Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; if (sessionMap.containsKey(url)) { @@ -91,7 +90,7 @@ } Map<String, Object> cacheMap = new HashMap<String, Object>(); cacheMap.put(url, nowDataMap); - redisCache.setCacheObject(cacheRepeatKey, cacheMap, Convert.toInt(intervalTime), TimeUnit.MILLISECONDS); + RedisUtils.setCacheObject(cacheRepeatKey, cacheMap, Convert.toInt(intervalTime), TimeUnit.MILLISECONDS); return false; } -- Gitblit v1.9.3