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:
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* 京东上架「发到哪一家店」(2026-11-24 客户口径:「如果没有店铺登入情况 软件怎么知道我们要上架
|
||||
* 是哪一个店铺?」)。
|
||||
*
|
||||
* 三份身份,各有唯一出处,三层同一标记:
|
||||
* 1. **来源店铺**=所勾商品行的 `shopName/shopId`(京东数据库快照)。服务端建单时按它做
|
||||
* 「一单只能发到一家店」校验(`JdPublishTaskService.resolveSingleShop`),并把它钉进
|
||||
* 任务载荷与明细下发(`JdPublishItemsPageVo.shopId/shopName`);
|
||||
* 2. **京麦当前登录店铺**=桥 `get_jd_shop_info` 现拉(客户端起有头浏览器读京麦首屏),
|
||||
* 不是页面缓存、也不是上次「同步分类」的残留;本页只拿它做提前告知;
|
||||
* 3. **最终强拦截**=客户端发布前用任务记录的店铺再核一次(`JdPublishPage.verify_shop`),
|
||||
* 不一致先上报标记再中止,服务端 `JdPublishStaleTaskService` 命中即整单判死——一条都不发。
|
||||
*
|
||||
* 本文件是纯函数(node --test 直测):只产状态与中文文案,复选框禁用/错误条/提示色由调用方选。
|
||||
*/
|
||||
|
||||
/** 判据标记:客户端 `SHOP_MISMATCH_MARK`、服务端 `JdPublishStaleTaskService.SHOP_MISMATCH_MARK` 同值。 */
|
||||
export const SHOP_MISMATCH_MARK = '京东店铺不匹配'
|
||||
|
||||
export interface JdShopRef {
|
||||
shopId?: string
|
||||
shopName?: string
|
||||
}
|
||||
|
||||
/** 来源店铺的最小子集(只要这两个字段,页面传 `JdPublishProductVo[]` 进来即可)。 */
|
||||
export interface JdShopSource {
|
||||
shopId?: string
|
||||
shopName?: string
|
||||
}
|
||||
|
||||
export type JdShopGuard =
|
||||
/** 勾选的商品没带店铺信息(旧数据/未勾选)⇒ 页面不拦,交给客户端与服务端兜底 */
|
||||
| { state: 'unknown' }
|
||||
/** 有来源店铺、还没检测京麦 ⇒ 提示可检测(不拦) */
|
||||
| { state: 'undetected'; expected: JdShopRef }
|
||||
| { state: 'match'; expected: JdShopRef; actual: JdShopRef }
|
||||
| { state: 'mismatch'; expected: JdShopRef; actual: JdShopRef; message: string }
|
||||
/** 勾选的商品来自多家店 ⇒ 服务端也会拒(按店分开勾) */
|
||||
| { state: 'multi'; shops: JdShopRef[]; message: string }
|
||||
|
||||
function text(value: unknown): string {
|
||||
return String(value ?? '').trim()
|
||||
}
|
||||
|
||||
/** 归一化店铺身份:两名皆空返回 null(把「没记录」和「记录了空串」当同一件事)。 */
|
||||
export function normalizeShopRef(raw: JdShopRef | null | undefined): JdShopRef | null {
|
||||
const shopId = text(raw?.shopId)
|
||||
const shopName = text(raw?.shopName)
|
||||
if (!shopId && !shopName) return null
|
||||
return { ...(shopId ? { shopId } : {}), ...(shopName ? { shopName } : {}) }
|
||||
}
|
||||
|
||||
/** 人读标签:`家居日用数据库店(shopId=228346061)`,缺一半只报有的那半。 */
|
||||
export function shopLabel(raw: JdShopRef | null | undefined): string {
|
||||
const shop = normalizeShopRef(raw)
|
||||
if (!shop) return '未记录店铺'
|
||||
if (shop.shopName && shop.shopId) return `${shop.shopName}(shopId=${shop.shopId})`
|
||||
if (shop.shopName) return shop.shopName
|
||||
return `shopId=${shop.shopId}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 勾选商品的来源店铺去重(id 优先、回退店名):同一家店的不同行只算一家,
|
||||
* 顺序按勾选先后稳定输出(页面文案不会因 Map 重排跳字)。
|
||||
*
|
||||
* 跨形状归一:库存里有行带 id、有行只带店名(快照字段缺失),both 指同一家店时
|
||||
* 必须并成一条并补齐缺的字段——否则页面对同店勾选误报「来自多个店铺」。
|
||||
*/
|
||||
export function sourceShopRefs(products: ReadonlyArray<JdShopSource> | null | undefined): JdShopRef[] {
|
||||
const refs: JdShopRef[] = []
|
||||
for (const product of products ?? []) {
|
||||
const shop = normalizeShopRef(product)
|
||||
if (!shop) continue
|
||||
const existing = refs.find((ref) => (shop.shopId && ref.shopId === shop.shopId)
|
||||
|| (shop.shopName && ref.shopName === shop.shopName))
|
||||
if (existing) {
|
||||
if (shop.shopId && !existing.shopId) existing.shopId = shop.shopId
|
||||
if (shop.shopName && !existing.shopName) existing.shopName = shop.shopName
|
||||
continue
|
||||
}
|
||||
refs.push({ ...shop })
|
||||
}
|
||||
return refs
|
||||
}
|
||||
|
||||
/** 不匹配整句:开头即标记,点名「勾选的店」与「京麦现在登的店」,给动作句(不写「稍后重试」)。 */
|
||||
export function shopMismatchMessage(expected: JdShopRef | null | undefined, actual: JdShopRef | null | undefined): string {
|
||||
const expectedLabel = shopLabel(expected)
|
||||
return (`${SHOP_MISMATCH_MARK}:本次勾选的商品来自「${expectedLabel}」,`
|
||||
+ `当前京麦登录「${shopLabel(actual)}」;请先在京麦切换到「${expectedLabel}」再上架。`)
|
||||
}
|
||||
|
||||
/** 跨店勾选整句(与服务端建单拒绝文案同口径:按店分开勾)。 */
|
||||
export function multiShopMessage(shops: ReadonlyArray<JdShopRef>): string {
|
||||
const labels = shops.map((shop) => shopLabel(shop)).join('、')
|
||||
return `本次勾选的商品来自多个店铺(${labels}),一次上架只能发到一家店,请按店铺分开勾选。`
|
||||
}
|
||||
|
||||
/** true/false=能比;null=两边都缺可比字段(只认同一维度:id 对 id、名对名)。 */
|
||||
function sameShop(expected: JdShopRef, actual: JdShopRef): boolean | null {
|
||||
if (expected.shopId && actual.shopId) return expected.shopId === actual.shopId
|
||||
if (expected.shopName && actual.shopName) return expected.shopName === actual.shopName
|
||||
return null
|
||||
}
|
||||
|
||||
/** 页面判据:来源店铺(勾选集) vs 京麦当前登录店铺(检测结果,null=没检测/没读到)。 */
|
||||
export function evaluateShopGuard(
|
||||
products: ReadonlyArray<JdShopSource> | null | undefined,
|
||||
detected: JdShopRef | null | undefined,
|
||||
): JdShopGuard {
|
||||
const refs = sourceShopRefs(products)
|
||||
if (refs.length > 1) return { state: 'multi', shops: refs, message: multiShopMessage(refs) }
|
||||
const expected = refs[0]
|
||||
if (!expected) return { state: 'unknown' }
|
||||
const actual = normalizeShopRef(detected)
|
||||
if (!actual) return { state: 'undetected', expected }
|
||||
const same = sameShop(expected, actual)
|
||||
// 比不了(一边只有店名、另一边只有 id)不判不匹配:宁可留给客户端强拦截,也不误拦真实任务。
|
||||
if (same === null) return { state: 'undetected', expected }
|
||||
if (same) return { state: 'match', expected, actual }
|
||||
return { state: 'mismatch', expected, actual, message: shopMismatchMessage(expected, actual) }
|
||||
}
|
||||
|
||||
/** UI 唯一处断:命中这两档才禁「上架」按钮(unknown/undetected 不拦)。 */
|
||||
export function shopGuardBlocks(guard: JdShopGuard): guard is Extract<JdShopGuard, { state: 'mismatch' | 'multi' }> {
|
||||
return guard.state === 'mismatch' || guard.state === 'multi'
|
||||
}
|
||||
Reference in New Issue
Block a user