Java Code Examples for com.ruoyi.system.domain.SysRole#getDataScope()

The following examples show how to use com.ruoyi.system.domain.SysRole#getDataScope() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataScopeAspect.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 数据范围过滤
 * @param joinPoint 切点
 * @param user 用户
 * @param alias 别名
 */
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String alias)
{
    StringBuilder sqlString = new StringBuilder();

    for (SysRole role : user.getRoles())
    {
        String dataScope = role.getDataScope();
        if (DATA_SCOPE_ALL.equals(dataScope))
        {
            sqlString = new StringBuilder();
            break;
        }
        else if (DATA_SCOPE_CUSTOM.equals(dataScope))
        {
            sqlString.append(StringUtils.format(
                    " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", alias,
                    role.getRoleId()));
        }
    }

    if (StringUtils.isNotBlank(sqlString.toString()))
    {
        BaseEntity baseEntity = (BaseEntity) joinPoint.getArgs()[0];
        baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
    }
}
 
Example 2
Source File: DataScopeAspect.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 数据范围过滤
 */
private static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String alias) {
    StringBuilder sqlString = new StringBuilder();

    for (SysRole role : user.getRoles()) {
        String dataScope = role.getDataScope();
        if (DATA_SCOPE_ALL.equals(dataScope)) {
            sqlString = new StringBuilder();
            break;
        } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
            sqlString.append(String.format(
                    " OR %s.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = %d ) " , alias,
                    role.getRoleId()));
        }else if (DATA_SCOPE_DEPT.equals(dataScope)){
            sqlString.append(String.format(" OR %s.dept_id = %d ", alias, user.getDeptId()));
        }else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)){
            String deptChild = user.getDept().getParentId() + "," + user.getDeptId();
            sqlString.append(String.format(
                    " OR  %s.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id =  %d or ancestors LIKE '%%%s%%' )",
                    alias, user.getDeptId(), deptChild));
        }
    }

    if (StrUtil.isNotBlank(sqlString.toString())) {
        BaseEntity baseEntity = (BaseEntity) joinPoint.getArgs()[0];
        baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
    }
}
 
Example 3
Source File: DataScopeAspect.java    From supplierShop with MIT License 4 votes vote down vote up
/**
 * 数据范围过滤
 * 
 * @param joinPoint 切点
 * @param user 用户
 * @param alias 别名
 */
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
{
    StringBuilder sqlString = new StringBuilder();

    for (SysRole role : user.getRoles())
    {
        String dataScope = role.getDataScope();
        if (DATA_SCOPE_ALL.equals(dataScope))
        {
            sqlString = new StringBuilder();
            break;
        }
        else if (DATA_SCOPE_CUSTOM.equals(dataScope))
        {
            sqlString.append(StringUtils.format(
                    " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
                    role.getRoleId()));
        }
        else if (DATA_SCOPE_DEPT.equals(dataScope))
        {
            sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
        }
        else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
        {
            sqlString.append(StringUtils.format(
                    " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
                    deptAlias, user.getDeptId(), user.getDeptId()));
        }
        else if (DATA_SCOPE_SELF.equals(dataScope))
        {
            if (StringUtils.isNotBlank(userAlias))
            {
                sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
            }
            else
            {
                // 数据权限为仅本人且没有userAlias别名不查询任何数据
                sqlString.append(" OR 1=0 ");
            }
        }
    }

    if (StringUtils.isNotBlank(sqlString.toString()))
    {
        BaseEntity baseEntity = (BaseEntity) joinPoint.getArgs()[0];
        baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
    }
}