package com.qianwen.core.tenant.config; import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; import com.qianwen.core.mp.config.MybatisPlusConfiguration; import com.qianwen.core.tenant.BladeTenantHandler; import com.qianwen.core.tenant.BladeTenantId; import com.qianwen.core.tenant.BladeTenantInterceptor; import com.qianwen.core.tenant.BladeTenantProperties; import com.qianwen.core.tenant.TenantId; import com.qianwen.core.tenant.aspect.BladeTenantAspect; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @AutoConfigureBefore({MybatisPlusConfiguration.class}) @EnableConfigurationProperties({BladeTenantProperties.class}) @Configuration(proxyBeanMethods = false) public class TenantConfiguration { @Bean @Primary public TenantLineHandler bladeTenantHandler(BladeTenantProperties tenantProperties) { return new BladeTenantHandler(tenantProperties); } @Bean @Primary public TenantLineInnerInterceptor tenantLineInnerInterceptor(TenantLineHandler tenantHandler, BladeTenantProperties tenantProperties) { BladeTenantInterceptor tenantInterceptor = new BladeTenantInterceptor(); tenantInterceptor.setTenantLineHandler(tenantHandler); tenantInterceptor.setTenantProperties(tenantProperties); return tenantInterceptor; } @ConditionalOnMissingBean({TenantId.class}) @Bean public TenantId tenantId() { return new BladeTenantId(); } @Bean public BladeTenantAspect bladeTenantAspect() { return new BladeTenantAspect(); } }