|
@@ -418,6 +418,9 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
|
|
|
List<MenuVo> childMenus = new ArrayList<>();
|
|
|
|
|
|
+ Map<Long, MenuVo> menuMap = menuVos.stream()
|
|
|
+ .collect(Collectors.toMap(MenuVo::getId, menu -> menu));
|
|
|
+
|
|
|
menuVos.forEach((node) -> {
|
|
|
Long parentId = node.getParentId();
|
|
|
|
|
@@ -434,16 +437,19 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
|
|
|
if (!StrUtil.isEmptyIfStr(parentId) || !StrUtil.equals(String.valueOf(parentId), String.valueOf(GlobalConstant.FIRST_NODE_VALUE))) {
|
|
|
|
|
|
- menuVos.stream().filter(x -> StrUtil.equals(x.getId().toString(), String.valueOf(parentId)))
|
|
|
- .findAny()
|
|
|
- .ifPresent(parentNode -> {
|
|
|
- node.setSystemId(parentNode.getSystemId());
|
|
|
- node.setSystemName(parentNode.getSystemName());
|
|
|
- node.setParentSortCode(parentNode.getSortCode());
|
|
|
- });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Long number = menuVos.stream().filter(x -> x.getParentId().equals(node.getId())).count();
|
|
|
- if (number == 0) {
|
|
|
- node.setParentSortCode(node.getParentSortCode() == null ? 0 : node.getParentSortCode());
|
|
|
+ if (number == 0 && !Objects.equals(parentId, GlobalConstant.FIRST_NODE_VALUE)) {
|
|
|
+ MenuVo parentMenu = getParentMenu(parentId, menuMap);
|
|
|
+ node.setSystemId(parentMenu.getSystemId());
|
|
|
+ node.setSystemName(parentMenu.getSystemName());
|
|
|
+ node.setParentSortCode(parentMenu.getSortCode());
|
|
|
childMenus.add(node);
|
|
|
}
|
|
|
}
|
|
@@ -458,6 +464,17 @@ public class MenuServiceImpl extends MPJBaseServiceImpl<MenuMapper, Menu> implem
|
|
|
return new ArrayList<>(menuVoMap.values());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 找到顶级菜单
|
|
|
+ */
|
|
|
+ private MenuVo getParentMenu(Long parentId, Map<Long, MenuVo> menuMap) {
|
|
|
+ MenuVo menuVo = menuMap.get(parentId);
|
|
|
+ if (menuVo.getParentId().equals(GlobalConstant.FIRST_NODE_VALUE)) {
|
|
|
+ return menuVo;
|
|
|
+ }
|
|
|
+ return getParentMenu(menuVo.getParentId(), menuMap);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 获取所有子级菜单
|
|
|
*/
|