Commit 2505d61b08582c56577bfb1a61c0cda8a0479b5a

Authored by YunaiV
1 parent fc509837

Swagger 增加 tenant-id 头

yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java
... ... @@ -9,7 +9,9 @@ import org.springframework.context.annotation.Bean;
9 9 import org.springframework.context.annotation.Configuration;
10 10 import org.springframework.http.HttpHeaders;
11 11 import springfox.documentation.builders.ApiInfoBuilder;
  12 +import springfox.documentation.builders.ExampleBuilder;
12 13 import springfox.documentation.builders.PathSelectors;
  14 +import springfox.documentation.builders.RequestParameterBuilder;
13 15 import springfox.documentation.service.*;
14 16 import springfox.documentation.spi.DocumentationType;
15 17 import springfox.documentation.spi.service.contexts.SecurityContext;
... ... @@ -55,9 +57,12 @@ public class YudaoSwaggerAutoConfiguration {
55 57 .paths(PathSelectors.any())
56 58 .build()
57 59 .securitySchemes(securitySchemes())
  60 + .globalRequestParameters(globalRequestParameters())
58 61 .securityContexts(securityContexts());
59 62 }
60 63  
  64 + // ========== apiInfo ==========
  65 +
61 66 /**
62 67 * API 摘要信息
63 68 */
... ... @@ -70,6 +75,8 @@ public class YudaoSwaggerAutoConfiguration {
70 75 .build();
71 76 }
72 77  
  78 + // ========== securitySchemes ==========
  79 +
73 80 /**
74 81 * 安全模式,这里配置通过请求头 Authorization 传递 token 参数
75 82 */
... ... @@ -98,4 +105,12 @@ public class YudaoSwaggerAutoConfiguration {
98 105 return new AuthorizationScope[]{new AuthorizationScope("global", "accessEverything")};
99 106 }
100 107  
  108 + // ========== globalRequestParameters ==========
  109 +
  110 + private static List<RequestParameter> globalRequestParameters() {
  111 + RequestParameterBuilder tenantParameter = new RequestParameterBuilder().name("tenant-id").description("租户编号")
  112 + .in(ParameterType.HEADER).example(new ExampleBuilder().value(1L).build());
  113 + return Collections.singletonList(tenantParameter.build());
  114 + }
  115 +
101 116 }
... ...
yudao-module-pay/yudao-module-pay-impl/src/test/java/cn/iocoder/yudao/module/pay/test/BaseRedisUnitTest.java
1 1 package cn.iocoder.yudao.module.pay.test;
2 2  
3 3 import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
  4 +import cn.iocoder.yudao.framework.test.config.RedisTestConfiguration;
4 5 import org.redisson.spring.starter.RedissonAutoConfiguration;
5 6 import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
6 7 import org.springframework.boot.test.context.SpringBootTest;
... ...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenant/TenantMapper.java
... ... @@ -44,7 +44,7 @@ public interface TenantMapper extends BaseMapperX&lt;TenantDO&gt; {
44 44 return selectOne(TenantDO::getName, name);
45 45 }
46 46  
47   - default Integer selectCountByPackageId(Long packageId) {
  47 + default Long selectCountByPackageId(Long packageId) {
48 48 return selectCount(TenantDO::getPackageId, packageId);
49 49 }
50 50  
... ...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
... ... @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableMap;
18 18 import com.google.common.collect.ImmutableMultimap;
19 19 import com.google.common.collect.Multimap;
20 20 import lombok.extern.slf4j.Slf4j;
  21 +import org.springframework.context.annotation.Lazy;
21 22 import org.springframework.scheduling.annotation.Scheduled;
22 23 import org.springframework.stereotype.Service;
23 24 import org.springframework.transaction.annotation.Transactional;
... ... @@ -71,6 +72,7 @@ public class MenuServiceImpl implements MenuService {
71 72 @Resource
72 73 private PermissionService permissionService;
73 74 @Resource
  75 + @Lazy // 延迟,避免循环依赖报错
74 76 private TenantService tenantService;
75 77  
76 78 @Resource
... ...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java
... ... @@ -95,7 +95,7 @@ public interface TenantService extends TenantFrameworkService {
95 95 * @param packageId 租户套餐编号
96 96 * @return 租户数量
97 97 */
98   - Integer getTenantCountByPackageId(Long packageId);
  98 + Long getTenantCountByPackageId(Long packageId);
99 99  
100 100 /**
101 101 * 获得使用指定套餐的租户数组
... ...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java
... ... @@ -301,7 +301,7 @@ public class TenantServiceImpl implements TenantService {
301 301 }
302 302  
303 303 @Override
304   - public Integer getTenantCountByPackageId(Long packageId) {
  304 + public Long getTenantCountByPackageId(Long packageId) {
305 305 return tenantMapper.selectCountByPackageId(packageId);
306 306 }
307 307  
... ...
yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImplTest.java
... ... @@ -102,7 +102,7 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest {
102 102 // 准备参数
103 103 Long id = dbTenantPackage.getId();
104 104 // mock 租户未使用该套餐
105   - when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(0);
  105 + when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(0L);
106 106  
107 107 // 调用
108 108 tenantPackageService.deleteTenantPackage(id);
... ... @@ -127,7 +127,7 @@ public class TenantPackageServiceImplTest extends BaseDbUnitTest {
127 127 // 准备参数
128 128 Long id = dbTenantPackage.getId();
129 129 // mock 租户在使用该套餐
130   - when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(1);
  130 + when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(1L);
131 131  
132 132 // 调用, 并断言异常
133 133 assertServiceException(() -> tenantPackageService.deleteTenantPackage(id), TENANT_PACKAGE_USED);
... ...
yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java
... ... @@ -431,7 +431,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
431 431 tenantMapper.insert(dbTenant2);// @Sql: 先插入出一条存在的数据
432 432  
433 433 // 调用
434   - Integer count = tenantService.getTenantCountByPackageId(1L);
  434 + Long count = tenantService.getTenantCountByPackageId(1L);
435 435 assertEquals(1, count);
436 436 }
437 437  
... ...