From 9a2ff8ac884e88631cd24f751a40600f25579213 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期六, 14 二月 2026 17:26:06 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/Robotaxi
---
xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/SysMenuServiceImpl.java | 77 +++++++++++++++++++++++++++++++++++++-
1 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/SysMenuServiceImpl.java b/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/SysMenuServiceImpl.java
index ae2523c..4501a89 100644
--- a/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/SysMenuServiceImpl.java
+++ b/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/SysMenuServiceImpl.java
@@ -6,8 +6,8 @@
import com.xiaopeng.operation.service.ISysMenuService;
import org.springframework.stereotype.Service;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* <p>
@@ -35,4 +35,77 @@
// 使用 MyBatis-Plus 的 listByIds 方法批量查询
return this.listByIds(menuIds);
}
+
+ @Override
+ public List<SysMenu> getMenuTree() {
+ List<SysMenu> all = list();
+ if (all == null || all.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ // 1) 按 parentId 分组(M/C/F 都先放进去,后面再按类型筛)
+ Map<Long, List<SysMenu>> childrenMap = all.stream()
+ .filter(Objects::nonNull)
+ .collect(Collectors.groupingBy(m -> m.getParentId() == null ? 0L : m.getParentId()));
+
+ // 2) 找到根目录:通常 parentId = 0 或 null 的目录(M)
+ List<SysMenu> roots = childrenMap.getOrDefault(0L, Collections.emptyList()).stream()
+ .filter(m -> "M".equals(m.getMenuType()))
+ .sorted(Comparator.comparing(SysMenu::getOrderNum, Comparator.nullsLast(Integer::compareTo)))
+ .collect(Collectors.toList());
+
+ // 3) 递归挂载:M 下挂 C;C 下挂 F(也允许 C 下还有 C,或 M 下还有 M,按你的数据结构来)
+ for (SysMenu root : roots) {
+ fillChildren(root, childrenMap);
+ }
+
+ return roots;
+ }
+
+ private void fillChildren(SysMenu node, Map<Long, List<SysMenu>> childrenMap) {
+ Long id = node.getId();
+ if (id == null) {
+ node.setChildren(Collections.emptyList());
+ return;
+ }
+
+ List<SysMenu> rawChildren = childrenMap.getOrDefault(id, Collections.emptyList());
+ if (rawChildren.isEmpty()) {
+ node.setChildren(Collections.emptyList());
+ return;
+ }
+
+ // 根据你的层级规则过滤子节点:
+ // - M 只能挂 M/C(看你业务,很多系统 M 下是 C)
+ // - C 只能挂 F(按钮)或(有些系统 C 下还能挂 C)
+ // - F 一般不挂任何子节点
+ String type = node.getMenuType();
+
+ List<SysMenu> children = rawChildren.stream()
+ .filter(Objects::nonNull)
+ .filter(child -> {
+ if ("M".equals(type)) {
+ return "M".equals(child.getMenuType()) || "C".equals(child.getMenuType());
+ }
+ if ("C".equals(type)) {
+ return "F".equals(child.getMenuType()); // 若允许 C 下还有 C,可改为:return "C".equals(...) || "F".equals(...)
+ }
+ return false; // F 不再往下挂
+ })
+ .sorted(Comparator.comparing(SysMenu::getOrderNum, Comparator.nullsLast(Integer::compareTo)))
+ .collect(Collectors.toList());
+
+ node.setChildren(children);
+
+ // 继续递归
+ for (SysMenu child : children) {
+ fillChildren(child, childrenMap);
+ }
+ }
+
+ @Override
+ public List<SysMenu> getPermission() {
+
+ return Collections.emptyList();
+ }
}
--
Gitblit v1.7.1