From c99b9262a8ec9f826684c70fb4fce68ca85ceaab Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期六, 18 九月 2021 18:05:50 +0800
Subject: [PATCH] update 优化aop写法 使用spring自动注入注解参数

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java |   28 ++--------------------------
 1 files changed, 2 insertions(+), 26 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..3814a2c 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
@@ -14,16 +14,12 @@
 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;
 
 /**
  * 闃叉閲嶅鎻愪氦
@@ -40,14 +36,8 @@
     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) {
@@ -74,20 +64,6 @@
         if (lock == null) {
             throw new ServiceException("涓嶅厑璁搁噸澶嶆彁浜わ紝璇风◢鍚庡啀璇�!");
         }
-    }
-
-    /**
-     * 鏄惁瀛樺湪娉ㄨВ锛屽鏋滃瓨鍦ㄥ氨鑾峰彇
-     */
-    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