|
|
|
@ -13,7 +13,9 @@ import apelet.common.core.util.MyPageUtil; |
|
|
|
import apelet.common.log.annotation.OperationLog; |
|
|
|
import apelet.common.log.annotation.OperationLog; |
|
|
|
import apelet.common.log.model.constant.SysOperationLogType; |
|
|
|
import apelet.common.log.model.constant.SysOperationLogType; |
|
|
|
import apelet.common.openapi.constant.SysUserSecretStatus; |
|
|
|
import apelet.common.openapi.constant.SysUserSecretStatus; |
|
|
|
|
|
|
|
import apelet.common.openapi.model.OpenApiApp; |
|
|
|
import apelet.common.openapi.model.SysUserSecret; |
|
|
|
import apelet.common.openapi.model.SysUserSecret; |
|
|
|
|
|
|
|
import apelet.common.openapi.service.OpenApiAppService; |
|
|
|
import apelet.common.openapi.service.SysUserSecretService; |
|
|
|
import apelet.common.openapi.service.SysUserSecretService; |
|
|
|
import apelet.common.openapi.vo.SysUserSecretIssueVo; |
|
|
|
import apelet.common.openapi.vo.SysUserSecretIssueVo; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
@ -54,6 +56,8 @@ public class SysUserSecretController { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private SysUserSecretService sysUserSecretService; |
|
|
|
private SysUserSecretService sysUserSecretService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private OpenApiAppService openApiAppService; |
|
|
|
@Autowired(required = false) |
|
|
|
@Autowired(required = false) |
|
|
|
private McpAccountProvider mcpAccountProvider; |
|
|
|
private McpAccountProvider mcpAccountProvider; |
|
|
|
|
|
|
|
|
|
|
|
@ -85,7 +89,7 @@ public class SysUserSecretController { |
|
|
|
if (secretList instanceof Page) { |
|
|
|
if (secretList instanceof Page) { |
|
|
|
totalCount = ((Page<SysUserSecret>) secretList).getTotal(); |
|
|
|
totalCount = ((Page<SysUserSecret>) secretList).getTotal(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.fillAccountInfo(secretList); |
|
|
|
this.fillDisplayInfo(secretList); |
|
|
|
secretList.forEach(this::maskForResponse); |
|
|
|
secretList.forEach(this::maskForResponse); |
|
|
|
return ResponseResult.success(MyPageUtil.makeResponseData(secretList, totalCount)); |
|
|
|
return ResponseResult.success(MyPageUtil.makeResponseData(secretList, totalCount)); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -108,7 +112,7 @@ public class SysUserSecretController { |
|
|
|
if (!this.isSelfOrAdmin(userSecret)) { |
|
|
|
if (!this.isSelfOrAdmin(userSecret)) { |
|
|
|
return ResponseResult.error(ErrorCodeEnum.NO_OPERATION_PERMISSION); |
|
|
|
return ResponseResult.error(ErrorCodeEnum.NO_OPERATION_PERMISSION); |
|
|
|
} |
|
|
|
} |
|
|
|
this.fillAccountInfo(Collections.singletonList(userSecret)); |
|
|
|
this.fillDisplayInfo(Collections.singletonList(userSecret)); |
|
|
|
this.maskForResponse(userSecret); |
|
|
|
this.maskForResponse(userSecret); |
|
|
|
return ResponseResult.success(userSecret); |
|
|
|
return ResponseResult.success(userSecret); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -190,12 +194,27 @@ public class SysUserSecretController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 补全账号展示字段。密钥表本身不含账号信息,通过 SPI 批量补齐。 |
|
|
|
* 补全展示字段:账号姓名/手机号、绑定应用编码。 |
|
|
|
|
|
|
|
* <p>密钥表本身只存 userId / appId,展示所需的账号与应用信息在这里批量补齐, |
|
|
|
|
|
|
|
* 避免 service 层反向依赖应用侧模型。</p> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param secretList 密钥列表。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void fillDisplayInfo(List<SysUserSecret> secretList) { |
|
|
|
|
|
|
|
if (secretList == null || secretList.isEmpty()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.fillAccountInfo(secretList); |
|
|
|
|
|
|
|
this.fillAppCode(secretList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 补全账号展示字段(姓名/手机号)。 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param secretList 密钥列表。 |
|
|
|
* @param secretList 密钥列表。 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void fillAccountInfo(List<SysUserSecret> secretList) { |
|
|
|
private void fillAccountInfo(List<SysUserSecret> secretList) { |
|
|
|
if (secretList == null || secretList.isEmpty() || mcpAccountProvider == null) { |
|
|
|
if (mcpAccountProvider == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
Set<Long> userIdSet = secretList.stream().map(SysUserSecret::getUserId).filter(Objects::nonNull).collect(Collectors.toSet()); |
|
|
|
Set<Long> 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<SysUserSecret> secretList) { |
|
|
|
|
|
|
|
Set<Long> appIdSet = secretList.stream().map(SysUserSecret::getAppId).filter(Objects::nonNull).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
if (appIdSet.isEmpty()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Map<Long, String> 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 目标密钥记录。 |
|
|
|
* @param userSecret 目标密钥记录。 |
|
|
|
|