多租户模式彻底架构化,脱离实体类注解配置
This commit is contained in:
parent
ee2c046425
commit
d265ddec06
@ -1,9 +1,13 @@
|
||||
package com.cdzy.operations.config;
|
||||
|
||||
import com.cdzy.operations.component.EbikeTenantFactory;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.dialect.DbType;
|
||||
import com.mybatisflex.core.keygen.KeyGenerators;
|
||||
import com.mybatisflex.core.tenant.TenantFactory;
|
||||
import com.mybatisflex.core.tenant.TenantManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -29,27 +33,33 @@ public class MyBatisFlexConfiguration {
|
||||
, auditMessage.getElapsedTime())
|
||||
);
|
||||
|
||||
FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
|
||||
//全局ID生成策略配置
|
||||
FlexGlobalConfig.KeyConfig keyConfig = new FlexGlobalConfig.KeyConfig();
|
||||
keyConfig.setKeyType(KeyType.Generator);
|
||||
keyConfig.setValue("snowFlakeId");
|
||||
keyConfig.setValue(KeyGenerators.snowFlakeId);
|
||||
keyConfig.setBefore(true);
|
||||
|
||||
|
||||
FlexGlobalConfig.getDefaultConfig().setKeyConfig(keyConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FlexGlobalConfig flexGlobalConfig() {
|
||||
FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
|
||||
globalConfig.setTenantColumn("operator_id");
|
||||
globalConfig.setKeyConfig(keyConfig);
|
||||
//方言配置
|
||||
globalConfig.setDbType(DbType.POSTGRE_SQL); // 关键配置
|
||||
//设置数据库正常时的值
|
||||
globalConfig.setNormalValueOfLogicDelete(Boolean.FALSE);
|
||||
|
||||
//设置数据已被删除时的值
|
||||
//设置数据已被删除时的值
|
||||
globalConfig.setDeletedValueOfLogicDelete(Boolean.TRUE);
|
||||
globalConfig.setTenantColumn("operator_id");
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 详细的租户工厂配置
|
||||
*/
|
||||
@Bean
|
||||
public static TenantFactory tenantFactory() {
|
||||
logger.info("开始初始化租户工厂...");
|
||||
EbikeTenantFactory factory = new EbikeTenantFactory();
|
||||
TenantManager.setTenantFactory(factory);
|
||||
return new EbikeTenantFactory();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +1,7 @@
|
||||
package com.cdzy.operations.config;
|
||||
|
||||
|
||||
import com.cdzy.operations.component.EbikeTenantFactory;
|
||||
import com.cdzy.operations.component.TenantInterceptor;
|
||||
import com.mybatisflex.core.tenant.TenantFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@ -12,11 +9,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public TenantFactory tenantFactory(){
|
||||
return new EbikeTenantFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new TenantInterceptor());
|
||||
|
||||
@ -34,7 +34,6 @@ public class EbikeBatteryInfo implements Serializable {
|
||||
@Id
|
||||
private Long batteryId;
|
||||
|
||||
@Column(tenantId = true)
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
|
||||
@ -37,7 +37,6 @@ public class EbikeEcuInfo implements Serializable {
|
||||
/**
|
||||
* 运营商ID
|
||||
*/
|
||||
@Column(tenantId = true)
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
package com.cdzy.staff.config;
|
||||
|
||||
import com.cdzy.staff.component.EbikeTenantFactory;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.dialect.DbType;
|
||||
import com.mybatisflex.core.keygen.KeyGenerators;
|
||||
import com.mybatisflex.core.tenant.TenantFactory;
|
||||
import com.mybatisflex.core.tenant.TenantManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -29,27 +33,33 @@ public class MyBatisFlexConfiguration {
|
||||
, auditMessage.getElapsedTime())
|
||||
);
|
||||
|
||||
FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
|
||||
//全局ID生成策略配置
|
||||
FlexGlobalConfig.KeyConfig keyConfig = new FlexGlobalConfig.KeyConfig();
|
||||
keyConfig.setKeyType(KeyType.Generator);
|
||||
keyConfig.setValue("snowFlakeId");
|
||||
keyConfig.setValue(KeyGenerators.snowFlakeId);
|
||||
keyConfig.setBefore(true);
|
||||
|
||||
|
||||
FlexGlobalConfig.getDefaultConfig().setKeyConfig(keyConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FlexGlobalConfig flexGlobalConfig() {
|
||||
FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
|
||||
globalConfig.setTenantColumn("operator_id");
|
||||
globalConfig.setKeyConfig(keyConfig);
|
||||
//方言配置
|
||||
globalConfig.setDbType(DbType.POSTGRE_SQL); // 关键配置
|
||||
//设置数据库正常时的值
|
||||
globalConfig.setNormalValueOfLogicDelete(Boolean.FALSE);
|
||||
|
||||
//设置数据已被删除时的值
|
||||
//设置数据已被删除时的值
|
||||
globalConfig.setDeletedValueOfLogicDelete(Boolean.TRUE);
|
||||
globalConfig.setTenantColumn("operator_id");
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 详细的租户工厂配置
|
||||
*/
|
||||
@Bean
|
||||
public static TenantFactory tenantFactory() {
|
||||
logger.info("开始初始化租户工厂...");
|
||||
EbikeTenantFactory factory = new EbikeTenantFactory();
|
||||
TenantManager.setTenantFactory(factory);
|
||||
return new EbikeTenantFactory();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
package com.cdzy.staff.config;
|
||||
|
||||
import com.cdzy.staff.component.EbikeTenantFactory;
|
||||
|
||||
import com.cdzy.staff.component.TenantInterceptor;
|
||||
import com.mybatisflex.core.tenant.TenantFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@ -11,11 +9,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public TenantFactory tenantFactory(){
|
||||
return new EbikeTenantFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new TenantInterceptor());
|
||||
|
||||
@ -29,7 +29,6 @@ public class EbikeOperator implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Column(tenantId = true)
|
||||
private Long operatorId;
|
||||
|
||||
private String operatorName;
|
||||
|
||||
@ -37,7 +37,6 @@ public class EbikeOperatorStaff implements Serializable {
|
||||
|
||||
private String salt;
|
||||
|
||||
@Column(tenantId = true)
|
||||
private Long operatorId;
|
||||
|
||||
@Column(onInsertValue = "1")
|
||||
|
||||
@ -44,7 +44,6 @@ public class EbikeRole implements Serializable {
|
||||
/**
|
||||
* 所属运营商
|
||||
*/
|
||||
@Column(tenantId = true)
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -29,7 +29,7 @@
|
||||
<jackson.version>2.18.0</jackson.version>
|
||||
<hutool.version>5.8.26</hutool.version>
|
||||
<org.projectlombok.version>1.18.30</org.projectlombok.version>
|
||||
<mybatis-flex.version>1.11.0</mybatis-flex.version>
|
||||
<mybatis-flex.version>1.11.3</mybatis-flex.version>
|
||||
<mybatis.version>3.0.4</mybatis.version>
|
||||
<satoken.version>1.40.0</satoken.version>
|
||||
<mysql.version>8.0.32</mysql.version>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user