xinwei #54
@ -28,10 +28,7 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description 票务抽数服务
|
||||
@ -64,7 +61,7 @@ public class TicketDataMigration {
|
||||
int failedCount = 0;
|
||||
int pageNumber = 1;
|
||||
XxlJobHelper.log("抽数服务:mysql销售数据开始抽数...");
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
int totalRows = ticketingSamplingRespVO.getTotalRows();
|
||||
List<Map<String, Object>> mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 总条数小于等于每页条数 则直接按照总条数进行插入即可
|
||||
@ -79,7 +76,7 @@ public class TicketDataMigration {
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 对最后一页进行处理,得到最后一页的实际条数
|
||||
@ -103,7 +100,7 @@ public class TicketDataMigration {
|
||||
int failedCount = 0;
|
||||
int pageNumber = 1;
|
||||
XxlJobHelper.log("抽数服务:mysql检票数据开始抽数...");
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
int totalRows = ticketingSamplingRespVO.getTotalRows();
|
||||
List<Map<String, Object>> mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 总条数小于等于每页条数 则直接按照总条数进行插入即可
|
||||
@ -118,7 +115,7 @@ public class TicketDataMigration {
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 对最后一页进行处理,得到最后一页的实际条数
|
||||
if (pageNumber != totalPages) {
|
||||
@ -248,6 +245,7 @@ public class TicketDataMigration {
|
||||
}
|
||||
XxlJobHelper.log("抽数结束!!!");
|
||||
}
|
||||
|
||||
@XxlJob("getSaleDataByMongoDBLastMonthToNow")
|
||||
public void getSaleDataByMongoDBLastMonthToNow() throws Exception {
|
||||
XxlJobHelper.log("抽数服务:mongodb售票数据开始抽数...");
|
||||
@ -302,6 +300,86 @@ public class TicketDataMigration {
|
||||
}
|
||||
XxlJobHelper.log("抽数结束!!!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用于更新指定日期的检票或售票数据(mongodb)
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return void
|
||||
*/
|
||||
public String getTicketDataByTimeZonesToMongo(Calendar startDate, Calendar endDate, String method) throws Exception {
|
||||
String methodName;
|
||||
String respService;
|
||||
String respMethod;
|
||||
if ("checkTicket".equals(method)) {
|
||||
methodName = "检票";
|
||||
respService = CHECK_TICKET_SERVICE;
|
||||
respMethod = CHECK_TICKET_METHOD;
|
||||
} else if ("saleData".equals(method)) {
|
||||
methodName = "售票";
|
||||
respService = SALE_DATA_SERVICE;
|
||||
respMethod = SALE_DATA_METHOD;
|
||||
} else {
|
||||
XxlJobHelper.log("服务名错误");
|
||||
logger.error("服务名错误");
|
||||
return null;
|
||||
}
|
||||
StringJoiner result = new StringJoiner("\n");
|
||||
XxlJobHelper.log("抽数服务:mongodb{}数据开始抽数...", methodName);
|
||||
result.add("抽数服务:mongodb" + methodName + "数据开始抽数...");
|
||||
int successCount;
|
||||
int duplicatesCount;
|
||||
int pageNumber;
|
||||
|
||||
// 循环从开始日期到结束日期
|
||||
while (!startDate.after(endDate)) {
|
||||
successCount = 0;
|
||||
duplicatesCount = 0;
|
||||
String dateString = TickingDateUtils.format(startDate.getTime());
|
||||
pageNumber = 1;
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(respService, respMethod, dateString, pageNumber);
|
||||
if (ticketingSamplingRespVO == null) {
|
||||
startDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
continue;
|
||||
}
|
||||
int totalRows = ticketingSamplingRespVO.getTotalRows();
|
||||
List<Map<String, Object>> mapList;
|
||||
|
||||
// 获得总页数
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(respService, respMethod, dateString, pageNumber);
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
List<Integer> resultNum = null;
|
||||
if ("checkTicket".equals(method)) {
|
||||
resultNum = checkTicketService.insertByMongoDB(BeanUtils.toBean(mapList, CheckTicket.class));
|
||||
} else if ("saleData".equals(method)) {
|
||||
resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class));
|
||||
}
|
||||
if (resultNum == null) {
|
||||
result.add("数据批量插入异常!");
|
||||
} else {
|
||||
successCount += resultNum.get(0);
|
||||
duplicatesCount += resultNum.get(1);
|
||||
}
|
||||
}
|
||||
int currentYear = startDate.get(Calendar.YEAR);
|
||||
int currentMonth = startDate.get(Calendar.MONTH) + 1; // 加1以得到1-12的月份
|
||||
int currentDay = startDate.get(Calendar.DAY_OF_MONTH);
|
||||
result.add(String.format("抽数服务:%d年%d月%d日:" + methodName + "数据抽数正常结束!总共:%d条数据,%d条数据重复,%d条数据插入成功!", currentYear, currentMonth, currentDay, totalRows, duplicatesCount, successCount));
|
||||
XxlJobHelper.log("抽数服务:{}年{}月{}日:{}数据抽数正常结束!总共:{}条数据,{}条数据重复,{}条数据插入成功!", currentYear, currentMonth, currentDay, methodName, totalRows, duplicatesCount, successCount);
|
||||
// 日期递增一天
|
||||
startDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
result.add("抽数结束!!!");
|
||||
logger.info(result.toString());
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入销售数据的方法(mysql)
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user