mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 20:28:44 +08:00 
			
		
		
		
	统一 TenantApi 的封装,与 yudao-cloud~
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Long> getTenantIds() {
 | 
			
		||||
        return tenantApi.getTenantIds();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void validTenant(Long id) {
 | 
			
		||||
        tenantApi.validTenant(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
package cn.iocoder.yudao.module.system.api.tenant;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 多租户的 API 接口
 | 
			
		||||
 *
 | 
			
		||||
 * @author 芋道源码
 | 
			
		||||
 */
 | 
			
		||||
public interface TenantApi {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得所有租户
 | 
			
		||||
     *
 | 
			
		||||
     * @return 租户编号数组
 | 
			
		||||
     */
 | 
			
		||||
    List<Long> getTenantIds();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 校验租户是否合法
 | 
			
		||||
     *
 | 
			
		||||
     * @param id 租户编号
 | 
			
		||||
     */
 | 
			
		||||
    void validTenant(Long id);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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<Long> getTenantIds() {
 | 
			
		||||
        return tenantService.getTenantIds();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void validTenant(Long id) {
 | 
			
		||||
        tenantService.validTenant(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -120,4 +120,18 @@ public interface TenantService extends TenantFrameworkService {
 | 
			
		||||
     * @param handler 处理器
 | 
			
		||||
     */
 | 
			
		||||
    void handleTenantMenu(TenantMenuHandler handler);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得所有租户
 | 
			
		||||
     *
 | 
			
		||||
     * @return 租户编号数组
 | 
			
		||||
     */
 | 
			
		||||
    List<Long> getTenantIds();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 校验租户是否合法
 | 
			
		||||
     *
 | 
			
		||||
     * @param id 租户编号
 | 
			
		||||
     */
 | 
			
		||||
    void validTenant(Long id);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user