Commit 52bbc016447af3d2351d972f5c5c6fa700dfb604
1 parent
94bd886a
访问限制优化
Signed-off-by: TanYibin <5491541@qq.com>
Showing
2 changed files
with
4 additions
and
6 deletions
huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimit.java
huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimitInterceptor.java
@@ -44,13 +44,11 @@ public class AccessLimitInterceptor extends HandlerInterceptorAdapter { | @@ -44,13 +44,11 @@ public class AccessLimitInterceptor extends HandlerInterceptorAdapter { | ||
44 | return true; | 44 | return true; |
45 | } | 45 | } |
46 | int seconds = accessLimit.seconds(); | 46 | int seconds = accessLimit.seconds(); |
47 | - int maxCount = accessLimit.maxCount(); | 47 | + long maxCount = accessLimit.maxCount(); |
48 | String accessLimitKey = "Access_Limit_" + request.getRequestURI(); | 48 | String accessLimitKey = "Access_Limit_" + request.getRequestURI(); |
49 | synchronized (accessLimitKey) { | 49 | synchronized (accessLimitKey) { |
50 | - Integer count = huahengRedisUtil.get(accessLimitKey, Integer.class); | ||
51 | - if (count == null || count < maxCount) { | ||
52 | - huahengRedisUtil.incr(accessLimitKey, seconds); | ||
53 | - } else { | 50 | + long count = huahengRedisUtil.incr(accessLimitKey, seconds); |
51 | + if (count > maxCount) { | ||
54 | log.error("{},超出访问频次限制。限制频次:{}秒{}次", request.getRequestURI(), maxCount, seconds); | 52 | log.error("{},超出访问频次限制。限制频次:{}秒{}次", request.getRequestURI(), maxCount, seconds); |
55 | throw new JeecgBootException("超出访问频次限制"); | 53 | throw new JeecgBootException("超出访问频次限制"); |
56 | } | 54 | } |