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