From 39e7d8a84b71af2aaea749be2026e1e3f0a95611 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Sat, 18 Sep 2021 21:20:18 +0800
Subject: [PATCH] 优化aop语法 使用spring自动注入注解 基于注解拦截的aop注解不可能为空
---
ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java | 40 ++++------------------------------------
1 files changed, 4 insertions(+), 36 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java
index 453c79c..6254db9 100644
--- a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java
+++ b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java
@@ -1,12 +1,8 @@
package com.ruoyi.common.datascope.aspect;
-import java.lang.reflect.Method;
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 com.ruoyi.common.core.utils.StringUtils;
@@ -59,27 +55,15 @@
@Autowired
private TokenService tokenService;
- // 配置织入点
- @Pointcut("@annotation(com.ruoyi.common.datascope.annotation.DataScope)")
- public void dataScopePointCut()
- {
- }
-
- @Before("dataScopePointCut()")
- public void doBefore(JoinPoint point) throws Throwable
+ @Before("@annotation(controllerDataScope)")
+ public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable
{
clearDataScope(point);
- handleDataScope(point);
+ handleDataScope(point, controllerDataScope);
}
- protected void handleDataScope(final JoinPoint joinPoint)
+ protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope)
{
- // 获得注解
- DataScope controllerDataScope = getAnnotationLog(joinPoint);
- if (controllerDataScope == null)
- {
- return;
- }
// 获取当前的用户
LoginUser loginUser = tokenService.getLoginUser();
if (StringUtils.isNotNull(loginUser))
@@ -153,22 +137,6 @@
baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
}
}
- }
-
- /**
- * 是否存在注解,如果存在就获取
- */
- private DataScope getAnnotationLog(JoinPoint joinPoint)
- {
- Signature signature = joinPoint.getSignature();
- MethodSignature methodSignature = (MethodSignature) signature;
- Method method = methodSignature.getMethod();
-
- if (method != null)
- {
- return method.getAnnotation(DataScope.class);
- }
- return null;
}
/**
--
Gitblit v1.9.3