Commit d1271f8bff3a110822d454983c2d26b50219de50
1 parent
58e4f11c
统一 TenantApi 的封装,与 yudao-cloud~
Showing
5 changed files
with
105 additions
and
0 deletions
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java
| @@ -11,9 +11,11 @@ import cn.iocoder.yudao.framework.tenant.core.job.TenantJobHandlerDecorator; | @@ -11,9 +11,11 @@ import cn.iocoder.yudao.framework.tenant.core.job.TenantJobHandlerDecorator; | ||
| 11 | import cn.iocoder.yudao.framework.tenant.core.mq.TenantRedisMessageInterceptor; | 11 | import cn.iocoder.yudao.framework.tenant.core.mq.TenantRedisMessageInterceptor; |
| 12 | import cn.iocoder.yudao.framework.tenant.core.security.TenantSecurityWebFilter; | 12 | import cn.iocoder.yudao.framework.tenant.core.security.TenantSecurityWebFilter; |
| 13 | import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; | 13 | import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; |
| 14 | +import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkServiceImpl; | ||
| 14 | import cn.iocoder.yudao.framework.tenant.core.web.TenantContextWebFilter; | 15 | import cn.iocoder.yudao.framework.tenant.core.web.TenantContextWebFilter; |
| 15 | import cn.iocoder.yudao.framework.web.config.WebProperties; | 16 | import cn.iocoder.yudao.framework.web.config.WebProperties; |
| 16 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; | 17 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; |
| 18 | +import cn.iocoder.yudao.module.system.api.tenant.TenantApi; | ||
| 17 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | 19 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
| 18 | import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; | 20 | import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; |
| 19 | import org.springframework.beans.BeansException; | 21 | import org.springframework.beans.BeansException; |
| @@ -29,6 +31,11 @@ import org.springframework.context.annotation.Configuration; | @@ -29,6 +31,11 @@ import org.springframework.context.annotation.Configuration; | ||
| 29 | @EnableConfigurationProperties(TenantProperties.class) | 31 | @EnableConfigurationProperties(TenantProperties.class) |
| 30 | public class YudaoTenantAutoConfiguration { | 32 | public class YudaoTenantAutoConfiguration { |
| 31 | 33 | ||
| 34 | + @Bean | ||
| 35 | + public TenantFrameworkService tenantFrameworkService(TenantApi tenantApi) { | ||
| 36 | + return new TenantFrameworkServiceImpl(tenantApi); | ||
| 37 | + } | ||
| 38 | + | ||
| 32 | // ========== AOP ========== | 39 | // ========== AOP ========== |
| 33 | 40 | ||
| 34 | @Bean | 41 | @Bean |
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/service/TenantFrameworkServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.tenant.core.service; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.system.api.tenant.TenantApi; | ||
| 4 | +import lombok.RequiredArgsConstructor; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Tenant 框架 Service 实现类 | ||
| 10 | + * | ||
| 11 | + * @author 芋道源码 | ||
| 12 | + */ | ||
| 13 | +@RequiredArgsConstructor | ||
| 14 | +public class TenantFrameworkServiceImpl implements TenantFrameworkService { | ||
| 15 | + | ||
| 16 | + private final TenantApi tenantApi; | ||
| 17 | + | ||
| 18 | + @Override | ||
| 19 | + public List<Long> getTenantIds() { | ||
| 20 | + return tenantApi.getTenantIds(); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + @Override | ||
| 24 | + public void validTenant(Long id) { | ||
| 25 | + tenantApi.validTenant(id); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | +} |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApi.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.api.tenant; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 多租户的 API 接口 | ||
| 7 | + * | ||
| 8 | + * @author 芋道源码 | ||
| 9 | + */ | ||
| 10 | +public interface TenantApi { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 获得所有租户 | ||
| 14 | + * | ||
| 15 | + * @return 租户编号数组 | ||
| 16 | + */ | ||
| 17 | + List<Long> getTenantIds(); | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 校验租户是否合法 | ||
| 21 | + * | ||
| 22 | + * @param id 租户编号 | ||
| 23 | + */ | ||
| 24 | + void validTenant(Long id); | ||
| 25 | + | ||
| 26 | +} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApiImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.api.tenant; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.system.service.tenant.TenantService; | ||
| 4 | +import org.springframework.stereotype.Service; | ||
| 5 | + | ||
| 6 | +import javax.annotation.Resource; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 多租户的 API 实现类 | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@Service | ||
| 15 | +public class TenantApiImpl implements TenantApi { | ||
| 16 | + | ||
| 17 | + @Resource | ||
| 18 | + private TenantService tenantService; | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public List<Long> getTenantIds() { | ||
| 22 | + return tenantService.getTenantIds(); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public void validTenant(Long id) { | ||
| 27 | + tenantService.validTenant(id); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | +} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java
| @@ -120,4 +120,18 @@ public interface TenantService extends TenantFrameworkService { | @@ -120,4 +120,18 @@ public interface TenantService extends TenantFrameworkService { | ||
| 120 | * @param handler 处理器 | 120 | * @param handler 处理器 |
| 121 | */ | 121 | */ |
| 122 | void handleTenantMenu(TenantMenuHandler handler); | 122 | void handleTenantMenu(TenantMenuHandler handler); |
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * 获得所有租户 | ||
| 126 | + * | ||
| 127 | + * @return 租户编号数组 | ||
| 128 | + */ | ||
| 129 | + List<Long> getTenantIds(); | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 校验租户是否合法 | ||
| 133 | + * | ||
| 134 | + * @param id 租户编号 | ||
| 135 | + */ | ||
| 136 | + void validTenant(Long id); | ||
| 123 | } | 137 | } |