From d1271f8bff3a110822d454983c2d26b50219de50 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 16 Jun 2022 22:29:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=20TenantApi=20=E7=9A=84?= =?UTF-8?q?=E5=B0=81=E8=A3=85=EF=BC=8C=E4=B8=8E=20yudao-cloud~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoTenantAutoConfiguration.java | 7 +++++ .../service/TenantFrameworkServiceImpl.java | 28 +++++++++++++++++ .../module/system/api/tenant/TenantApi.java | 26 ++++++++++++++++ .../system/api/tenant/TenantApiImpl.java | 30 +++++++++++++++++++ .../system/service/tenant/TenantService.java | 14 +++++++++ 5 files changed, 105 insertions(+) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/service/TenantFrameworkServiceImpl.java create mode 100644 yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApi.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApiImpl.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java index 5c1376534..c1c969439 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java +++ b/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; import cn.iocoder.yudao.framework.tenant.core.mq.TenantRedisMessageInterceptor; import cn.iocoder.yudao.framework.tenant.core.security.TenantSecurityWebFilter; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; +import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkServiceImpl; import cn.iocoder.yudao.framework.tenant.core.web.TenantContextWebFilter; import cn.iocoder.yudao.framework.web.config.WebProperties; import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; +import cn.iocoder.yudao.module.system.api.tenant.TenantApi; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; import org.springframework.beans.BeansException; @@ -29,6 +31,11 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(TenantProperties.class) public class YudaoTenantAutoConfiguration { + @Bean + public TenantFrameworkService tenantFrameworkService(TenantApi tenantApi) { + return new TenantFrameworkServiceImpl(tenantApi); + } + // ========== AOP ========== @Bean diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/service/TenantFrameworkServiceImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/service/TenantFrameworkServiceImpl.java new file mode 100644 index 000000000..6262f9903 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/service/TenantFrameworkServiceImpl.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.framework.tenant.core.service; + +import cn.iocoder.yudao.module.system.api.tenant.TenantApi; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +/** + * Tenant 框架 Service 实现类 + * + * @author 芋道源码 + */ +@RequiredArgsConstructor +public class TenantFrameworkServiceImpl implements TenantFrameworkService { + + private final TenantApi tenantApi; + + @Override + public List getTenantIds() { + return tenantApi.getTenantIds(); + } + + @Override + public void validTenant(Long id) { + tenantApi.validTenant(id); + } + +} diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApi.java new file mode 100644 index 000000000..3f255d55a --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApi.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.system.api.tenant; + +import java.util.List; + +/** + * 多租户的 API 接口 + * + * @author 芋道源码 + */ +public interface TenantApi { + + /** + * 获得所有租户 + * + * @return 租户编号数组 + */ + List getTenantIds(); + + /** + * 校验租户是否合法 + * + * @param id 租户编号 + */ + void validTenant(Long id); + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApiImpl.java new file mode 100644 index 000000000..6ea4c795e --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/tenant/TenantApiImpl.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.system.api.tenant; + +import cn.iocoder.yudao.module.system.service.tenant.TenantService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 多租户的 API 实现类 + * + * @author 芋道源码 + */ +@Service +public class TenantApiImpl implements TenantApi { + + @Resource + private TenantService tenantService; + + @Override + public List getTenantIds() { + return tenantService.getTenantIds(); + } + + @Override + public void validTenant(Long id) { + tenantService.validTenant(id); + } + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java index 1743991d8..19318869a 100755 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantService.java +++ b/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 { * @param handler 处理器 */ void handleTenantMenu(TenantMenuHandler handler); + + /** + * 获得所有租户 + * + * @return 租户编号数组 + */ + List getTenantIds(); + + /** + * 校验租户是否合法 + * + * @param id 租户编号 + */ + void validTenant(Long id); }