|
|
@@ -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<Long, List<MenuRoleVO>> menuGroup = CollUtils.group(treeList, MenuTreeEntity::getPid); |
|
|
|
Map<Long, MenuRoleVO> 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<MenuRoleVO> buildUserMenuTree(Map<Long, List<MenuRoleVO>> menuGroup, Map<Long, MenuRoleVO> menuMap, Long parentId) { |
|
|
|
private static List<MenuRoleVO> buildUserMenuTree(Map<Long, List<MenuRoleVO>> menuGroup, |
|
|
|
Map<Long, MenuRoleVO> menuMap, |
|
|
|
Long parentId, |
|
|
|
ListIterator<MenuRoleVO> parentIter) { |
|
|
|
List<MenuRoleVO> currMenus = menuGroup.get(parentId); |
|
|
|
if (currMenus == null) { |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
List<MenuRoleVO> menus = new ArrayList<>(currMenus); |
|
|
|
for (MenuRoleVO curr : currMenus) { |
|
|
|
List<MenuRoleVO> menus; |
|
|
|
if (!parentId.equals(StrPool.DEF_PARENT_ID)) { |
|
|
|
Map<MenuTypeEnum, List<MenuRoleVO>> 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<MenuRoleVO> 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<MenuRoleVO> childMenus = menuGroup.get(curr.getId()); |
|
|
|
if (childMenus != null) { |
|
|
|
Map<MenuTypeEnum, List<MenuRoleVO>> 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; |
|
|
|
} |
|
|
|