diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java index 64436ad..0bd168c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java @@ -10,10 +10,7 @@ import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum; import com.ningdatech.pmapi.sys.model.vo.MenuRoleVO; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -125,32 +122,37 @@ public final class TreeUtil { } Map> menuGroup = CollUtils.group(treeList, MenuTreeEntity::getPid); Map menuMap = CollUtils.listToMap(treeList, MenuTreeEntity::getId); - return buildUserMenuTree(menuGroup, menuMap, StrPool.DEF_PARENT_ID); + return buildUserMenuTree(menuGroup, menuMap, StrPool.DEF_PARENT_ID, null); } - private static List buildUserMenuTree(Map> menuGroup, Map menuMap, Long parentId) { + private static List buildUserMenuTree(Map> menuGroup, + Map menuMap, + Long parentId, + ListIterator parentIter) { List currMenus = menuGroup.get(parentId); if (currMenus == null) { return Collections.emptyList(); } - List menus = new ArrayList<>(currMenus); - for (MenuRoleVO curr : currMenus) { + List menus; + if (!parentId.equals(StrPool.DEF_PARENT_ID)) { + Map> group = CollUtils.group(currMenus, MenuRoleVO::getMenuType); + for (MenuRoleVO vo : group.getOrDefault(MenuTypeEnum.BUTTON, Collections.emptyList())) { + parentIter.add(vo); + } + menus = group.getOrDefault(MenuTypeEnum.MENU, Collections.emptyList()); + } else { + menus = new ArrayList<>(currMenus); + } + ListIterator currIter = menus.listIterator(); + while (currIter.hasNext()) { + MenuRoleVO curr = currIter.next(); if (curr.getPid().equals(StrPool.DEF_PARENT_ID)) { curr.setPid(null); curr.setTopMenu(curr.getName()); } else { curr.setTopMenu(menuMap.get(curr.getPid()).getTopMenu()); } - List childMenus = menuGroup.get(curr.getId()); - if (childMenus != null) { - Map> groupByType = CollUtils.group(childMenus, MenuRoleVO::getMenuType); - menus.addAll(groupByType.getOrDefault(MenuTypeEnum.BUTTON, Collections.emptyList())); - curr.setChildren(groupByType.get(MenuTypeEnum.MENU)); - for (MenuRoleVO child : curr.getChildren()) { - child.setTopMenu(curr.getTopMenu()); - child.setChildren(buildUserMenuTree(menuGroup, menuMap, child.getId())); - } - } + curr.setChildren(buildUserMenuTree(menuGroup, menuMap, curr.getId(), currIter)); } return menus; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java index ee76257..49be37e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java @@ -1,5 +1,6 @@ package com.ningdatech.pmapi.sys.model.dto; +import com.ningdatech.pmapi.sys.model.enumeration.MenuTypeEnum; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.*; @@ -48,7 +49,7 @@ public class MenuUpdateDTO implements Serializable { * 类型 */ @ApiModelProperty(value = "类型") - private Integer type; + private MenuTypeEnum menuType; /** * 页面路径 diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java index 33f7709..2894537 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java @@ -79,7 +79,7 @@ public class MenuServiceImpl extends ServiceImpl implements IM @Override @Transactional(rollbackFor = Exception.class) public boolean update(MenuUpdateDTO data, Long userId) { - if (MenuTypeEnum.MENU.getCode().equals(data.getType())) { + if (MenuTypeEnum.MENU.equals(data.getMenuType())) { if (StrUtil.isBlank(data.getPath())) { throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】不能为空"); }