Commit 52bbc016447af3d2351d972f5c5c6fa700dfb604

Authored by 谭毅彬
1 parent 94bd886a

访问限制优化

Signed-off-by: TanYibin <5491541@qq.com>
huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimit.java
... ... @@ -13,5 +13,5 @@ public @interface AccessLimit {
13 13 int seconds();
14 14  
15 15 // 最大次数
16   - int maxCount();
  16 + long maxCount();
17 17 }
18 18 \ No newline at end of file
... ...
huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimitInterceptor.java
... ... @@ -44,13 +44,11 @@ public class AccessLimitInterceptor extends HandlerInterceptorAdapter {
44 44 return true;
45 45 }
46 46 int seconds = accessLimit.seconds();
47   - int maxCount = accessLimit.maxCount();
  47 + long maxCount = accessLimit.maxCount();
48 48 String accessLimitKey = "Access_Limit_" + request.getRequestURI();
49 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 52 log.error("{},超出访问频次限制。限制频次:{}秒{}次", request.getRequestURI(), maxCount, seconds);
55 53 throw new JeecgBootException("超出访问频次限制");
56 54 }
... ...