feat(京东发布): 选完分类即可建单——多店未检测按京麦当前登录店新增上架

客户口径「不要限制,就是可以上架到任何店,选完分类就行了」:
- 前端:shopGuardBlocks 多店未检测不再拦;挂载静默自动检测一次;删「我已确认」checkbox;
  检测不到登录店时建单带 targetFromLogin=true(不带 target 键)
- 后端:applyTargetShop 加第⓪档(flag+无目标→NEW(null target),类目路径必填闸
  抽为 requireCategoriesForNew 两档共用);老前端不发 flag,四档逐字不变 fail-closed
- 客户端协议≥4 投递闸不动;单店未检测仍走 CLONE+运行时核对(语义不变)

判据:前端纯函数 18/18+mount 34/34(反向红绿);后端 JdPublishTaskServiceTest
32/32(反向红绿);可读基线两条点名(JdPublishTaskService 880→896、
JdPublishTab.vue 1134→1039 缩);catch/PageDefaults/IdentityOutlet 棘轮全绿
This commit is contained in:
2026-11-28 02:21:31 +08:00
parent 2ab740c529
commit 57c717f10b
8 changed files with 241 additions and 69 deletions
@@ -57,6 +57,17 @@ public class JdPublishTaskCreateRequest {
/** 目标店铺名(与 {@link #targetShopId} 配对;ID 缺失时按店名核对,失败文案点名用)。 */
private String targetShopName;
/**
* 目标店=京麦当前登录店、建单时不钉(2026-11-28 客户口径「不要限制,选完分类就建单」)。
*
* <p>用户端在「多店勾选且京麦登录店没检测到」时置真(前端 detectShop 静默档失败即此形状):
* 服务端照旧落 {@code publishMode=NEW} 但 {@code targetShopId/targetShopName} 留空,
* 客户端 {@code verify_shop} 对未钉目标店只 WARNING 跳过核对、按京麦当前登录店发布并落日志。
* 仅在没带 targetShopId/targetShopName 时有意义;老前端不发送该键(Spring 忽略未知字段,
* 行为与 5.1.3 逐字一致),多店未检测的老页面仍走 fail-closed 400。</p>
*/
private Boolean targetFromLogin;
/**
* 发布模式(服务端按来源店/目标店判定后回填,请求体自带值一律被覆盖):
* {@code CLONE}=同店克隆(京麦 publishType=8,带本店源 productId);
@@ -517,14 +517,17 @@ public class JdPublishTaskService {
/**
* 目标店与发布模式归一化写回请求体(铁律 27a 同源:request_json 里存的就是闸门认可的值)。
*
* <p>四档:① 请求没带目标店且勾选为单店/无店铺标识 ⇒ 旧语义,目标店=来源店、模式 CLONE
* <p>五档:⓪ 请求带 {@code targetFromLogin=true} 且没带目标店 ⇒ 2026-11-28 客户口径
* 「不要限制,选完分类就建单」:用户端多店勾选且京麦登录店没检测到时发送,落
* {@code NEW} 但不钉目标店——客户端 {@code verify_shop} 对未钉目标店只 WARNING 跳过
* 核对、按京麦当前登录店发布。新增路径必须有类目路径(靠末级类目名在授权树里定位
* {@code cateList}),没有类目路径的商品必然行级失败,建单即点名拒绝(脏输入不进任务)。
* ① 请求没带目标店且勾选为单店/无店铺标识 ⇒ 旧语义,目标店=来源店、模式 CLONE
* (V218 之前建的任务与老页面提交逐字不变,客户端仍按来源店核对);② 没带目标店但勾选
* 跨了多家店 ⇒ 老页面/老客户端没有「在京麦登录店整单新增」的概念,仍拒并点名店铺;
* ③ 带的店铺与唯一来源店同一家 ⇒ CLONE(有 venderId 按 ID 比,只剩店名的按店名比——
* 同一家店的两种形状);④ 异店<b>或多店</b> ⇒ NEW(2026-11-26 晚客户口径「去掉这个约束」:
* 多店商品整单在京麦当前登录店以「新增商品」新建),且勾选商品必须有类目路径:
* 新增路径靠末级类目名在目标店授权树里定位 {@code cateList},
* 没有类目路径的商品必然行级失败,建单即点名拒绝(脏输入不进任务)。</p>
* 多店商品整单在京麦当前登录店以「新增商品」新建),类目路径要求同⓪。</p>
*/
private static void applyTargetShop(JdPublishTaskCreateRequest request, List<ShopIdentity> sources,
List<JdProductEntity> products) {
@@ -533,6 +536,11 @@ public class JdPublishTaskService {
request.setTargetShopId(targetId);
request.setTargetShopName(targetName);
ShopIdentity source = sources.size() == 1 ? sources.get(0) : null;
if (targetId == null && targetName == null && Boolean.TRUE.equals(request.getTargetFromLogin())) {
requireCategoriesForNew(products);
request.setPublishMode(PUBLISH_MODE_NEW);
return;
}
if (targetId == null && targetName == null) {
if (sources.size() > 1) {
throw new BusinessException(400, "本次勾选的商品来自多个店铺("
@@ -553,6 +561,15 @@ public class JdPublishTaskService {
request.setPublishMode(PUBLISH_MODE_CLONE);
return;
}
requireCategoriesForNew(products);
request.setPublishMode(PUBLISH_MODE_NEW);
}
/**
* 新增商品路径(⓪/④ 两档)的类目路径硬闸:跨店匹配靠末级类目名在目标店授权树里定位,
* 没有类目路径的商品必然行级失败——建单即点名拒绝,脏输入不进任务。
*/
private static void requireCategoriesForNew(List<JdProductEntity> products) {
long missingCategory = products.stream()
.filter(product -> trimToNull(product.getCategoryPath()) == null)
.count();
@@ -560,7 +577,6 @@ public class JdPublishTaskService {
throw new BusinessException(400, "跨店上架需要商品类目路径:勾选里有 " + missingCategory
+ " 个商品没有类目信息,无法在目标店匹配类目,请重新采集后再上架");
}
request.setPublishMode(PUBLISH_MODE_NEW);
}
/** 店铺标识列的形状校验(空串按缺省;超长/控制字符当场 400 点名)。 */
@@ -574,6 +574,81 @@ class JdPublishTaskServiceTest {
.containsExactlyInAnyOrder("1001", "2002");
}
@Test
void 多店未检测带targetFromLogin落NEW且不钉目标店() {
// 2026-11-28 客户口径「不要限制,选完分类就建单」:用户端多店勾选且京麦登录店没检测到
// 时带 targetFromLogin——服务端照旧落 NEW 但不钉目标店,客户端按京麦当前登录店发布。
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());
stubMultiShopProducts();
when(fileTaskMapper.insert(any(FileTaskEntity.class))).thenAnswer(invocation -> {
invocation.getArgument(0, FileTaskEntity.class).setId(34424L);
return 1;
});
when(jdPublishItemMapper.insert(any(JdPublishItemEntity.class))).thenReturn(1);
JdPublishTaskCreateRequest request = validRequest(7L);
request.setTargetFromLogin(Boolean.TRUE);
service.createTask(request, null);
ArgumentCaptor<FileTaskEntity> taskCaptor = ArgumentCaptor.forClass(FileTaskEntity.class);
verify(fileTaskMapper).insert(taskCaptor.capture());
assertThat(taskCaptor.getValue().getRequestJson())
.as("targetFromLogin=NEW 但不钉目标店:request_json 里目标店两键都没有值")
.contains("\"publishMode\":\"NEW\"")
.doesNotContain("\"targetShopId\":\"")
.doesNotContain("\"targetShopName\":\"");
ArgumentCaptor<JdPublishItemEntity> itemCaptor = ArgumentCaptor.forClass(JdPublishItemEntity.class);
verify(jdPublishItemMapper, org.mockito.Mockito.times(2)).insert(itemCaptor.capture());
assertThat(itemCaptor.getAllValues()).allSatisfy(item -> {
assertThat(item.getPublishMode()).isEqualTo("NEW");
assertThat(item.getTargetShopId()).isNull();
});
}
@Test
void targetFromLogin带目标店仍按原档判定() {
// 旗标只在「没带目标店」时生效:带了目标店就走既有③/④档,多店+目标店=NEW 钉店。
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());
stubMultiShopProducts();
when(fileTaskMapper.insert(any(FileTaskEntity.class))).thenAnswer(invocation -> {
invocation.getArgument(0, FileTaskEntity.class).setId(34425L);
return 1;
});
when(jdPublishItemMapper.insert(any(JdPublishItemEntity.class))).thenReturn(1);
JdPublishTaskCreateRequest request = crossRequest();
request.setTargetFromLogin(Boolean.TRUE);
service.createTask(request, null);
ArgumentCaptor<FileTaskEntity> taskCaptor = ArgumentCaptor.forClass(FileTaskEntity.class);
verify(fileTaskMapper).insert(taskCaptor.capture());
assertThat(taskCaptor.getValue().getRequestJson())
.contains("\"publishMode\":\"NEW\"")
.contains("\"targetShopId\":\"21248199\"");
}
@Test
void targetFromLogin缺类目路径仍当场拒() {
// 类目路径硬闸在⓪档同样生效:新增路径靠末级类目名在授权树里定位,缺类目必行级失败。
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());
stubVisibleGroups(7L, 2L, 11L);
stubAssign(11L, 101L, 102L, 103L);
JdProductEntity noCategory = product(103L, 7L, "连衣裙C");
noCategory.setShopId("3003");
noCategory.setShopName("服装数据库店");
noCategory.setCategoryPath(null);
when(jdProductMapper.selectBatchIds(List.of(101L, 102L, 103L)))
.thenReturn(List.of(product(101L, 7L, "连衣裙A"), product(102L, 7L, "连衣裙B"), noCategory));
JdPublishTaskCreateRequest request = validRequest(7L);
request.setProductIds(List.of(101L, 102L, 103L));
request.setTargetFromLogin(Boolean.TRUE);
assertThatThrownBy(() -> service.createTask(request, null))
.isInstanceOf(BusinessException.class)
.hasMessageContaining("类目路径");
verify(fileTaskMapper, never()).insert(any(FileTaskEntity.class));
}
@Test
void 建单把来源店铺钉进载荷与推送载荷() {
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());