抽数删除多余数据和更新去年明天的数据

This commit is contained in:
XinWei 2024-08-29 10:59:56 +08:00
parent 3d7b4a00a2
commit ab9fee09bf

View File

@ -303,6 +303,45 @@ public class TicketDataMigration {
XxlJobHelper.log("抽数结束!!!"); XxlJobHelper.log("抽数结束!!!");
} }
/**
* 删除今年和去年往前推31天外的数据和抽取去年明天的数据
*/
@XxlJob("deleteTwoYearOneMonthAgoAndUpdateLastYearTomorrow")
public void deleteTwoYearOneMonthAgoAndUpdateLastYearTomorrow(){
XxlJobHelper.log("删除多余数据开始...");
// 检票数据今年多余删除
Calendar today = Calendar.getInstance();
Calendar thirtyDaysAgo = (Calendar) today.clone(); // 克隆当前日期
thirtyDaysAgo.add(Calendar.DAY_OF_MONTH, -31);
List<String> thisYearCheckTicketList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(thirtyDaysAgo.getTime()), TickingDateUtils.format(today.getTime()));
XxlJobHelper.log("删除今年检票日期为{}", thisYearCheckTicketList.toString());
// 检票数据去年多余删除
Calendar lastYearToday = (Calendar) today.clone();
lastYearToday.add(Calendar.YEAR, -1);
Calendar lastYearThirtyDaysAgo = (Calendar) lastYearToday.clone();
lastYearThirtyDaysAgo.add(Calendar.DAY_OF_MONTH, -31);
List<String> lastYearCheckTicketList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(lastYearThirtyDaysAgo.getTime()), TickingDateUtils.format(lastYearToday.getTime()));
XxlJobHelper.log("删除去年检票日期为{}", lastYearCheckTicketList.toString());
// 售票数据今年多余删除
List<String> thisYearSaleDataList = saleDataService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(thirtyDaysAgo.getTime()), TickingDateUtils.format(today.getTime()));
XxlJobHelper.log("删除今年售票日期为{}", thisYearSaleDataList.toString());
// 售票数据去年多余删除
List<String> lastYearSaleDataList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(lastYearThirtyDaysAgo.getTime()), TickingDateUtils.format(lastYearToday.getTime()));
XxlJobHelper.log("删除去年检票日期为{}", lastYearSaleDataList.toString());
// 抽取去年明天的检票和售票数据
Calendar lastYearTomorrow = (Calendar) lastYearToday.clone();
lastYearTomorrow.add(Calendar.DAY_OF_MONTH, 1);
try {
this.getTicketDataByTimeZonesToMongo(lastYearTomorrow, lastYearTomorrow, "checkTicket");
} catch (Exception e) {
XxlJobHelper.log("抽取去年明天的检票数据失败,日期为{}", TickingDateUtils.format(lastYearTomorrow.getTime()));
}
try {
this.getTicketDataByTimeZonesToMongo(lastYearTomorrow, lastYearTomorrow, "saleData");
} catch (Exception e) {
XxlJobHelper.log("抽取去年明天的售票数据失败,日期为{}", TickingDateUtils.format(lastYearTomorrow.getTime()));
}
}
/** /**
* 用于更新指定日期的检票或售票数据(mongodb) * 用于更新指定日期的检票或售票数据(mongodb)
@ -358,9 +397,9 @@ public class TicketDataMigration {
mapList = ticketingSamplingRespVO.getDataMapList(); mapList = ticketingSamplingRespVO.getDataMapList();
List<Integer> resultNum = null; List<Integer> resultNum = null;
if ("checkTicket".equals(method)) { if ("checkTicket".equals(method)) {
resultNum = checkTicketService.insertByMongoDB(BeanUtils.toBean(mapList, CheckTicket.class)); resultNum = checkTicketService.insertTodayByMongoDB(BeanUtils.toBean(mapList, CheckTicketToday.class));
} else if ("saleData".equals(method)) { } else if ("saleData".equals(method)) {
resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class)); resultNum = saleDataService.insertTodayByMongoDB(BeanUtils.toBean(mapList, SaleDataToday.class));
} }
if (resultNum == null) { if (resultNum == null) {
result.add("数据批量插入异常!"); result.add("数据批量插入异常!");