feat(jd-collect): 建单页按京麦店内分类多选采集

客户口径「类目不需要只要分类」「做成多选的」:采集建单页下线类目级联与平台分组,
换京麦「店内分类」快照多选(getShopCategoryList 2026-11-16 取证 9 个,见
ops docs/jd-collect-api-contract.md §2.6)。建单请求体/页面推送/兜底拉取三处同键
shopCategoryNames+shopCategoryIds(label+id 双键,行级填充形状未取证,客户端任一
命中即命中);categoryPaths 标 @Deprecated 仅历史行兼容。超长归一化文案泛化为
normalizeStringSelection;历史行 VO 带回双键供重试/继续同源。
删除建单页唯一消费方的死件:JdCategoryCascader.vue/jd-category-tree.ts/其测试
(后管另有在用副本,不受影响)。

判据:JdCollectTaskServiceTest 三例(双键归一化/空白归 null/51 个拒)+
JdTaskPullSpiImplTest 七键载荷透传;前端 jd-collect-tab/jd-shop-category/mount
三支(快照消费、双键同链、绊线:级联组件与分组接口不得回流建单页)。
可读棘轮:JdCollectTab.vue 804→786 行(同款返回按钮 CSS 合并、死 .download 类删除)。
客户端侧(app_client jd_base 行级过滤)同窗另一仓提交。
This commit is contained in:
2026-11-16 20:14:40 +08:00
parent 61c361222d
commit e621deea58
16 changed files with 435 additions and 855 deletions
@@ -31,6 +31,25 @@ public class JdCollectTaskCreateRequest {
* 要采集的京麦末级类目名(多选,客户端按行 {@code categoryPath} 等值过滤,只对命中商品
* 开详情采集);null/空=全店采集。服务端建单口归一化(trim/去空/去重)后写进
* {@code request_json},与派发载荷、客户端过滤同源。
*
* @deprecated 2026-11-16 建单页类目级联已下线(客户口径「类目不需要只要分类」),UI 不再
* 产生该值;字段保留只为兼容已发版页面的历史行/在途任务(重试链从 request_json 回读)。
*/
@Deprecated
private List<String> categoryPaths;
/**
* 要采集的京麦「店内分类」名(2026-11-16 取证后新增,客户口径「选京麦的内部分类去采集」):
* 多选 {@code ShopCategoryReadViewService.getShopCategoryList} 的 {@code label};客户端按行
* {@code shopCategorys/shopCategoryPath/groupId} 等值过滤(任一键命中即命中)。null/空=全店采集。
* 服务端建单口归一化后写进 {@code request_json},与派发载荷、客户端过滤三处同键。
*/
private List<String> shopCategoryNames;
/**
* 要采集的京麦「店内分类」id(与 {@link #shopCategoryNames} 同一多选的 {@code value} 集)。
* 行级 {@code shopCategorys} 填充形状未取证(可能是 id 数组也可能是对象),双键同发任一
* 命中即命中;null/空=无 id 维度过滤。
*/
private List<String> shopCategoryIds;
}
@@ -43,9 +43,17 @@ public class JdCollectHistoryItemVo {
private List<String> listTabs;
@Schema(description = "建单时选择的采集类目(京麦末级类目名多选;空=全店采集)。"
+ "「继续/重试」从历史行重建推送载荷时同源带回")
+ "「继续/重试」从历史行重建推送载荷时同源带回。2026-11-16 建单页类目级联下线,"
+ "仅历史行/在途任务兼容")
private List<String> categoryPaths;
@Schema(description = "建单时选择的京麦店内分类名(多选;空=全店采集)。"
+ "「继续/重试」从历史行重建推送载荷时同源带回")
private List<String> shopCategoryNames;
@Schema(description = "建单时选择的京麦店内分类 id(与 shopCategoryNames 同一多选的 value 集)")
private List<String> shopCategoryIds;
@Schema(description = "已落京东数据库的商品行数(biz_jd_product 按 task_id 计数)", example = "1407")
private Integer rowCount;
@@ -165,6 +165,9 @@ public class JdCollectBoardService {
// 类目随建单载荷同源带回:重试/继续时页面从历史行重建推送载荷,缺了它
// 客户端会按全店采集跑(兜底拉取路径读 request_json 不受影响)。
item.setCategoryPaths(request.getCategoryPaths());
// 店内分类双键同源带回(2026-11-16):label 与 id 都带,客户端任一键命中即命中。
item.setShopCategoryNames(request.getShopCategoryNames());
item.setShopCategoryIds(request.getShopCategoryIds());
}
item.setRowCount(rowCount == null ? 0 : rowCount);
fillProgress(item, task, scope);
@@ -156,36 +156,39 @@ public class JdCollectTaskService {
if (request.getMaxProducts() != null && request.getMaxProducts() < 0) {
throw new BusinessException("采集范围上限不能为负数");
}
// 类目归一化写回请求体:request_json 里的值必须就是闸门认可的值(铁律 27a 同源),
// 类目/分类归一化写回请求体:request_json 里的值必须就是闸门认可的值(铁律 27a 同源),
// 派发载荷与客户端过滤都从这里读,不再各归各的。
request.setCategoryPaths(normalizeCategoryPaths(request.getCategoryPaths()));
request.setCategoryPaths(normalizeStringSelection(request.getCategoryPaths(), "采集类目"));
request.setShopCategoryNames(normalizeStringSelection(request.getShopCategoryNames(), "采集分类"));
request.setShopCategoryIds(normalizeStringSelection(request.getShopCategoryIds(), "采集分类ID"));
}
/**
* 类目多选归一化:trim/去空/保序去重;全空白归 null(=不过滤,全店采集)。
* 多选值归一化:trim/去空/保序去重;全空白归 null(=不过滤,全店采集)。
* 超限当场点名拒绝(建单口必须拦注定失败的输入),不静默截断。
* {@code label} 进拒绝文案(类目/分类两条链共用同一上限常量)。
*/
private List<String> normalizeCategoryPaths(List<String> categoryPaths) {
if (categoryPaths == null || categoryPaths.isEmpty()) {
private List<String> normalizeStringSelection(List<String> raw, String label) {
if (raw == null || raw.isEmpty()) {
return null;
}
Set<String> normalized = new java.util.LinkedHashSet<>();
for (String raw : categoryPaths) {
if (raw == null) {
for (String item : raw) {
if (item == null) {
continue;
}
String path = raw.trim();
String path = item.trim();
if (path.isEmpty()) {
continue;
}
if (path.length() > MAX_CATEGORY_PATH_LENGTH) {
throw new BusinessException("采集类目名过长(上限 " + MAX_CATEGORY_PATH_LENGTH
throw new BusinessException(label + "名过长(上限 " + MAX_CATEGORY_PATH_LENGTH
+ " 字): " + path.substring(0, 50) + "…");
}
normalized.add(path);
}
if (normalized.size() > MAX_CATEGORY_PATHS) {
throw new BusinessException("采集类目最多选 " + MAX_CATEGORY_PATHS + " 个,当前 "
throw new BusinessException(label + "最多选 " + MAX_CATEGORY_PATHS + " 个,当前 "
+ normalized.size() + " 个");
}
return normalized.isEmpty() ? null : List.copyOf(normalized);
@@ -17,9 +17,10 @@ import java.util.Map;
* <p>页面推送缺失(只建单没推送 / 推送前关页面 / 纯浏览器打开)时任务会停在 PENDING,
* {@code TaskClientPullService} 认领后由本实现组装可直接入队的载荷。{@code data} 的键集
* 与客户端 {@code jd_base.process_task} 的读取契约同键({@code taskId / shopName /
* listTabs / maxProducts / categoryPaths},{@code QUEUE_TYPE} 与客户端
* {@code amazon.jd.jd_base.QUEUE_TYPE} 同值 {@code jd-shop-collect-run})——两处任意一处
* 漂移,兜底拉下来的任务客户端不识别(categoryPaths 客户端读不到=不过滤,全店采集)。</p>
* listTabs / maxProducts / categoryPaths / shopCategoryNames / shopCategoryIds},
* {@code QUEUE_TYPE} 与客户端 {@code amazon.jd.jd_base.QUEUE_TYPE} 同值
* {@code jd-shop-collect-run})——两处任意一处漂移,兜底拉下来的任务客户端不识别
* (categoryPaths/shopCategory* 客户端读不到=不过滤,全店采集)。</p>
*
* <p>shopName/listTabs/maxProducts 从建单载荷({@code request_json})回读,与页面推送
* 同源;载荷解析失败按 SPI 语义返回 null(调用方会把任务标失败并回写原因),不静默出空载荷。</p>
@@ -50,9 +51,16 @@ public class JdTaskPullSpiImpl implements ClientTaskPullSpi {
// 缺省放空列表(不是 null):键集稳定,客户端读空集合=不过滤,语义与缺键一致。
data.put("categoryPaths", create.getCategoryPaths() == null
? List.of() : create.getCategoryPaths());
log.info("[jd-collect] 兜底载荷已组装 taskId={} shopName={} tabs={} categories={}",
// 店内分类双键(2026-11-16):label 与 value(id) 同发,行级填充形状未取证(可能是
// id 数组也可能是对象),客户端任一键命中即命中——只发一个键会让另一形状全空。
data.put("shopCategoryNames", create.getShopCategoryNames() == null
? List.of() : create.getShopCategoryNames());
data.put("shopCategoryIds", create.getShopCategoryIds() == null
? List.of() : create.getShopCategoryIds());
log.info("[jd-collect] 兜底载荷已组装 taskId={} shopName={} tabs={} categories={} shopCategories={}",
task.getId(), create.getShopName(), create.getListTabs(),
create.getCategoryPaths() == null ? 0 : create.getCategoryPaths().size());
create.getCategoryPaths() == null ? 0 : create.getCategoryPaths().size(),
create.getShopCategoryNames() == null ? 0 : create.getShopCategoryNames().size());
return Map.of("type", QUEUE_TYPE, "data", data);
}
}
@@ -162,4 +162,65 @@ class JdCollectTaskServiceTest {
assertThat(stored.getCategoryPaths())
.as("全空白类目归 null=全店采集(既有行为,不因新参数收紧)").isNull();
}
@Test
void 店内分类双键归一化后落requestJson() throws Exception {
when(fileTaskMapper.insert(any(FileTaskEntity.class))).thenAnswer(invocation -> {
invocation.getArgument(0, FileTaskEntity.class).setId(33893L);
return 1;
});
JdCollectTaskCreateRequest request = validRequest();
// 2026-11-16 店内分类双键(label + value/id):与类目同一归一化出口(trim/去空/保序去重)。
request.setShopCategoryNames(new java.util.ArrayList<>(java.util.Arrays.asList(
" 工作制服 ", "拉丁舞服", "工作制服", " ")));
request.setShopCategoryIds(new java.util.ArrayList<>(java.util.Arrays.asList(
" 1024347567 ", "1024347572", "1024347567")));
service.createTask(request, "device-abc");
ArgumentCaptor<FileTaskEntity> taskCaptor = ArgumentCaptor.forClass(FileTaskEntity.class);
verify(fileTaskMapper).insert(taskCaptor.capture());
JdCollectTaskCreateRequest stored = new ObjectMapper().readValue(
taskCaptor.getValue().getRequestJson(), JdCollectTaskCreateRequest.class);
assertThat(stored.getShopCategoryNames())
.as("request_json 里的店内分类名=归一化后的值(铁律 27a 同源)")
.containsExactly("工作制服", "拉丁舞服");
assertThat(stored.getShopCategoryIds()).containsExactly("1024347567", "1024347572");
}
@Test
void 店内分类全空白视为不过滤() throws Exception {
when(fileTaskMapper.insert(any(FileTaskEntity.class))).thenAnswer(invocation -> {
invocation.getArgument(0, FileTaskEntity.class).setId(33894L);
return 1;
});
JdCollectTaskCreateRequest request = validRequest();
request.setShopCategoryNames(new java.util.ArrayList<>(java.util.Arrays.asList(" ", "")));
request.setShopCategoryIds(new java.util.ArrayList<>(java.util.Arrays.asList(" ", "")));
service.createTask(request, "device-abc");
ArgumentCaptor<FileTaskEntity> taskCaptor = ArgumentCaptor.forClass(FileTaskEntity.class);
verify(fileTaskMapper).insert(taskCaptor.capture());
JdCollectTaskCreateRequest stored = new ObjectMapper().readValue(
taskCaptor.getValue().getRequestJson(), JdCollectTaskCreateRequest.class);
assertThat(stored.getShopCategoryNames())
.as("全空白分类归 null=全店采集(与类目同口径)").isNull();
assertThat(stored.getShopCategoryIds()).isNull();
}
@Test
void 超过店内分类上限建单被拒并点名() {
JdCollectTaskCreateRequest request = validRequest();
java.util.List<String> tooMany = new java.util.ArrayList<>();
for (int i = 0; i < 51; i++) {
tooMany.add("分类" + i);
}
request.setShopCategoryNames(tooMany);
assertThatThrownBy(() -> service.createTask(request, null))
.isInstanceOf(BusinessException.class)
.hasMessageContaining("采集分类最多选 50 个");
verify(fileTaskMapper, never()).insert(any(FileTaskEntity.class));
}
}
@@ -71,10 +71,16 @@ class JdTaskPullSpiImplTest {
assertThat(data.get("categoryPaths"))
.as("建单没选类目时派空列表(键集稳定,客户端读空=不过滤全店采集)")
.isEqualTo(List.of());
// 客户端 process_task 只读这五键:多键无害,缺键即空跑——所以逐键钉
assertThat(data.get("shopCategoryNames"))
.as("建单没选店内分类时派空列表(2026-11-16 双键契约,同 categoryPaths 口径)")
.isEqualTo(List.of());
assertThat(data.get("shopCategoryIds")).isEqualTo(List.of());
// 客户端 process_task 只读这七键:多键无害,缺键即空跑——所以逐键钉
assertThat(data.keySet())
.as("data 键集与客户端 jd_base.process_task 读取契约同键(taskId/shopName/listTabs/maxProducts/categoryPaths)")
.containsExactlyInAnyOrder("taskId", "shopName", "listTabs", "maxProducts", "categoryPaths");
.as("data 键集与客户端 jd_base.process_task 读取契约同键(taskId/shopName/listTabs/"
+ "maxProducts/categoryPaths/shopCategoryNames/shopCategoryIds)")
.containsExactlyInAnyOrder("taskId", "shopName", "listTabs", "maxProducts",
"categoryPaths", "shopCategoryNames", "shopCategoryIds");
}
@Test
@@ -97,6 +103,31 @@ class JdTaskPullSpiImplTest {
.isEqualTo(List.of("女装", "男装"));
}
@Test
void 店内分类双键随载荷透传客户端() throws Exception {
FileTaskEntity withShopCategories = task();
withShopCategories.setRequestJson("{\"userId\":7,\"shopName\":\"测试旗舰店\","
+ "\"listTabs\":[\"ONSALE\"],\"maxProducts\":0,"
+ "\"shopCategoryNames\":[\"工作制服\",\"拉丁舞服\"],"
+ "\"shopCategoryIds\":[\"1024347567\",\"1024347572\"]}");
when(collectTaskService.readCreateRequest(any(FileTaskEntity.class)))
.thenAnswer(invocation -> {
FileTaskEntity t = invocation.getArgument(0);
return new ObjectMapper().readValue(t.getRequestJson(), JdCollectTaskCreateRequest.class);
});
Map<String, Object> payload = spi.buildQueuePayload(withShopCategories);
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) payload.get("data");
assertThat(data.get("shopCategoryNames"))
.as("店内分类 label 原样透传(客户端按行 shopCategorys/shopCategoryPath 等值过滤)")
.isEqualTo(List.of("工作制服", "拉丁舞服"));
assertThat(data.get("shopCategoryIds"))
.as("店内分类 id 原样透传(行级填充形状未取证,双键同发任一命中即命中)")
.isEqualTo(List.of("1024347567", "1024347572"));
}
@Test
void 建单载荷缺失按SPI语义返回异常路径而非空载荷() {
FileTaskEntity broken = task();