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 缺失时按店名核对,失败文案点名用)。 */ /** 目标店铺名(与 {@link #targetShopId} 配对;ID 缺失时按店名核对,失败文案点名用)。 */
private String targetShopName; 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); * {@code CLONE}=同店克隆(京麦 publishType=8,带本店源 productId);
@@ -517,14 +517,17 @@ public class JdPublishTaskService {
/** /**
* 目标店与发布模式归一化写回请求体(铁律 27a 同源:request_json 里存的就是闸门认可的值)。 * 目标店与发布模式归一化写回请求体(铁律 27a 同源:request_json 里存的就是闸门认可的值)。
* *
* <p>四档:① 请求没带目标店且勾选为单店/无店铺标识 ⇒ 旧语义,目标店=来源店、模式 CLONE * <p>五档:⓪ 请求带 {@code targetFromLogin=true} 且没带目标店 ⇒ 2026-11-28 客户口径
* 「不要限制,选完分类就建单」:用户端多店勾选且京麦登录店没检测到时发送,落
* {@code NEW} 但不钉目标店——客户端 {@code verify_shop} 对未钉目标店只 WARNING 跳过
* 核对、按京麦当前登录店发布。新增路径必须有类目路径(靠末级类目名在授权树里定位
* {@code cateList}),没有类目路径的商品必然行级失败,建单即点名拒绝(脏输入不进任务)。
* ① 请求没带目标店且勾选为单店/无店铺标识 ⇒ 旧语义,目标店=来源店、模式 CLONE
* (V218 之前建的任务与老页面提交逐字不变,客户端仍按来源店核对);② 没带目标店但勾选 * (V218 之前建的任务与老页面提交逐字不变,客户端仍按来源店核对);② 没带目标店但勾选
* 跨了多家店 ⇒ 老页面/老客户端没有「在京麦登录店整单新增」的概念,仍拒并点名店铺; * 跨了多家店 ⇒ 老页面/老客户端没有「在京麦登录店整单新增」的概念,仍拒并点名店铺;
* ③ 带的店铺与唯一来源店同一家 ⇒ CLONE(有 venderId 按 ID 比,只剩店名的按店名比—— * ③ 带的店铺与唯一来源店同一家 ⇒ CLONE(有 venderId 按 ID 比,只剩店名的按店名比——
* 同一家店的两种形状);④ 异店<b>或多店</b> ⇒ NEW(2026-11-26 晚客户口径「去掉这个约束」: * 同一家店的两种形状);④ 异店<b>或多店</b> ⇒ NEW(2026-11-26 晚客户口径「去掉这个约束」:
* 多店商品整单在京麦当前登录店以「新增商品」新建),且勾选商品必须有类目路径: * 多店商品整单在京麦当前登录店以「新增商品」新建),类目路径要求同⓪。</p>
* 新增路径靠末级类目名在目标店授权树里定位 {@code cateList},
* 没有类目路径的商品必然行级失败,建单即点名拒绝(脏输入不进任务)。</p>
*/ */
private static void applyTargetShop(JdPublishTaskCreateRequest request, List<ShopIdentity> sources, private static void applyTargetShop(JdPublishTaskCreateRequest request, List<ShopIdentity> sources,
List<JdProductEntity> products) { List<JdProductEntity> products) {
@@ -533,6 +536,11 @@ public class JdPublishTaskService {
request.setTargetShopId(targetId); request.setTargetShopId(targetId);
request.setTargetShopName(targetName); request.setTargetShopName(targetName);
ShopIdentity source = sources.size() == 1 ? sources.get(0) : null; 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 (targetId == null && targetName == null) {
if (sources.size() > 1) { if (sources.size() > 1) {
throw new BusinessException(400, "本次勾选的商品来自多个店铺(" throw new BusinessException(400, "本次勾选的商品来自多个店铺("
@@ -553,6 +561,15 @@ public class JdPublishTaskService {
request.setPublishMode(PUBLISH_MODE_CLONE); request.setPublishMode(PUBLISH_MODE_CLONE);
return; return;
} }
requireCategoriesForNew(products);
request.setPublishMode(PUBLISH_MODE_NEW);
}
/**
* 新增商品路径(⓪/④ 两档)的类目路径硬闸:跨店匹配靠末级类目名在目标店授权树里定位,
* 没有类目路径的商品必然行级失败——建单即点名拒绝,脏输入不进任务。
*/
private static void requireCategoriesForNew(List<JdProductEntity> products) {
long missingCategory = products.stream() long missingCategory = products.stream()
.filter(product -> trimToNull(product.getCategoryPath()) == null) .filter(product -> trimToNull(product.getCategoryPath()) == null)
.count(); .count();
@@ -560,7 +577,6 @@ public class JdPublishTaskService {
throw new BusinessException(400, "跨店上架需要商品类目路径:勾选里有 " + missingCategory throw new BusinessException(400, "跨店上架需要商品类目路径:勾选里有 " + missingCategory
+ " 个商品没有类目信息,无法在目标店匹配类目,请重新采集后再上架"); + " 个商品没有类目信息,无法在目标店匹配类目,请重新采集后再上架");
} }
request.setPublishMode(PUBLISH_MODE_NEW);
} }
/** 店铺标识列的形状校验(空串按缺省;超长/控制字符当场 400 点名)。 */ /** 店铺标识列的形状校验(空串按缺省;超长/控制字符当场 400 点名)。 */
@@ -574,6 +574,81 @@ class JdPublishTaskServiceTest {
.containsExactlyInAnyOrder("1001", "2002"); .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 @Test
void 建单把来源店铺钉进载荷与推送载荷() { void 建单把来源店铺钉进载荷与推送载荷() {
when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity()); when(adminUserMapper.selectById(7L)).thenReturn(new AdminUserEntity());
+43 -30
View File
@@ -173,7 +173,10 @@ function isValidBrand(name: string) {
const priceValueMissing = computed(() => priceMode.value !== 'none' && (priceValue.value == null || priceValue.value < 0)) const priceValueMissing = computed(() => priceMode.value !== 'none' && (priceValue.value == null || priceValue.value < 0))
// ---- 本次上架到哪家店(2026-11-24 客户口径「软件怎么知道要上架哪一家店铺」)---- // ---- 本次上架到哪家店(2026-11-24 客户口径「软件怎么知道要上架哪一家店铺」)----
/** 来源店铺=勾选商品行的快照店铺;京麦当前店铺=桥现拉(不缓存、不猜、不自动探测)。 */ /** 来源店铺=勾选商品行的快照店铺;京麦当前店铺=桥现拉(不缓存、不猜)。
* 挂载自动探测一次(2026-11-28 客户口径「不要限制,选完分类就建单」反转了 5.1.1 的
* 「不自动探测」口径):静默档只落说明不弹窗不拦建单,检测不到就按 targetFromLogin
* 建单,由客户端按京麦当前登录店发布。 */
const selectedProductRows = computed(() => Array.from(selectedProducts.value.values())) const selectedProductRows = computed(() => Array.from(selectedProducts.value.values()))
const currentShop = ref<JdShopRef | null>(null) const currentShop = ref<JdShopRef | null>(null)
const detectingShop = ref(false) const detectingShop = ref(false)
@@ -193,9 +196,10 @@ const crossSupported = computed(() => localProtocol.value >= JD_PUBLISH_CROSS_PR
* 多店已检测=同一档(2026-11-26 晚「去掉一次只能发一家店的约束」):整单在京麦登录店新增。 */ * 多店已检测=同一档(2026-11-26 晚「去掉一次只能发一家店的约束」):整单在京麦登录店新增。 */
const usesCrossShop = computed(() => shopGuard.value.state === 'cross' const usesCrossShop = computed(() => shopGuard.value.state === 'cross'
|| (shopGuard.value.state === 'multi' && shopGuard.value.target != null)) || (shopGuard.value.state === 'multi' && shopGuard.value.target != null))
/** 跨店必须人工确认一次(会在目标店新建商品、要过京东审核),勾选或店铺变化即重置。 */ /** 新增商品路径(跨店/多店,含未检测的 targetFromLogin 档)都要协议 ≥4:
const crossConfirmed = ref(false) * 服务端只把 NEW 任务投给 v4+ 客户端,协议不够时建了也永远没人领。 */
watch(shopGuard, () => { crossConfirmed.value = false }) const needsCrossProtocol = computed(() => shopGuard.value.state === 'cross'
|| shopGuard.value.state === 'multi')
async function readPublishProtocol(): Promise<number> { async function readPublishProtocol(): Promise<number> {
try { try {
@@ -240,8 +244,10 @@ async function refreshPublishProtocol() {
* 点「检测当前京麦店铺」:桥现拉京麦首屏(会起客户端专用浏览器,秒级)。 * 点「检测当前京麦店铺」:桥现拉京麦首屏(会起客户端专用浏览器,秒级)。
* 失败按 code 分档——jd_busy 走 amber 说明、jd_login 走自动登录链路(登录成功后自动重测一次)、 * 失败按 code 分档——jd_busy 走 amber 说明、jd_login 走自动登录链路(登录成功后自动重测一次)、
* jd_page/未知走红色错误。返回值只作 `startPublish` 的判断输入,展示通道由本函数自理。 * jd_page/未知走红色错误。返回值只作 `startPublish` 的判断输入,展示通道由本函数自理。
* `silent`(挂载自动探测专用):任何失败只落 amber 说明——不弹京麦登录窗、不写红色错误,
* 检测不到不影响建单(targetFromLogin 兜底)。
*/ */
async function detectShop(options?: { fromAutoLogin?: boolean }) { async function detectShop(options?: { fromAutoLogin?: boolean; silent?: boolean }) {
if (detectingShop.value && !options?.fromAutoLogin) return if (detectingShop.value && !options?.fromAutoLogin) return
shopError.value = '' shopError.value = ''
shopNote.value = '' shopNote.value = ''
@@ -264,8 +270,10 @@ async function detectShop(options?: { fromAutoLogin?: boolean }) {
return return
} }
if (result?.code === 'jd_login') { if (result?.code === 'jd_login') {
if (options?.fromAutoLogin) { if (options?.fromAutoLogin || options?.silent) {
shopError.value = result.error || '京麦未登录(登录态失效)' const hint = result.error || '京麦未登录(登录态失效)'
if (options?.silent) shopNote.value = `京麦未登录,建单将按客户端登录店发布;点「检测京麦店铺」登录后可钉定目标店`
else shopError.value = hint
return return
} }
markJdLoginExpired() markJdLoginExpired()
@@ -285,6 +293,10 @@ async function detectShop(options?: { fromAutoLogin?: boolean }) {
} }
return return
} }
if (options?.silent) {
shopNote.value = '京麦店铺未检测到:建单将按客户端登录店发布,可点「检测京麦店铺」重试'
return
}
shopError.value = result?.error || '检测京麦店铺失败,请稍后重试' shopError.value = result?.error || '检测京麦店铺失败,请稍后重试'
} finally { } finally {
detectingShop.value = false detectingShop.value = false
@@ -292,15 +304,18 @@ async function detectShop(options?: { fromAutoLogin?: boolean }) {
} }
/** /**
* 建单前把店铺核一次:已检测且同店就不再开浏览器;跨店档要本机协议支持(≥4,否则升级提示)。 * 建单前把店铺核一次:已检测就不再开浏览器;单店未检测与多店未检测都补测一轮
* 检测失败(页面结构变更、老客户端、京麦任务在跑)**不**拦创建——最终强拦截在客户端 * (检测到就能钉定目标店,客户端发布前强核对)。检测失败(页面结构变更、老客户端、
* 执行器(先上报标记再中止)与服务端(命中即整单判死),页面这层只负责提前告知。 * 京麦任务在跑)**不**拦创建——单店走克隆+客户端运行时核对,多店走 targetFromLogin
* 按登录店发布;最终强拦截在客户端执行器与服务端,页面这层只负责提前告知。
*/ */
async function ensureShopChecked(): Promise<string> { async function ensureShopChecked(): Promise<string> {
const guard = shopGuard.value const issue = shopGuardMessage(shopGuard.value, crossSupported.value)
const issue = shopGuardMessage(guard, crossSupported.value)
if (issue) return issue if (issue) return issue
if (guard.state !== 'undetected') return '' const guard = shopGuard.value
const undetected = guard.state === 'undetected'
|| (guard.state === 'multi' && !guard.target)
if (!undetected) return ''
await detectShop() await detectShop()
return shopGuardMessage(shopGuard.value, crossSupported.value) return shopGuardMessage(shopGuard.value, crossSupported.value)
} }
@@ -309,7 +324,6 @@ const submitDisabled = computed(() =>
submitting.value submitting.value
|| detectingShop.value || detectingShop.value
|| shopGuardBlocks(shopGuard.value, crossSupported.value) || shopGuardBlocks(shopGuard.value, crossSupported.value)
|| (usesCrossShop.value && !crossConfirmed.value)
|| !selectedGroupId.value || !selectedGroupId.value
|| !selectedProducts.value.size || !selectedProducts.value.size
|| !isValidBrand(targetBrandName.value) || !isValidBrand(targetBrandName.value)
@@ -736,18 +750,20 @@ async function startPublish() {
errorMessage.value = BRAND_UPGRADE_NOTICE errorMessage.value = BRAND_UPGRADE_NOTICE
return return
} }
if (usesCrossShop.value && !crossSupported.value) { if (needsCrossProtocol.value && !crossSupported.value) {
errorMessage.value = CROSS_UPGRADE_NOTICE errorMessage.value = CROSS_UPGRADE_NOTICE
return return
} }
// 店铺核对在建单之前:多店勾选、或本机不支持跨店时一条都不发; // 店铺核对在建单之前:协议不够时一条都不发;未检测档补测一轮(检测到就钉目标店)。
// 异店(跨店)档由用户在上方勾选确认后才允许建单。
const shopIssue = await ensureShopChecked() const shopIssue = await ensureShopChecked()
if (shopIssue) { if (shopIssue) {
errorMessage.value = shopIssue errorMessage.value = shopIssue
return return
} }
// 跨店与「多店已检测」同档:目标店=京麦当前登录店,服务端据此算 publishMode=NEW。 // 跨店与「多店已检测」同档:目标店=京麦当前登录店,服务端据此算 publishMode=NEW;
// 多店仍检测不到(2026-11-28 客户口径「选完分类就建单」)=targetFromLogin:服务端
// 同样落 NEW 但不钉目标店,客户端按京麦当前登录店发布并落日志点名实际店。
// 单店未检测/同店照旧不带 target(服务端第①档克隆+客户端运行时核对,形状逐字不变)。
const guardForCreate = shopGuard.value const guardForCreate = shopGuard.value
const createTarget = guardForCreate.state === 'cross' || guardForCreate.state === 'multi' const createTarget = guardForCreate.state === 'cross' || guardForCreate.state === 'multi'
? guardForCreate.target ? guardForCreate.target
@@ -757,6 +773,8 @@ async function startPublish() {
: undefined : undefined
const vo = targetShop const vo = targetShop
? await createJdPublishTask(categoryId, productIds, priceRule, brand, targetShop) ? await createJdPublishTask(categoryId, productIds, priceRule, brand, targetShop)
: guardForCreate.state === 'multi'
? await createJdPublishTask(categoryId, productIds, priceRule, brand, undefined, true)
: await createJdPublishTask(categoryId, productIds, priceRule, brand) : await createJdPublishTask(categoryId, productIds, priceRule, brand)
board.addPollingTask(vo.taskId) board.addPollingTask(vo.taskId)
const pushNote = await pushToClientQueue(vo.queuePayload) const pushNote = await pushToClientQueue(vo.queuePayload)
@@ -776,6 +794,9 @@ onMounted(async () => {
if (localName) username.value = localName if (localName) username.value = localName
refreshShopDetectability() refreshShopDetectability()
void refreshPublishProtocol() void refreshPublishProtocol()
// 挂载即静默探测一次京麦登录店(2026-11-28 客户口径「选完分类就建单」):检测到就
// 钉定目标店,检测不到只落说明、建单照常(targetFromLogin 兜底);不弹登录窗不拦界面。
if (canDetectShop.value) void detectShop({ silent: true })
board.loadPollingIds() board.loadPollingIds()
await Promise.all([ await Promise.all([
loadGroups().catch(() => undefined), loadGroups().catch(() => undefined),
@@ -839,17 +860,10 @@ onUnmounted(() => {
<span class="shop-line__value">{{ crossTargetText }}</span> <span class="shop-line__value">{{ crossTargetText }}</span>
</p> </p>
<p v-if="shopError" class="shop-alert">{{ shopError }}</p> <p v-if="shopError" class="shop-alert">{{ shopError }}</p>
<!-- 多店还没检测:先点检测(没有目标店服务端也会拒)。 --> <!-- 协议不够:升级提示在前(NEW 任务只投给 v4+ 客户端),跨店/多店同受这道闸。 -->
<p v-else-if="shopGuard.state === 'multi' && !shopGuard.target" class="shop-alert">{{ shopGuard.message }}</p> <p v-else-if="needsCrossProtocol && !crossSupported" class="shop-alert">{{ CROSS_UPGRADE_NOTICE }}</p>
<!-- 跨店与多店同档:协议不够给升级提示,够则琥珀说明+人工确认。 --> <!-- 跨店/多店(已检测钉定目标店或未检测 targetFromLogin):琥珀说明,不再拦建单。 -->
<p v-else-if="(shopGuard.state === 'cross' || shopGuard.state === 'multi') && !crossSupported" class="shop-alert">{{ CROSS_UPGRADE_NOTICE }}</p> <p v-else-if="shopGuard.state === 'cross' || shopGuard.state === 'multi'" class="shop-alert shop-alert--cross">{{ shopGuard.message }}</p>
<template v-else-if="shopGuard.state === 'cross' || shopGuard.state === 'multi'">
<p class="shop-alert shop-alert--cross">{{ shopGuard.message }}</p>
<label class="shop-cross-confirm">
<input v-model="crossConfirmed" type="checkbox" />
我已确认在目标店新建商品
</label>
</template>
<p v-else-if="shopGuard.state === 'match'" class="shop-ok"> <p v-else-if="shopGuard.state === 'match'" class="shop-ok">
店铺一致:商品会发布到「{{ shopLabel(shopGuard.expected) }}」。 店铺一致:商品会发布到「{{ shopLabel(shopGuard.expected) }}」。
</p> </p>
@@ -990,7 +1004,6 @@ onUnmounted(() => {
.shop-alert { margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: rgba(248, 113, 113, 0.12); color: #fca5a5; font-size: 12px; line-height: 1.6; } .shop-alert { margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: rgba(248, 113, 113, 0.12); color: #fca5a5; font-size: 12px; line-height: 1.6; }
/* 跨店档是「可继续但要知道代价」:琥珀档(同 --bell-warning 口径),与红色硬拦截区分开。 */ /* 跨店档是「可继续但要知道代价」:琥珀档(同 --bell-warning 口径),与红色硬拦截区分开。 */
.shop-alert--cross { background: rgba(240, 187, 97, 0.12); color: #f0bb61; } .shop-alert--cross { background: rgba(240, 187, 97, 0.12); color: #f0bb61; }
.shop-cross-confirm { display: flex; align-items: flex-start; gap: 6px; margin: 6px 0 0; color: #c8d2e2; font-size: 12px; line-height: 1.6; cursor: pointer; }
.shop-ok { margin: 6px 0 0; color: #6ee7b7; font-size: 12px; } .shop-ok { margin: 6px 0 0; color: #6ee7b7; font-size: 12px; }
.shop-cat-select { width: 100%; } .shop-cat-select { width: 100%; }
.shop-cat-select :deep(.el-select__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; } .shop-cat-select :deep(.el-select__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; }
+16 -9
View File
@@ -50,9 +50,11 @@ export type JdShopGuard =
/** 京麦登录的不是来源店 ⇒ 跨店上架(目标店=京麦当前登录店,走新增商品路径) */ /** 京麦登录的不是来源店 ⇒ 跨店上架(目标店=京麦当前登录店,走新增商品路径) */
| { state: 'cross'; expected: JdShopRef; target: JdShopRef; message: string } | { state: 'cross'; expected: JdShopRef; target: JdShopRef; message: string }
/** /**
* 勾选的商品来自多家店(2026-11-26 晚客户口径「去掉一次只能发一家店的约束」): * 勾选的商品来自多家店(2026-11-26 晚客户口径「去掉一次只能发一家店的约束」;
* 2026-11-28 客户口径「不要限制,选完分类就建单」后未检测不再拦):
* 已检测京麦 ⇒ 整单按跨店新增放行(目标店=京麦登录店,服务端 publishMode=NEW, * 已检测京麦 ⇒ 整单按跨店新增放行(目标店=京麦登录店,服务端 publishMode=NEW,
* 与 cross 档同样要协议 ≥4 与人工确认);未检测 ⇒ 拦(建单没有目标店,服务端也会拒)。 * 与 cross 档同样要协议 ≥4);未检测 ⇒ 建单带 targetFromLogin(服务端仍 NEW 但不钉
* 目标店),客户端按**京麦当前登录店**发布(verify_shop 对未钉目标店只 WARNING 跳过核对)。
*/ */
| { state: 'multi'; shops: JdShopRef[]; target: JdShopRef | null; message: string } | { state: 'multi'; shops: JdShopRef[]; target: JdShopRef | null; message: string }
@@ -119,10 +121,15 @@ export function multiShopCrossMessage(shops: ReadonlyArray<JdShopRef>, target: J
+ '新建上架(需类目已授权,并通过京东审核)。') + '新建上架(需类目已授权,并通过京东审核)。')
} }
/** 多店还没检测京麦:先检测的指引句(不带目标店建单服务端也会拒)。 */ /**
* 多店还没检测京麦:建议句(2026-11-28 客户口径「不要限制」后不再拦建单)——
* 不检测也照常建单(targetFromLogin),客户端按京麦当前登录店发布;检测可钉定目标店、
* 客户端发布前会强核对,发了不匹配的店会整单判死,所以仍建议先检测。
*/
export function multiShopDetectMessage(shops: ReadonlyArray<JdShopRef>): string { export function multiShopDetectMessage(shops: ReadonlyArray<JdShopRef>): string {
const labels = shops.map((shop) => shopLabel(shop)).join('、') const labels = shops.map((shop) => shopLabel(shop)).join('、')
return `勾选的商品来自多个店铺(${labels}),请先点「检测京麦店铺」确认登录店后再建单。` return (`勾选的商品来自多个店铺(${labels}),将按京麦当前登录店铺新建上架;`
+ '建议先点「检测京麦店铺」钉定目标店,发错店会被整单判死。')
} }
/** true/false=能比;null=两边都缺可比字段(只认同一维度:id 对 id、名对名)。 */ /** true/false=能比;null=两边都缺可比字段(只认同一维度:id 对 id、名对名)。 */
@@ -158,13 +165,13 @@ export function evaluateShopGuard(
} }
/** /**
* UI 唯一处断:跨店与「多店已检测」档默认拦(本机不支持跨店=协议 < 4), * UI 唯一处断:跨店与多店档默认拦(本机不支持跨店=协议 < 4),``crossAllowed``
* ``crossAllowed`` 为真时放行(客户端会走新增商品路径); * 为真时放行(客户端会走新增商品路径)。2026-11-28 客户口径「不要限制」后多店
* 多店还没检测京麦必拦(建单没有目标店,服务端也会拒)。 * 未检测不再拦:建单带 targetFromLogin,客户端按京麦当前登录店发布(页面只建议检测)。
*/ */
export function shopGuardBlocks(guard: JdShopGuard, crossAllowed = false): boolean { export function shopGuardBlocks(guard: JdShopGuard, crossAllowed = false): boolean {
if (guard.state === 'cross') return !crossAllowed if (guard.state === 'cross') return !crossAllowed
if (guard.state === 'multi') return !guard.target || !crossAllowed if (guard.state === 'multi') return !crossAllowed
return false return false
} }
@@ -172,6 +179,6 @@ export function shopGuardBlocks(guard: JdShopGuard, crossAllowed = false): boole
export function shopGuardMessage(guard: JdShopGuard, crossAllowed = false): string { export function shopGuardMessage(guard: JdShopGuard, crossAllowed = false): string {
if (guard.state === 'cross') return crossAllowed ? '' : CROSS_UPGRADE_NOTICE if (guard.state === 'cross') return crossAllowed ? '' : CROSS_UPGRADE_NOTICE
if (guard.state !== 'multi') return '' if (guard.state !== 'multi') return ''
if (!guard.target) return guard.message if (!guard.target) return ''
return crossAllowed ? '' : CROSS_UPGRADE_NOTICE return crossAllowed ? '' : CROSS_UPGRADE_NOTICE
} }
@@ -35,6 +35,10 @@ export interface JdPublishPriceRule {
* 建单(AC-1/AC-8;作用域闸 2026-11-25 改口径):categoryId=所选自定义分类;productIds=勾选的商品行 id 集 * 建单(AC-1/AC-8;作用域闸 2026-11-25 改口径):categoryId=所选自定义分类;productIds=勾选的商品行 id 集
* (服务端按「可见数据权限分组的分类归属行」校验,跨公司/跨组商品或超配额当场业务码拒绝并点名文案)。 * (服务端按「可见数据权限分组的分类归属行」校验,跨公司/跨组商品或超配额当场业务码拒绝并点名文案)。
* 请求体是 JSON(@RequestBody + JdPublishTaskCreateRequest),字段名 camelCase 与采集建单同口径。 * 请求体是 JSON(@RequestBody + JdPublishTaskCreateRequest),字段名 camelCase 与采集建单同口径。
*
* `targetFromLogin`(2026-11-28 客户口径「不要限制,选完分类就建单」):多店勾选且京麦
* 登录店没检测到时置真——服务端同样落 publishMode=NEW 但不钉目标店,客户端按京麦当前
* 登录店发布。仅在「没带 targetShop」时有意义;老后端忽略未知字段=回落今日行为。
*/ */
export function createJdPublishTask( export function createJdPublishTask(
categoryId: number | null, categoryId: number | null,
@@ -42,6 +46,7 @@ export function createJdPublishTask(
priceRule: JdPublishPriceRule, priceRule: JdPublishPriceRule,
targetBrandName: string, targetBrandName: string,
targetShop?: { shopId?: string; shopName?: string }, targetShop?: { shopId?: string; shopName?: string },
targetFromLogin?: boolean,
) { ) {
return unwrapJavaResponse(post<JavaApiResponse<JdPublishTaskVo>, Record<string, unknown>>( return unwrapJavaResponse(post<JavaApiResponse<JdPublishTaskVo>, Record<string, unknown>>(
buildJavaUrl(API_ENDPOINTS.jdPublish.createWithTargetBrand), buildJavaUrl(API_ENDPOINTS.jdPublish.createWithTargetBrand),
@@ -53,9 +58,10 @@ export function createJdPublishTask(
priceRule: priceRule.mode === 'none' ? { mode: 'none' } : priceRule, priceRule: priceRule.mode === 'none' ? { mode: 'none' } : priceRule,
targetBrandName, targetBrandName,
// 跨店(2026-11-26)才带目标店:服务端据此落 publishMode=NEW 与目标店快照; // 跨店(2026-11-26)才带目标店:服务端据此落 publishMode=NEW 与目标店快照;
// 不带=回落来源店走本店克隆,与 5.0.13 行为逐字一致。 // 不带 targetShop 且未声明 targetFromLogin =回落来源店走本店克隆,与 5.0.13 行为逐字一致。
...(targetShop?.shopId ? { targetShopId: targetShop.shopId } : {}), ...(targetShop?.shopId ? { targetShopId: targetShop.shopId } : {}),
...(targetShop?.shopName ? { targetShopName: targetShop.shopName } : {}), ...(targetShop?.shopName ? { targetShopName: targetShop.shopName } : {}),
...(targetFromLogin ? { targetFromLogin: true } : {}),
}, },
)) ))
} }
+18 -9
View File
@@ -130,17 +130,24 @@ test('只有店名时按店名比对;比不了(一边只有 id)按未检
}) })
// 2026-11-26 晚客户口径「去掉一次只能发一家店的约束」:多店不再整单拦死。 // 2026-11-26 晚客户口径「去掉一次只能发一家店的约束」:多店不再整单拦死。
test('多店未检测京麦:拦并点名两家店与「先检测」动作(没有目标店服务端也会拒)', () => { // 2026-11-28 客户口径「不要限制,选完分类就建单」:未检测也不拦——建单带 targetFromLogin,
// 服务端落 NEW 但不钉目标店,客户端按京麦当前登录店发布(verify_shop 对未钉目标店只 WARNING)。
test('多店未检测京麦:不拦建单(targetFromLogin 兜底),文案点名各店并保留检测建议', () => {
const guard = evaluateShopGuard([{ shopId: '1', shopName: '甲店' }, { shopId: '2', shopName: '乙店' }], null) const guard = evaluateShopGuard([{ shopId: '1', shopName: '甲店' }, { shopId: '2', shopName: '乙店' }], null)
assert.equal(guard.state, 'multi') assert.equal(guard.state, 'multi')
if (guard.state === 'multi') assert.equal(guard.target, null) if (guard.state === 'multi') assert.equal(guard.target, null)
assert.ok(shopGuardBlocks(guard)) assert.ok(shopGuardBlocks(guard), '协议 <4 默认档仍拦:NEW 任务只投给 v4+ 客户端')
assert.ok(shopGuardMessage(guard).includes('甲店') && shopGuardMessage(guard).includes('乙店')) assert.ok(!shopGuardBlocks(guard, true), '协议 ≥4 时未检测不再拦建单(targetFromLogin 兜底,2026-11-28 口径)')
assert.ok(shopGuardMessage(guard).includes('检测')) assert.equal(shopGuardMessage(guard), '', 'shopGuardMessage 空串=点击建单不被中止,走 targetFromLogin')
assert.ok(!shopGuardMessage(guard).includes('分开勾选'), '旧「按店分开勾选」口径不得复活') assert.equal(shopGuardMessage(guard, true), '')
const display = guard.state === 'multi' ? guard.message : ''
assert.ok(display.includes('甲店') && display.includes('乙店'), '页面展示文案仍要点名各家店')
assert.ok(display.includes('检测'), '保留「先检测钉定目标店」的建议')
assert.ok(display.includes('登录'), '说明不检测时按京麦当前登录店发布')
assert.ok(!display.includes('分开勾选'), '旧「按店分开勾选」口径不得复活')
}) })
test('多店已检测京麦:整单按跨店新增放行(协议 ≥4+人工确认),文案点名各来源店与目标店', () => { test('多店已检测京麦:整单按跨店新增放行(协议 ≥4),文案点名各来源店与目标店', () => {
const guard = evaluateShopGuard( const guard = evaluateShopGuard(
[{ shopId: '1', shopName: '甲店' }, { shopId: '2', shopName: '乙店' }], [{ shopId: '1', shopName: '甲店' }, { shopId: '2', shopName: '乙店' }],
{ shopId: '3', shopName: '丙店' }, { shopId: '3', shopName: '丙店' },
@@ -155,7 +162,7 @@ test('多店已检测京麦:整单按跨店新增放行(协议 ≥4+人工
} }
assert.ok(shopGuardBlocks(guard), '协议 < 4 仍拦:老客户端没有新增商品路径') assert.ok(shopGuardBlocks(guard), '协议 < 4 仍拦:老客户端没有新增商品路径')
assert.equal(shopGuardMessage(guard), CROSS_UPGRADE_NOTICE) assert.equal(shopGuardMessage(guard), CROSS_UPGRADE_NOTICE)
assert.ok(!shopGuardBlocks(guard, true), '协议 ≥4 放行(建单前还要页面二次确认,那是页面层硬闸)') assert.ok(!shopGuardBlocks(guard, true), '协议 ≥4 放行(2026-11-28 起不再要求页面二次确认)')
assert.equal(shopGuardMessage(guard, true), '') assert.equal(shopGuardMessage(guard, true), '')
}) })
@@ -197,15 +204,17 @@ test('上架页不得自己拼店铺身份(只用勾选商品快照 + 桥结
assert.ok(!tab.includes('jd-shop-info'), '页面不得自拼店铺读取 URL(唯一口是桥)') assert.ok(!tab.includes('jd-shop-info'), '页面不得自拼店铺读取 URL(唯一口是桥)')
}) })
test('跨店接线:建单把目标店交给服务端、协议按最低档判定、二次确认是硬闸', () => { test('跨店接线:建单把目标店交给服务端、协议按最低档判定、未检测档带 targetFromLogin', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页') const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
assert.ok(tab.includes('targetShop'), '跨店建单必须把目标店(京麦当前登录店)传给服务端') assert.ok(tab.includes('targetShop'), '跨店建单必须把目标店(京麦当前登录店)传给服务端')
assert.ok(tab.includes('JD_PUBLISH_CROSS_PROTOCOL'), '跨店协议闸必须引用常量单出口') assert.ok(tab.includes('JD_PUBLISH_CROSS_PROTOCOL'), '跨店协议闸必须引用常量单出口')
assert.ok(tab.includes('crossConfirmed'), '跨店必须人工二次确认(会在目标店新建商品并过审)') assert.ok(tab.includes('targetFromLogin'), '多店未检测建单必须带 targetFromLogin(按京麦登录店发布)')
assert.ok(!tab.includes('crossConfirmed'), '2026-11-28 口径:人工二次确认硬闸已摘除,不得残留')
assert.ok(!/jd_publish_protocol[^\n]*===\s*3/.test(tab), '协议判定不得再等值钉 3(v4 是 v3 的超集)') assert.ok(!/jd_publish_protocol[^\n]*===\s*3/.test(tab), '协议判定不得再等值钉 3(v4 是 v3 的超集)')
const api = read('src/shared/api/types/modules/jd-publish.ts', 'jd-publish API') const api = read('src/shared/api/types/modules/jd-publish.ts', 'jd-publish API')
assert.ok(api.includes('targetShopId') && api.includes('targetShopName'), assert.ok(api.includes('targetShopId') && api.includes('targetShopName'),
'建单请求体必须带 targetShopId/targetShopName 两个键(服务端据此算 publishMode)') '建单请求体必须带 targetShopId/targetShopName 两个键(服务端据此算 publishMode)')
assert.ok(api.includes('targetFromLogin'), '建单请求体必须支持 targetFromLogin(多店未检测档)')
}) })
test('/jd-publish 直达路由挂权限守卫,权限接口失败按放行处理', () => { test('/jd-publish 直达路由挂权限守卫,权限接口失败按放行处理', () => {
@@ -390,44 +390,77 @@ it('协议 3 的本机遇跨店只给升级提示,一条都不建单', async (
api.protocol.mockResolvedValue(3) api.protocol.mockResolvedValue(3)
const page = await mountPage() const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌') await page.get('.target-brand-input').setValue('示例品牌')
// 未检测:不拦,点下去才开始核对(选分类即整分类上架,无逐行勾选步骤) // 挂载即自动检测(2026-11-28 口径):检测到异店=跨店档,协议 <4 按钮直接禁用+升级提示
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false)
await page.get('.collect-btn').trigger('click')
await flushPromises() await flushPromises()
expect(api.shop).toHaveBeenCalledOnce() expect(api.shop).toHaveBeenCalledOnce()
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
expect(page.text()).toContain('升级')
await page.get('.collect-btn').trigger('click')
await flushPromises()
expect(api.create).not.toHaveBeenCalled() expect(api.create).not.toHaveBeenCalled()
expect(api.enqueue).not.toHaveBeenCalled() expect(api.enqueue).not.toHaveBeenCalled()
expect(page.text()).toContain('升级')
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
}) })
it('协议 4 跨店:显形目标店与风险句,确认后才建单并带目标店', async () => { it('协议 4 跨店:挂载自动检测显形目标店与琥珀说明,直接建单并带目标店(不再勾确认)', async () => {
crossShopProducts() crossShopProducts()
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' }) withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
api.protocol.mockResolvedValue(4) api.protocol.mockResolvedValue(4)
const page = await mountPage() const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌') await page.get('.target-brand-input').setValue('示例品牌')
await page.get('.shop-detect-btn').trigger('click')
await flushPromises() await flushPromises()
expect(page.text()).toContain('跨店上架') expect(page.text()).toContain('跨店上架')
expect(page.text()).toContain('目标店(跨店)') expect(page.text()).toContain('目标店(跨店)')
expect(page.text()).toContain('家居日用数据库店') expect(page.text()).toContain('家居日用数据库店')
expect(page.text()).not.toContain('京东店铺不匹配') expect(page.text()).not.toContain('京东店铺不匹配')
// 二次确认是硬闸:没勾之前按钮禁用 // 2026-11-28 口径:人工二次确认硬闸已摘除,检测到目标店后按钮即可用
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
await page.get<HTMLInputElement>('.shop-cross-confirm input').setValue(true)
await flushPromises()
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false) expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false)
expect(page.find('.shop-cross-confirm').exists()).toBe(false)
await page.get('.collect-btn').trigger('click') await page.get('.collect-btn').trigger('click')
await flushPromises() await flushPromises()
expect(api.shop).toHaveBeenCalledOnce() // 已检测过,不再重复起浏览器 expect(api.shop).toHaveBeenCalledOnce() // 挂载检测过,建单前不再重复起浏览器
expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23], { mode: 'none' }, '示例品牌', expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23], { mode: 'none' }, '示例品牌',
{ shopId: '228346061', shopName: '家居日用数据库店' }) { shopId: '228346061', shopName: '家居日用数据库店' })
expect(api.enqueue).toHaveBeenCalledOnce() expect(api.enqueue).toHaveBeenCalledOnce()
}) })
it('多店未检测京麦:不拦建单,带 targetFromLogin 且不带目标店(2026-11-28 客户口径「选完分类就建单」)', async () => {
api.products.mockResolvedValue({
items: [
{ id: 23, title: '甲', shopId: '148191738', shopName: '汽车用品数据库店' },
{ id: 24, title: '乙', shopId: '228346061', shopName: '家居日用数据库店' },
], total: 2,
})
// 桥上没有检测方法(客户端不在线/旧客户端):挂载自动检测跳过,点击补测也失败
api.bridge.mockReturnValue({ jd_publish_protocol: api.protocol, enqueue_json: api.enqueue })
api.protocol.mockResolvedValue(4)
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false)
expect(page.text()).toContain('将按京麦当前登录店铺新建上架')
await startPublish(page)
expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23, 24], { mode: 'none' }, '示例品牌', undefined, true)
expect(api.enqueue).toHaveBeenCalledOnce()
})
it('多店未检测且协议 3:仍拦(NEW 任务只投给 v4+ 客户端,建了也没人领)', async () => {
api.products.mockResolvedValue({
items: [
{ id: 23, title: '甲', shopId: '148191738', shopName: '汽车用品数据库店' },
{ id: 24, title: '乙', shopId: '228346061', shopName: '家居日用数据库店' },
], total: 2,
})
api.bridge.mockReturnValue({ jd_publish_protocol: api.protocol, enqueue_json: api.enqueue })
api.protocol.mockResolvedValue(3)
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
expect(page.text()).toContain('升级')
await startPublish(page)
expect(api.create).not.toHaveBeenCalled()
})
it('京麦与来源店铺一致时照常建单', async () => { it('京麦与来源店铺一致时照常建单', async () => {
api.products.mockResolvedValue({ api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1, items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
@@ -446,11 +479,13 @@ it('检测过且一致后不再重复起浏览器', async () => {
}) })
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' }) withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
const page = await mountPage() const page = await mountPage()
await flushPromises()
expect(api.shop).toHaveBeenCalledOnce() // 挂载自动检测
await page.get('.shop-detect-btn').trigger('click') await page.get('.shop-detect-btn').trigger('click')
await flushPromises() await flushPromises()
expect(api.shop).toHaveBeenCalledOnce() expect(api.shop).toHaveBeenCalledTimes(2) // 手动按钮再来一次(现拉,不缓存)
await startPublish(page) await startPublish(page)
expect(api.shop).toHaveBeenCalledOnce() expect(api.shop).toHaveBeenCalledTimes(2) // 建单前不再重复起浏览器
expect(api.create).toHaveBeenCalledOnce() expect(api.create).toHaveBeenCalledOnce()
}) })