分页查询菜单树
This commit is contained in:
@ -133,4 +133,13 @@ public interface ISysMenuService
|
||||
* @return 结果
|
||||
*/
|
||||
public String checkMenuNameUnique(SysMenu menu);
|
||||
|
||||
/**
|
||||
* 分页查询菜单树
|
||||
*
|
||||
* @param menu
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public List<SysMenu> selectTreeByPage(SysMenu menu, Long userId);
|
||||
}
|
||||
|
@ -79,6 +79,60 @@ public class SysMenuServiceImpl implements ISysMenuService
|
||||
return menuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询菜单树
|
||||
*
|
||||
* @param menu
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> selectTreeByPage(SysMenu menu, Long userId)
|
||||
{
|
||||
List<SysMenu> menuList = null;
|
||||
menu.setParentId(0L);
|
||||
|
||||
// 管理员显示所有菜单信息
|
||||
if (SysUser.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectMenuList(menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.getParams().put("userId", userId);
|
||||
menuList = menuMapper.selectMenuListByUserId(menu);
|
||||
}
|
||||
return findChildren(menuList, userId);
|
||||
}
|
||||
|
||||
public List<SysMenu> findChildren(List<SysMenu> sysMenuList, Long userId)
|
||||
{
|
||||
List<SysMenu> children = null;
|
||||
SysMenu menu = new SysMenu();
|
||||
|
||||
for (SysMenu sysMenu : sysMenuList)
|
||||
{
|
||||
menu.setParentId(sysMenu.getMenuId());
|
||||
|
||||
// 管理员显示所有菜单信息
|
||||
if (SysUser.isAdmin(userId))
|
||||
{
|
||||
children = menuMapper.selectMenuList(menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.getParams().put("userId", userId);
|
||||
children = menuMapper.selectMenuListByUserId(menu);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotNull(children) && children.size() > 0)
|
||||
{
|
||||
findChildren(children, userId);
|
||||
sysMenu.setChildren(children);
|
||||
}
|
||||
}
|
||||
return sysMenuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询权限
|
||||
*
|
||||
|
@ -35,6 +35,9 @@
|
||||
<select id="selectMenuList" parameterType="SysMenu" resultMap="SysMenuResult">
|
||||
<include refid="selectMenuVo"/>
|
||||
<where>
|
||||
<if test="parentId != null">
|
||||
AND parent_id = #{parentId}
|
||||
</if>
|
||||
<if test="menuName != null and menuName != ''">
|
||||
AND menu_name like concat('%', #{menuName}, '%')
|
||||
</if>
|
||||
@ -61,6 +64,9 @@
|
||||
left join sys_user_role ur on rm.role_id = ur.role_id
|
||||
left join sys_role ro on ur.role_id = ro.role_id
|
||||
where ur.user_id = #{params.userId}
|
||||
<if test="parentId != null and parentId != ''">
|
||||
AND m.parent_id = #{parentId}
|
||||
</if>
|
||||
<if test="menuName != null and menuName != ''">
|
||||
AND m.menu_name like concat('%', #{menuName}, '%')
|
||||
</if>
|
||||
|
Reference in New Issue
Block a user