Browse Source

修复前端树组件未全选导致父节点没有入库从而引发顶部菜单生成的bug

test
smallchill 4 years ago
parent
commit
73ec23460e
  1. 16
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java
  2. 17
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml
  3. 24
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

16
blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java

@ -133,6 +133,22 @@ public interface MenuMapper extends BaseMapper<Menu> {
*/ */
List<Menu> roleMenu(List<Long> roleId, Long topMenuId); List<Menu> roleMenu(List<Long> roleId, Long topMenuId);
/**
* 权限配置菜单
*
* @param roleId
* @return
*/
List<Menu> roleMenuByRoleId(List<Long> roleId);
/**
* 权限配置菜单
*
* @param topMenuId
* @return
*/
List<Menu> roleMenuByTopMenuId(Long topMenuId);
/** /**
* 菜单树形结构 * 菜单树形结构
* *

17
blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml

@ -124,6 +124,23 @@
) )
</if> </if>
</select> </select>
<select id="roleMenuByRoleId" resultMap="menuResultMap">
select * from blade_menu where is_deleted = 0 and id IN
( SELECT menu_id FROM blade_role_menu WHERE role_id IN
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
)
</select>
<select id="roleMenuByTopMenuId" resultMap="menuResultMap">
select * from blade_menu where is_deleted = 0 and id IN
(
SELECT menu_id FROM blade_top_menu_setting WHERE top_menu_id = #{param1}
)
</select>
<select id="routes" resultMap="menuResultMap"> <select id="routes" resultMap="menuResultMap">
SELECT SELECT
* *

24
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

@ -88,7 +88,29 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
return null; return null;
} }
List<Menu> allMenus = baseMapper.allMenu(); List<Menu> allMenus = baseMapper.allMenu();
List<Menu> roleMenus = (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) ? allMenus : baseMapper.roleMenu(Func.toLongList(roleId), topMenuId); List<Menu> roleMenus;
// 超级管理员并且不是顶部菜单请求则返回全部菜单
if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
roleMenus = allMenus;
}
// 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
else if (!AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
roleMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
}
// 顶部菜单请求返回对应角色权限菜单
else {
// 角色配置对应菜单
List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
// 反向递归角色菜单所有父级
List<Menu> routes = new LinkedList<>(roleIdMenus);
roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
// 顶部配置对应菜单
List<Menu> topIdMenus = baseMapper.roleMenuByTopMenuId(topMenuId);
// 筛选匹配角色对应的权限菜单
roleMenus = topIdMenus.stream().filter(x ->
routes.stream().anyMatch(route -> route.getId().longValue() == x.getId().longValue())
).collect(Collectors.toList());
}
return buildRoutes(allMenus, roleMenus); return buildRoutes(allMenus, roleMenus);
} }

Loading…
Cancel
Save