From ab9fee09bfe37b145ed80f733fcca8fdb648b60c Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Thu, 29 Aug 2024 10:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E6=95=B0=E5=88=A0=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E6=95=B0=E6=8D=AE=E5=92=8C=E6=9B=B4=E6=96=B0=E5=8E=BB?= =?UTF-8?q?=E5=B9=B4=E6=98=8E=E5=A4=A9=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../job/ticketing/TicketDataMigration.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java index 4dfea2874..a89643322 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java @@ -303,6 +303,45 @@ public class TicketDataMigration { 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 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 lastYearCheckTicketList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(lastYearThirtyDaysAgo.getTime()), TickingDateUtils.format(lastYearToday.getTime())); + XxlJobHelper.log("删除去年检票日期为{}", lastYearCheckTicketList.toString()); + // 售票数据今年多余删除 + List thisYearSaleDataList = saleDataService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(thirtyDaysAgo.getTime()), TickingDateUtils.format(today.getTime())); + XxlJobHelper.log("删除今年售票日期为{}", thisYearSaleDataList.toString()); + // 售票数据去年多余删除 + List 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) @@ -358,9 +397,9 @@ public class TicketDataMigration { mapList = ticketingSamplingRespVO.getDataMapList(); List resultNum = null; 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)) { - resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class)); + resultNum = saleDataService.insertTodayByMongoDB(BeanUtils.toBean(mapList, SaleDataToday.class)); } if (resultNum == null) { result.add("数据批量插入异常!");