From 52bbc016447af3d2351d972f5c5c6fa700dfb604 Mon Sep 17 00:00:00 2001
From: TanYibin <5491541@qq.com>
Date: Tue, 13 Jun 2023 14:22:51 +0800
Subject: [PATCH] 访问限制优化

---
 huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimit.java            | 2 +-
 huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimitInterceptor.java | 8 +++-----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimit.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimit.java
index c41fb3d..08f8f7a 100644
--- a/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimit.java
+++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimit.java
@@ -13,5 +13,5 @@ public @interface AccessLimit {
     int seconds();
 
     // 最大次数
-    int maxCount();
+    long maxCount();
 }
\ No newline at end of file
diff --git a/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimitInterceptor.java b/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimitInterceptor.java
index 3fc6821..a35c39a 100644
--- a/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimitInterceptor.java
+++ b/huaheng-wms-core/src/main/java/org/jeecg/utils/interceptor/AccessLimitInterceptor.java
@@ -44,13 +44,11 @@ public class AccessLimitInterceptor extends HandlerInterceptorAdapter {
                 return true;
             }
             int seconds = accessLimit.seconds();
-            int maxCount = accessLimit.maxCount();
+            long maxCount = accessLimit.maxCount();
             String accessLimitKey = "Access_Limit_" + request.getRequestURI();
             synchronized (accessLimitKey) {
-                Integer count = huahengRedisUtil.get(accessLimitKey, Integer.class);
-                if (count == null || count < maxCount) {
-                    huahengRedisUtil.incr(accessLimitKey, seconds);
-                } else {
+                long count = huahengRedisUtil.incr(accessLimitKey, seconds);
+                if (count > maxCount) {
                     log.error("{},超出访问频次限制。限制频次:{}秒{}次", request.getRequestURI(), maxCount, seconds);
                     throw new JeecgBootException("超出访问频次限制");
                 }
--
libgit2 0.22.2