新增imes-token获取组织id接口

This commit is contained in:
gaoqr
2026-07-22 17:37:24 +08:00
parent 43e8b9d0ac
commit d1099fd34e
7 changed files with 16 additions and 12 deletions
@@ -13,10 +13,11 @@ import lombok.Data;
public class AuthAppTokenReqVO { public class AuthAppTokenReqVO {
/** /**
* system_config_token 表中存储的应用 Token * 外部应用 Token,支持携带 imes- 前缀
*/ */
@Schema(description = "应用 Token", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "应用 Token,格式为 imes-{system_config_token.app_token}",
requiredMode = Schema.RequiredMode.REQUIRED, example = "imes-b91111d8ced245086edad0459a653ffd")
@NotBlank(message = "{auth.appToken.notBlank}") @NotBlank(message = "{auth.appToken.notBlank}")
@Size(max = 255, message = "{auth.appToken.size}") @Size(max = 260, message = "{auth.appToken.size}")
private String appToken; private String appToken;
} }
@@ -58,7 +58,7 @@ public interface TokenConfigService {
Long checkTokenConfig(String token); Long checkTokenConfig(String token);
/** /**
* 根据数据库中存储的应用 Token 获取所属组织编号。 * 根据应用 Token 获取所属组织编号,支持解析 imes- 前缀
* *
* @param appToken 应用 Token * @param appToken 应用 Token
* @return 组织编号 * @return 组织编号
@@ -3,6 +3,7 @@ package com.cf.imes.module.system.service.tokenconfig;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.cf.imes.framework.common.enums.CommonStatusEnum; import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult; import com.cf.imes.framework.common.pojo.PageResult;
@@ -207,13 +208,15 @@ public class TokenConfigServiceImpl implements TokenConfigService{
@Override @Override
public Long checkTokenConfig(String token) { public Long checkTokenConfig(String token) {
return getOrganIdByAppToken(token.substring(FIELD_IMES.length())); return getOrganIdByAppToken(token);
} }
@Override @Override
public Long getOrganIdByAppToken(String appToken) { public Long getOrganIdByAppToken(String appToken) {
// 外部 Token 使用 imes-{app_token} 格式,数据库仅存储去除前缀后的 app_token。
String databaseAppToken = StrUtil.removePrefix(appToken, FIELD_IMES);
// 应用 Token 必须存在且处于有效期内,避免失效配置继续访问外部接口。 // 应用 Token 必须存在且处于有效期内,避免失效配置继续访问外部接口。
TokenConfigDO tokenConfigDO = tokenConfigMapper.selectByToken(appToken); TokenConfigDO tokenConfigDO = tokenConfigMapper.selectByToken(databaseAppToken);
if(tokenConfigDO == null){ if(tokenConfigDO == null){
throw new ServiceException(TOKEN_CONFIG_NOT_EXISTS); throw new ServiceException(TOKEN_CONFIG_NOT_EXISTS);
@@ -110,4 +110,4 @@ assembly.config.save.structure.config.notNull=裝備設定結構配寘不能為
common.status.invalid=狀態不合法 common.status.invalid=狀態不合法
auth.appToken.notBlank=應用 Token 不能為空 auth.appToken.notBlank=應用 Token 不能為空
auth.appToken.size=應用 Token 長度不能超過 255 個字元 auth.appToken.size=應用 Token 長度不能超過 260 個字元
@@ -110,4 +110,4 @@ assembly.config.save.structure.config.notNull=Assembly setting structure configu
common.status.invalid=The status is illegal common.status.invalid=The status is illegal
auth.appToken.notBlank=Application Token cannot be blank auth.appToken.notBlank=Application Token cannot be blank
auth.appToken.size=Application Token cannot exceed 255 characters auth.appToken.size=Application Token cannot exceed 260 characters
@@ -110,4 +110,4 @@ assembly.config.save.structure.config.notNull=装备设置结构配置不能为
common.status.invalid=状态不合法 common.status.invalid=状态不合法
auth.appToken.notBlank=应用 Token 不能为空 auth.appToken.notBlank=应用 Token 不能为空
auth.appToken.size=应用 Token 长度不能超过 255 个字符 auth.appToken.size=应用 Token 长度不能超过 260 个字符
@@ -208,15 +208,15 @@ class AuthControllerTest extends BaseWebUnitTest {
@Test @Test
void testGetOrganIdByAppToken() throws Exception { void testGetOrganIdByAppToken() throws Exception {
when(tokenConfigService.getOrganIdByAppToken("test-app-token")).thenReturn(100L); when(tokenConfigService.getOrganIdByAppToken("imes-test-app-token")).thenReturn(100L);
mockMvc.perform(post("/admin-api/system/auth/app-token/organ-id") mockMvc.perform(post("/admin-api/system/auth/app-token/organ-id")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content("{\"appToken\":\"test-app-token\"}")) .content("{\"appToken\":\"imes-test-app-token\"}"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.data").value(100L)); .andExpect(jsonPath("$.data").value(100L));
verify(tokenConfigService, times(1)).getOrganIdByAppToken("test-app-token"); verify(tokenConfigService, times(1)).getOrganIdByAppToken("imes-test-app-token");
} }
@Test @Test