作者 RuoYi

优化多个相同角色数据导致权限SQL重复问题

1 package com.ruoyi.framework.aspectj; 1 package com.ruoyi.framework.aspectj;
2 2
  3 +import java.util.ArrayList;
  4 +import java.util.List;
3 import org.aspectj.lang.JoinPoint; 5 import org.aspectj.lang.JoinPoint;
4 import org.aspectj.lang.annotation.Aspect; 6 import org.aspectj.lang.annotation.Aspect;
5 import org.aspectj.lang.annotation.Before; 7 import org.aspectj.lang.annotation.Before;
@@ -79,15 +81,21 @@ public class DataScopeAspect @@ -79,15 +81,21 @@ public class DataScopeAspect
79 * 81 *
80 * @param joinPoint 切点 82 * @param joinPoint 切点
81 * @param user 用户 83 * @param user 用户
82 - * @param userAlias 别名 84 + * @param deptAlias 部门别名
  85 + * @param userAlias 用户别名
83 */ 86 */
84 public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) 87 public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
85 { 88 {
86 StringBuilder sqlString = new StringBuilder(); 89 StringBuilder sqlString = new StringBuilder();
  90 + List<String> conditions = new ArrayList<String>();
87 91
88 for (SysRole role : user.getRoles()) 92 for (SysRole role : user.getRoles())
89 { 93 {
90 String dataScope = role.getDataScope(); 94 String dataScope = role.getDataScope();
  95 + if (conditions.contains(dataScope))
  96 + {
  97 + continue;
  98 + }
91 if (DATA_SCOPE_ALL.equals(dataScope)) 99 if (DATA_SCOPE_ALL.equals(dataScope))
92 { 100 {
93 sqlString = new StringBuilder(); 101 sqlString = new StringBuilder();
@@ -121,6 +129,7 @@ public class DataScopeAspect @@ -121,6 +129,7 @@ public class DataScopeAspect
121 sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias)); 129 sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
122 } 130 }
123 } 131 }
  132 + conditions.add(dataScope);
124 } 133 }
125 134
126 if (StringUtils.isNotBlank(sqlString.toString())) 135 if (StringUtils.isNotBlank(sqlString.toString()))