提交代码

master
胡锐 7 months ago committed by yuanye
parent c91f46d857
commit 4557c16db7
  1. 68
      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<Map<String,Object>> mapList = new ArrayList<>();
Map<String,Object> map;
List<SecMenu> menuList = secMenuService.getAllList();
// 获取最顶层菜单
List<SecMenu> 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<Map<String,Object>> recursionMenu2(List<SecMenu> dataSource, Long parentMenuId) {
List<Map<String,Object>> mapList = new ArrayList<>();
Map<String,Object> map;
List<SecMenu> 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<Map<String, Object>> recursioned = recursionMenu2(dataSource, menu.getId());
if (recursioned.isEmpty()) {
map.put("isLeaf", true);
} else {
map.put("children", recursioned);
}
mapList.add(map);
}
}
return mapList;
}
/** /**
* 递归菜单 * 递归菜单
* @param sysMenu 系统菜单 * @param sysMenu 系统菜单

Loading…
Cancel
Save