|
|
|
@ -170,44 +170,17 @@ public class SecMenuController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/queryAssignMenuTree",method = RequestMethod.GET) |
|
|
|
|
@RequestMapping(value="/queryRoleMenuArray",method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "查询分配菜单树") |
|
|
|
|
public ResponseData queryAssignMenuTree(@RequestParam(value = "roleId" , required = true) Long roleId) { |
|
|
|
|
public ResponseData queryRoleMenuArray(@RequestParam(value = "roleId" , required = true) Long roleId) { |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
List<MenuTreeModel> treeModelList = new ArrayList<>(); |
|
|
|
|
MenuTreeModel menuTree; |
|
|
|
|
// 查询角色菜单权限
|
|
|
|
|
List<SecRoleMenuRel> roleMenuList = secRoleMenuRelService.getRelListByRole(roleId); |
|
|
|
|
|
|
|
|
|
// 获取系统菜单
|
|
|
|
|
List<SecMenu> sysMenuList = secMenuService.getAllList(); |
|
|
|
|
Map<Long, SecRoleMenuRel> roleMenuRelMap = secRoleMenuRelService.getRelListByRole(roleId) |
|
|
|
|
.stream() |
|
|
|
|
.collect(Collectors.toMap(SecRoleMenuRel::getMenuId, Function.identity())); |
|
|
|
|
|
|
|
|
|
// 获取系统顶级菜单
|
|
|
|
|
List<SecMenu> topLevelMenuList = sysMenuList.stream().filter(o -> o.getMenuPSid() == null) |
|
|
|
|
.sorted(Comparator.comparing(SecMenu::getMenuSort)) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
for (SecMenu topLevelMenu : topLevelMenuList) { |
|
|
|
|
menuTree = new MenuTreeModel(); |
|
|
|
|
menuTree.setId(topLevelMenu.getId()); |
|
|
|
|
menuTree.setMenuName(topLevelMenu.getMenuName()); |
|
|
|
|
menuTree.setMenuType(topLevelMenu.getMenuType()); |
|
|
|
|
menuTree.setMenuUrl(topLevelMenu.getMenuUrl()); |
|
|
|
|
menuTree.setMenuUrlImg(topLevelMenu.getMenuUrlImg()); |
|
|
|
|
menuTree.setMenuPSid(topLevelMenu.getMenuPSid()); |
|
|
|
|
menuTree.setMenuSort(topLevelMenu.getMenuSort()); |
|
|
|
|
menuTree.setMenuDesc(topLevelMenu.getMenuDesc()); |
|
|
|
|
// 递归子菜单
|
|
|
|
|
menuTree.setChildMenuList(recursionMenu(sysMenuList, roleMenuRelMap, topLevelMenu.getId())); |
|
|
|
|
// 获取角色菜单
|
|
|
|
|
menuTree.setAuthority(roleMenuRelMap.get(topLevelMenu.getId()) != null ? true : false); |
|
|
|
|
treeModelList.add(menuTree); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(treeModelList); |
|
|
|
|
return ResponseMsgUtil.success(roleMenuList.stream().map(SecRoleMenuRel::getMenuId).collect(Collectors.toList()) |
|
|
|
|
.stream().map(Object::toString).collect(Collectors.toList())); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("error!",e); |
|
|
|
@ -229,10 +202,10 @@ public class SecMenuController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/queryRoleMenuTreeCustomized",method = RequestMethod.POST) |
|
|
|
|
@RequestMapping(value="/queryMenuTree",method = RequestMethod.POST) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "查询角色菜单树") |
|
|
|
|
public ResponseData queryRoleMenuTreeCustomized(@RequestParam(value = "roleId" , required = false) Long roleId) { |
|
|
|
|
public ResponseData queryMenuTree() { |
|
|
|
|
try { |
|
|
|
|
List<Map<String,Object>> mapList = new ArrayList<>(); |
|
|
|
|
Map<String,Object> map; |
|
|
|
@ -252,7 +225,7 @@ public class SecMenuController { |
|
|
|
|
map.put("key", ""+topLevelMenu.getId()); |
|
|
|
|
map.put("title", topLevelMenu.getMenuName()); |
|
|
|
|
// 获取下级菜单
|
|
|
|
|
map.put("children", recursionMenu2(menuList, topLevelMenu.getId())); |
|
|
|
|
map.put("children", recursionMenu(menuList, topLevelMenu.getId())); |
|
|
|
|
mapList.add(map); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -271,7 +244,7 @@ public class SecMenuController { |
|
|
|
|
* @param parentMenuId 父级菜单id |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public List<Map<String,Object>> recursionMenu2(List<SecMenu> dataSource, Long parentMenuId) { |
|
|
|
|
public List<Map<String,Object>> recursionMenu(List<SecMenu> dataSource, Long parentMenuId) { |
|
|
|
|
List<Map<String,Object>> mapList = new ArrayList<>(); |
|
|
|
|
Map<String,Object> map; |
|
|
|
|
|
|
|
|
@ -285,7 +258,7 @@ public class SecMenuController { |
|
|
|
|
map.put("key", ""+menu.getId()); |
|
|
|
|
map.put("title", menu.getMenuName()); |
|
|
|
|
// 获取下级菜单
|
|
|
|
|
List<Map<String, Object>> recursioned = recursionMenu2(dataSource, menu.getId()); |
|
|
|
|
List<Map<String, Object>> recursioned = recursionMenu(dataSource, menu.getId()); |
|
|
|
|
if (recursioned.isEmpty()) { |
|
|
|
|
map.put("isLeaf", true); |
|
|
|
|
} else { |
|
|
|
@ -297,36 +270,4 @@ public class SecMenuController { |
|
|
|
|
return mapList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 递归菜单 |
|
|
|
|
* @param sysMenu 系统菜单 |
|
|
|
|
* @param roleMenuRel 角色菜单 |
|
|
|
|
* @param parentMenuId 父类菜单id |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public List<MenuTreeModel> recursionMenu(List<SecMenu> sysMenu, Map<Long, SecRoleMenuRel> roleMenuRel, Long parentMenuId) { |
|
|
|
|
List<MenuTreeModel> treeModelList = new ArrayList<>(); |
|
|
|
|
MenuTreeModel menuTree; |
|
|
|
|
|
|
|
|
|
List<SecMenu> collect = sysMenu.stream() |
|
|
|
|
.filter(o -> o.getMenuPSid() != null && o.getMenuPSid().equals(parentMenuId)) |
|
|
|
|
.sorted(Comparator.comparing(SecMenu::getMenuSort)) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
for (SecMenu menu : collect) { |
|
|
|
|
menuTree = new MenuTreeModel(); |
|
|
|
|
menuTree.setId(menu.getId()); |
|
|
|
|
menuTree.setMenuName(menu.getMenuName()); |
|
|
|
|
menuTree.setMenuType(menu.getMenuType()); |
|
|
|
|
menuTree.setMenuUrl(menu.getMenuUrl()); |
|
|
|
|
menuTree.setMenuUrlImg(menu.getMenuUrlImg()); |
|
|
|
|
menuTree.setMenuPSid(menu.getMenuPSid()); |
|
|
|
|
menuTree.setMenuSort(menu.getMenuSort()); |
|
|
|
|
menuTree.setMenuDesc(menu.getMenuDesc()); |
|
|
|
|
// 获取角色菜单
|
|
|
|
|
menuTree.setAuthority(roleMenuRel.get(menuTree.getId()) != null ? true : false); |
|
|
|
|
menuTree.setChildMenuList(recursionMenu(sysMenu, roleMenuRel, menu.getId())); |
|
|
|
|
treeModelList.add(menuTree); |
|
|
|
|
} |
|
|
|
|
return treeModelList; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|