This commit is contained in:
van
2026-04-09 01:19:15 +08:00
parent a2c4589046
commit 31e7e6853b
3 changed files with 45 additions and 2 deletions

View File

@@ -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;
}