feat: 凭据分页查询自动关联租户真实名称
This commit is contained in:
@@ -34,6 +34,9 @@ public class OpenClientAdminController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private OpenClientMapper clientMapper;
|
private OpenClientMapper clientMapper;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private org.springframework.jdbc.core.JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
private static final SecureRandom RANDOM = new SecureRandom();
|
private static final SecureRandom RANDOM = new SecureRandom();
|
||||||
|
|
||||||
@Operation(summary = "获取所有可授权的作用域 (Scopes) 枚举字典列表")
|
@Operation(summary = "获取所有可授权的作用域 (Scopes) 枚举字典列表")
|
||||||
@@ -60,7 +63,33 @@ public class OpenClientAdminController {
|
|||||||
.or().like(OpenClient::getClientId, keyword));
|
.or().like(OpenClient::getClientId, keyword));
|
||||||
}
|
}
|
||||||
qw.orderByDesc(OpenClient::getCreateTime);
|
qw.orderByDesc(OpenClient::getCreateTime);
|
||||||
return Result.success(clientMapper.selectPage(page, qw));
|
Page<OpenClient> resPage = clientMapper.selectPage(page, qw);
|
||||||
|
populateTenantNames(resPage.getRecords());
|
||||||
|
return Result.success(resPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateTenantNames(List<OpenClient> clients) {
|
||||||
|
if (clients == null || clients.isEmpty() || jdbcTemplate == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
java.util.Map<Long, String> tenantNameMap = new java.util.HashMap<>();
|
||||||
|
List<Map<String, Object>> rows = jdbcTemplate.queryForList("SELECT id, tenant_name FROM sys_tenant");
|
||||||
|
for (Map<String, Object> r : rows) {
|
||||||
|
Object idObj = r.get("id");
|
||||||
|
Object nameObj = r.get("tenant_name");
|
||||||
|
if (idObj instanceof Number && nameObj != null) {
|
||||||
|
tenantNameMap.put(((Number) idObj).longValue(), nameObj.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (OpenClient c : clients) {
|
||||||
|
if (c.getTenantId() != null) {
|
||||||
|
c.setTenantName(tenantNameMap.getOrDefault(c.getTenantId(), "租户 #" + c.getTenantId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("查询关联租户名称失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "获取凭据详情")
|
@Operation(summary = "获取凭据详情")
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ public class OpenClient implements Serializable {
|
|||||||
private String clientSecret;
|
private String clientSecret;
|
||||||
private String clientName;
|
private String clientName;
|
||||||
private Long tenantId;
|
private Long tenantId;
|
||||||
|
|
||||||
|
@com.baomidou.mybatisplus.annotation.TableField(exist = false)
|
||||||
|
private String tenantName;
|
||||||
|
|
||||||
private String scopes;
|
private String scopes;
|
||||||
private String ipWhitelist;
|
private String ipWhitelist;
|
||||||
private Integer rateLimit;
|
private Integer rateLimit;
|
||||||
|
|||||||
Reference in New Issue
Block a user