|
|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import com.txz.cif.configurer.Parameters;
|
|
|
+import com.txz.cif.dao.ShardingMapper;
|
|
|
import com.txz.cif.dubbo.client.OrderDubboServiceClient;
|
|
|
import com.txz.cif.model.RedEnvelope;
|
|
|
import com.txz.cif.service.DayCutService;
|
|
|
@@ -49,10 +50,13 @@ public class GeneralJob {
|
|
|
|
|
|
@Resource
|
|
|
private RechargeRecordService rechargeRecordService;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private RedEnvelopeService redEnvelopeService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ShardingMapper shardingMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 日切
|
|
|
*/
|
|
|
@@ -68,11 +72,14 @@ public class GeneralJob {
|
|
|
}
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 结算
|
|
|
+ *
|
|
|
* @param param
|
|
|
+ *
|
|
|
* @return
|
|
|
+ *
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@XxlJob("settle")
|
|
|
@@ -80,13 +87,13 @@ public class GeneralJob {
|
|
|
try {
|
|
|
logger.info("【执行结算】开始");
|
|
|
Condition c = new Condition(RedEnvelope.class);
|
|
|
- c.createCriteria().andEqualTo("status",1).andLessThanOrEqualTo("settleTime", DateUtil.now());
|
|
|
+ c.createCriteria().andEqualTo("status", 1).andLessThanOrEqualTo("settleTime", DateUtil.now());
|
|
|
List<RedEnvelope> redEnvelopes = redEnvelopeService.findByCondition(c);
|
|
|
- if (CollUtil.isNotEmpty(redEnvelopes)){
|
|
|
- for (RedEnvelope r: redEnvelopes){
|
|
|
+ if (CollUtil.isNotEmpty(redEnvelopes)) {
|
|
|
+ for (RedEnvelope r : redEnvelopes) {
|
|
|
try {
|
|
|
redEnvelopeService.settle(r);
|
|
|
- }catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
logger.error("【执行结算】异常:e{}", e);
|
|
|
return ReturnT.FAIL;
|
|
|
}
|
|
|
@@ -112,7 +119,7 @@ public class GeneralJob {
|
|
|
String ret = HttpRequest.post("https://chynet01.azureedge.net/user/checkin").cookie(cookie).timeout(-1).execute().body();
|
|
|
logger.error("[checkin]:" + ret);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
|
@@ -156,7 +163,7 @@ public class GeneralJob {
|
|
|
}
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@XxlJob("activityStatusJudgmentTimedTask")
|
|
|
public ReturnT<String> activityStatusJudgmentTimedTask(String param) throws Exception {
|
|
|
try {
|
|
|
@@ -169,8 +176,8 @@ public class GeneralJob {
|
|
|
}
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
@XxlJob("closeRecharge")
|
|
|
public ReturnT<String> closeRecharge() throws Exception {
|
|
|
try {
|
|
|
@@ -186,42 +193,22 @@ public class GeneralJob {
|
|
|
|
|
|
/**
|
|
|
* 定时创建分表任务
|
|
|
- * 用于创建未来3个月的分表,确保分表在使用前已经创建好
|
|
|
*/
|
|
|
@XxlJob("createFutureTables")
|
|
|
public ReturnT<String> createFutureTables(String param) throws Exception {
|
|
|
try {
|
|
|
logger.info("【创建未来分表任务】开始");
|
|
|
|
|
|
- // 获取当前日期和未来3个月的日期
|
|
|
- Date now = new Date();
|
|
|
- Date nextMonth = DateUtil.offsetMonth(now, 1);
|
|
|
- Date nextTwoMonths = DateUtil.offsetMonth(now, 2);
|
|
|
- Date nextThreeMonths = DateUtil.offsetMonth(now, 3);
|
|
|
+ String currentMonthSuffix = DateUtil.format(new Date(), "yyyyMM");
|
|
|
|
|
|
- // 构造表名后缀
|
|
|
- String currentMonthSuffix = DateUtil.format(now, "yyyyMM");
|
|
|
- String nextMonthSuffix = DateUtil.format(nextMonth, "yyyyMM");
|
|
|
- String nextTwoMonthsSuffix = DateUtil.format(nextTwoMonths, "yyyyMM");
|
|
|
- String nextThreeMonthsSuffix = DateUtil.format(nextThreeMonths, "yyyyMM");
|
|
|
-
|
|
|
- // 需要创建的表名列表
|
|
|
- String[] tableSuffixes = {currentMonthSuffix, nextMonthSuffix, nextTwoMonthsSuffix, nextThreeMonthsSuffix};
|
|
|
-
|
|
|
- // 表名前缀
|
|
|
String[] tablePrefixes = {"c_account_flow_", "c_flow_", "c_red_envelope_"};
|
|
|
|
|
|
- // 数据源
|
|
|
- String[] dataSources = {"ds0", "ds1"};
|
|
|
+ String[] dataSources = {"cif_0", "cif_1"};
|
|
|
|
|
|
- // 创建表的逻辑
|
|
|
for (String dataSource : dataSources) {
|
|
|
for (String tablePrefix : tablePrefixes) {
|
|
|
- for (String tableSuffix : tableSuffixes) {
|
|
|
- String tableName = tablePrefix + tableSuffix;
|
|
|
- // 这里应该调用实际的建表方法
|
|
|
- createTableIfNotExists(dataSource, tableName);
|
|
|
- }
|
|
|
+ String sql = "CREATE TABLE IF NOT EXISTS " + dataSource + "." + tablePrefix + currentMonthSuffix + " LIKE cif.c_account_flow";
|
|
|
+ shardingMapper.createTable(sql);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -233,26 +220,6 @@ public class GeneralJob {
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 创建表(如果不存在)
|
|
|
- * @param dataSource 数据源名称
|
|
|
- * @param tableName 表名
|
|
|
- */
|
|
|
- private void createTableIfNotExists(String dataSource, String tableName) {
|
|
|
- // 这里应该实现实际的建表逻辑
|
|
|
- // 可以通过JDBC或者调用数据库管理服务来创建表
|
|
|
- logger.info("检查并创建表: {} 在数据源: {}", tableName, dataSource);
|
|
|
-
|
|
|
- // 示例建表SQL(根据实际表结构调整)
|
|
|
- /*
|
|
|
- CREATE TABLE IF NOT EXISTS table_name (
|
|
|
- id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
|
- ...
|
|
|
- )
|
|
|
- */
|
|
|
-
|
|
|
- // 实际实现应该连接到对应数据源执行建表语句
|
|
|
- }
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
// int quhao = 154;
|