diff --git a/bweb/src/main/java/com/bweb/controller/SecMenuController.java b/bweb/src/main/java/com/bweb/controller/SecMenuController.java index 5c56e99..acac466 100644 --- a/bweb/src/main/java/com/bweb/controller/SecMenuController.java +++ b/bweb/src/main/java/com/bweb/controller/SecMenuController.java @@ -202,6 +202,74 @@ public class SecMenuController { } } + @RequestMapping(value="/queryRoleMenuTree2",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询角色菜单树") + public ResponseData queryRoleMenuTree2(@RequestParam(value = "roleId" , required = false) Long roleId) { + try { + + List> mapList = new ArrayList<>(); + Map map; + + List menuList = secMenuService.getAllList(); + + // 获取最顶层菜单 + List topLevelMenuList = menuList.stream() + .filter(o -> o.getMenuPSid() == null) + .sorted(Comparator.comparing(SecMenu::getMenuSort)) + .collect(Collectors.toList()); + + for (SecMenu topLevelMenu : topLevelMenuList) { + if (topLevelMenu.getMenuType().equals(SecMenuTypeEnum.type1.getCode())) { + map = new HashMap<>(); + map.put("key", topLevelMenu.getId()); + map.put("title", topLevelMenu.getMenuName()); + // 获取下级菜单 + map.put("children", recursionMenu2(menuList, topLevelMenu.getId())); + mapList.add(map); + } + } + + return ResponseMsgUtil.success(mapList); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + /** + * 递归获取菜单 + * @param dataSource 数据源 + * @param parentMenuId 父级菜单id + * @return + */ + public List> recursionMenu2(List dataSource, Long parentMenuId) { + List> mapList = new ArrayList<>(); + Map map; + + List collect = dataSource.stream() + .filter(o -> o.getMenuPSid() != null && o.getMenuPSid().equals(parentMenuId)) + .sorted(Comparator.comparing(SecMenu::getMenuSort)) + .collect(Collectors.toList()); + for (SecMenu menu : collect) { + if (menu.getMenuType().equals(SecMenuTypeEnum.type1.getCode())) { + map = new HashMap<>(); + map.put("key", menu.getId()); + map.put("title", menu.getMenuName()); + // 获取下级菜单 + List> recursioned = recursionMenu2(dataSource, menu.getId()); + if (recursioned.isEmpty()) { + map.put("isLeaf", true); + } else { + map.put("children", recursioned); + } + mapList.add(map); + } + } + return mapList; + } + /** * 递归菜单 * @param sysMenu 系统菜单