优化多角色数据权限匹配规则
This commit is contained in:
@ -49,6 +49,14 @@ public interface SysMenuMapper
|
||||
*/
|
||||
public List<String> selectPermsByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
public List<String> selectPermsByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单
|
||||
*
|
||||
|
@ -48,6 +48,14 @@ public interface ISysMenuService
|
||||
*/
|
||||
public Set<String> selectPermsByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
public Set<String> selectPermsByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -71,18 +70,12 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||
public List<Ztree> selectDeptTreeExcludeChild(SysDept dept)
|
||||
{
|
||||
Long excludeId = dept.getExcludeId();
|
||||
List<SysDept> deptList = deptMapper.selectDeptList(dept);
|
||||
Iterator<SysDept> it = deptList.iterator();
|
||||
while (it.hasNext())
|
||||
List<SysDept> depts = deptMapper.selectDeptList(dept);
|
||||
if (excludeId.intValue() > 0)
|
||||
{
|
||||
SysDept d = (SysDept) it.next();
|
||||
if (d.getDeptId().intValue() == excludeId
|
||||
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), excludeId + ""))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
depts.removeIf(d -> d.getDeptId().intValue() == excludeId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), excludeId + ""));
|
||||
}
|
||||
List<Ztree> ztrees = initZtree(deptList);
|
||||
List<Ztree> ztrees = initZtree(depts);
|
||||
return ztrees;
|
||||
}
|
||||
|
||||
@ -97,7 +90,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||
{
|
||||
Long roleId = role.getRoleId();
|
||||
List<Ztree> ztrees = new ArrayList<Ztree>();
|
||||
List<SysDept> deptList = selectDeptList(new SysDept());
|
||||
List<SysDept> deptList = SpringUtils.getAopProxy(this).selectDeptList(new SysDept());
|
||||
if (StringUtils.isNotNull(roleId))
|
||||
{
|
||||
List<String> roleDeptList = deptMapper.selectRoleDeptTree(roleId);
|
||||
|
@ -121,6 +121,27 @@ public class SysMenuServiceImpl implements ISysMenuService
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
@Override
|
||||
public Set<String> selectPermsByRoleId(Long roleId)
|
||||
{
|
||||
List<String> perms = menuMapper.selectPermsByRoleId(roleId);
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (String perm : perms)
|
||||
{
|
||||
if (StringUtils.isNotEmpty(perm))
|
||||
{
|
||||
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
|
||||
}
|
||||
}
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询菜单
|
||||
*
|
||||
|
@ -70,6 +70,13 @@
|
||||
where m.visible = '0' and r.status = '0' and ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectPermsByRoleId" parameterType="Long" resultType="String">
|
||||
select distinct m.perms
|
||||
from sys_menu m
|
||||
left join sys_role_menu rm on m.menu_id = rm.menu_id
|
||||
where m.visible = '0' and rm.role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
<select id="selectMenuTree" parameterType="Long" resultType="String">
|
||||
select concat(m.menu_id, ifnull(m.perms,'')) as perms
|
||||
from sys_menu m
|
||||
|
Reference in New Issue
Block a user