From dbc4616dc648d25b3a1e3792f2e53b125ccfdc00 Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期一, 20 九月 2021 18:56:43 +0800 Subject: [PATCH] reset dataSourceAspect --- src/main/java/com/ruoyi/framework/aspectj/RateLimiterAspect.java | 33 ++++----------------------------- 1 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/ruoyi/framework/aspectj/RateLimiterAspect.java b/src/main/java/com/ruoyi/framework/aspectj/RateLimiterAspect.java index c31a67e..71169e0 100644 --- a/src/main/java/com/ruoyi/framework/aspectj/RateLimiterAspect.java +++ b/src/main/java/com/ruoyi/framework/aspectj/RateLimiterAspect.java @@ -4,10 +4,8 @@ import java.util.Collections; import java.util.List; 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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,16 +47,9 @@ this.limitScript = limitScript; } - // 閰嶇疆缁囧叆鐐� - @Pointcut("@annotation(com.ruoyi.framework.aspectj.lang.annotation.RateLimiter)") - public void rateLimiterPointCut() + @Before("@annotation(rateLimiter)") + public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable { - } - - @Before("rateLimiterPointCut()") - public void doBefore(JoinPoint point) throws Throwable - { - RateLimiter rateLimiter = getAnnotationRateLimiter(point); String key = rateLimiter.key(); int time = rateLimiter.time(); int count = rateLimiter.count(); @@ -84,33 +75,17 @@ } } - /** - * 鏄惁瀛樺湪娉ㄨВ锛屽鏋滃瓨鍦ㄥ氨鑾峰彇 - */ - private RateLimiter getAnnotationRateLimiter(JoinPoint joinPoint) - { - Signature signature = joinPoint.getSignature(); - MethodSignature methodSignature = (MethodSignature) signature; - Method method = methodSignature.getMethod(); - - if (method != null) - { - return method.getAnnotation(RateLimiter.class); - } - return null; - } - public String getCombineKey(RateLimiter rateLimiter, JoinPoint point) { StringBuffer stringBuffer = new StringBuffer(rateLimiter.key()); if (rateLimiter.limitType() == LimitType.IP) { - stringBuffer.append(IpUtils.getIpAddr(ServletUtils.getRequest())); + stringBuffer.append(IpUtils.getIpAddr(ServletUtils.getRequest())).append("-"); } MethodSignature signature = (MethodSignature) point.getSignature(); Method method = signature.getMethod(); Class<?> targetClass = method.getDeclaringClass(); - stringBuffer.append("-").append(targetClass.getName()).append("- ").append(method.getName()); + stringBuffer.append(targetClass.getName()).append("-").append(method.getName()); return stringBuffer.toString(); } } -- Gitblit v1.9.3