feat(jd-collect): 进度/历史透传轮次游标 shopCatName/shopCatMerged——任务卡显示「正在采集分类」(多轮页码归 1 消歧,2026-11-21 方案 C 客户端侧配套)

客户端多选店内分类改逐分类轮次采集后,游标新增两键。HistoryItemVo/ProgressVo 加字段(注释与建单多选集合 shopCategoryNames 明确区分:这是「当前正在采的那一个」);BoardService#fillProgress 与 TaskService#queryProgress 读侧白名单逐键取(shopCatMerged 宽松布尔:true 字符串也认)。前端 toJdTaskView extraLines 加「正在采集分类:X(合并兜底时缀 等(页面筛选未生效,兜底翻页中))」。判据:JdCollectBoardServiceTest 游标键透传两支(selectList mock 必须 ArrayList 包 List.of——history 服务原地排序,不可变列表打爆)+jd-collect-progress.mount.test.ts 两支+jd-collect-tab.test.ts 源码绊线;门禁 mvn -o test-compile rc0+目标 49 绿、vue-tsc rc0、node --test 15 绿、vitest 24 绿。
This commit is contained in:
2026-11-21 12:07:05 +08:00
parent a2aeae9974
commit c59296da72
9 changed files with 143 additions and 0 deletions
@@ -69,6 +69,15 @@ public class JdCollectHistoryItemVo {
@Schema(description = "当前采集 Tab(ONSALE/OFFSALE)")
private String listTab;
@Schema(description = "正在采集的京麦店内分类名(客户端逐分类轮次游标 shopCatName;"
+ "与建单多选集合 shopCategoryNames 区分——这是「当前正在采的那一个」。"
+ "多轮页码归 1 时任务卡靠它消歧;非轮次任务为空)")
private String shopCatName;
@Schema(description = "当前轮是否合并兜底(客户端页面级筛选未生效,剩余分类并单轮"
+ "行级过滤采完,游标 shopCatMerged)")
private Boolean shopCatMerged;
@Schema(description = "已收到的分片批次数")
private Integer batches;
@@ -35,6 +35,12 @@ public class JdCollectProgressVo {
/** 当前采集 Tab(ONSALE / OFFSALE)。 */
private String listTab;
/** 正在采集的京麦店内分类名(客户端逐分类轮次游标 shopCatName;非轮次任务为 null)。 */
private String shopCatName;
/** 当前轮是否合并兜底(页面级筛选未生效,剩余分类并单轮行级过滤;游标 shopCatMerged)。 */
private Boolean shopCatMerged;
/** 已收到的分片批次数。 */
private Integer batches;
@@ -206,6 +206,15 @@ public class JdCollectBoardService {
item.setPage(JdScopeStateReader.asNullableInt(cursor.get("page")));
Object tab = cursor.get("tab");
item.setListTab(tab == null ? null : String.valueOf(tab));
// 逐分类轮次游标(2026-11-21 方案 C):shopCatName=当前正在采的那一个店内
// 分类(与建单多选集合 shopCategoryNames 区分),shopCatMerged=该轮合并兜底。
// 值为 null 视为没带(mergeCursor 语义),非轮次任务两键缺省为空。
Object shopCatName = cursor.get("shopCatName");
item.setShopCatName(shopCatName == null ? null : String.valueOf(shopCatName));
Object shopCatMerged = cursor.get("shopCatMerged");
item.setShopCatMerged(shopCatMerged == null ? null
: Boolean.TRUE.equals(shopCatMerged)
|| "true".equalsIgnoreCase(String.valueOf(shopCatMerged)));
item.setBatches(scope.getReceivedChunkCount() == null ? 0 : scope.getReceivedChunkCount());
}
if (scope != null && scope.getUpdatedAt() != null) {
@@ -289,6 +289,13 @@ public class JdCollectTaskService {
vo.setPage(JdScopeStateReader.asNullableInt(cursor.get("page")));
Object tab = cursor.get("tab");
vo.setListTab(tab == null ? null : String.valueOf(tab));
// 逐分类轮次游标(2026-11-21 方案 C),与 JdCollectBoardService#fillProgress 同口径。
Object shopCatName = cursor.get("shopCatName");
vo.setShopCatName(shopCatName == null ? null : String.valueOf(shopCatName));
Object shopCatMerged = cursor.get("shopCatMerged");
vo.setShopCatMerged(shopCatMerged == null ? null
: Boolean.TRUE.equals(shopCatMerged)
|| "true".equalsIgnoreCase(String.valueOf(shopCatMerged)));
vo.setBatches(scope.getReceivedChunkCount() == null ? 0 : scope.getReceivedChunkCount());
if (scope.getUpdatedAt() != null) {
vo.setUpdatedAt(scope.getUpdatedAt());
@@ -149,6 +149,43 @@ class JdCollectBoardServiceTest {
assertThat(vo.getItems().get(1).getTaskStatus()).isEqualTo("FAILED");
}
@Test
void 历史行读游标轮次键_shopCatName与合并兜底() {
FileTaskEntity running = task(34500L, 7L, "RUNNING");
// selectList 返回会被服务端按活跃排序原地改写,必须给可变列表(与上方主查询同因)
when(fileTaskMapper.selectList(any()))
.thenReturn(new java.util.ArrayList<>(List.of(running)));
when(jdProductMapper.selectMaps(any())).thenReturn(List.of(Map.of("task_id", 34500L, "cnt", 8L)));
when(taskScopeStateMapper.selectList(any())).thenReturn(List.of(
scope(34500L, "{\"cursor\":{\"total\":15,\"page\":1,\"shopCatName\":\"B类\","
+ "\"shopCatMerged\":true},\"itemsReceived\":8}", 2)));
var vo = service.history(7L, 50);
JdCollectHistoryItemVo row = vo.getItems().get(0);
assertThat(row.getShopCatName())
.as("游标轮次键=当前正在采的那一个(与建单集合字段 shopCategoryNames 区分)")
.isEqualTo("B类");
assertThat(row.getShopCatMerged()).as("合并兜底标记透传给任务卡展示").isTrue();
assertThat(row.getTotal()).as("轮次模式 total=各已入账轮合计").isEqualTo(15);
}
@Test
void 历史行游标无轮次键_两字段缺省为空() {
FileTaskEntity running = task(34501L, 7L, "RUNNING");
when(fileTaskMapper.selectList(any()))
.thenReturn(new java.util.ArrayList<>(List.of(running)));
when(jdProductMapper.selectMaps(any())).thenReturn(List.of(Map.of("task_id", 34501L, "cnt", 1L)));
when(taskScopeStateMapper.selectList(any())).thenReturn(List.of(
scope(34501L, "{\"cursor\":{\"total\":300,\"page\":3},\"itemsReceived\":1}", 1)));
var vo = service.history(7L, 50);
JdCollectHistoryItemVo row = vo.getItems().get(0);
assertThat(row.getShopCatName()).as("非轮次任务(单选/全店)游标无轮次键").isNull();
assertThat(row.getShopCatMerged()).as("游标没带的键不冒充 FALSE").isNull();
}
@Test
void 批量进度按模块过滤_非本模块任务进missingTaskIds() {
FileTaskEntity jd = task(88L, 7L, "RUNNING");
@@ -345,6 +345,12 @@ function toJdTaskView(item: JdCollectHistoryItemVo): TaskItemView {
...(showProgress && typeof item.page === 'number' && item.page > 0
? [`断点游标:第 ${item.page} 页 · 已回传 ${item.batches ?? 0} 批`]
: []),
// 逐分类轮次游标(2026-11-21 方案 C):多轮采集时页码归 1,靠「正在采集分类」
// 消解「任务重跑了」的歧义;合并兜底轮(页面筛选未生效)明确标注,别让用户
// 以为只采了 shopCatName 这一个分类。
...(showProgress && item.shopCatName
? [`正在采集分类:${item.shopCatName}${item.shopCatMerged ? ' 等(页面筛选未生效,兜底翻页中)' : ''}`]
: []),
...(item.errorMessage ? [`错误:${userNotice(item.errorMessage)}`] : []),
],
progress: showProgress ? { percent: progressPercent(item), countLabel: progressCountLabel(item) } : null,
@@ -33,6 +33,11 @@ export interface JdCollectProgressVo {
total?: number;
page?: number;
listTab?: string;
/** 正在采集的京麦店内分类名(客户端逐分类轮次游标 shopCatName——与建单多选集合
* shopCategoryNames 区分,这是「当前正在采的那一个」;多轮页码归 1 时任务卡靠它消歧) */
shopCatName?: string;
/** 当前轮是否合并兜底(页面级筛选未生效,剩余分类并单轮行级过滤采完) */
shopCatMerged?: boolean;
batches?: number;
message?: string;
updatedAt?: string;
@@ -181,6 +186,11 @@ export interface JdCollectHistoryItemVo {
total?: number;
page?: number;
listTab?: string;
/** 正在采集的京麦店内分类名(客户端逐分类轮次游标 shopCatName——与建单多选集合
* shopCategoryNames 区分,这是「当前正在采的那一个」;多轮页码归 1 时任务卡靠它消歧) */
shopCatName?: string;
/** 当前轮是否合并兜底(页面级筛选未生效,剩余分类并单轮行级过滤采完) */
shopCatMerged?: boolean;
batches?: number;
updatedAt?: string;
createdAt?: string;
+23
View File
@@ -283,3 +283,26 @@ test('采集状态多选:售卖中/已下架可勾选,空选禁止建单', (
assert.ok(body.includes('请至少勾选一个采集状态'),
'空选必须给「至少勾选一个」提示(按钮禁用之外的第二道)')
})
/** 2026-11-21 逐分类轮次采集(方案 C):多选店内分类时客户端逐轮驱动页面级筛选拿真
* 分母,任务卡用游标 shopCatName 显示「正在采集分类」消解多轮页码归 1 的歧义;
* 合并兜底轮(页面筛选未生效)必须明确标注,别让用户以为只采了一个分类。 */
test('任务卡展示轮次游标:正在采集分类 + 合并兜底标注', () => {
const page = readIfExists(
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
'JdCollectTab.vue',
)
const types = readIfExists(
join(process.cwd(), 'src', 'shared', 'api', 'types', 'modules', 'jd-collect.ts'),
'jd-collect.ts',
)
assert.ok(types.includes('shopCatName'), '历史行 VO 必须带轮次游标键 shopCatName')
assert.ok(types.includes('shopCatMerged'), '历史行 VO 必须带合并兜底标记 shopCatMerged')
const toJdTaskView = page.indexOf('function toJdTaskView')
assert.ok(toJdTaskView > 0, 'JdCollectTab.vue 缺 toJdTaskView')
const body = page.slice(toJdTaskView, page.indexOf('// ---- 本模块的状态语义'))
assert.ok(body.includes('正在采集分类:${item.shopCatName}'),
'toJdTaskView 必须在 extraLines 展示「正在采集分类」(页码归 1 消歧)')
assert.ok(body.includes('等(页面筛选未生效,兜底翻页中)'),
'合并兜底轮必须带「页面筛选未生效」标注')
})
@@ -231,6 +231,42 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
expect(w.find('.file-progress-meta').text()).toContain('已采集 30/100 个商品(30%)')
})
it('轮次采集时任务卡片显示「正在采集分类」,页码归 1 不再像重跑(2026-11-21 方案 C)', async () => {
api.fetchJdCollectTaskProgressBatch.mockResolvedValue(
batchOf(historyItem({ total: 15, itemsReceived: 8, rowCount: 8, page: 1,
shopCatName: '礼服/演出服', batches: 2 })),
)
const w = await mountPage()
await startCollect(w)
await flushPromises()
const text = w.find('.task-item').text()
expect(text).toContain('正在采集分类:礼服/演出服')
expect(text).toContain('断点游标:第 1 页')
expect(text).not.toContain('兜底翻页中')
})
it('合并兜底轮标注「页面筛选未生效」;非轮次任务不出现该行', async () => {
api.fetchJdCollectTaskProgressBatch.mockResolvedValue(
batchOf(historyItem({ total: 6, itemsReceived: 4, rowCount: 4, page: 1,
shopCatName: '工作制服', shopCatMerged: true, batches: 1 })),
)
const w = await mountPage()
await startCollect(w)
await flushPromises()
expect(w.find('.task-item').text())
.toContain('正在采集分类:工作制服 等(页面筛选未生效,兜底翻页中)')
// 非轮次任务(游标无 shopCatName):不出现该行,其余文案不受影响
api.fetchJdCollectTaskProgressBatch.mockResolvedValue(
batchOf(historyItem({ total: 300, itemsReceived: 30, rowCount: 30, page: 3, batches: 4 })),
)
const w2 = await mountPage()
await startCollect(w2)
await flushPromises()
expect(w2.find('.task-item').text()).not.toContain('正在采集分类')
})
it('没有分母(total 缺失)时只显示已采集行数,不编造百分比', async () => {
api.fetchJdCollectTaskProgressBatch.mockResolvedValue(
batchOf(historyItem({ total: null, page: null, itemsReceived: 30, rowCount: 30 })),