yangys
2024-05-18 040976de6f9934b99f30268a28e2ecf42260e217
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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();
    }
}