7 天以前 0c3f0f3e387fa66e520d8a065011232b559e6acc
src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
@@ -107,7 +107,10 @@
            {
                continue;
            }
            if (!StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
            // 无权限字符上下文(permission 为空,如员工删除这类无@PreAuthorize的接口)时,
            // 不做基于权限字符的预过滤,否则"全部数据"角色会在命中 DATA_SCOPE_ALL 前被 continue,
            // 最终落入"无任何角色匹配"的兜底,导致无法删除
            if (StringUtils.isNotBlank(permission) && !StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
            {
                continue;
            }
@@ -117,36 +120,36 @@
                conditions.add(dataScope);
                break;
            }
            else if (DATA_SCOPE_CUSTOM.equals(dataScope))
            {
                if (scopeCustomIds.size() > 1)
                {
                    // 多个自定数据权限使用in查询,避免多次拼接。
                    sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id in ({}) ) ", deptAlias, String.join(",", scopeCustomIds)));
                }
                else
                {
                    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_CUSTOM.equals(dataScope))
//            {
//                if (scopeCustomIds.size() > 1)
//                {
//                    // 多个自定数据权限使用in查询,避免多次拼接。
//                    sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id in ({}) ) ", deptAlias, String.join(",", scopeCustomIds)));
//                }
//                else
//                {
//                    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_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
                else if (StringUtils.isNotBlank(deptAlias))
                {
                    // 数据权限为仅本人且没有userAlias别名不查询任何数据
                    sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
                    sqlString.append(StringUtils.format(" OR {}.dept_id = -1 ", deptAlias));
                }
                else
                {
                    sqlString.append(" OR 1 = 0 ");
                }
            }
            conditions.add(dataScope);
@@ -155,7 +158,18 @@
        // 角色都不包含传递过来的权限字符,这个时候sqlString也会为空,所以要限制一下,不查询任何数据
        if (StringUtils.isEmpty(conditions))
        {
            sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
            if (StringUtils.isNotBlank(deptAlias))
            {
                sqlString.append(StringUtils.format(" OR {}.dept_id = -1 ", deptAlias));
            }
            else if (StringUtils.isNotBlank(userAlias))
            {
                sqlString.append(StringUtils.format(" OR {}.user_id = -1 ", userAlias));
            }
            else
            {
                sqlString.append(" OR 1 = 0 ");
            }
        }
        if (StringUtils.isNotBlank(sqlString.toString()))