Search in sources :

Example 1 with DataPermission

use of com.ruoyi.common.annotation.DataPermission in project RuoYi-Vue-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 : DataColumn(com.ruoyi.common.annotation.DataColumn) Arrays(java.util.Arrays) ObjectUtil(cn.hutool.core.util.ObjectUtil) SpringUtils(com.ruoyi.common.utils.spring.SpringUtils) ServiceException(com.ruoyi.common.exception.ServiceException) ParserContext(org.springframework.expression.ParserContext) RoleDTO(com.ruoyi.common.core.domain.dto.RoleDTO) ClassUtil(cn.hutool.core.util.ClassUtil) JSQLParserException(net.sf.jsqlparser.JSQLParserException) TemplateParserContext(org.springframework.expression.common.TemplateParserContext) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) StringUtils(com.ruoyi.common.utils.StringUtils) BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) Map(java.util.Map) Method(java.lang.reflect.Method) DataPermission(com.ruoyi.common.annotation.DataPermission) CCJSqlParserUtil(net.sf.jsqlparser.parser.CCJSqlParserUtil) DataScopeType(com.ruoyi.common.enums.DataScopeType) AnnotationUtil(cn.hutool.core.annotation.AnnotationUtil) ConcurrentHashSet(cn.hutool.core.collection.ConcurrentHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) LoginHelper(com.ruoyi.common.helper.LoginHelper) 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) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) ArrayUtil(cn.hutool.core.util.ArrayUtil) DataPermissionHelper(com.ruoyi.common.helper.DataPermissionHelper) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Parenthesis(net.sf.jsqlparser.expression.Parenthesis) DataPermission(com.ruoyi.common.annotation.DataPermission) Method(java.lang.reflect.Method)

Example 2 with DataPermission

use of com.ruoyi.common.annotation.DataPermission in project RuoYi-Flowable-Plus by KonBAI-Q.

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 : DataColumn(com.ruoyi.common.annotation.DataColumn) Arrays(java.util.Arrays) ObjectUtil(cn.hutool.core.util.ObjectUtil) SpringUtils(com.ruoyi.common.utils.spring.SpringUtils) ServiceException(com.ruoyi.common.exception.ServiceException) ParserContext(org.springframework.expression.ParserContext) RoleDTO(com.ruoyi.common.core.domain.dto.RoleDTO) ClassUtil(cn.hutool.core.util.ClassUtil) JSQLParserException(net.sf.jsqlparser.JSQLParserException) TemplateParserContext(org.springframework.expression.common.TemplateParserContext) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) StringUtils(com.ruoyi.common.utils.StringUtils) BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) Map(java.util.Map) Method(java.lang.reflect.Method) DataPermission(com.ruoyi.common.annotation.DataPermission) CCJSqlParserUtil(net.sf.jsqlparser.parser.CCJSqlParserUtil) DataScopeType(com.ruoyi.common.enums.DataScopeType) AnnotationUtil(cn.hutool.core.annotation.AnnotationUtil) ConcurrentHashSet(cn.hutool.core.collection.ConcurrentHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) LoginHelper(com.ruoyi.common.helper.LoginHelper) 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) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) ArrayUtil(cn.hutool.core.util.ArrayUtil) DataPermissionHelper(com.ruoyi.common.helper.DataPermissionHelper) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Parenthesis(net.sf.jsqlparser.expression.Parenthesis) DataPermission(com.ruoyi.common.annotation.DataPermission) Method(java.lang.reflect.Method)

Aggregations

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