1
This commit is contained in:
@@ -219,30 +219,35 @@ public class JDUtils {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 每小时拉取过去两个月的订单
|
||||
* 因为有的延迟发货,而接口只能拉取两个月前的数据
|
||||
*/
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void fetchHistoricalOrders() throws Exception {
|
||||
System.out.println("开始拉取历史订单");
|
||||
/**
|
||||
* 每小时拉取过去两个月的订单
|
||||
* 因为有的延迟发货,而接口只能拉取两个月前的数据
|
||||
*/
|
||||
@Scheduled(cron = "0 0 * * * ?")
|
||||
public void fetchHistoricalOrders() {
|
||||
System.out.println("开始拉取历史订单");
|
||||
|
||||
// 获取当前时间,并调整为整点开始
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS);
|
||||
LocalDateTime startDate = lastHour.minusMonths(2).truncatedTo(ChronoUnit.HOURS);
|
||||
// 获取当前时间,并调整为整点开始
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS);
|
||||
LocalDateTime startDate = lastHour.minusMonths(2).truncatedTo(ChronoUnit.HOURS);
|
||||
|
||||
// 循环从两个月前到现在最近的整点
|
||||
while (!startDate.isEqual(lastHour)) {
|
||||
Integer pageIndex = 1;
|
||||
Boolean hasMore = true;
|
||||
// 循环从两个月前到现在最近的整点
|
||||
while (!startDate.isEqual(lastHour)) {
|
||||
Integer pageIndex = 1;
|
||||
Boolean hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex); // 假的代表历史订单
|
||||
while (hasMore) {
|
||||
try {
|
||||
UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex); // 请求历史订单数据
|
||||
|
||||
if (response != null && response.getQueryResult().getCode() == 200) {
|
||||
if (response != null && response.getQueryResult() != null && response.getQueryResult().getCode() == 200) {
|
||||
OrderRowResp[] orderRowResps = response.getQueryResult().getData();
|
||||
|
||||
// 安全地获取hasMore信息
|
||||
Boolean tempHasMore = response.getQueryResult().getHasMore();
|
||||
hasMore = tempHasMore != null && tempHasMore;
|
||||
|
||||
if (orderRowResps != null) {
|
||||
for (OrderRowResp orderRowResp : orderRowResps) {
|
||||
// 固化到数据库
|
||||
@@ -250,23 +255,26 @@ public class JDUtils {
|
||||
// 订单号不存在就保存,存在就更新订单状态
|
||||
orderRowRepository.save(orderRow);
|
||||
}
|
||||
} else {
|
||||
hasMore = false;
|
||||
}
|
||||
|
||||
// 判断是否有更多页面
|
||||
hasMore = response.getQueryResult().getHasMore();
|
||||
if (hasMore) {
|
||||
pageIndex++;
|
||||
}
|
||||
if (hasMore) pageIndex++;
|
||||
} else {
|
||||
hasMore = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 在这里处理任何抛出的异常,防止它打断整个抓取过程
|
||||
System.err.println("处理时间 " + startDate + " 时出错: " + e.getMessage());
|
||||
// 可以选择继续或中断当前小时的处理
|
||||
hasMore = false; // 选择中断当前小时的处理
|
||||
}
|
||||
|
||||
// 每处理完一个小时的数据,递增到下一个小时
|
||||
startDate = startDate.plusHours(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 每处理完一个小时的数据,递增到下一个小时
|
||||
startDate = startDate.plusHours(1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 手动调用 将订单发送到微信
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user