build / build-push (push) Successful in 1m36s
- SvcHallClient:由手搓 IDHttp + yh.svchall.base-url 拼 URL 改为 YschOpenCall 命名目标 svchall(服务目录 yh.open.services.svchall)。原形态对带 context-path 的 svc-hall 必 401(共享拦截器只剥 yh.open.base-path=/userbase);per-target base-path 与提供方 ctx 对齐后签名天然一致。目录未配时回落 legacy 键;两者皆缺则构造期 fail-fast。 - SvcItemRemoteQuery:新增 businessAbsent 判定,统一两条出站路径的「业务 code=2 → 404 哨兵/空集,其余上抛」语义(目录路径抛 DException,legacy 抛 DHttpException)。 - import 迁移:YschBaseOpenApi → openapi.base.*(SDK 领域分包)。 - application.yml:新增 yh.open.services.svchall,删 yh.svchall.base-url。 - 测试:新增 SvcHallClientTest(8 例:目录目标/参数映射/空参不下发/fire-and-forget/ 回落/fail-fast);SvcItemRemoteQueryTest 补目录路径错误语义 4 例。104 测试全绿。
72 lines
2.9 KiB
Java
72 lines
2.9 KiB
Java
package com.yunhai.cms.service.impl;
|
||
|
||
import com.yunhai.platform.apistd.BizException;
|
||
import com.yunhai.platform.openapi.base.YschBaseOpenApi;
|
||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||
import com.yunhai.platform.utils.model.BoaModule;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Collections;
|
||
import java.util.LinkedHashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 用户中心代理(Notice UserCenterService 同款逻辑平移):
|
||
* 模块菜单树来自基础平台 SDK(YschBaseOpenApi.getUserModule),层级由用户中心 {@code BoaModule.children}
|
||
* 直接下发,本侧仅映射为前端 layout 契约(modId/page/children)。
|
||
*/
|
||
@Slf4j
|
||
@Service
|
||
public class CmsUserCenterService {
|
||
|
||
/**
|
||
* 当前用户已授权模块树(左侧菜单)。
|
||
*/
|
||
public List<Map<String, Object>> getUserModuleTree(Integer userId, Integer schId) {
|
||
if (userId == null) {
|
||
throw new BizException(ErrorCode.PARAM_ERROR, "用户ID不得为空");
|
||
}
|
||
List<BoaModule> modules;
|
||
try {
|
||
modules = YschBaseOpenApi.getUserModule(userId, schId);
|
||
} catch (Exception e) {
|
||
// 平台不可达时菜单降级为空(登录/站点能力不受影响),避免整页不可用
|
||
log.warn("[cms] 获取用户模块失败, schId={}: {}", schId, e.getMessage());
|
||
return Collections.emptyList();
|
||
}
|
||
if (modules == null || modules.isEmpty()) {
|
||
return Collections.emptyList();
|
||
}
|
||
return toFrontendTree(modules);
|
||
}
|
||
|
||
/**
|
||
* BoaModule 树 → 前端 layout 期望的字段形状(递归,<b>只改名不组树</b>;Notice/svc-hall 同款口径)。<br>
|
||
* 层级与兄弟顺序均由用户中心决定(customId 升序),本侧不重排;叶子 children 为空列表。
|
||
*/
|
||
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());
|
||
node.put("modId", m.getId());
|
||
node.put("name", m.getName());
|
||
node.put("parentId", m.getParentId() != null ? m.getParentId() : 0);
|
||
node.put("page", m.getPath() != null ? m.getPath() : "");
|
||
node.put("level", m.getLevel() != null ? m.getLevel() : 0);
|
||
node.put("icon", m.getIcon() != null ? m.getIcon() : "");
|
||
node.put("orderNumber", m.getSortNo() != null ? m.getSortNo() : 0);
|
||
node.put("usable", true);
|
||
node.put("children", toFrontendTree(m.getChildren()));
|
||
result.add(node);
|
||
}
|
||
return result;
|
||
}
|
||
}
|