From 7dbf47524e6c13cc95ec7e40a2dd1b869fd6dda0 Mon Sep 17 00:00:00 2001 From: chenchuchuan <13554600537@163.com> Date: Wed, 21 Oct 2026 10:00:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(openapi):=20=E8=A1=A5=E5=85=85=E5=AF=86?= =?UTF-8?q?=E9=92=A5=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E7=9A=84=E5=BA=94=E7=94=A8=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SysUserSecret 模型中新增 appCode 非数据库字段用于列表展示 - 新增 fillAppCode 方法,通过 OpenApiAppService 批量查询应用编码 - 将 fillAccountInfo 重构为 fillDisplayInfo,统一补全账号和应用展示信息 - 密钥列表和详情接口均调用 fillDisplayInfo 补全展示字段 --- .../controller/SysUserSecretController.java | 44 ++++++++++++++++++++-- .../apelet/common/openapi/model/SysUserSecret.java | 6 +++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/common/common-openapi/src/main/java/apelet/common/openapi/controller/SysUserSecretController.java b/common/common-openapi/src/main/java/apelet/common/openapi/controller/SysUserSecretController.java index f4f984c..78c1ab3 100644 --- a/common/common-openapi/src/main/java/apelet/common/openapi/controller/SysUserSecretController.java +++ b/common/common-openapi/src/main/java/apelet/common/openapi/controller/SysUserSecretController.java @@ -13,7 +13,9 @@ import apelet.common.core.util.MyPageUtil; import apelet.common.log.annotation.OperationLog; import apelet.common.log.model.constant.SysOperationLogType; import apelet.common.openapi.constant.SysUserSecretStatus; +import apelet.common.openapi.model.OpenApiApp; import apelet.common.openapi.model.SysUserSecret; +import apelet.common.openapi.service.OpenApiAppService; import apelet.common.openapi.service.SysUserSecretService; import apelet.common.openapi.vo.SysUserSecretIssueVo; import cn.hutool.core.date.DateUtil; @@ -54,6 +56,8 @@ public class SysUserSecretController { @Autowired private SysUserSecretService sysUserSecretService; + @Autowired + private OpenApiAppService openApiAppService; @Autowired(required = false) private McpAccountProvider mcpAccountProvider; @@ -85,7 +89,7 @@ public class SysUserSecretController { if (secretList instanceof Page) { totalCount = ((Page) secretList).getTotal(); } - this.fillAccountInfo(secretList); + this.fillDisplayInfo(secretList); secretList.forEach(this::maskForResponse); return ResponseResult.success(MyPageUtil.makeResponseData(secretList, totalCount)); } @@ -108,7 +112,7 @@ public class SysUserSecretController { if (!this.isSelfOrAdmin(userSecret)) { return ResponseResult.error(ErrorCodeEnum.NO_OPERATION_PERMISSION); } - this.fillAccountInfo(Collections.singletonList(userSecret)); + this.fillDisplayInfo(Collections.singletonList(userSecret)); this.maskForResponse(userSecret); return ResponseResult.success(userSecret); } @@ -190,12 +194,27 @@ public class SysUserSecretController { } /** - * 补全账号展示字段。密钥表本身不含账号信息,通过 SPI 批量补齐。 + * 补全展示字段:账号姓名/手机号、绑定应用编码。 + *

密钥表本身只存 userId / appId,展示所需的账号与应用信息在这里批量补齐, + * 避免 service 层反向依赖应用侧模型。

+ * + * @param secretList 密钥列表。 + */ + private void fillDisplayInfo(List secretList) { + if (secretList == null || secretList.isEmpty()) { + return; + } + this.fillAccountInfo(secretList); + this.fillAppCode(secretList); + } + + /** + * 补全账号展示字段(姓名/手机号)。 * * @param secretList 密钥列表。 */ private void fillAccountInfo(List secretList) { - if (secretList == null || secretList.isEmpty() || mcpAccountProvider == null) { + if (mcpAccountProvider == null) { return; } Set userIdSet = secretList.stream().map(SysUserSecret::getUserId).filter(Objects::nonNull).collect(Collectors.toSet()); @@ -215,6 +234,23 @@ public class SysUserSecretController { } /** + * 补全绑定应用的编码。列表里显示 appId 数字没有意义,展示 appCode 更可读。 + * + * @param secretList 密钥列表。 + */ + private void fillAppCode(List secretList) { + Set appIdSet = secretList.stream().map(SysUserSecret::getAppId).filter(Objects::nonNull).collect(Collectors.toSet()); + if (appIdSet.isEmpty()) { + return; + } + Map appCodeMap = openApiAppService.listByIds(appIdSet).stream() + .collect(Collectors.toMap(OpenApiApp::getId, OpenApiApp::getAppCode, (a, b) -> a)); + for (SysUserSecret userSecret : secretList) { + userSecret.setAppCode(appCodeMap.get(userSecret.getAppId())); + } + } + + /** * 判断当前登录人是否有权操作该密钥:管理员放行,否则要求是该密钥的绑定账号。 * * @param userSecret 目标密钥记录。 diff --git a/common/common-openapi/src/main/java/apelet/common/openapi/model/SysUserSecret.java b/common/common-openapi/src/main/java/apelet/common/openapi/model/SysUserSecret.java index c197b8c..b9457f2 100644 --- a/common/common-openapi/src/main/java/apelet/common/openapi/model/SysUserSecret.java +++ b/common/common-openapi/src/main/java/apelet/common/openapi/model/SysUserSecret.java @@ -95,4 +95,10 @@ public class SysUserSecret extends BaseModel { */ @TableField(exist = false) private String mobile; + + /** + * 绑定的OpenAPI应用编码(非数据库字段,仅用于列表展示)。 + */ + @TableField(exist = false) + private String appCode; }