1
This commit is contained in:
@@ -4,7 +4,6 @@ package cn.van.business.util;
|
|||||||
import cn.van.business.model.jd.GoodsInfoVO;
|
import cn.van.business.model.jd.GoodsInfoVO;
|
||||||
import cn.van.business.model.jd.OrderRow;
|
import cn.van.business.model.jd.OrderRow;
|
||||||
import cn.van.business.repository.OrderRowRepository;
|
import cn.van.business.repository.OrderRowRepository;
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.alibaba.fastjson2.util.DateUtils;
|
import com.alibaba.fastjson2.util.DateUtils;
|
||||||
import com.jd.open.api.sdk.DefaultJdClient;
|
import com.jd.open.api.sdk.DefaultJdClient;
|
||||||
import com.jd.open.api.sdk.JdClient;
|
import com.jd.open.api.sdk.JdClient;
|
||||||
@@ -12,9 +11,7 @@ import com.jd.open.api.sdk.domain.kplunion.OrderService.request.query.OrderRowRe
|
|||||||
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.GoodsInfo;
|
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.GoodsInfo;
|
||||||
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.OrderRowResp;
|
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.OrderRowResp;
|
||||||
import com.jd.open.api.sdk.request.kplunion.UnionOpenOrderRowQueryRequest;
|
import com.jd.open.api.sdk.request.kplunion.UnionOpenOrderRowQueryRequest;
|
||||||
import com.jd.open.api.sdk.request.kplunion.UnionOpenPromotionBysubunionidGetRequest;
|
|
||||||
import com.jd.open.api.sdk.response.kplunion.UnionOpenOrderRowQueryResponse;
|
import com.jd.open.api.sdk.response.kplunion.UnionOpenOrderRowQueryResponse;
|
||||||
import com.jd.open.api.sdk.response.kplunion.UnionOpenPromotionCommonGetResponse;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -312,14 +309,14 @@ public class JDUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每10分钟拉取最近14天的订单
|
* 每10分钟拉取07-14天的订单
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 */10 * * * ?")
|
@Scheduled(cron = "0 */10 * * * ?")
|
||||||
public void fetchHistoricalOrders0014() {
|
public void fetchHistoricalOrders0714() {
|
||||||
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());
|
logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());
|
||||||
LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS);
|
LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS).minusDays(7);
|
||||||
LocalDateTime startDate = lastHour.minusDays(14).truncatedTo(ChronoUnit.HOURS);
|
LocalDateTime startDate = lastHour.minusDays(14).truncatedTo(ChronoUnit.HOURS);
|
||||||
|
|
||||||
while (!startDate.isEqual(lastHour)) {
|
while (!startDate.isEqual(lastHour)) {
|
||||||
@@ -357,7 +354,49 @@ public class JDUtils {
|
|||||||
startDate = startDate.plusMinutes(10);
|
startDate = startDate.plusMinutes(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Scheduled(cron = "0 */2 * * * ?")
|
||||||
|
public void fetchHistoricalOrders0007() {
|
||||||
|
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());
|
||||||
|
LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS);
|
||||||
|
LocalDateTime startDate = lastHour.minusDays(7).truncatedTo(ChronoUnit.HOURS);
|
||||||
|
|
||||||
|
while (!startDate.isEqual(lastHour)) {
|
||||||
|
Integer pageIndex = 1;
|
||||||
|
boolean hasMore = true;
|
||||||
|
|
||||||
|
while (hasMore) {
|
||||||
|
try {
|
||||||
|
UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex, true);
|
||||||
|
if (response != null && response.getQueryResult() != null) {
|
||||||
|
if (response.getQueryResult().getCode() == 200) {
|
||||||
|
OrderRowResp[] orderRowResps = response.getQueryResult().getData();
|
||||||
|
if (orderRowResps != null) {
|
||||||
|
for (OrderRowResp orderRowResp : orderRowResps) {
|
||||||
|
if (orderRowResp != null) { // Check each orderRowResp is not null
|
||||||
|
OrderRow orderRow = createOrderRow(orderRowResp);
|
||||||
|
if (orderRow != null) { // Ensure orderRow is not null after creation
|
||||||
|
orderRowRepository.save(orderRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hasMore = Boolean.TRUE.equals(response.getQueryResult().getHasMore());
|
||||||
|
} else {
|
||||||
|
hasMore = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hasMore = false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
hasMore = false; // Optionally break out of the while loop if required
|
||||||
|
}
|
||||||
|
if (hasMore) pageIndex++;
|
||||||
|
}
|
||||||
|
startDate = startDate.plusMinutes(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据指定的日期时间拉取订单
|
* 根据指定的日期时间拉取订单
|
||||||
@@ -425,7 +464,7 @@ public class JDUtils {
|
|||||||
content.append("刷新三天\r");
|
content.append("刷新三天\r");
|
||||||
content.append("刷新3060\r\n");
|
content.append("刷新3060\r\n");
|
||||||
content.append("刷新1430\r\n");
|
content.append("刷新1430\r\n");
|
||||||
content.append("刷新0014\r\n");
|
content.append("刷新0714\r\n");
|
||||||
|
|
||||||
content.append(":::高级菜单:::\r");
|
content.append(":::高级菜单:::\r");
|
||||||
content.append("菜单:京+高级+命令 \n 如: 京高级违规30\r");
|
content.append("菜单:京+高级+命令 \n 如: 京高级违规30\r");
|
||||||
@@ -663,9 +702,9 @@ public class JDUtils {
|
|||||||
content.append("刷新1430,耗时: ").append(time).append("ms, ").append((time) / 1000).append(" s\r");
|
content.append("刷新1430,耗时: ").append(time).append("ms, ").append((time) / 1000).append(" s\r");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "刷新0014": {
|
case "刷新0714": {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
fetchHistoricalOrders0014();
|
fetchHistoricalOrders0714();
|
||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
content.append("刷新0014,耗时: ").append(time).append("ms, ").append((time) / 1000).append(" s\r");
|
content.append("刷新0014,耗时: ").append(time).append("ms, ").append((time) / 1000).append(" s\r");
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user