顾挽11.13
This commit is contained in:
parent
06c042b523
commit
fe76b12b8c
|
@ -9,7 +9,10 @@ import lombok.RequiredArgsConstructor;
|
|||
import org.springframework.stereotype.Service;
|
||||
import service.SystemUsersService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
|
@ -77,7 +80,7 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper, Syste
|
|||
|
||||
// System.out.println("systemMenus = " + systemMenus);
|
||||
|
||||
systemMenus.stream().filter(systemMenu -> !systemMenu.getDeleted() && systemMenu.getVisible())
|
||||
/* systemMenus.stream().filter(systemMenu -> !systemMenu.getDeleted() && systemMenu.getVisible())
|
||||
.map(systemMenu -> {
|
||||
|
||||
// 角色码列表
|
||||
|
@ -93,11 +96,36 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper, Syste
|
|||
|
||||
return null;
|
||||
|
||||
}).distinct().toList();
|
||||
}).distinct().toList();*/
|
||||
|
||||
System.out.println("systemMenus = " + buildMenuTree(systemMenus));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 方法:将菜单列表构建为树形结构
|
||||
public static List<SystemMenu> buildMenuTree(List<SystemMenu> menuList) {
|
||||
// 以 parentId 分组菜单
|
||||
Map<Long, List<SystemMenu>> parentIdMap = menuList.stream()
|
||||
.collect(Collectors.groupingBy(SystemMenu::getParentId));
|
||||
|
||||
// 从根节点(parentId 为 null 或 0)递归构建树
|
||||
return buildTree(parentIdMap, 0L); // 假设顶级节点 parentId 为 0
|
||||
}
|
||||
|
||||
// 递归构建树形结构
|
||||
private static List<SystemMenu> buildTree(Map<Long, List<SystemMenu>> parentIdMap, Long parentId) {
|
||||
List<SystemMenu> children = parentIdMap.getOrDefault(parentId, new ArrayList<>());
|
||||
|
||||
for (SystemMenu menu : children) {
|
||||
// 递归设置子菜单
|
||||
menu.setChildren(buildTree(parentIdMap, menu.getId()));
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue