Search in sources :

Example 1 with DataPermission

use of com.ruoyi.common.mybatis.annotation.DataPermission in project RuoYi-Cloud-Plus by JavaLionLi.

the class PlusDataPermissionHandler method findAnnotation.

private DataColumn[] findAnnotation(String mappedStatementId) {
    StringBuilder sb = new StringBuilder(mappedStatementId);
    int index = sb.lastIndexOf(".");
    String clazzName = sb.substring(0, index);
    String methodName = sb.substring(index + 1, sb.length());
    Class<?> clazz = ClassUtil.loadClass(clazzName);
    List<Method> methods = Arrays.stream(ClassUtil.getDeclaredMethods(clazz)).filter(method -> method.getName().equals(methodName)).collect(Collectors.toList());
    DataPermission dataPermission;
    // 获取方法注解
    for (Method method : methods) {
        dataPermission = dataPermissionCacheMap.get(mappedStatementId);
        if (ObjectUtil.isNotNull(dataPermission)) {
            return dataPermission.value();
        }
        if (AnnotationUtil.hasAnnotation(method, DataPermission.class)) {
            dataPermission = AnnotationUtil.getAnnotation(method, DataPermission.class);
            dataPermissionCacheMap.put(mappedStatementId, dataPermission);
            return dataPermission.value();
        }
    }
    dataPermission = dataPermissionCacheMap.get(clazz.getName());
    if (ObjectUtil.isNotNull(dataPermission)) {
        return dataPermission.value();
    }
    // 获取类注解
    if (AnnotationUtil.hasAnnotation(clazz, DataPermission.class)) {
        dataPermission = AnnotationUtil.getAnnotation(clazz, DataPermission.class);
        dataPermissionCacheMap.put(clazz.getName(), dataPermission);
        return dataPermission.value();
    }
    return null;
}
Also used : Arrays(java.util.Arrays) ObjectUtil(cn.hutool.core.util.ObjectUtil) ParserContext(org.springframework.expression.ParserContext) DataPermissionHelper(com.ruoyi.common.mybatis.helper.DataPermissionHelper) ClassUtil(cn.hutool.core.util.ClassUtil) LoginHelper(com.ruoyi.common.satoken.utils.LoginHelper) ServiceException(com.ruoyi.common.core.exception.ServiceException) JSQLParserException(net.sf.jsqlparser.JSQLParserException) TemplateParserContext(org.springframework.expression.common.TemplateParserContext) DataPermission(com.ruoyi.common.mybatis.annotation.DataPermission) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) SpringUtils(com.ruoyi.common.core.utils.SpringUtils) BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) Map(java.util.Map) DataScopeType(com.ruoyi.common.mybatis.enums.DataScopeType) Method(java.lang.reflect.Method) LoginUser(com.ruoyi.system.api.model.LoginUser) CCJSqlParserUtil(net.sf.jsqlparser.parser.CCJSqlParserUtil) AnnotationUtil(cn.hutool.core.annotation.AnnotationUtil) ConcurrentHashSet(cn.hutool.core.collection.ConcurrentHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) StringUtils(com.ruoyi.common.core.utils.StringUtils) Expression(net.sf.jsqlparser.expression.Expression) Collectors(java.util.stream.Collectors) BeanResolver(org.springframework.expression.BeanResolver) ExpressionParser(org.springframework.expression.ExpressionParser) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) RoleDTO(com.ruoyi.system.api.model.RoleDTO) DataColumn(com.ruoyi.common.mybatis.annotation.DataColumn) ArrayUtil(cn.hutool.core.util.ArrayUtil) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Parenthesis(net.sf.jsqlparser.expression.Parenthesis) DataPermission(com.ruoyi.common.mybatis.annotation.DataPermission) Method(java.lang.reflect.Method)

Aggregations

AnnotationUtil (cn.hutool.core.annotation.AnnotationUtil)1 ConcurrentHashSet (cn.hutool.core.collection.ConcurrentHashSet)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 ClassUtil (cn.hutool.core.util.ClassUtil)1 ObjectUtil (cn.hutool.core.util.ObjectUtil)1 ServiceException (com.ruoyi.common.core.exception.ServiceException)1 SpringUtils (com.ruoyi.common.core.utils.SpringUtils)1 StringUtils (com.ruoyi.common.core.utils.StringUtils)1 DataColumn (com.ruoyi.common.mybatis.annotation.DataColumn)1 DataPermission (com.ruoyi.common.mybatis.annotation.DataPermission)1 DataScopeType (com.ruoyi.common.mybatis.enums.DataScopeType)1 DataPermissionHelper (com.ruoyi.common.mybatis.helper.DataPermissionHelper)1 LoginHelper (com.ruoyi.common.satoken.utils.LoginHelper)1 LoginUser (com.ruoyi.system.api.model.LoginUser)1 RoleDTO (com.ruoyi.system.api.model.RoleDTO)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1