This commit is contained in:
雷欧(林平凡)
2025-01-09 14:52:17 +08:00
parent ad2e300b3d
commit f5f4bc281b

View File

@@ -178,11 +178,16 @@ public class JDUtils {
/** /**
* 实时刷新最近10分钟的订单 * 实时刷新最近10分钟的订单
*/ */
@Scheduled(cron = "0 * * * * ?") // 每分钟执行一次 //@Scheduled(cron = "0 * * * * ?") // 每分钟执行一次
public void fetchLatestOrder() { public void fetchLatestOrder() {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
LocalDateTime lastMinute = now.minusMinutes(10).withSecond(0).withNano(0); LocalDateTime lastMinute = now.minusMinutes(10).withSecond(0).withNano(0);
/**临时代码*/
/**下面是原先的代码*/
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) { for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
//String wxid = entry.getKey(); //String wxid = entry.getKey();
WXUtil.SuperAdmin admin = entry.getValue(); WXUtil.SuperAdmin admin = entry.getValue();
@@ -214,6 +219,62 @@ public class JDUtils {
} }
public void test01() {
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
//String wxid = entry.getKey();
WXUtil.SuperAdmin admin = entry.getValue();
String appKey = admin.getAppKey();
String secretKey = admin.getSecretKey();
if (Util.isAnyEmpty(appKey,secretKey)){
continue;
}
LocalDateTime now = LocalDateTime.now();
//logger.info("拉取历史订单---> , {} 点,{} 分", now.getHour(), now.getMinute());
LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS);
LocalDateTime startDate = lastHour.minusMonths(3).truncatedTo(ChronoUnit.HOURS);
while (!startDate.isEqual(lastHour)) {
Integer pageIndex = 1;
boolean hasMore = true;
while (hasMore) {
try {
// 30-60 天 ,非实时,非分钟
UnionOpenOrderRowQueryResponse response = fetchOrdersForDateTime(startDate, false, pageIndex, false,appKey,secretKey);
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.plusHours(1);
}
}
}
/** /**
* 扫描订单发送到微信 * 扫描订单发送到微信
* 每分钟的30秒执行一次 * 每分钟的30秒执行一次
@@ -239,8 +300,9 @@ public class JDUtils {
/** /**
* 一天拉取三次 30天到60天前的订单 * 一天拉取三次 30天到60天前的订单
*/ */
@Scheduled(cron = "0 0 */4 * * ?") //@Scheduled(cron = "0 0 */4 * * ?")
public void fetchHistoricalOrders3090() { public void fetchHistoricalOrders3090() {
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) { for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
//String wxid = entry.getKey(); //String wxid = entry.getKey();
WXUtil.SuperAdmin admin = entry.getValue(); WXUtil.SuperAdmin admin = entry.getValue();
@@ -262,6 +324,7 @@ public class JDUtils {
LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS).minusMonths(1); LocalDateTime lastHour = now.truncatedTo(ChronoUnit.HOURS).minusMonths(1);
LocalDateTime startDate = lastHour.minusMonths(3).truncatedTo(ChronoUnit.HOURS); LocalDateTime startDate = lastHour.minusMonths(3).truncatedTo(ChronoUnit.HOURS);
while (!startDate.isEqual(lastHour)) { while (!startDate.isEqual(lastHour)) {
Integer pageIndex = 1; Integer pageIndex = 1;
boolean hasMore = true; boolean hasMore = true;
@@ -304,7 +367,7 @@ public class JDUtils {
/** /**
* 一天拉取6次 14天到30天前的订单 * 一天拉取6次 14天到30天前的订单
*/ */
@Scheduled(cron = "0 0 * * * ?") //@Scheduled(cron = "0 0 * * * ?")
public void fetchHistoricalOrders1430() { public void fetchHistoricalOrders1430() {
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) { for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
//String wxid = entry.getKey(); //String wxid = entry.getKey();
@@ -368,7 +431,7 @@ public class JDUtils {
/** /**
* 每10分钟拉取07-14天的订单 * 每10分钟拉取07-14天的订单
*/ */
@Scheduled(cron = "0 0 * * * ?") //@Scheduled(cron = "0 0 * * * ?")
public void fetchHistoricalOrders0714() { public void fetchHistoricalOrders0714() {
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) { for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
//String wxid = entry.getKey(); //String wxid = entry.getKey();
@@ -428,7 +491,7 @@ public class JDUtils {
return count; return count;
} }
@Scheduled(cron = "0 * * * * ?") //@Scheduled(cron = "0 * * * * ?")
public void fetchHistoricalOrders0007() { public void fetchHistoricalOrders0007() {
for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) { for (Map.Entry<String, WXUtil.SuperAdmin> entry : super_admins.entrySet()) {
//String wxid = entry.getKey(); //String wxid = entry.getKey();
@@ -501,12 +564,14 @@ public class JDUtils {
LocalDateTime endTime = isMinutes ? startTime.plusMinutes(30) : startTime.plusHours(1); LocalDateTime endTime = isMinutes ? startTime.plusMinutes(30) : startTime.plusHours(1);
String hourMinuteTag = isRealTime ? "minute" : "hour"; String hourMinuteTag = isRealTime ? "minute" : "hour";
String timeTag = JD_REFRESH_TAG +":"+appKey +":"+ startTime.format(DATE_TIME_FORMATTER); //String oldTimeTag = JD_REFRESH_TAG + startTime.format(DATE_TIME_FORMATTER);
String newTimeTag = JD_REFRESH_TAG +":"+appKey +":"+ startTime.format(DATE_TIME_FORMATTER);
HashOperations<String, String, String> hashOps = redisTemplate.opsForHash(); HashOperations<String, String, String> hashOps = redisTemplate.opsForHash();
// 检查这个小时或分钟是否已经被处理过 // 检查这个小时或分钟是否已经被处理过
if (hashOps.hasKey(timeTag, hourMinuteTag)) { if (hashOps.hasKey(newTimeTag, hourMinuteTag)) {
if (!isMinutes) { if (!isMinutes) {
return null; return null;
} }
@@ -519,7 +584,7 @@ public class JDUtils {
if (!isRealTime) { if (!isRealTime) {
// 只有没有订单的才进行标记为已拉取 // 只有没有订单的才进行标记为已拉取
if (unionOpenOrderRowQueryResponse != null && unionOpenOrderRowQueryResponse.getQueryResult() != null && unionOpenOrderRowQueryResponse.getQueryResult().getData() == null) { if (unionOpenOrderRowQueryResponse != null && unionOpenOrderRowQueryResponse.getQueryResult() != null && unionOpenOrderRowQueryResponse.getQueryResult().getData() == null) {
hashOps.put(timeTag, hourMinuteTag, "done"); hashOps.put(newTimeTag, hourMinuteTag, "done");
} }
} }
@@ -533,6 +598,22 @@ public class JDUtils {
} }
public void test(LocalDateTime startTime, boolean isRealTime, Integer page, boolean isMinutes,String appKey,String secretKey){
String oldTimeTag = JD_REFRESH_TAG + startTime.format(DATE_TIME_FORMATTER);
String newTimeTag = JD_REFRESH_TAG +":"+appKey +":"+ startTime.format(DATE_TIME_FORMATTER);
StringRedisTemplate redisTemplate = new StringRedisTemplate();
HashOperations<String, String, String> hashOps = redisTemplate.opsForHash();
// get all entries from the old hash
Map<String, String> entries = hashOps.entries(oldTimeTag);
// put all entries into the new hash
hashOps.putAll(newTimeTag, entries);
// delete the old hash
redisTemplate.delete(oldTimeTag);
}
/** /**
* 接收京粉指令指令 * 接收京粉指令指令
@@ -578,6 +659,10 @@ public class JDUtils {
content.append("京高级+订单号\r\""); content.append("京高级+订单号\r\"");
content.append("京高级SKU+sku\\r\""); content.append("京高级SKU+sku\\r\"");
break; break;
case "测试指令":{
test01();
break;
}
case "今日统计": { case "今日统计": {
List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0); List<OrderRow> todayOrders = filterOrdersByDate(orderRows, 0);
// 订单总数,已付款,已取消,佣金总计 // 订单总数,已付款,已取消,佣金总计