完成基本京粉功能推送,订单统计,订单拉取的稳定版初版
This commit is contained in:
@@ -203,7 +203,7 @@ public class JDUtils {
|
|||||||
/**
|
/**
|
||||||
* 指令
|
* 指令
|
||||||
*/
|
*/
|
||||||
public void sendOrderToWxByOrder(String order) {
|
public void sendOrderToWxByOrder(String order) throws Exception {
|
||||||
int[] parm = {-1};
|
int[] parm = {-1};
|
||||||
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);
|
List<OrderRow> orderRows = orderRowRepository.findByValidCodeNotInOrderByOrderTimeDesc(parm);
|
||||||
/**
|
/**
|
||||||
@@ -225,6 +225,7 @@ public class JDUtils {
|
|||||||
content += "最近一个月统计\r";
|
content += "最近一个月统计\r";
|
||||||
content += "今天订单\r";
|
content += "今天订单\r";
|
||||||
content += "昨天订单\r";
|
content += "昨天订单\r";
|
||||||
|
content += "刷新三天\r";
|
||||||
break;
|
break;
|
||||||
case "今日统计": {
|
case "今日统计": {
|
||||||
List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0);
|
List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0);
|
||||||
@@ -295,6 +296,38 @@ public class JDUtils {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "刷新三天": {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
int count = 0;
|
||||||
|
LocalDateTime startDate = LocalDateTime.now().minusDays(3).withMinute(0).withSecond(0).withNano(0);
|
||||||
|
LocalDateTime lastHour = LocalDateTime.now().minusHours(1).withMinute(0).withSecond(0).withNano(0);
|
||||||
|
while (!startDate.isEqual(lastHour)) {
|
||||||
|
startDate = startDate.plusHours(1);
|
||||||
|
UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false);
|
||||||
|
if (response != null) {
|
||||||
|
|
||||||
|
int code = response.getQueryResult().getCode();
|
||||||
|
if (code == 200) {
|
||||||
|
if (response.getQueryResult().getCode() == 200) {
|
||||||
|
OrderRowResp[] orderRowResps = response.getQueryResult().getData();
|
||||||
|
if (orderRowResps == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (OrderRowResp orderRowResp : orderRowResps) {
|
||||||
|
// 固化到数据库
|
||||||
|
OrderRow orderRow = createOrderRow(orderRowResp);
|
||||||
|
// 订单号不存在就保存,存在就更新订单状态
|
||||||
|
orderRowRepository.save(orderRow);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
content = "刷新三天成功,耗时" + (System.currentTimeMillis() - start) / 1000 + "秒\r" + "刷新订单数:" + count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content, 1, WXUtil.super_admin_wxid);
|
wxUtil.sendTextMessage(WXUtil.super_admin_wxid, content, 1, WXUtil.super_admin_wxid);
|
||||||
@@ -355,9 +388,10 @@ public class JDUtils {
|
|||||||
/**
|
/**
|
||||||
* 根据指定的日期时间拉取订单
|
* 根据指定的日期时间拉取订单
|
||||||
*/
|
*/
|
||||||
public UnionOpenOrderRowQueryResponse fetchOrdersForDateTime(LocalDateTime dateTime, boolean isRealTime) throws Exception {
|
public UnionOpenOrderRowQueryResponse fetchOrdersForDateTime(LocalDateTime startTime, boolean isRealTime) throws Exception {
|
||||||
LocalDateTime endTime = isRealTime ? dateTime.plusMinutes(10) : dateTime.plusHours(1);
|
|
||||||
String key = dateTime.format(DATE_TIME_FORMATTER);
|
LocalDateTime endTime = isRealTime ? startTime.plusMinutes(10) : startTime.plusHours(1);
|
||||||
|
String key = startTime.format(DATE_TIME_FORMATTER);
|
||||||
String hourRange = isRealTime ? "minute" : "hour";
|
String hourRange = isRealTime ? "minute" : "hour";
|
||||||
|
|
||||||
SetOperations<String, String> setOps = redisTemplate.opsForSet();
|
SetOperations<String, String> setOps = redisTemplate.opsForSet();
|
||||||
@@ -369,10 +403,13 @@ public class JDUtils {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// 调用 API 以拉取订单
|
// 调用 API 以拉取订单
|
||||||
UnionOpenOrderRowQueryResponse unionOpenOrderRowQueryResponse = getUnionOpenOrderRowQueryResponse(dateTime, endTime);
|
UnionOpenOrderRowQueryResponse unionOpenOrderRowQueryResponse = getUnionOpenOrderRowQueryResponse(startTime, endTime);
|
||||||
|
|
||||||
// 标记已拉取
|
// 标记已拉取
|
||||||
setOps.add(key, hourRange);
|
setOps.add(key, hourRange);
|
||||||
|
// 打印方法调用和开始结束时间
|
||||||
|
|
||||||
|
System.out.println("拉取订单:" + "开始时间:" + startTime.format(DATE_TIME_FORMATTER) + "结束时间:" + endTime.format(DATE_TIME_FORMATTER));
|
||||||
return unionOpenOrderRowQueryResponse;
|
return unionOpenOrderRowQueryResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,7 +487,7 @@ public class JDUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拉取历史订单 2880 次请求
|
// 拉取历史订单 2880 次请求
|
||||||
@Scheduled(cron = "0 0 8,23 * * ?")
|
@Scheduled(cron = "0 0 8,12,20,0 * * ?")
|
||||||
public void fetchHistoricalOrders() throws Exception {
|
public void fetchHistoricalOrders() throws Exception {
|
||||||
// 从设定的开始日期到昨天的同一时间
|
// 从设定的开始日期到昨天的同一时间
|
||||||
System.out.println("开始拉取历史订单");
|
System.out.println("开始拉取历史订单");
|
||||||
|
|||||||
Reference in New Issue
Block a user