shardingConfig2
This commit is contained in:
parent
4157bac93f
commit
f4998e1073
|
|
@ -6,6 +6,7 @@ import com.zaxxer.hikari.HikariConfig;
|
|||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;
|
||||
import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
|
||||
import org.apache.shardingsphere.api.config.sharding.TableRuleConfiguration;
|
||||
|
|
@ -105,6 +106,12 @@ public class ShardingConfig {
|
|||
// 配置表的切分策略
|
||||
shardingRuleConfig.setTableRuleConfigs(addTableRuleConfigs());
|
||||
|
||||
// 配置表绑定规则
|
||||
List<Set<String>> sets = new ArrayList<>();
|
||||
sets.add(regionTables);
|
||||
shardingRuleConfig.setBindingTableGroups(bindingTableGroups(sets));
|
||||
|
||||
|
||||
// 配置是否显示sql
|
||||
Properties props = new Properties();
|
||||
props.put("sql.show", showSql);
|
||||
|
|
@ -193,4 +200,38 @@ public class ShardingConfig {
|
|||
});
|
||||
return sets;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定表的分片规则
|
||||
*/
|
||||
public static Set<String> bindingTableGroups(List<Set<String>> sets) {
|
||||
if (sets != null && !sets.isEmpty()) {
|
||||
Set<String> tableGroups = new HashSet<>();
|
||||
for (Set<String> set : sets) {
|
||||
String tableNames = bindingTable(set.toArray(new String[0]));
|
||||
if (StringUtils.isNotBlank(tableNames)) {
|
||||
tableGroups.add(tableNames);
|
||||
}
|
||||
}
|
||||
return tableGroups;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量绑定表规则
|
||||
*
|
||||
* @param tables 批量绑定的标规则
|
||||
* @return tableNames
|
||||
*/
|
||||
private static String bindingTable(String... tables) {
|
||||
StringBuilder tableNames = new StringBuilder();
|
||||
if (tables != null && tables.length != 0) {
|
||||
for (String table : tables) {
|
||||
tableNames.append(table).append(",");
|
||||
}
|
||||
tableNames.deleteCharAt(tableNames.length() - 1);
|
||||
}
|
||||
return tableNames.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -101,14 +101,14 @@ public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectDao, Cour
|
|||
@CachePut(value = "app:courseCollect", key = "#userId")
|
||||
public Result selectByUserId(Integer page, Integer limit, Long userId,Integer classify) {
|
||||
Page<Course> pages=new Page<>(page,limit);
|
||||
IPage<Course> courseIPage = baseMapper.selectCourseByCollect(pages, userId,classify);
|
||||
List<Course> courses = courseIPage.getRecords();
|
||||
if (courses != null && courses.size() > 0) {
|
||||
for (Course course : courses) {
|
||||
course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
||||
}
|
||||
}
|
||||
return Result.success().put("data",courseIPage);
|
||||
// IPage<Course> courseIPage = baseMapper.selectCourseByCollect(pages, userId,classify);
|
||||
// List<Course> courses = courseIPage.getRecords();
|
||||
// if (courses != null && courses.size() > 0) {
|
||||
// for (Course course : courses) {
|
||||
// course.setCourseClassification(courseClassificationDao.selectById(course.getClassifyId()));
|
||||
// }
|
||||
// }
|
||||
return Result.success().put("data",null);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
swagger:
|
||||
enabled: false
|
||||
enabled: false
|
||||
pay:
|
||||
h5BaseUrl: https://dj-h5.hnsiyao.cn/me/detail/detail?allId=
|
||||
orderNotifyUrl: https://pay.hnsiyao.cn/czg/app/wuyou/notify
|
||||
extractNotifyUrl: https://pay.hnsiyao.cn/czg/app/wuyou/extractNotify
|
||||
h5BaseUrl: https://dj-h5.hnsiyao.cn/me/detail/detail?allId=
|
||||
orderNotifyUrl: https://pay.hnsiyao.cn/czg/app/wuyou/notify
|
||||
extractNotifyUrl: https://pay.hnsiyao.cn/czg/app/wuyou/extractNotify
|
||||
|
||||
# 数据源的一些配置
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
|
@ -19,167 +19,174 @@ max-lifetime: 30000
|
|||
connection-timeout: 30000
|
||||
|
||||
spring:
|
||||
# sharding-jdbc 配置
|
||||
shardingsphere:
|
||||
# 显示sharding-jdbc改写的sql语句
|
||||
show-sql: false
|
||||
# sharding-jdbc 配置
|
||||
shardingsphere:
|
||||
# 显示sharding-jdbc改写的sql语句
|
||||
show-sql: true
|
||||
|
||||
center-tables-data-node: duanju.%s
|
||||
# 区域表的数据源节点
|
||||
region-tables-data-node: duanju-$->{0..4}.%s
|
||||
# 区域分库策略的计算字段
|
||||
region-tables-sharding-database-column: user_id
|
||||
# 分库的计算方法
|
||||
region-tables-sharding-database-algorithm: duanju-$->{Math.abs(user_id) % 5}
|
||||
center-tables-data-node: duanju.%s
|
||||
# 区域表的数据源节点
|
||||
region-tables-data-node: duanju-$->{0..4}.%s
|
||||
# 区域分库策略的计算字段
|
||||
region-tables-sharding-database-column: user_id
|
||||
# 分库的计算方法
|
||||
region-tables-sharding-database-algorithm: duanju-$->{user_id%5}
|
||||
|
||||
# 短剧集表 拆分
|
||||
course_details-sharding-database-column: course_id
|
||||
course_details-sharding-database-algorithm: duanju-$->{Math.abs(course_id) % 5}
|
||||
# 短剧集表 拆分
|
||||
course_details-sharding-database-column: course_id
|
||||
course_details-sharding-database-algorithm: duanju-$->{course_i%5}
|
||||
|
||||
# 数据源名称
|
||||
datasource:
|
||||
master:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://rm-gc7xx913734hv5w5q.mysql.cn-chengdu.rds.aliyuncs.com/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: video_user
|
||||
password: VideoUser@1
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
# 数据源配置begin
|
||||
master-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
master-1:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
master-2:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
master-3:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
master-4:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave-1:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave-2:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave-3:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
slave-4:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url:
|
||||
username:
|
||||
password:
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
# 数据源配置end
|
||||
# 数据源名称
|
||||
datasource:
|
||||
duanju:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
# 数据源配置begin
|
||||
duanju-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-0?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-1:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-2:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-2?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-3:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-3?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-4:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-4?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
|
||||
# 读写分离配置begin
|
||||
master-slave-rules:
|
||||
#数据源
|
||||
duanju:
|
||||
master-data-source-name: master
|
||||
slave-data-source-names: slave
|
||||
duanju-0:
|
||||
master-data-source-name: master-0
|
||||
slave-data-source-names: slave-0
|
||||
duanju-1:
|
||||
master-data-source-name: master-1
|
||||
slave-data-source-names: slave-1
|
||||
duanju-2:
|
||||
master-data-source-name: master-2
|
||||
slave-data-source-names: slave-2
|
||||
duanju-3:
|
||||
master-data-source-name: master-3
|
||||
slave-data-source-names: slave-3
|
||||
duanju-4:
|
||||
master-data-source-name: master-4
|
||||
slave-data-source-names: slave-4
|
||||
duanju-slave:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-slave-0:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-0?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-slave-1:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-slave-2:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-2?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-slave-3:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-3?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
duanju-slave-4:
|
||||
driver-class-name: ${driver-class-name}
|
||||
jdbc-url: jdbc:mysql://192.168.1.5:3306/duanju-4?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
||||
username: root
|
||||
password: gongyijieqp002
|
||||
minimum-idle: ${minimum-idle}
|
||||
maximum-pool-size: ${maximum-pool-size}
|
||||
idle-timeout: ${idle-timeout}
|
||||
max-lifetime: ${max-lifetime}
|
||||
connection-timeout: ${connection-timeout}
|
||||
# 数据源配置end
|
||||
|
||||
# 读写分离配置begin
|
||||
master-slave-rules:
|
||||
#数据源
|
||||
center:
|
||||
masterDataSourceName: duanju
|
||||
slaveDataSourceNames:
|
||||
- duanju-slave
|
||||
duanju-0:
|
||||
masterDataSourceName: duanju-0
|
||||
slaveDataSourceNames:
|
||||
- duanju-slave-0
|
||||
duanju-1:
|
||||
masterDataSourceName: duanju-1
|
||||
slaveDataSourceNames:
|
||||
- duanju-slave-1
|
||||
duanju-2:
|
||||
masterDataSourceName: duanju-2
|
||||
slaveDataSourceNames:
|
||||
- duanju-slave-2
|
||||
duanju-3:
|
||||
masterDataSourceName: duanju-3
|
||||
slaveDataSourceNames:
|
||||
- duanju-slave-3
|
||||
duanju-4:
|
||||
masterDataSourceName: duanju-4
|
||||
slaveDataSourceNames:
|
||||
- duanju-slave-4
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ spring:
|
|||
allow-bean-definition-overriding: true
|
||||
# 环境 dev|test|prod
|
||||
profiles:
|
||||
active: dev
|
||||
active: prod
|
||||
# jackson时间格式化
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
|
|
|
|||
Loading…
Reference in New Issue