Procházet zdrojové kódy

递归处理菜单

tags/24080901
WendyYang před 1 rokem
rodič
revize
c9f9bb85ed
3 změnil soubory, kde provedl 23 přidání a 20 odebrání
  1. +20
    -18
      pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java
  2. +2
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java
  3. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java

+ 20
- 18
pmapi/src/main/java/com/ningdatech/pmapi/common/util/TreeUtil.java Zobrazit soubor

@@ -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;
}


+ 2
- 1
pmapi/src/main/java/com/ningdatech/pmapi/sys/model/dto/MenuUpdateDTO.java Zobrazit soubor

@@ -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;

/**
* 页面路径


+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java Zobrazit soubor

@@ -79,7 +79,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> 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, "【地址栏路径】不能为空");
}


Načítá se…
Zrušit
Uložit