feat(jd): 上架按账号授权 + 建单钉来源店铺 + 店铺不匹配整单判死

2026-11-24 客户(心向大海)两条口径:
「如果没有店铺登入情况 软件怎么知道我们要上架是哪一个店铺?」
「上架的账户 我是这个权限不开给他的」

后端半边(用户端页头与会话核对见 frontend-vue 同笔;客户端发布前核对见 app_client 0f8bcdf)。

一、按账号授权(拒绝型能力,quiet fail 全靠本类判据)
- JdPublishPermissionSupport:V209 app 菜单组键 jd_tools 或子键 jd-publish 命中即放行,
  超管直放;有效键集按 AdminMenuPlatformScope 过滤到账号平台(与登录分发同源)。
  无权限抛 403 + 中文动作句(告诉管理员去哪儿勾)。
- JdPublishController:建单/改品牌重试/选品/面板/历史/批量进度六个用户面入口一律先判;
  客户端执行面(items/chunk/activate/heartbeat/补值/删除)不判——执行器本来就只跑
  已建的任务,判在这里会让进行中的任务断在半路。

二、建单钉来源店铺(一次上架只发一家店)
- resolveSingleShop:按勾选商品快照判店铺,跨店勾选建单即拒并点名两家店;
  同店两种形状(有 id / 只有店名)归一到 id 再比。
- JdPublishTaskCreateRequest 落 shopId/shopName → 队列载荷两键 → 明细页
  JdPublishItemsPageVo.shopId/shopName 下发;旧任务载荷没这两键时回落明细行
  shop_name(V210 就有),保证老任务至少能按店名核对。

三、店铺不匹配整单判死
- JdPublishStaleTaskService.SHOP_MISMATCH_MARK/terminalizeOnJdShopMismatch:
  CAS RUNNING→FAILED、0/1 计数、原文追加动作句;不按累计行数收窄(确定性失败)。
- JdPublishIngestService.fail:命中标记排在凭据致命档之后、页面结构变更之前接线,
  回 accept=true 让客户端收口。

判据:JdPublishPermissionSupportTest 5 支(新)+TaskService +3/Stale +2/Ingest +2,
后端 JdPublish 九类 77 支全绿;四支既有护栏(catch 静默/请求身份/超管单出口/SQL 分层)绿。
This commit is contained in:
2026-11-24 15:21:27 +08:00
parent cf06872cb6
commit 1b10db4bf9
20 changed files with 1156 additions and 6 deletions
@@ -10,7 +10,7 @@ import {
const api = vi.hoisted(() => ({
create: vi.fn(), activate: vi.fn(), products: vi.fn(), groups: vi.fn(),
history: vi.fn(), progress: vi.fn(), dashboard: vi.fn(), retry: vi.fn(), enqueue: vi.fn(), bridge: vi.fn(),
protocol: vi.fn(), retryBrand: vi.fn(), alert: vi.fn(), prompt: vi.fn(),
protocol: vi.fn(), retryBrand: vi.fn(), alert: vi.fn(), prompt: vi.fn(), shop: vi.fn(),
}))
vi.mock('@/shared/api/types/modules/jd-collect', () => ({ fetchJdCollectGroups: api.groups }))
@@ -357,3 +357,78 @@ it('源商品身份缺失形状已被客户端放行,提示维持换店或重
await page.get('.history-btn').trigger('click')
expect(page.text()).not.toContain('非在售商品')
})
// ---- 店铺核对(2026-11-24 客户口径「软件怎么知道要上架哪一家店铺」)----
// 桥 get_jd_shop_info 现拉京麦当前登录店铺;与勾选商品的来源店铺不一致 ⇒ 页面强拦截,一条都不建单。
// 老客户端没有这个方法(默认替身就不带)⇒ 不拦,最终拦截由客户端执行器与服务端完成。
type ShopBridgeResult = {
success: boolean; shopId?: string; shopName?: string; code?: string; error?: string
}
function withShopBridge(result: ShopBridgeResult) {
api.bridge.mockReturnValue({
jd_publish_protocol: api.protocol, enqueue_json: api.enqueue, get_jd_shop_info: api.shop,
})
api.shop.mockResolvedValue(result)
}
it('京麦登录的不是勾选商品的店铺时不建单,并点名两家店', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
})
withShopBridge({ success: true, shopId: '165515933', shopName: '花屿巷旗舰店' })
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
await page.get<HTMLInputElement>('.product-check').setValue(true)
// 勾选后不检测:按钮仍可点(未检测不拦),点下去才开始核对
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false)
await page.get('.collect-btn').trigger('click')
await flushPromises()
expect(api.shop).toHaveBeenCalledOnce()
expect(api.create).not.toHaveBeenCalled()
expect(api.enqueue).not.toHaveBeenCalled()
expect(page.text()).toContain('京东店铺不匹配')
expect(page.text()).toContain('家居日用数据库店')
expect(page.text()).toContain('花屿巷旗舰店')
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
})
it('京麦与来源店铺一致时照常建单', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
})
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
const page = await mountPage()
await startPublish(page)
expect(api.shop).toHaveBeenCalledOnce()
expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23], { mode: 'none' }, '示例品牌')
expect(page.text()).toContain('店铺一致')
})
it('检测过且一致后不再重复起浏览器', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
})
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
const page = await mountPage()
await page.get<HTMLInputElement>('.product-check').setValue(true)
await page.get('.shop-detect-btn').trigger('click')
await flushPromises()
expect(api.shop).toHaveBeenCalledOnce()
await startPublish(page)
expect(api.shop).toHaveBeenCalledOnce()
expect(api.create).toHaveBeenCalledOnce()
})
it('京麦未登录时给登录指引,不静默建单', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
})
withShopBridge({ success: false, code: 'jd_busy', error: '京东任务正在运行,请稍后再试' })
const page = await mountPage()
await startPublish(page)
// jd_busy 档:不硬拦(任务可能在收尾),页面给 amber 说明;建单继续,最终拦截在客户端
expect(api.create).toHaveBeenCalledOnce()
expect(page.text()).toContain('京东任务正在运行')
})