正式 shardingsphere

This commit is contained in:
2024-12-30 23:07:28 +08:00
parent 7e89bb182b
commit 1123b518db
3 changed files with 60 additions and 38 deletions

View File

@@ -28,7 +28,7 @@ public class SpinningTask3 {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
@Scheduled(cron = "0 0/2 * * * ? ") @Scheduled(cron = "0 0/5 * * * ? ")
public void record() { public void record() {
record("1"); record("1");
} }
@@ -41,8 +41,8 @@ public class SpinningTask3 {
params = "1"; params = "1";
} }
// 获取五分钟前的时间 // 获取五分钟前的时间
Date fiveMinutesAgo = DateUtil.offsetMinute(now, Integer.valueOf(params) * -5); Date fiveMinutesAgo = DateUtil.offsetMinute(now, Integer.valueOf(params) * -6);
Date tenMinutesAgo = DateUtil.offsetMinute(now, (Integer.valueOf(params) * -5) - 5); Date tenMinutesAgo = DateUtil.offsetMinute(now, (Integer.valueOf(params) * -6) - 6);
// 将五分钟前的时间转换为指定格式的时间字符串,这里采用常见的"yyyy-MM-dd HH:mm:ss"格式 // 将五分钟前的时间转换为指定格式的时间字符串,这里采用常见的"yyyy-MM-dd HH:mm:ss"格式
String fiveMinutesAgoStr = DateUtil.format(fiveMinutesAgo, "yyyy-MM-dd HH:mm:ss"); String fiveMinutesAgoStr = DateUtil.format(fiveMinutesAgo, "yyyy-MM-dd HH:mm:ss");
String tenMinutesAgoStr = DateUtil.format(tenMinutesAgo, "yyyy-MM-dd HH:mm:ss"); String tenMinutesAgoStr = DateUtil.format(tenMinutesAgo, "yyyy-MM-dd HH:mm:ss");

View File

@@ -29,6 +29,7 @@ import com.sqx.modules.sys.entity.SysUserEntity;
import com.sqx.modules.sys.service.SysUserService; import com.sqx.modules.sys.service.SysUserService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -71,11 +72,13 @@ public class TempOrdersTask {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
public void run(String params) {
@Scheduled(cron = "0 0/10 * * * ? ")
public void order() {
logger.info("订单表数据处理开始"); logger.info("订单表数据处理开始");
List<Orders> orders = ordersDao.selectList(Wrappers.<Orders>lambdaQuery() List<Orders> orders = ordersDao.selectList(Wrappers.<Orders>lambdaQuery()
.eq(Orders::getStatus, 0) .eq(Orders::getStatus, 0)
.lt(Orders::getCreateTime, DateUtil.offsetMinute(DateUtil.date(), -5))); .lt(Orders::getCreateTime, DateUtil.offsetMinute(DateUtil.date(), -15)));
if (CollUtil.isEmpty(orders)) { if (CollUtil.isEmpty(orders)) {
return; return;
} }

View File

@@ -1,37 +1,56 @@
# 数据源的一些配置
driver-class-name: com.mysql.cj.jdbc.Driver
# 最小空闲连接默认值10小于0或大于maximum-pool-size都会重置为maximum-pool-size
minimum-idle: 5
# 最大连接数小于等于0会被重置为默认值10大于零小于1会被重置为minimum-idle的值
maximum-pool-size: 15
# 空闲连接超时时间默认值60000010分钟大于等于max-lifetime且max-lifetime>0会被重置为0不等于0且小于10秒会被重置为10秒。
idle-timeout: 30000
# 连接最大存活时间.不等于0且小于30秒会被重置为默认值30分钟.设置应该比mysql设置的超时时间短
max-lifetime: 30000
# 连接超时时间:毫秒小于250毫秒否则被重置为默认值30秒
connection-timeout: 30000
spring: spring:
# sharding-jdbc 配置
shardingsphere:
center-tables-data-node: duanju.%s
# 显示sharding-jdbc改写的sql语句
show-sql: false
# 数据源名称
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource # 数据源配置begin
druid: master-0:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: ${driver-class-name}
url: jdbc:mysql://rm-gc7xx913734hv5w5q.mysql.cn-chengdu.rds.aliyuncs.com/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT 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 username: video_user
password: VideoUser@1 password: VideoUser@1
initial-size: 50 minimum-idle: ${minimum-idle}
max-active: 200 maximum-pool-size: ${maximum-pool-size}
min-idle: 50 idle-timeout: ${idle-timeout}
max-wait: 60000 max-lifetime: ${max-lifetime}
pool-prepared-statements: true connection-timeout: ${connection-timeout}
max-pool-prepared-statement-per-connection-size: 20 slave-0:
time-between-eviction-runs-millis: 60000 driver-class-name: ${driver-class-name}
min-evictable-idle-time-millis: 300000 jdbc-url: jdbc:mysql://localhost:3306/duanju?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
#Oracle需要打开注释 username: root
#validation-query: SELECT 1 FROM DUAL password: acddb0c84a192ada
test-while-idle: true minimum-idle: ${minimum-idle}
test-on-borrow: false maximum-pool-size: ${maximum-pool-size}
test-on-return: false idle-timeout: ${idle-timeout}
stat-view-servlet: max-lifetime: ${max-lifetime}
enabled: true connection-timeout: ${connection-timeout}
url-pattern: /druid/* # 数据源配置end
#login-username: admin
#login-password: admin # 读写分离配置begin
filter: master-slave-rules:
stat: #数据源
log-slow-sql: true duanju:
slow-sql-millis: 1000 master-data-source-name: master-0
merge-sql: false slave-data-source-names: slave-0
wall: # - master-0
config: # - slave-0
multi-statement-allow: true
swagger: swagger:
enabled: false enabled: false
pay: pay: