邮件API
This commit is contained in:
@@ -9,6 +9,7 @@ import com.mini.capi.biz.service.SyncTaskService;
|
|||||||
import com.mini.capi.config.DataSourceConfig;
|
import com.mini.capi.config.DataSourceConfig;
|
||||||
import com.mini.capi.model.ApiResult;
|
import com.mini.capi.model.ApiResult;
|
||||||
import com.mini.capi.model.TabResult;
|
import com.mini.capi.model.TabResult;
|
||||||
|
import com.mini.capi.utils.DateUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
@@ -150,6 +151,8 @@ public class DbService {
|
|||||||
if (!tableExists(targetJdbc, targetTable)) {
|
if (!tableExists(targetJdbc, targetTable)) {
|
||||||
createTargetTable(sourceJdbc, targetJdbc, sourceTable, targetTable);
|
createTargetTable(sourceJdbc, targetJdbc, sourceTable, targetTable);
|
||||||
}
|
}
|
||||||
|
// 2. 清空目标表当前ds7天前值的数据
|
||||||
|
clearTargetTableLastWeekData(targetJdbc, targetTable);
|
||||||
// 2. 清空目标表当前ds值的数据
|
// 2. 清空目标表当前ds值的数据
|
||||||
clearTargetTableData(targetJdbc, targetTable, dsValue);
|
clearTargetTableData(targetJdbc, targetTable, dsValue);
|
||||||
// 3. 全量同步数据
|
// 3. 全量同步数据
|
||||||
@@ -315,6 +318,12 @@ public class DbService {
|
|||||||
targetJdbc.update(sql, dsValue);
|
targetJdbc.update(sql, dsValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void clearTargetTableLastWeekData(JdbcTemplate targetJdbc, String targetTable) {
|
||||||
|
String sql = "DELETE FROM " + targetTable + " WHERE ds = ?";
|
||||||
|
targetJdbc.update(sql, DateUtils.getSevenDaysAgo());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全量同步数据
|
* 全量同步数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.mini.capi.utils;
|
package com.mini.capi.utils;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ public class DateUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化当前日期
|
* 格式化当前日期
|
||||||
|
*
|
||||||
* @param pattern 格式模式
|
* @param pattern 格式模式
|
||||||
* @return 格式化后的日期字符串
|
* @return 格式化后的日期字符串
|
||||||
*/
|
*/
|
||||||
@@ -16,7 +18,8 @@ public class DateUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化指定日期
|
* 格式化指定日期
|
||||||
* @param date 日期
|
*
|
||||||
|
* @param date 日期
|
||||||
* @param pattern 格式模式
|
* @param pattern 格式模式
|
||||||
* @return 格式化后的日期字符串
|
* @return 格式化后的日期字符串
|
||||||
*/
|
*/
|
||||||
@@ -26,4 +29,15 @@ public class DateUtils {
|
|||||||
}
|
}
|
||||||
return date.format(DateTimeFormatter.ofPattern(pattern));
|
return date.format(DateTimeFormatter.ofPattern(pattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getSevenDaysAgo() {
|
||||||
|
// 获取当前日期
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
// 减去7天
|
||||||
|
LocalDate sevenDaysAgo = today.minusDays(7);
|
||||||
|
// 格式化日期为yyyymmdd
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
return sevenDaysAgo.format(formatter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user