diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index dfcfd9c..5f11165 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -272,8 +272,10 @@ jarvis: pull-page-size: 100 # 每授权单次最大页数(最大 100;与 page_size 乘积勿超 10000) pull-max-pages-per-shop: 100 - # 全量拉单按 update_time 分段(秒),默认 7 天 + # 全量拉单按 update_time 分段(秒),默认 7 天(且不超过 pull-max-update-time-range-seconds) pull-time-chunk-seconds: 604800 + # 单次列表请求 update_time 最大跨度(秒),须满足平台「6个月内」;默认 180 天 + pull-max-update-time-range-seconds: 15552000 # 全量拉单起点:距今多少天(默认约 3 年) pull-full-history-days: 1095 auto-ship-batch-size: 20 diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/config/JarvisGoofishProperties.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/config/JarvisGoofishProperties.java index 9d5dd4d..4e80734 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/config/JarvisGoofishProperties.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/config/JarvisGoofishProperties.java @@ -41,6 +41,11 @@ public class JarvisGoofishProperties { */ private int pullTimeChunkSeconds = 604800; + /** + * 订单列表单次请求中 update_time 区间最大跨度(秒)。开放平台返回「只能查询时间范围6个月内的数据」时须≤此值;默认约 180 天留余量 + */ + private int pullMaxUpdateTimeRangeSeconds = 15552000; + /** * 全量拉单从「当前时间」往前推多少天作为起点(仅 full 接口;可自行改大) */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderPipeline.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderPipeline.java index 15f64cf..eb8f9c4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderPipeline.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderPipeline.java @@ -682,10 +682,15 @@ public class GoofishOrderPipeline { days = 1; } long start = now - (long) days * 86400L; + int maxSpan = goofishProperties.getPullMaxUpdateTimeRangeSeconds(); + if (maxSpan < 86400) { + maxSpan = 86400; + } int chunk = goofishProperties.getPullTimeChunkSeconds(); if (chunk < 3600) { chunk = 86400; } + chunk = Math.min(chunk, maxSpan); int total = 0; for (long t = start; t <= now; t += chunk) { long end = Math.min(t + chunk - 1, now); @@ -704,9 +709,40 @@ public class GoofishOrderPipeline { } /** - * 按开放平台「订单列表」接口,限定 update_time 时间戳区间(秒,闭区间)拉取并落库。 + * 按 update_time 闭区间拉取;若区间超过开放平台「约 6 个月内」限制,自动拆成多段子区间再请求。 */ public int pullForAppKeyUpdateTimeRange(String appKey, long updateTimeStartSec, long updateTimeEndSec) { + if (StringUtils.isEmpty(appKey) || updateTimeEndSec < updateTimeStartSec) { + return 0; + } + int maxSpan = goofishProperties.getPullMaxUpdateTimeRangeSeconds(); + if (maxSpan < 86400) { + maxSpan = 86400; + } + // 闭区间 [start,end] 共 (end-start+1) 秒,不得超过平台允许的 update_time 跨度(约 6 个月) + long rangeWidth = updateTimeEndSec - updateTimeStartSec + 1; + if (rangeWidth <= maxSpan) { + return pullForAppKeyUpdateTimeRangeOnce(appKey, updateTimeStartSec, updateTimeEndSec); + } + int total = 0; + for (long cur = updateTimeStartSec; cur <= updateTimeEndSec; ) { + long subEnd = Math.min(cur + maxSpan - 1, updateTimeEndSec); + total += pullForAppKeyUpdateTimeRangeOnce(appKey, cur, subEnd); + cur = subEnd + 1; + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + break; + } + } + return total; + } + + /** + * 单次列表请求:update_time 已为平台允许跨度内(闭区间)。 + */ + private int pullForAppKeyUpdateTimeRangeOnce(String appKey, long updateTimeStartSec, long updateTimeEndSec) { if (StringUtils.isEmpty(appKey) || updateTimeEndSec < updateTimeStartSec) { return 0; }