Browse Source

:sparkles: 统计异常调用的次数

lag 6 months ago
parent
commit
957e13dd6b

+ 8 - 6
ghjg-item-datashare-server/src/main/java/com/shanghaichengdi/ghjgitem/config/FrequencyLimitInterceptor.java

@@ -43,7 +43,7 @@ public class FrequencyLimitInterceptor implements HandlerInterceptor {
     String requestURI = request.getRequestURI().replace(replacePackageName, "");
     FrequencyInfoVo frequencyInfoVo = dataShareServiceNewService.getFrequencyInfoFromCache(
         user.getClient(), requestURI);
-    if (frequencyInfoVo.getLockLimits() > 10) {
+    if (frequencyInfoVo.getLockLimits() > 9) {
       response.setCharacterEncoding(CharsetKit.UTF_8);
       response.setContentType("application/json;charset=utf-8");
       response.setHeader("Access-Control-Allow-Origin", "*");
@@ -80,15 +80,17 @@ public class FrequencyLimitInterceptor implements HandlerInterceptor {
   private boolean startDelay(FrequencyInfoVo vo) {
     long currentTime = System.currentTimeMillis();
     if (currentTime - vo.getLastTime() > vo.getFrequencyTime()) {
-      if (currentTime - vo.getLastTime() <= 60000) {
-        vo.setLockLimits(vo.getLockLimits() + 1);
-      } else {
-        vo.setLockLimits(0);
-      }
       vo.setLastTime(currentTime);
       dataShareServiceNewService.setNewLastRequestTime(vo);
       return true;
     }
+    if (currentTime - vo.getLastTime() <= 60000) {
+      vo.setLockLimits(vo.getLockLimits() + 1);
+    } else {
+      vo.setLockLimits(0);
+    }
+    vo.setLastTime(currentTime);
+    dataShareServiceNewService.setNewLastRequestTime(vo);
     log.warn("变化后的接口限制频率为:{}",
         com.alibaba.fastjson.JSONObject.toJSONString(vo));
     log.error("{},调用时间间隔为:{}毫秒,该接口调用频率限制为:{}毫秒,上次调用时间为{}",