diff --git a/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/saledata/SaleDataService.java b/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/saledata/SaleDataService.java index 61d3505a1..00fabde21 100644 --- a/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/saledata/SaleDataService.java +++ b/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/saledata/SaleDataService.java @@ -133,5 +133,10 @@ public interface SaleDataService { */ BigDecimal findyearJun(List list); + /** + * 插入售票信息到mongodb中 + * @param saleDataSaveReqDTO + * @return java.lang.String + */ String createSaleDataByMongoDB(SaleDataSaveReqDTO saleDataSaveReqDTO); } \ No newline at end of file diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/TickingDateUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/TickingDateUtils.java index 672e1e019..a250841a8 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/TickingDateUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/TickingDateUtils.java @@ -35,4 +35,11 @@ public class TickingDateUtils { public static String getNowDayFormat(){ return TickingDateUtils.format(new Date()); } + + public static String getPreviousDayFormat(){ + long time = new Date().getTime(); + // 获取前一天的当前时间 TODO 可能需要考虑时区,使用Calendar或java.time + time = time - (24 * 60 * 60 * 1000); + return TickingDateUtils.format(new Date(time)); + } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/ticketing/TicketDataMigration.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/ticketing/TicketDataMigration.java index e27096f03..d939a98dd 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/ticketing/TicketDataMigration.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/ticketing/TicketDataMigration.java @@ -27,7 +27,9 @@ import java.util.Map; @Component public class TicketDataMigration { private static Logger logger = LoggerFactory.getLogger(TicketDataMigration.class); - + // 目标地址 + private static String OBJECT_URL = "http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler"; + // 每次读取条数 private static final int PAGE_SIZE = 500; @Resource private TicketSaleDataApi ticketSaleDataApi; @@ -35,20 +37,24 @@ public class TicketDataMigration { @Resource private TicketCheckTicketApi ticketCheckTicketApi; + /** + * 存入售票数据的定时任务mysql + */ @XxlJob("getSaleData") public void getSaleDataHandler() throws Exception { int failedCount = 0; int pageNumber = 1; - XxlJobHelper.log("抽数服务:销售数据开始抽数..."); + XxlJobHelper.log("抽数服务:mysql销售数据开始抽数..."); // 准备请求参数 TicketingSamplingReqVO ticketingSamplingReqVO = new TicketingSamplingReqVO(); ticketingSamplingReqVO.setService("apiSaleService"); ticketingSamplingReqVO.setMethod("SaleDetail"); - ticketingSamplingReqVO.setQueryDate(TickingDateUtils.getNowDayFormat()); + // 抽取前一天的所有售票数据 + ticketingSamplingReqVO.setQueryDate(TickingDateUtils.getPreviousDayFormat()); ticketingSamplingReqVO.setPageNumber(pageNumber); ticketingSamplingReqVO.setPageSize(PAGE_SIZE); // 先发起第一次请求 - String str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(ticketingSamplingReqVO)); + String str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); // 解析读取响应数据 TicketingSamplingRespVO ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); // 如果访问失败则让调度中心重新调用 @@ -73,7 +79,7 @@ public class TicketDataMigration { // 处理剩余页的数据 for (; pageNumber <= totalPages; pageNumber++) { ticketingSamplingReqVO.setPageNumber(pageNumber); - str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(ticketingSamplingReqVO)); + str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); if (!ticketingSamplingRespVO.isPassflag()) { @@ -95,21 +101,24 @@ public class TicketDataMigration { XxlJobHelper.log("抽数服务:销售数据抽数正常结束!总共:{}条数据,{}条数据插入失败!", totalRows, failedCount); } - + /** + * 存入检票数据的定时任务mysql + */ @XxlJob("getCheckTicket") public void getCheckTicketHandler() throws Exception { int failedCount = 0; int pageNumber = 1; - XxlJobHelper.log("抽数服务:检票数据开始抽数..."); + XxlJobHelper.log("抽数服务:mysql检票数据开始抽数..."); // 准备请求参数 TicketingSamplingReqVO ticketingSamplingReqVO = new TicketingSamplingReqVO(); ticketingSamplingReqVO.setService("apiCheckService"); ticketingSamplingReqVO.setMethod("CheckDetail"); - ticketingSamplingReqVO.setQueryDate(TickingDateUtils.getNowDayFormat()); + // 抽取前一天的所有检票数据 + ticketingSamplingReqVO.setQueryDate(TickingDateUtils.getPreviousDayFormat()); ticketingSamplingReqVO.setPageNumber(pageNumber); ticketingSamplingReqVO.setPageSize(PAGE_SIZE); // 先发起第一次请求 - String str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(ticketingSamplingReqVO)); + String str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); // 解析读取响应数据 TicketingSamplingRespVO ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); @@ -135,7 +144,7 @@ public class TicketDataMigration { // 处理剩余页的数据 for (; pageNumber <= totalPages; pageNumber++) { ticketingSamplingReqVO.setPageNumber(pageNumber); - str = HttpUtil.post("http://shinanlundu.pro.jiutianda.com/joytime-erp-eportal/console/openapi/handler", JSONUtil.toJsonStr(ticketingSamplingReqVO)); + str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); if (!ticketingSamplingRespVO.isPassflag()) { @@ -158,7 +167,136 @@ public class TicketDataMigration { XxlJobHelper.log("抽数服务:检票数据抽数正常结束!总共:{}条数据,{}条数据插入失败!", totalRows, failedCount); } /** - * 插入销售数据的方法 + * 存入销售数据的定时任务mongodb + */ + @XxlJob("getSaleDataByMongoDB") + public void getSaleDataByMongoDBHandler() throws Exception { + int failedCount = 0; + int pageNumber = 1; + XxlJobHelper.log("抽数服务:mongodb销售数据开始抽数..."); + // 准备请求参数 + TicketingSamplingReqVO ticketingSamplingReqVO = new TicketingSamplingReqVO(); + ticketingSamplingReqVO.setService("apiSaleService"); + ticketingSamplingReqVO.setMethod("SaleDetail"); + // 抽取前一天的所有售票数据 + ticketingSamplingReqVO.setQueryDate(TickingDateUtils.getPreviousDayFormat()); + ticketingSamplingReqVO.setPageNumber(pageNumber); + ticketingSamplingReqVO.setPageSize(PAGE_SIZE); + // 先发起第一次请求 + String str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); + // 解析读取响应数据 + TicketingSamplingRespVO ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); + // 如果访问失败则让调度中心重新调用 + if (!ticketingSamplingRespVO.isPassflag()) { + // 让调度中心重新调用 + XxlJobHelper.log("抽数服务:销售数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg()); + XxlJobHelper.handleFail("销售数据抽数失败,请重试"); + return; + } + int totalRows = ticketingSamplingRespVO.getTotalRows(); + List> mapList = ticketingSamplingRespVO.getDataMapList(); + // 总条数小于等于每页条数 则直接按照总条数进行插入即可 + if (totalRows <= PAGE_SIZE) { + failedCount += insertSaleDataByMongoDB(mapList, totalRows, pageNumber); + } else { + // 总条数大于每页条数 执行完第一次插入后根据返回的页数继续进行请求和插入 + // 插入第一页的数据 + failedCount += insertSaleDataByMongoDB(mapList, PAGE_SIZE, pageNumber); + pageNumber++; + // 获得总页数 + int totalPages = ticketingSamplingRespVO.getTotalPages(); + // 处理剩余页的数据 + for (; pageNumber <= totalPages; pageNumber++) { + ticketingSamplingReqVO.setPageNumber(pageNumber); + str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); + ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); + + if (!ticketingSamplingRespVO.isPassflag()) { + XxlJobHelper.log("抽数服务:销售数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg()); + XxlJobHelper.handleFail("销售数据抽数失败,请重试"); + return; + } + + mapList = ticketingSamplingRespVO.getDataMapList(); + // 对最后一页进行处理,得到最后一页的实际条数 + if (pageNumber != totalPages) { + failedCount += insertSaleDataByMongoDB(mapList, PAGE_SIZE, pageNumber); + } else { + failedCount += insertSaleDataByMongoDB(mapList, totalRows % PAGE_SIZE, pageNumber); + } + } + + } + + XxlJobHelper.log("抽数服务:销售数据抽数正常结束!总共:{}条数据,{}条数据插入失败!", totalRows, failedCount); + } + /** + * 存入检票数据的定时任务mongodb + */ + @XxlJob("getCheckTicketByMongoDB") + public void getCheckTicketByMongoDBHandler() throws Exception { + int failedCount = 0; + int pageNumber = 1; + XxlJobHelper.log("抽数服务:mongodb检票数据开始抽数..."); + // 准备请求参数 + TicketingSamplingReqVO ticketingSamplingReqVO = new TicketingSamplingReqVO(); + ticketingSamplingReqVO.setService("apiCheckService"); + ticketingSamplingReqVO.setMethod("CheckDetail"); + // 抽取前一天的所有检票数据 + ticketingSamplingReqVO.setQueryDate(TickingDateUtils.getPreviousDayFormat()); + ticketingSamplingReqVO.setPageNumber(pageNumber); + ticketingSamplingReqVO.setPageSize(PAGE_SIZE); + // 先发起第一次请求 + String str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); + + // 解析读取响应数据 + TicketingSamplingRespVO ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); + // 如果访问失败则让调度中心重新调用 + if (!ticketingSamplingRespVO.isPassflag()) { + // 让调度中心重新调用 + XxlJobHelper.log("抽数服务:检票数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg()); + XxlJobHelper.handleFail("销售数据抽数失败,请重试"); + return; + } + int totalRows = ticketingSamplingRespVO.getTotalRows(); + List> mapList = ticketingSamplingRespVO.getDataMapList(); + // 总条数小于等于每页条数 则直接按照总条数进行插入即可 + if (totalRows <= PAGE_SIZE) { + failedCount += insertCheckTicketByMongoDB(mapList, totalRows, pageNumber); + } else { + // 总条数大于每页条数 执行完第一次插入后根据返回的页数继续进行请求和插入 + // 插入第一页的数据 + failedCount += insertCheckTicketByMongoDB(mapList, PAGE_SIZE, pageNumber); + pageNumber++; + // 获得总页数 + int totalPages = ticketingSamplingRespVO.getTotalPages(); + // 处理剩余页的数据 + for (; pageNumber <= totalPages; pageNumber++) { + ticketingSamplingReqVO.setPageNumber(pageNumber); + str = HttpUtil.post(OBJECT_URL, JSONUtil.toJsonStr(ticketingSamplingReqVO)); + ticketingSamplingRespVO = new ObjectMapper().readValue(str, TicketingSamplingRespVO.class); + + if (!ticketingSamplingRespVO.isPassflag()) { + XxlJobHelper.log("抽数服务:销售数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg()); + XxlJobHelper.handleFail("销售数据抽数失败,请重试"); + return; + } + + mapList = ticketingSamplingRespVO.getDataMapList(); + // 对最后一页进行处理,得到最后一页的实际条数 + if (pageNumber != totalPages) { + failedCount += insertCheckTicketByMongoDB(mapList, PAGE_SIZE, pageNumber); + } else { + failedCount += insertCheckTicketByMongoDB(mapList, totalRows % PAGE_SIZE, pageNumber); + } + } + + } + + XxlJobHelper.log("抽数服务:检票数据抽数正常结束!总共:{}条数据,{}条数据插入失败!", totalRows, failedCount); + } + /** + * 插入销售数据的方法(mysql) * @param mapList 数据集合数组 * @param listSize 实际个数 * @param pageNumber 每页显示条数 @@ -168,23 +306,7 @@ public class TicketDataMigration { int failedCount = 0; for (int i = 0; i < listSize; i++) { Map currentMap = mapList.get(i); - SaleDataSaveReqDTO saleData = new SaleDataSaveReqDTO(); - saleData.setDataId((String) currentMap.get("dataId")); - saleData.setSdno((String) currentMap.get("sdno")); - saleData.setTransactiontypeno((String) currentMap.get("transactiontypeno")); - saleData.setSddate((String) currentMap.get("sddate")); - saleData.setSdtime((String) currentMap.get("sdtime")); - saleData.setAmount(new BigDecimal(currentMap.get("amount").toString())); - saleData.setQuantity((Integer) currentMap.get("quantity")); - saleData.setCertificatetype((String) currentMap.get("certificatetype")); - saleData.setCertificateno((String) currentMap.get("certificateno")); - saleData.setProductbatchno((String) currentMap.get("productbatchno")); - saleData.setItem((String) currentMap.get("item")); - saleData.setItemtypename((String) currentMap.get("itemtypename")); - saleData.setItemtype((String) currentMap.get("itemtype")); - saleData.setItemname((String) currentMap.get("itemname")); - saleData.setSalepropetyvaluename((String) currentMap.get("salepropetyvaluename")); - saleData.setTenant_id(1L); + SaleDataSaveReqDTO saleData = mapToSaleDataSaveReqDTO(currentMap); if (ticketSaleDataApi.createSaleData(saleData).getCode() != 0) { failedCount++; XxlJobHelper.log("第{}条数据插入失败,数据值为:{}", ((pageNumber - 1) * PAGE_SIZE + i + 1), currentMap); @@ -193,7 +315,7 @@ public class TicketDataMigration { return failedCount; } /** - * 插入检票数据的方法 + * 插入检票数据的方法(mysql) * @param mapList 数据集合数组 * @param listSize 实际个数 * @param pageNumber 每页显示条数 @@ -203,17 +325,8 @@ public class TicketDataMigration { int failedCount = 0; for (int i = 0; i < listSize; i++) { Map currentMap = mapList.get(i); - CheckTicketSaveReqDTO checkTicket = new CheckTicketSaveReqDTO(); - checkTicket.setDataId((String) currentMap.get("dataId")); - checkTicket.setTicket((String) currentMap.get("ticket")); - checkTicket.setCheckticketdate((String) currentMap.get("checkticketdate")); - checkTicket.setChecktickettime((String) currentMap.get("checktickettime")); - checkTicket.setPersoncount((Integer) currentMap.get("personcount")); - checkTicket.setCheckstation((String) currentMap.get("checkstation")); - checkTicket.setCheckstationname((String) currentMap.get("checkstationname")); - checkTicket.setSdshipping((String) currentMap.get("sdshipping")); - checkTicket.setSalepropetyvaluename((String) currentMap.get("salepropetyvaluename")); - checkTicket.setTenant_id(1L); + // 把获取到的数据转为插入检票的参数类型 + CheckTicketSaveReqDTO checkTicket = mapToCheckTicketSaveReqDTO(currentMap); if (ticketCheckTicketApi.createCheckTicket(checkTicket).getCode() != 0) { failedCount++; XxlJobHelper.log("第{}条数据插入失败,数据值为:{}", ((pageNumber - 1) * PAGE_SIZE + i + 1), currentMap); @@ -221,4 +334,88 @@ public class TicketDataMigration { } return failedCount; } + /** + * 插入销售数据的方法(mongodb) + * @param mapList 数据集合数组 + * @param listSize 实际个数 + * @param pageNumber 每页显示条数 + * @return int 失败条数 + */ + private int insertSaleDataByMongoDB(List> mapList, int listSize, int pageNumber) { + int failedCount = 0; + for (int i = 0; i < listSize; i++) { + Map currentMap = mapList.get(i); + SaleDataSaveReqDTO saleData = mapToSaleDataSaveReqDTO(currentMap); + if (!"添加成功".equals(ticketSaleDataApi.createSaleDataByMongoDB(saleData).getData())) { + failedCount++; + XxlJobHelper.log("第{}条数据插入失败,数据值为:{}", ((pageNumber - 1) * PAGE_SIZE + i + 1), currentMap); + } + } + return failedCount; + } + /** + * 插入检票数据的方法(mongodb) + * @param mapList 数据集合数组 + * @param listSize 实际个数 + * @param pageNumber 每页显示条数 + * @return int 失败条数 + */ + private int insertCheckTicketByMongoDB(List> mapList, int listSize, int pageNumber) { + int failedCount = 0; + for (int i = 0; i < listSize; i++) { + Map currentMap = mapList.get(i); + // 把获取到的数据转为插入检票的参数类型 + CheckTicketSaveReqDTO checkTicket = mapToCheckTicketSaveReqDTO(currentMap); + if (!"添加成功".equals(ticketCheckTicketApi.createCheckTicketByMongoDB(checkTicket).getData())) { + failedCount++; + XxlJobHelper.log("第{}条数据插入失败,数据值为:{}", ((pageNumber - 1) * PAGE_SIZE + i + 1), currentMap); + } + } + return failedCount; + } + + /** + * 集合转检票类型 + * @param currentMap 当前集合 + * @return cn.iocoder.yudao.module.ticket.api.checkticket.dto.CheckTicketSaveReqDTO 插入检票数据的参数 + */ + private CheckTicketSaveReqDTO mapToCheckTicketSaveReqDTO(Map currentMap){ + CheckTicketSaveReqDTO checkTicket = new CheckTicketSaveReqDTO(); + checkTicket.setDataId((String) currentMap.get("dataId")); + checkTicket.setTicket((String) currentMap.get("ticket")); + checkTicket.setCheckticketdate((String) currentMap.get("checkticketdate")); + checkTicket.setChecktickettime((String) currentMap.get("checktickettime")); + checkTicket.setPersoncount((Integer) currentMap.get("personcount")); + checkTicket.setCheckstation((String) currentMap.get("checkstation")); + checkTicket.setCheckstationname((String) currentMap.get("checkstationname")); + checkTicket.setSdshipping((String) currentMap.get("sdshipping")); + checkTicket.setSalepropetyvaluename((String) currentMap.get("salepropetyvaluename")); + checkTicket.setTenant_id(1L); + return checkTicket; + } + /** + * 集合转售票类型 + * @param currentMap 当前集合 + * @return cn.iocoder.yudao.module.ticket.api.checkticket.dto.CheckTicketSaveReqDTO 插入检票数据的参数 + */ + private SaleDataSaveReqDTO mapToSaleDataSaveReqDTO(Map currentMap){ + SaleDataSaveReqDTO saleData = new SaleDataSaveReqDTO(); + saleData.setDataId((String) currentMap.get("dataId")); + saleData.setSdno((String) currentMap.get("sdno")); + saleData.setTransactiontypeno((String) currentMap.get("transactiontypeno")); + saleData.setSddate((String) currentMap.get("sddate")); + saleData.setSdtime((String) currentMap.get("sdtime")); + saleData.setAmount(new BigDecimal(currentMap.get("amount").toString())); + saleData.setQuantity((Integer) currentMap.get("quantity")); + saleData.setCertificatetype((String) currentMap.get("certificatetype")); + saleData.setCertificateno((String) currentMap.get("certificateno")); + saleData.setProductbatchno((String) currentMap.get("productbatchno")); + saleData.setItem((String) currentMap.get("item")); + saleData.setItemtypename((String) currentMap.get("itemtypename")); + saleData.setItemtype((String) currentMap.get("itemtype")); + saleData.setItemname((String) currentMap.get("itemname")); + saleData.setSalepropetyvaluename((String) currentMap.get("salepropetyvaluename")); + saleData.setTenant_id(1L); + return saleData; + } }