feat: 3.2.0
1.新增公共表前缀功能
This commit is contained in:
parent
76d29f5f6a
commit
789280aadf
@ -1,7 +1,6 @@
|
|||||||
package com.aizuda.easy.retry.template.datasource.config;
|
package com.aizuda.easy.retry.template.datasource.config;
|
||||||
|
|
||||||
import com.aizuda.easy.retry.template.datasource.access.Access;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
|
|
||||||
import com.aizuda.easy.retry.template.datasource.enums.DbTypeEnum;
|
import com.aizuda.easy.retry.template.datasource.enums.DbTypeEnum;
|
||||||
import com.aizuda.easy.retry.template.datasource.utils.RequestDataHelper;
|
import com.aizuda.easy.retry.template.datasource.utils.RequestDataHelper;
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
|
||||||
@ -23,6 +22,7 @@ import javax.sql.DataSource;
|
|||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: www.byteblogs.com
|
* @author: www.byteblogs.com
|
||||||
@ -56,7 +56,8 @@ public class EasyRetryTemplateAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
public MybatisPlusInterceptor mybatisPlusInterceptor(Environment environment) {
|
public MybatisPlusInterceptor mybatisPlusInterceptor(Environment environment) {
|
||||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
interceptor.addInnerInterceptor(dynamicTableNameInnerInterceptor());
|
String tablePrefix = Optional.ofNullable(environment.getProperty("mybatis-plus.global-config.db-config.table-prefix")).orElse(StrUtil.EMPTY);
|
||||||
|
interceptor.addInnerInterceptor(dynamicTableNameInnerInterceptor(tablePrefix));
|
||||||
String dbType = environment.getProperty("easy-retry.db-type");
|
String dbType = environment.getProperty("easy-retry.db-type");
|
||||||
DbTypeEnum dbTypeEnum = DbTypeEnum.modeOf(dbType);
|
DbTypeEnum dbTypeEnum = DbTypeEnum.modeOf(dbType);
|
||||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(dbTypeEnum.getMpDbType()));
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(dbTypeEnum.getMpDbType()));
|
||||||
@ -64,15 +65,16 @@ public class EasyRetryTemplateAutoConfiguration {
|
|||||||
return interceptor;
|
return interceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor() {
|
public DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor(String tablePrefix) {
|
||||||
DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor = new DynamicTableNameInnerInterceptor();
|
DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor = new DynamicTableNameInnerInterceptor();
|
||||||
dynamicTableNameInnerInterceptor.setTableNameHandler((sql, tableName) -> {
|
dynamicTableNameInnerInterceptor.setTableNameHandler((sql, tableName) -> {
|
||||||
if (!TABLES.contains(tableName)) {
|
if (TABLES.contains(tableName)) {
|
||||||
return tableName;
|
Integer partition = RequestDataHelper.getPartition();
|
||||||
|
RequestDataHelper.remove();
|
||||||
|
tableName = tableName + StrUtil.UNDERLINE + partition;
|
||||||
}
|
}
|
||||||
Integer partition = RequestDataHelper.getPartition();
|
|
||||||
RequestDataHelper.remove();
|
return tableName.startsWith(tablePrefix) ? tableName : tablePrefix + tableName;
|
||||||
return tableName + "_"+ partition;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return dynamicTableNameInnerInterceptor;
|
return dynamicTableNameInnerInterceptor;
|
||||||
|
@ -32,6 +32,7 @@ mybatis-plus:
|
|||||||
capital-mode: false
|
capital-mode: false
|
||||||
logic-delete-value: 1
|
logic-delete-value: 1
|
||||||
logic-not-delete-value: 0
|
logic-not-delete-value: 0
|
||||||
|
# table-prefix: er_
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
cache-enabled: true
|
cache-enabled: true
|
||||||
|
@ -24,6 +24,7 @@ import com.aizuda.easy.retry.template.datasource.access.TaskAccess;
|
|||||||
import com.aizuda.easy.retry.template.datasource.persistence.mapper.SequenceAllocMapper;
|
import com.aizuda.easy.retry.template.datasource.persistence.mapper.SequenceAllocMapper;
|
||||||
import com.aizuda.easy.retry.template.datasource.persistence.mapper.ServerNodeMapper;
|
import com.aizuda.easy.retry.template.datasource.persistence.mapper.ServerNodeMapper;
|
||||||
import com.aizuda.easy.retry.template.datasource.persistence.po.*;
|
import com.aizuda.easy.retry.template.datasource.persistence.po.*;
|
||||||
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||||
@ -70,6 +71,8 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
private SystemProperties systemProperties;
|
private SystemProperties systemProperties;
|
||||||
@Autowired
|
@Autowired
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
@Autowired
|
||||||
|
private MybatisPlusProperties mybatisPlusProperties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -338,10 +341,12 @@ public class GroupConfigServiceImpl implements GroupConfigService {
|
|||||||
String catalog = connection.getCatalog();
|
String catalog = connection.getCatalog();
|
||||||
String schema = connection.getSchema();
|
String schema = connection.getSchema();
|
||||||
|
|
||||||
|
String tablePrefix = Optional.ofNullable(mybatisPlusProperties.getGlobalConfig().getDbConfig().getTablePrefix()).orElse(StrUtil.EMPTY);
|
||||||
// https://gitee.com/aizuda/easy-retry/issues/I8DAMH
|
// https://gitee.com/aizuda/easy-retry/issues/I8DAMH
|
||||||
String sql = MessageFormatter.arrayFormat("SELECT table_name\n"
|
String sql = MessageFormatter.arrayFormat("SELECT table_name\n"
|
||||||
+ "FROM information_schema.tables\n"
|
+ "FROM information_schema.tables\n"
|
||||||
+ "WHERE table_name LIKE 'retry_task_%' AND (table_schema = '{}' OR table_schema = '{}' OR table_catalog = '{}' OR table_catalog = '{}')", new Object[]{schema, catalog, schema, catalog}).getMessage();
|
+ "WHERE table_name LIKE '{}retry_task_%' AND (table_schema = '{}' OR table_schema = '{}' OR table_catalog = '{}' OR table_catalog = '{}')",
|
||||||
|
new Object[]{tablePrefix, schema, catalog, schema, catalog}).getMessage();
|
||||||
|
|
||||||
List<String> tableList = jdbcTemplate.queryForList(sql, String.class);
|
List<String> tableList = jdbcTemplate.queryForList(sql, String.class);
|
||||||
return tableList.stream().map(ReUtil::getFirstNumber).filter(i ->
|
return tableList.stream().map(ReUtil::getFirstNumber).filter(i ->
|
||||||
|
Loading…
Reference in New Issue
Block a user