mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 21:49:01 +08:00
Merge branch 'devops' of 692961375/pigx into devops
This commit is contained in:
commit
ddfdff3664
8 files changed
+100
-4
No files matched your search
+19
-1
@@ -23,7 +23,9 @@ import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
|
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
|
||||||
import com.pig4cloud.pigx.common.data.datascope.DataScopeInterceptor;
|
import com.pig4cloud.pigx.common.data.datascope.DataScopeInterceptor;
|
||||||
|
import com.pig4cloud.pigx.common.data.tenant.PigxTenantConfig;
|
||||||
import com.pig4cloud.pigx.common.data.tenant.PigxTenantHandler;
|
import com.pig4cloud.pigx.common.data.tenant.PigxTenantHandler;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -39,8 +41,24 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@MapperScan("com.pig4cloud.pigx.*.mapper")
|
@MapperScan("com.pig4cloud.pigx.*.mapper")
|
||||||
|
@AllArgsConstructor
|
||||||
public class MybatisPlusConfig {
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
private final PigxTenantConfig pigxTenantConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建租户维护处理器对象
|
||||||
|
*
|
||||||
|
* @return 处理后的租户维护处理器
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public PigxTenantHandler pigxTenantHandler() {
|
||||||
|
PigxTenantHandler pigxTenantHandler = new PigxTenantHandler();
|
||||||
|
pigxTenantHandler.setTenantTables(pigxTenantConfig.getTenantTables());
|
||||||
|
return pigxTenantHandler;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页插件
|
* 分页插件
|
||||||
*
|
*
|
||||||
@@ -52,7 +70,7 @@ public class MybatisPlusConfig {
|
|||||||
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
|
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
|
||||||
List<ISqlParser> sqlParserList = new ArrayList<>();
|
List<ISqlParser> sqlParserList = new ArrayList<>();
|
||||||
TenantSqlParser tenantSqlParser = new TenantSqlParser();
|
TenantSqlParser tenantSqlParser = new TenantSqlParser();
|
||||||
tenantSqlParser.setTenantHandler(new PigxTenantHandler());
|
tenantSqlParser.setTenantHandler(pigxTenantHandler());
|
||||||
sqlParserList.add(tenantSqlParser);
|
sqlParserList.add(tenantSqlParser);
|
||||||
paginationInterceptor.setSqlParserList(sqlParserList);
|
paginationInterceptor.setSqlParserList(sqlParserList);
|
||||||
return paginationInterceptor;
|
return paginationInterceptor;
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package com.pig4cloud.pigx.common.data.tenant;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户自动配置类
|
||||||
|
*
|
||||||
|
* @author oathsign
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EnableConfigurationProperties(TenantProperties.class)
|
||||||
|
public class PigxTenantAutoConfiguration {
|
||||||
|
|
||||||
|
private final TenantProperties properties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
PigxTenantConfig pigxTenantTable() {
|
||||||
|
PigxTenantConfig pigxTenantConfig = new PigxTenantConfig();
|
||||||
|
pigxTenantConfig.setTenantTables(properties.getTables());
|
||||||
|
return pigxTenantConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package com.pig4cloud.pigx.common.data.tenant;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户配置
|
||||||
|
*
|
||||||
|
* @author oathsign
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PigxTenantConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用了多租户的数据表集合
|
||||||
|
*/
|
||||||
|
private String[] tenantTables = new String[]{};
|
||||||
|
}
|
||||||
+4
-3
@@ -19,6 +19,7 @@ package com.pig4cloud.pigx.common.data.tenant;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
|
import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
|
||||||
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
import net.sf.jsqlparser.expression.LongValue;
|
import net.sf.jsqlparser.expression.LongValue;
|
||||||
@@ -30,9 +31,9 @@ import net.sf.jsqlparser.expression.LongValue;
|
|||||||
* 租户维护处理器
|
* 租户维护处理器
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Data
|
||||||
public class PigxTenantHandler implements TenantHandler {
|
public class PigxTenantHandler implements TenantHandler {
|
||||||
private static final String[] TENANT_TABLES = new String[]{"sys_user", "sys_role", "sys_dept",
|
private String[] tenantTables = new String[]{};
|
||||||
"sys_log", "sys_social_details", "sys_dict", "sys_log", "oa_leave_bill"};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取租户值
|
* 获取租户值
|
||||||
@@ -64,6 +65,6 @@ public class PigxTenantHandler implements TenantHandler {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean doTableFilter(String tableName) {
|
public boolean doTableFilter(String tableName) {
|
||||||
return !ArrayUtil.contains(TENANT_TABLES, tableName);
|
return !ArrayUtil.contains(tenantTables, tableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package com.pig4cloud.pigx.common.data.tenant;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多租户配置类对应属性配置映射
|
||||||
|
*
|
||||||
|
* @author oathsign
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "pigx.tenant")
|
||||||
|
public class TenantProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务中应用多租户的数据库表名
|
||||||
|
*/
|
||||||
|
private String[] tables = new String[]{};
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
|||||||
com.pig4cloud.pigx.common.data.cache.RedisTemplateConfig,\
|
com.pig4cloud.pigx.common.data.cache.RedisTemplateConfig,\
|
||||||
com.pig4cloud.pigx.common.data.cache.RedisCacheManagerConfig,\
|
com.pig4cloud.pigx.common.data.cache.RedisCacheManagerConfig,\
|
||||||
com.pig4cloud.pigx.common.data.cache.RedisCacheAutoConfiguration,\
|
com.pig4cloud.pigx.common.data.cache.RedisCacheAutoConfiguration,\
|
||||||
|
com.pig4cloud.pigx.common.data.tenant.PigxTenantAutoConfiguration,\
|
||||||
com.pig4cloud.pigx.common.data.tenant.TenantContextHolderFilter,\
|
com.pig4cloud.pigx.common.data.tenant.TenantContextHolderFilter,\
|
||||||
com.pig4cloud.pigx.common.data.tenant.PigxFeignTenantConfiguration,\
|
com.pig4cloud.pigx.common.data.tenant.PigxFeignTenantConfiguration,\
|
||||||
com.pig4cloud.pigx.common.data.mybatis.MybatisPlusConfig
|
com.pig4cloud.pigx.common.data.mybatis.MybatisPlusConfig
|
||||||
@@ -25,3 +25,7 @@ spring:
|
|||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
url: jdbc:mysql://pigx-mysql:3306/pigxx_ac?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://pigx-mysql:3306/pigxx_ac?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
|
||||||
|
pigx:
|
||||||
|
tenant:
|
||||||
|
tables:
|
||||||
|
- oa_leave_bill
|
||||||
@@ -44,3 +44,13 @@ minio:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.pig4cloud.pigx.admin.mapper: debug
|
com.pig4cloud.pigx.admin.mapper: debug
|
||||||
|
pigx:
|
||||||
|
tenant:
|
||||||
|
tables:
|
||||||
|
- sys_user
|
||||||
|
- sys_role
|
||||||
|
- sys_dept
|
||||||
|
- sys_log
|
||||||
|
- sys_social_details
|
||||||
|
- sys_dict
|
||||||
|
- sys_log
|
||||||
Reference in new issue
Block a user