refactor(base): GetUserMod 不再本地组树,改为映射用户中心下发的 children
build / build-push (push) Successful in 2m27s
build / build-push (push) Successful in 2m27s
用户中心已将模块层级经平台 BoaModule.children 下发,本仓原先按 parentId 重建父子 关系的 buildModuleTree 变成空转(且每个子应用各抄一份),现收敛为 toFrontendTree: 只做前端 layout 需要的字段改名(path→page、id→modId、补 usable/orderNumber)并递归 映射 children,层级与兄弟顺序一律以上游为准,本侧不重排。 前端契约不变(children 恒为数组),未触碰任何 .vue/.ts;收到旧版用户中心的扁平结果 (children=null)时退化为与今日一致的扁平菜单,不抛 NPE。
This commit is contained in:
@@ -40,8 +40,8 @@ public interface IUserCenterService {
|
||||
|
||||
/**
|
||||
* 获取当前用户可访问的模块树(左侧菜单)。
|
||||
* <p>从基础平台拉取当前用户模块列表(含学校上下文),组装为前端 layout 期望的树结构
|
||||
* ({@code modId/page/children}),对应前端 GetUserMod 接口。</p>
|
||||
* <p>从基础平台拉取当前用户模块树(含学校上下文);<b>层级由用户中心 {@code BoaModule.children} 下发</b>,
|
||||
* 本侧仅映射为前端 layout 期望的字段形状({@code modId/page/children}),对应前端 GetUserMod 接口。</p>
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param schId 学校ID(可为 null)
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户中心门面服务实现。
|
||||
@@ -219,20 +218,20 @@ public class UserCenterService implements IUserCenterService {
|
||||
if (modules == null || modules.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 扁平 BoaModule → 树结构(modId/page/children),对齐前端 layout 期望
|
||||
return buildModuleTree(modules);
|
||||
// 用户中心已按 BoaModule.children 下发模块树:本地不再重组层级,仅做前端字段改名映射
|
||||
return toFrontendTree(modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将扁平模块列表组装为树(对应原 NoticeController.buildModuleTree)。
|
||||
* 顶层取 parentId=0 或父节点不在列表中的节点,子节点按 orderNumber 排序。
|
||||
* BoaModule 树 → 前端 layout 期望的字段形状(递归,<b>只改名不组树</b>)。<br>
|
||||
* 层级与兄弟顺序均由用户中心 {@code BoaModule.children} + customId 升序决定,本侧不重排;
|
||||
* 叶子节点 children 为空列表(用户中心保证),前端可无判空递归。
|
||||
*/
|
||||
private List<Map<String, Object>> buildModuleTree(List<BoaModule> modules) {
|
||||
Map<Integer, BoaModule> moduleMap = modules.stream()
|
||||
.collect(Collectors.toMap(BoaModule::getId, m -> m, (a, b) -> a));
|
||||
|
||||
// 每个模块节点(含 children 占位)
|
||||
Map<Integer, Map<String, Object>> nodeMap = new LinkedHashMap<>();
|
||||
private List<Map<String, Object>> toFrontendTree(List<BoaModule> modules) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
if (modules == null || modules.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
for (BoaModule m : modules) {
|
||||
Map<String, Object> node = new LinkedHashMap<>();
|
||||
node.put("id", m.getId());
|
||||
@@ -244,25 +243,9 @@ public class UserCenterService implements IUserCenterService {
|
||||
node.put("icon", m.getIcon() != null ? m.getIcon() : "");
|
||||
node.put("orderNumber", m.getSortNo() != null ? m.getSortNo() : 0);
|
||||
node.put("usable", true);
|
||||
node.put("children", new ArrayList<>());
|
||||
nodeMap.put(m.getId(), node);
|
||||
node.put("children", toFrontendTree(m.getChildren()));
|
||||
result.add(node);
|
||||
}
|
||||
|
||||
// 挂父子关系
|
||||
List<Map<String, Object>> roots = new ArrayList<>();
|
||||
for (BoaModule m : modules) {
|
||||
Map<String, Object> node = nodeMap.get(m.getId());
|
||||
int parentId = m.getParentId() != null ? m.getParentId() : 0;
|
||||
if (parentId == 0 || !moduleMap.containsKey(parentId)) {
|
||||
roots.add(node);
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) nodeMap.get(parentId).get("children");
|
||||
children.add(node);
|
||||
}
|
||||
}
|
||||
|
||||
// 保持 SDK(用户中心)返回顺序,不再按 orderNumber 重排
|
||||
return roots;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user