From 9220bbdc825055eefe837d48b5737fa309f1fde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Thu, 19 Nov 2026 23:35:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(jd-collect):=20=E4=BB=BB=E5=8A=A1=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E8=A1=8C=E5=B7=B2=E9=87=87=E8=AE=A1=E6=95=B0=E5=8F=96?= =?UTF-8?q?=20max(itemsReceived,=20rowCount)=E2=80=94=E2=80=94=E5=88=86?= =?UTF-8?q?=E7=89=87=E8=A2=AB=E6=8B=92=E6=97=B6=E4=B8=8D=E5=86=8D=E4=B8=8E?= =?UTF-8?q?=E8=A1=8C=E6=95=B0=E8=A1=8C=E8=87=AA=E7=9B=B8=E7=9F=9B=E7=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 34959 实录:8 行已落京东数据库、分片回传 500 ⇒ 服务端 itemsReceived=0、rowCount=8,卡片 extraLines 显示「已采集 8 个商品」而进度行显示「已采集 0 个商品」。rowCount 是落库真值,进度百分比与计数文案统一取两者大者;分母(cursor.total)口径不变——客户端筛选生效时会写真分母(app_client 123777d 同窗)。判据:jd-collect-progress.mount 新增两支(分片被拒显示 8/8 99%、无分母取 rowCount 真值)18/18 绿+jd-collect-tab 12/12+vue-tsc rc0 --- frontend-vue/src/pages/jd/JdCollectTab.vue | 16 ++++++++-- .../mount/jd-collect-progress.mount.test.ts | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/frontend-vue/src/pages/jd/JdCollectTab.vue b/frontend-vue/src/pages/jd/JdCollectTab.vue index 68d30b278..3c40ca4e4 100644 --- a/frontend-vue/src/pages/jd/JdCollectTab.vue +++ b/frontend-vue/src/pages/jd/JdCollectTab.vue @@ -284,13 +284,23 @@ function statusClass(item: JdCollectHistoryItemVo) { return 'pending' } -/** 百分比:有 total 按已落库商品数算(封顶 99 直到服务端落 SUCCESS);没有 total 不编造分母。 */ +/** 已采计数口径:``rowCount`` 是「已落京东数据库」的真值,``itemsReceived`` 只是服务端 + * 已收下的分片行数——分片被拒/回传失败时后者低估(34959 实录:8 行已落库、分片回传 + * 500 ⇒ itemsReceived=0,卡片 extraLines 显示「已采集 8 个商品」而进度行显示 0, + * 同屏自相矛盾)。进度取两者大者。 */ +function collectedCount(item: JdCollectHistoryItemVo) { + return Math.max(item.itemsReceived ?? 0, item.rowCount ?? 0) +} + +/** 百分比:有 total 按已落库商品数算(封顶 99 直到服务端落 SUCCESS);没有 total 不编造分母。 + * 分母来自服务端游标 cursor.total——客户端在页面级店内分类筛选生效时会写真分母 + * (2026-11-19 起),行级过滤兜底时仍记 0 ⇒ 走无分母口径只报行数。 */ function progressPercent(item: JdCollectHistoryItemVo) { const status = normalizeTaskStatus(item) if (status === 'SUCCESS') return 100 const total = typeof item.total === 'number' && item.total > 0 ? item.total : null if (!total) return 0 - const done = Math.min(item.itemsReceived ?? 0, total) + const done = Math.min(collectedCount(item), total) return Math.max(0, Math.min(99, Math.round((done * 100) / total))) } @@ -298,7 +308,7 @@ function progressPercent(item: JdCollectHistoryItemVo) { * countLabel 会顶掉「总进度 X%」那行字,百分比只能随 countLabel 一起出; * 没有 total 保持只报行数,不编造分母(与本页 progressPercent 同一口径)。 */ function progressCountLabel(item: JdCollectHistoryItemVo) { - const received = item.itemsReceived ?? item.rowCount ?? 0 + const received = collectedCount(item) const total = typeof item.total === 'number' && item.total > 0 ? item.total : null if (!total) return `已采集 ${received} 个商品` return `已采集 ${received}/${total} 个商品(${progressPercent(item)}%)` diff --git a/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts b/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts index 1e8e5ce42..753dbb271 100644 --- a/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts +++ b/frontend-vue/tests/mount/jd-collect-progress.mount.test.ts @@ -242,6 +242,35 @@ describe('获取店铺数据:一键采集 + 任务面板', () => { expect(w.find('.file-progress-bar').attributes('style')).toContain('width: 0%') }) + it('分片被拒时进度行以落库 rowCount 为准(itemsReceived 低估不再与行数行自相矛盾)', async () => { + // 34959 实录(2026-11-19):8 行已落京东数据库、分片回传 500 ⇒ 服务端 + // itemsReceived=0、rowCount=8,extraLines 显示「已采集 8 个商品」而进度行显示 0。 + api.fetchJdCollectTaskProgressBatch.mockResolvedValue( + batchOf(historyItem({ total: 8, itemsReceived: 0, rowCount: 8 })), + ) + const w = await mountPage() + await startCollect(w) + await flushPromises() + + const meta = w.find('.file-progress-meta') + expect(meta.text()).toContain('已采集 8/8 个商品(99%)') + expect(meta.text()).not.toContain('已采集 0 个') + // 已落库 8/8:条形按 99% 封顶(SUCCESS 才满格) + expect(w.find('.file-progress-bar').attributes('style')).toContain('width: 99%') + }) + + it('没有分母且分片被拒时已采行数也取 rowCount 真值', async () => { + api.fetchJdCollectTaskProgressBatch.mockResolvedValue( + batchOf(historyItem({ total: null, page: null, itemsReceived: 0, rowCount: 8 })), + ) + const w = await mountPage() + await startCollect(w) + await flushPromises() + + expect(w.find('.file-progress-meta').text()).toContain('已采集 8 个商品') + expect(w.find('.file-progress-meta').text()).not.toContain('已采集 0 个') + }) + it('SUCCESS 终态:状态徽章落「获取完成」、进度满格,且从轮询中收手', async () => { const w = await mountPage() await startCollect(w)