mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 09:11:52 +08:00
Swagger 增加 tenant-id 头
This commit is contained in:
parent
fc509837a1
commit
2505d61b08
@ -9,7 +9,9 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.ExampleBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestParameterBuilder;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
@ -55,9 +57,12 @@ public class YudaoSwaggerAutoConfiguration {
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.securitySchemes(securitySchemes())
|
||||
.globalRequestParameters(globalRequestParameters())
|
||||
.securityContexts(securityContexts());
|
||||
}
|
||||
|
||||
// ========== apiInfo ==========
|
||||
|
||||
/**
|
||||
* API 摘要信息
|
||||
*/
|
||||
@ -70,6 +75,8 @@ public class YudaoSwaggerAutoConfiguration {
|
||||
.build();
|
||||
}
|
||||
|
||||
// ========== securitySchemes ==========
|
||||
|
||||
/**
|
||||
* 安全模式,这里配置通过请求头 Authorization 传递 token 参数
|
||||
*/
|
||||
@ -98,4 +105,12 @@ public class YudaoSwaggerAutoConfiguration {
|
||||
return new AuthorizationScope[]{new AuthorizationScope("global", "accessEverything")};
|
||||
}
|
||||
|
||||
// ========== globalRequestParameters ==========
|
||||
|
||||
private static List<RequestParameter> globalRequestParameters() {
|
||||
RequestParameterBuilder tenantParameter = new RequestParameterBuilder().name("tenant-id").description("租户编号")
|
||||
.in(ParameterType.HEADER).example(new ExampleBuilder().value(1L).build());
|
||||
return Collections.singletonList(tenantParameter.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.test;
|
||||
|
||||
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
|
||||
import cn.iocoder.yudao.framework.test.config.RedisTestConfiguration;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -44,7 +44,7 @@ public interface TenantMapper extends BaseMapperX<TenantDO> {
|
||||
return selectOne(TenantDO::getName, name);
|
||||
}
|
||||
|
||||
default Integer selectCountByPackageId(Long packageId) {
|
||||
default Long selectCountByPackageId(Long packageId) {
|
||||
return selectCount(TenantDO::getPackageId, packageId);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -71,6 +72,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
@Resource
|
||||
@Lazy // 延迟,避免循环依赖报错
|
||||
private TenantService tenantService;
|
||||
|
||||
@Resource
|
||||
|
@ -95,7 +95,7 @@ public interface TenantService extends TenantFrameworkService {
|
||||
* @param packageId 租户套餐编号
|
||||
* @return 租户数量
|
||||
*/
|
||||
Integer getTenantCountByPackageId(Long packageId);
|
||||
Long getTenantCountByPackageId(Long packageId);
|
||||
|
||||
/**
|
||||
* 获得使用指定套餐的租户数组
|
||||
|
@ -301,7 +301,7 @@ public class TenantServiceImpl implements TenantService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTenantCountByPackageId(Long packageId) {
|
||||
public Long getTenantCountByPackageId(Long packageId) {
|
||||
return tenantMapper.selectCountByPackageId(packageId);
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest {
|
||||
// 准备参数
|
||||
Long id = dbTenantPackage.getId();
|
||||
// mock 租户未使用该套餐
|
||||
when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(0);
|
||||
when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(0L);
|
||||
|
||||
// 调用
|
||||
tenantPackageService.deleteTenantPackage(id);
|
||||
@ -127,7 +127,7 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest {
|
||||
// 准备参数
|
||||
Long id = dbTenantPackage.getId();
|
||||
// mock 租户在使用该套餐
|
||||
when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(1);
|
||||
when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(1L);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> tenantPackageService.deleteTenantPackage(id), TENANT_PACKAGE_USED);
|
||||
|
@ -431,7 +431,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
||||
tenantMapper.insert(dbTenant2);// @Sql: 先插入出一条存在的数据
|
||||
|
||||
// 调用
|
||||
Integer count = tenantService.getTenantCountByPackageId(1L);
|
||||
Long count = tenantService.getTenantCountByPackageId(1L);
|
||||
assertEquals(1, count);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user