Search in sources :

Example 6 with DataColumn

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

the class PlusDataPermissionHandler method getSqlSegment.

public Expression getSqlSegment(Expression where, String mappedStatementId, boolean isSelect) {
    DataColumn[] dataColumns = findAnnotation(mappedStatementId);
    if (ArrayUtil.isEmpty(dataColumns)) {
        inavlidCacheSet.add(mappedStatementId);
        return where;
    }
    LoginUser currentUser = DataPermissionHelper.getVariable("user");
    if (ObjectUtil.isNull(currentUser)) {
        currentUser = LoginHelper.getLoginUser();
        DataPermissionHelper.setVariable("user", currentUser);
    }
    // 如果是超级管理员,则不过滤数据
    if (LoginHelper.isAdmin()) {
        return where;
    }
    String dataFilterSql = buildDataFilter(dataColumns, isSelect);
    if (StringUtils.isBlank(dataFilterSql)) {
        return where;
    }
    try {
        Expression expression = CCJSqlParserUtil.parseExpression(dataFilterSql);
        // 数据权限使用单独的括号 防止与其他条件冲突
        Parenthesis parenthesis = new Parenthesis(expression);
        if (ObjectUtil.isNotNull(where)) {
            return new AndExpression(where, parenthesis);
        } else {
            return parenthesis;
        }
    } catch (JSQLParserException e) {
        throw new ServiceException("数据权限解析异常 => " + e.getMessage());
    }
}
Also used : Parenthesis(net.sf.jsqlparser.expression.Parenthesis) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) ServiceException(com.ruoyi.common.exception.ServiceException) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) Expression(net.sf.jsqlparser.expression.Expression) JSQLParserException(net.sf.jsqlparser.JSQLParserException) DataColumn(com.ruoyi.common.annotation.DataColumn) LoginUser(com.ruoyi.common.core.domain.model.LoginUser)

Aggregations

DataColumn (com.ruoyi.common.annotation.DataColumn)6 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)6 ServiceException (com.ruoyi.common.exception.ServiceException)6 RoleDTO (com.ruoyi.common.core.domain.dto.RoleDTO)4 DataScopeType (com.ruoyi.common.enums.DataScopeType)4 JSQLParserException (net.sf.jsqlparser.JSQLParserException)4 Expression (net.sf.jsqlparser.expression.Expression)4 Parenthesis (net.sf.jsqlparser.expression.Parenthesis)4 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)4 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)4 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 DataPermission (com.ruoyi.common.annotation.DataPermission)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