feat(京东上架): 选分类=整分类上架+多店勾选不再整单拒(2026-11-26 晚客户口径)

客户口径「商品信息不要显示,选分类上架就行」「去掉一次只能发一家店的约束」:

- 后端 JdPublishTaskService:resolveSingleShop→resolveSourceShops(多店不整单判死);
  applyTargetShop 四档——没带目标店且多店仍拒(老页面/老客户端 fail-closed),
  带目标店时异店或多店一律 NEW;多店任务级来源店不钉死(明细行各带来源店快照)
- 用户端:商品勾选列表/分页器下线,选中分类自动分页拉全整分类商品纳入上架集
  (终止按累计行数对撞 total,不按本页满不满判);multi 档带 target=与 cross 同档
  (协议≥4+琥珀人工确认),未检测=先点检测;建单目标店透传
- 台账:catch-silence blocks 338→339(loadProducts 拉取失败有红色出口,非静默)
- 判据:JdPublishTaskServiceTest 多店两支(新增不钉来源/老口径仍拒)+
  jd-publish-shop 纯函数+jd-publish-tab/mount 对齐
This commit is contained in:
2026-11-26 17:59:31 +08:00
parent bddde97285
commit 9092849ae9
9 changed files with 257 additions and 170 deletions
@@ -158,16 +158,18 @@ public class JdPublishTaskService {
"勾选的商品不在你可上架的店铺分类内(跨公司/跨组商品不能上架),请刷新后重新勾选");
}
}
// 来源店铺闸(2026-11-24 客户口径「软件怎么知道要上架哪一家店」):一次任务只允许
// 单店商品——客户端发布前只核对「本机京麦登录店铺」这一家,跨店勾选没法用一家店的
// 登录态发对两家店,属建单即错,当场拒并点名店铺(fail-closed,不静默挑第一家)。
ShopIdentity shop = resolveSingleShop(products);
request.setShopId(shop.id());
request.setShopName(shop.name());
// 来源店铺闸(2026-11-24 客户口径「软件怎么知道要上架哪一家店」;2026-11-26 晚客户
// 口径「去掉这个约束」):多店勾选不再整单拒——多店只能整单走「新增商品」(目标店=
// 京麦当前登录店),任务级来源店铺不钉死(明细行仍各带自己的来源店快照);
// 单店行为逐字不变。没带目标店的老页面/老客户端仍按旧语义判,多店即拒(fail-closed)。
List<ShopIdentity> sources = resolveSourceShops(products);
ShopIdentity singleShop = sources.size() == 1 ? sources.get(0) : null;
request.setShopId(singleShop == null ? null : singleShop.id());
request.setShopName(singleShop == null ? null : singleShop.name());
// 跨店上架(2026-11-26 客户口径「要跨店」):目标店由用户端从「本机京麦当前登录店」
// 读出后随建单下发。没给=旧语义(同店克隆,行为与 V218 之前逐字一致);给了就按
// 店铺身份判模式——同店仍走克隆(京麦带 productId 更稳),异店只能走「新增商品」。
applyTargetShop(request, shop, products);
// 店铺身份判模式——同店仍走克隆(京麦带 productId 更稳),异店或多店只能走「新增商品」。
applyTargetShop(request, sources, products);
LocalDateTime now = LocalDateTime.now();
FileTaskEntity task = new FileTaskEntity();
@@ -463,15 +465,16 @@ public class JdPublishTaskService {
}
/**
* 一次上架只允许单店商品:客户端发布前只核对「本机京麦当前登录店铺」这一家,跨店勾选
* 没有任何一家登录态能同时发对两家店 ⇒ 建单即拒并点名店铺(fail-closed)。
* 勾选集里的来源店铺去重清单(2026-11-26 晚客户口径「去掉一次只能发一家店的约束」):
* 多店不再整单拒绝——多店只能整单走「新增商品」,目标店=京麦当前登录店,由
* {@link #applyTargetShop} 判模式;克隆(同店)路径仍只在单店时成立。
*
* <p>判定按「商品行实际带什么」分三档:有 venderId 用 ID 当键;只有店名且该店名在本次
* 勾选里出现过对应 ID 的(同一家店的两种形状)归一到 ID;只剩店名的按名字当键。
* 完全没有店铺标识的旧行不参与判定——那种行本来就没有可核对的锚点,客户端会明确
* 告警「任务未记录来源店铺」,不在这里冒充已核对。</p>
*/
private static ShopIdentity resolveSingleShop(List<JdProductEntity> products) {
private static List<ShopIdentity> resolveSourceShops(List<JdProductEntity> products) {
Map<String, String> nameToId = new LinkedHashMap<>();
for (JdProductEntity product : products) {
String id = trimToNull(product.getShopId());
@@ -498,17 +501,12 @@ public class JdPublishTaskService {
keys.add(key);
labelByKey.putIfAbsent(key, name != null ? name : id);
}
if (keys.size() > 1) {
throw new BusinessException(400, "本次勾选的商品来自多个店铺("
+ String.join("、", labelByKey.values())
+ "),一次上架只能发到一家店,请按店铺分开勾选");
List<ShopIdentity> shops = new java.util.ArrayList<>();
for (String key : keys) {
String id = key.startsWith("id:") ? key.substring(3) : null;
shops.add(new ShopIdentity(id, labelByKey.get(key)));
}
if (keys.isEmpty()) {
return new ShopIdentity(null, null);
}
String key = keys.iterator().next();
String id = key.startsWith("id:") ? key.substring(3) : null;
return new ShopIdentity(id, labelByKey.get(key));
return shops;
}
private static String trimToNull(String value) {
@@ -519,27 +517,38 @@ public class JdPublishTaskService {
/**
* 目标店与发布模式归一化写回请求体(铁律 27a 同源:request_json 里存的就是闸门认可的值)。
*
* <p>三档:① 请求没带目标店 ⇒ 旧语义,目标店=来源店、模式 CLONE(V218 之前建的任务
* 与老页面提交逐字不变,客户端仍按来源店核对);② 带的店铺与来源店同一家 ⇒ CLONE
* (有 venderId 按 ID 比,只剩店名的按店名比——同一家店的两种形状);③ 异店 ⇒ NEW,
* 且勾选商品必须有类目路径:新增路径靠末级类目名在目标店授权树里定位 {@code cateList},
* <p>四档:① 请求没带目标店且勾选为单店/无店铺标识 ⇒ 旧语义,目标店=来源店、模式 CLONE
* (V218 之前建的任务与老页面提交逐字不变,客户端仍按来源店核对);② 没带目标店但勾选
* 跨了多家店 ⇒ 老页面/老客户端没有「在京麦登录店整单新增」的概念,仍拒并点名店铺;
* ③ 带的店铺与唯一来源店同一家 ⇒ CLONE(有 venderId 按 ID 比,只剩店名的按店名比——
* 同一家店的两种形状);④ 异店<b>或多店</b> ⇒ NEW(2026-11-26 晚客户口径「去掉这个约束」:
* 多店商品整单在京麦当前登录店以「新增商品」新建),且勾选商品必须有类目路径:
* 新增路径靠末级类目名在目标店授权树里定位 {@code cateList},
* 没有类目路径的商品必然行级失败,建单即点名拒绝(脏输入不进任务)。</p>
*/
private static void applyTargetShop(JdPublishTaskCreateRequest request, ShopIdentity source,
private static void applyTargetShop(JdPublishTaskCreateRequest request, List<ShopIdentity> sources,
List<JdProductEntity> products) {
String targetId = requireShopToken(request.getTargetShopId(), 128, "目标店铺 ID");
String targetName = requireShopToken(request.getTargetShopName(), 255, "目标店铺名");
request.setTargetShopId(targetId);
request.setTargetShopName(targetName);
ShopIdentity source = sources.size() == 1 ? sources.get(0) : null;
if (targetId == null && targetName == null) {
request.setTargetShopId(source.id());
request.setTargetShopName(source.name());
if (sources.size() > 1) {
throw new BusinessException(400, "本次勾选的商品来自多个店铺("
+ String.join("、", sources.stream()
.map(s -> s.name() != null ? s.name() : s.id()).toList())
+ "),多店商品只能整单在京麦当前登录店铺以新增商品方式上架,"
+ "请先在页面点「检测京麦店铺」确认登录店后重新建单(老版本页面/客户端不支持多店)");
}
request.setTargetShopId(source == null ? null : source.id());
request.setTargetShopName(source == null ? null : source.name());
request.setPublishMode(PUBLISH_MODE_CLONE);
return;
}
boolean sameShop = targetId != null && source.id() != null
boolean sameShop = source != null && (targetId != null && source.id() != null
? targetId.equals(source.id())
: targetName != null && source.name() != null && targetName.equals(source.name());
: targetName != null && targetName.equals(source.name()));
if (sameShop) {
request.setPublishMode(PUBLISH_MODE_CLONE);
return;
@@ -508,7 +508,7 @@ class JdPublishTaskServiceTest {
// ---- 来源店铺闸(2026-11-24 客户口径「软件怎么知道要上架哪一家店」)----
@Test
void 跨店勾选建单被拒并点名两家店() {
void 多店勾选不带目标店仍被拒并点名两家店() {
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());
JdProductEntity first = product(101L, 7L, "连衣裙A");
first.setShopId("1001");
@@ -528,6 +528,52 @@ class JdPublishTaskServiceTest {
verify(fileTaskMapper, never()).insert(any(FileTaskEntity.class));
}
/** 多店勾选桩:101 来自花屿巷旗舰店、102 来自家居日用数据库店(2026-11-26 晚「去掉约束」窗)。 */
private void stubMultiShopProducts() {
JdProductEntity first = product(101L, 7L, "连衣裙A");
first.setShopId("1001");
first.setShopName("花屿巷旗舰店");
JdProductEntity second = product(102L, 7L, "连衣裙B");
second.setShopId("2002");
second.setShopName("家居日用数据库店");
when(jdProductMapper.selectBatchIds(List.of(101L, 102L))).thenReturn(List.of(first, second));
stubVisibleGroups(7L, 2L, 11L);
stubAssign(11L, 101L, 102L);
}
@Test
void 多店勾选带目标店整单走新增不钉任务级来源店() {
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());
stubMultiShopProducts();
when(fileTaskMapper.insert(any(FileTaskEntity.class))).thenAnswer(invocation -> {
invocation.getArgument(0, FileTaskEntity.class).setId(34423L);
return 1;
});
when(jdPublishItemMapper.insert(any(JdPublishItemEntity.class))).thenReturn(1);
ArgumentCaptor<JdPublishItemEntity> itemCaptor = ArgumentCaptor.forClass(JdPublishItemEntity.class);
service.createTask(crossRequest(), null);
ArgumentCaptor<FileTaskEntity> taskCaptor = ArgumentCaptor.forClass(FileTaskEntity.class);
verify(fileTaskMapper).insert(taskCaptor.capture());
assertThat(taskCaptor.getValue().getRequestJson())
.as("多店=整单在京麦登录店新增:模式 NEW、目标店照旧归一;"
+ "任务级来源店没有唯一答案,不静默挑第一家")
.contains("\"publishMode\":\"NEW\"")
.contains("\"targetShopId\":\"21248199\"")
.doesNotContain("\"shopId\":\"1001\"")
.doesNotContain("\"shopId\":\"2002\"");
verify(jdPublishItemMapper, org.mockito.Mockito.times(2)).insert(itemCaptor.capture());
assertThat(itemCaptor.getAllValues()).allSatisfy(item -> {
assertThat(item.getPublishMode()).isEqualTo("NEW");
assertThat(item.getTargetShopId()).isEqualTo("21248199");
});
assertThat(itemCaptor.getAllValues())
.as("明细行仍各带自己的来源店快照(回传与排查按行归因)")
.extracting(JdPublishItemEntity::getShopId)
.containsExactlyInAnyOrder("1001", "2002");
}
@Test
void 建单把来源店铺钉进载荷与推送载荷() {
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());