优化多个相同角色数据导致权限SQL重复问题
This commit is contained in:
		
							parent
							
								
									2c79dc906e
								
							
						
					
					
						commit
						28b9fbb4d2
					
				@ -1,5 +1,7 @@
 | 
			
		||||
package com.ruoyi.framework.aspectj;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import org.aspectj.lang.JoinPoint;
 | 
			
		||||
import org.aspectj.lang.annotation.Aspect;
 | 
			
		||||
import org.aspectj.lang.annotation.Before;
 | 
			
		||||
@ -79,15 +81,21 @@ public class DataScopeAspect
 | 
			
		||||
     *
 | 
			
		||||
     * @param joinPoint 切点
 | 
			
		||||
     * @param user 用户
 | 
			
		||||
     * @param userAlias 别名
 | 
			
		||||
     * @param deptAlias 部门别名
 | 
			
		||||
     * @param userAlias 用户别名
 | 
			
		||||
     */
 | 
			
		||||
    public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
 | 
			
		||||
    {
 | 
			
		||||
        StringBuilder sqlString = new StringBuilder();
 | 
			
		||||
        List<String> conditions = new ArrayList<String>();
 | 
			
		||||
 | 
			
		||||
        for (SysRole role : user.getRoles())
 | 
			
		||||
        {
 | 
			
		||||
            String dataScope = role.getDataScope();
 | 
			
		||||
            if (conditions.contains(dataScope))
 | 
			
		||||
            {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            if (DATA_SCOPE_ALL.equals(dataScope))
 | 
			
		||||
            {
 | 
			
		||||
                sqlString = new StringBuilder();
 | 
			
		||||
@ -121,6 +129,7 @@ public class DataScopeAspect
 | 
			
		||||
                    sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            conditions.add(dataScope);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (StringUtils.isNotBlank(sqlString.toString()))
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user