From 87f629ac2950ec939f20411d491a08e6299dcb7c Mon Sep 17 00:00:00 2001 From: ray <1416431931@qq.com> Date: Fri, 8 May 2026 13:26:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=E6=95=88?= =?UTF-8?q?=E7=8E=87=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aliyun-sync/aliyun-aps-sync/src/sync.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/aliyun-sync/aliyun-aps-sync/src/sync.js b/aliyun-sync/aliyun-aps-sync/src/sync.js index 259b279..7a4a8cb 100644 --- a/aliyun-sync/aliyun-aps-sync/src/sync.js +++ b/aliyun-sync/aliyun-aps-sync/src/sync.js @@ -719,6 +719,7 @@ async function syncCustomerDetails(page, options = {}) { console.log(`[客户详情] 共 ${customerTargets.length} 个客户需要获取详情`); const allDetails = Array.isArray(resumeCheckpoint?.records) ? resumeCheckpoint.records : []; let currentListPage = 0; + let currentGroupKey = ''; let startIndex = Number.parseInt(String(resumeCheckpoint?.currentIndex || 0), 10) || 0; if (startIndex > 0) { console.log(`[客户详情续爬] 从 checkpoint 恢复: index=${startIndex}, records=${allDetails.length}`); @@ -745,6 +746,11 @@ async function syncCustomerDetails(page, options = {}) { currentListPage = target.pageNum; } + const nextGroupKey = `${target.pageNum}`; + if (currentGroupKey !== nextGroupKey) { + currentGroupKey = nextGroupKey; + } + const clicked = await clickCustomerDetailFromListWithRetry(page, target); if (!clicked) { console.warn(`[客户详情] 列表中未找到 accountId=${target.accountId},跳过`); @@ -761,7 +767,7 @@ async function syncCustomerDetails(page, options = {}) { } catch { console.warn(`[客户详情] ${target.accountId} 详情页加载超时,跳过`); await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null); - await recoverCustomerListState(page, currentListPage).catch(() => null); + await waitForStableCustomerList(page).catch(() => null); continue; } @@ -774,7 +780,7 @@ async function syncCustomerDetails(page, options = {}) { } await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null); - await recoverCustomerListState(page, currentListPage).catch(() => null); + await waitForStableCustomerList(page).catch(() => null); currentListPage = target.pageNum; } @@ -1353,6 +1359,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) { } let currentListPage = 0; let currentWindowKey = ''; + let currentGroupKey = ''; await page.goto(datasets.orders.url, { waitUntil: 'domcontentloaded' }); await waitUntilReady(page, datasets.orders.heading); @@ -1370,7 +1377,8 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) { currentListPage = 1; } - if (target.pageNum > 0 && currentListPage !== target.pageNum) { + const nextGroupKey = `${nextWindowKey}|${target.pageNum}`; + if (target.pageNum > 0 && (currentListPage !== target.pageNum || currentGroupKey !== nextGroupKey)) { const reached = await jumpToOrderPage(page, target.pageNum); if (!reached) { console.warn(`[订单详情] 无法跳到第 ${target.pageNum} 页,跳过 ${target.orderId}`); @@ -1378,6 +1386,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) { } currentListPage = target.pageNum; } + currentGroupKey = nextGroupKey; const clicked = await clickOrderDetailFromListWithRetry(page, target); if (!clicked) { @@ -1395,7 +1404,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) { } catch { console.warn(`[订单详情] ${target.orderId} 详情页加载超时,跳过`); await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null); - await recoverOrderListState(page, currentListPage).catch(() => null); + await waitForStableOrderList(page).catch(() => null); continue; } @@ -1411,7 +1420,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) { } await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null); - await recoverOrderListState(page, currentListPage, target.windowStart, target.windowEnd).catch(() => null); + await waitForStableOrderList(page).catch(() => null); currentListPage = target.pageNum; }