From 6e73d8b3ab93571cd3e7141bb865d2943d5f439b Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期三, 27 十月 2021 13:28:26 +0800
Subject: [PATCH] update 同步 dev 分支 更新最新改动

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java |   45 ++++++++++-----------------------------------
 1 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java
index b91b2e3..bb8b0f1 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java
@@ -1,5 +1,6 @@
 package com.ruoyi.framework.aspectj;
 
+import cn.dev33.satoken.SaManager;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
 import com.baomidou.lock.LockInfo;
@@ -7,23 +8,18 @@
 import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.exception.ServiceException;
-import com.ruoyi.common.properties.TokenProperties;
 import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.config.properties.RepeatSubmitProperties;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.Signature;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-import org.aspectj.lang.reflect.MethodSignature;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
-import java.lang.reflect.Method;
 
 /**
  * 闃叉閲嶅鎻愪氦
@@ -36,24 +32,17 @@
 @Component
 public class RepeatSubmitAspect {
 
-    private final TokenProperties tokenProperties;
     private final RepeatSubmitProperties repeatSubmitProperties;
     private final LockTemplate lockTemplate;
 
-    // 閰嶇疆缁囧叆鐐�
-    @Pointcut("@annotation(com.ruoyi.common.annotation.RepeatSubmit)")
-    public void repeatSubmitPointCut() {
-    }
-
-    @Before("repeatSubmitPointCut()")
-    public void doBefore(JoinPoint point) throws Throwable {
-        RepeatSubmit repeatSubmit = getAnnotationRateLimiter(point);
+    @Before("@annotation(repeatSubmit)")
+    public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
         // 濡傛灉娉ㄨВ涓嶄负0 鍒欎娇鐢ㄦ敞瑙f暟鍊�
-        long intervalTime = repeatSubmitProperties.getIntervalTime();
-        if (repeatSubmit.intervalTime() > 0) {
-            intervalTime = repeatSubmit.timeUnit().toMillis(repeatSubmit.intervalTime());
+        long interval = repeatSubmitProperties.getInterval();
+        if (repeatSubmit.interval() > 0) {
+            interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
         }
-        if (intervalTime < 1000) {
+        if (interval < 1000) {
             throw new ServiceException("閲嶅鎻愪氦闂撮殧鏃堕棿涓嶈兘灏忎簬'1'绉�");
         }
         HttpServletRequest request = ServletUtils.getRequest();
@@ -63,31 +52,17 @@
         String url = request.getRequestURI();
 
         // 鍞竴鍊硷紙娌℃湁娑堟伅澶村垯浣跨敤璇锋眰鍦板潃锛�
-        String submitKey = request.getHeader(tokenProperties.getHeader());
+        String submitKey = request.getHeader(SaManager.getConfig().getTokenName());
         if (StringUtils.isEmpty(submitKey)) {
             submitKey = url;
         }
         submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
         // 鍞竴鏍囪瘑锛堟寚瀹歬ey + 娑堟伅澶达級
         String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + submitKey;
-        LockInfo lock = lockTemplate.lock(cacheRepeatKey, intervalTime, intervalTime / 2);
+        LockInfo lock = lockTemplate.lock(cacheRepeatKey, interval, interval / 2);
         if (lock == null) {
-            throw new ServiceException("涓嶅厑璁搁噸澶嶆彁浜わ紝璇风◢鍚庡啀璇�!");
+            throw new ServiceException(repeatSubmit.message());
         }
-    }
-
-    /**
-     * 鏄惁瀛樺湪娉ㄨВ锛屽鏋滃瓨鍦ㄥ氨鑾峰彇
-     */
-    private RepeatSubmit getAnnotationRateLimiter(JoinPoint joinPoint) {
-        Signature signature = joinPoint.getSignature();
-        MethodSignature methodSignature = (MethodSignature) signature;
-        Method method = methodSignature.getMethod();
-
-        if (method != null) {
-            return method.getAnnotation(RepeatSubmit.class);
-        }
-        return null;
     }
 
 }

--
Gitblit v1.9.3