im.shs.tick.mybatis.config.TenantConfig Maven / Gradle / Ivy
The newest version!
package im.shs.tick.mybatis.config;
import com.baomidou.mybatisplus.core.parser.ISqlParser;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
import im.shs.tick.mybatis.handler.TenantHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import java.util.ArrayList;
import java.util.List;
/**
* 租户配置
*
* @author SimpleJuly
*/
@Configuration
@ConditionalOnProperty(value = "tick.config.tenant.enabled", havingValue = "true")
public class TenantConfig {
/**
* 创建租户维护处理器对象
*
* @return 处理后的租户维护处理器
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "tick.config.tenant.enabled", havingValue = "true")
public TenantHandler tenantHandler() {
return new TenantHandler();
}
/**
* 分页插件
*
* @param tenantHandler 租户处理器
* @return PaginationInterceptor
*/
@Bean
@Primary
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "tick.config.tenant.enabled", havingValue = "true")
public PaginationInterceptor paginationInterceptor(TenantHandler tenantHandler) {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
List sqlParserList = new ArrayList<>();
TenantSqlParser tenantSqlParser = new TenantSqlParser();
tenantSqlParser.setTenantHandler(tenantHandler);
sqlParserList.add(tenantSqlParser);
paginationInterceptor.setSqlParserList(sqlParserList);
return paginationInterceptor;
}
}