feat(jd额度): 上架额度改按在架商品数计+管理员向员工分配额度闸+在架商品面板
客户口径(2026-11-25):「上限=同时在架商品数,下架 10 个就能再上架 10 个换着卖」+
「管理员下的普通员工总和也不能超过这个上限」。
后端
- 计数正本从 biz_jd_product 占有行数迁到 biz_jd_publish_item:发布成功(SUCCESS)
且未标记下架(delisted_at IS NULL)的去重商品数(DISTINCT product_id,同商品跨任务
重复发布只占一位)。旧 JdProductMapper#countByUserIds 整条删除——口径源只能一份。
- V216 给发布明细加 delisted_at(NULL=在架);V217 把普通账号存量默认 5000 清 0
(0=未分配,分配闸上线的前置清账)。
- JdPublishQuotaService:quotaOf 读数换正本;assertWithinQuota 改收勾选商品集,
批内已在架的不双计(重复上架不重复占位)。
- 新增 JdPublishOnShelfService+/api/jd-publish/on-shelf(团队在架分页+余量,读数与
建单闸同一正本)与 /api/jd-publish/items/{itemId}/delisted(标记/撤销按商品整组回写,
跨团队 403;京麦下架执行链自动回流记欠账)。
- AdminUserService 新增分配闸:Σ(直接下属非零额度,被编辑账号取新值) ≤ 锚点额度;
站超管/锚点 0=不限放行;旧 400「只能为管理员设置额度」废止。新增
/api/admin/user/{uid}/jd-quota 只读快照(编辑弹窗展示「当前在架 X/上限 Y」)。
后管
- 编辑弹窗额度项改为「京东侧+操作者写权」即出(普通账号也可分配),带当前在架读数
(读不到只显一句失败话,不挡保存);列表「上架上限」列 0 按档显「不限」/「未分配」;
普通账号回填缺省 0(避免「打开就保存」凭空分配额度)。展示规则单出口 user-edit-model。
用户端
- 新增在架商品面板(JdOnShelfPanel):余量读数、空态、满额提醒、标记已下架确认与回执
文案单出口 jd-on-shelf.ts;endpoints 快照同步 onShelf/markDelisted。
判据
- 后端:JdPublishQuotaServiceTest 11、JdPublishOnShelfServiceTest 8、
JdPublishOnShelfSqlTest 3(三条 SQL 谓词逐字钉:SUCCESS+delisted_at IS NULL+DISTINCT)、
AdminUserServiceCompanySuperAdminTest +5(Σ 闸四态)、JdSchemaContractTest 钉 V216/V217、
两条 SQL 台账(XML_SELECT_TOTAL 109→111、XML_STATEMENT_TOTAL 156→158)逐条点名。
- 后管:jd-publish-quota-edit.test.ts 3(含 0 语义分档与「绝不拼/0」)、
platform-account-pages 源码钉子改钉新形状、source-pin 台账 cases 1867→1868 逐条点名。
- 用户端:jd-on-shelf.test.ts 纯函数+mount 面板判据;catch-silence 台账 blocks 336→338 点名。
This commit is contained in:
@@ -118,7 +118,11 @@ const BASELINE = {
|
||||
// 原文只进 console;「读不到权限」不等于「没权限」,把有权限的人锁在门外比放进去后被
|
||||
// 服务端 403 更难解释(与 JdConsolePage 的 permissionUnavailable 同口径)。非静默:
|
||||
// 首条语句是状态写入、不是 console.*,silent 一格没涨、perFile 无新增条目,只进 blocks。
|
||||
blocks: 336,
|
||||
// 338 = 336 + 2(2026-11-25 京东上架额度改口径「在架商品面板」):JdOnShelfPanel.vue 的
|
||||
// load(在架清单读取失败 → ElMessage.error 报原文,面板清空不显旧数)与 markDelisted
|
||||
// (标记失败 → ElMessage.error 透出服务端原文,跨团队 403 等;确认框取消走 reject 两臂
|
||||
// 不新增 catch)各一支,都有用户可见出口,silent 一格没涨、perFile 无新增条目,只进 blocks。
|
||||
blocks: 338,
|
||||
// 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处
|
||||
// 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进
|
||||
// useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动,
|
||||
|
||||
@@ -349,7 +349,10 @@ test('test_endpoints_frozen_snapshot', () => {
|
||||
"history": "/api/jd-publish/history",
|
||||
"progressBatch": "/api/jd-publish/tasks/progress/batch",
|
||||
"progress": "/api/jd-publish/tasks/{taskId}/progress",
|
||||
"deleteTask": "/api/jd-publish/tasks/{taskId}"
|
||||
"deleteTask": "/api/jd-publish/tasks/{taskId}",
|
||||
// 2026-11-25 额度改口径:在架清单+标记已下架腾额度(JdOnShelfPanel 唯一落点)。
|
||||
"onShelf": "/api/jd-publish/on-shelf",
|
||||
"markDelisted": "/api/jd-publish/items/{itemId}/delisted"
|
||||
},
|
||||
"userSecret": {
|
||||
"bundle": "/api/user-secrets",
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import {
|
||||
clampPageSize,
|
||||
markButtonLabel,
|
||||
markDelistedNotice,
|
||||
onShelfEmptyText,
|
||||
quotaNearLimit,
|
||||
quotaReadoutText,
|
||||
} from '../src/pages/jd/jd-on-shelf.ts'
|
||||
|
||||
/**
|
||||
* 在架商品面板纯函数与接线绊线(2026-11-25 客户口径「上限=同时在架商品数,
|
||||
* 下架 10 个就能再上 10 个换着卖」)。
|
||||
*
|
||||
* 绊线盯的是「安静地不做」类回退:面板绕过 api 模块裸拼 URL(落点台账失效)、
|
||||
* 文案在组件里硬拼(单出口失效)、JdPublishTab 不挂面板(功能整面失踪)——
|
||||
* 行为测试全绿也拦不住,只有源码绊线拦得住。
|
||||
*/
|
||||
|
||||
const ROOT = process.cwd()
|
||||
|
||||
function read(relativePath: string, what: string): string {
|
||||
const path = join(ROOT, relativePath)
|
||||
assert.ok(existsSync(path), `${what} 尚未落地:${path}`)
|
||||
return readFileSync(path, 'utf8')
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------- 纯函数:余量文案
|
||||
|
||||
test('余量读数:正常档显「在架 X/Y」,不限档绝不显「/0」', () => {
|
||||
assert.equal(quotaReadoutText(120, 5000, false), '当前在架 120/5000')
|
||||
assert.equal(quotaReadoutText(120, 0, true), '当前在架 120/不限')
|
||||
// limit≤0 但 unlimited 没带(防御:服务端两键同值,坏一个也不出「/0」坏数)
|
||||
assert.equal(quotaReadoutText(3, 0, false), '当前在架 3/不限')
|
||||
assert.equal(quotaReadoutText(Number.NaN, 5000, false), '当前在架 0/5000')
|
||||
assert.equal(quotaReadoutText(12.7, 5000.9, false), '当前在架 12/5000')
|
||||
})
|
||||
|
||||
test('到顶判据:used≥limit 才提醒;不限档永不提醒', () => {
|
||||
assert.equal(quotaNearLimit(5000, 5000, false), true)
|
||||
assert.equal(quotaNearLimit(5001, 5000, false), true)
|
||||
assert.equal(quotaNearLimit(4999, 5000, false), false)
|
||||
assert.equal(quotaNearLimit(999999, 0, true), false)
|
||||
})
|
||||
|
||||
test('空态文案:未占用点名「采集入库不占额度」,翻页态不冒充空账', () => {
|
||||
assert.match(onShelfEmptyText(false, 0), /采集入库不占/)
|
||||
assert.match(onShelfEmptyText(true, 0), /上架成功后.*计入额度/s)
|
||||
assert.equal(onShelfEmptyText(false, 25), '本页暂无更多在架商品,可翻页查看')
|
||||
})
|
||||
|
||||
test('分页钳制与服务端 MAX_PAGE_SIZE=100 同口径', () => {
|
||||
assert.equal(clampPageSize(9999), 100)
|
||||
assert.equal(clampPageSize(20), 20)
|
||||
assert.equal(clampPageSize(0), 20)
|
||||
assert.equal(clampPageSize(-1), 20)
|
||||
})
|
||||
|
||||
test('标记回执点名商品编码与确认义务,不写「操作成功」空话', () => {
|
||||
assert.match(markDelistedNotice('100365361600'), /商品 100365361600/)
|
||||
assert.match(markDelistedNotice('100365361600'), /额度已腾出/)
|
||||
assert.match(markDelistedNotice(), /已标记下架,额度已腾出/)
|
||||
assert.equal(markButtonLabel(), '标记已下架')
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------- 源码绊线:接线与单出口
|
||||
|
||||
test('绊线:在架端点只在 endpoints.ts 登记一处,面板必须走 api 模块出口', () => {
|
||||
const endpoints = read('src/shared/api/endpoints.ts', '端点表')
|
||||
assert.match(endpoints, /onShelf: '\/api\/jd-publish\/on-shelf'/)
|
||||
assert.match(endpoints, /markDelisted: '\/api\/jd-publish\/items\/\{itemId\}\/delisted'/)
|
||||
|
||||
const apiModule = read('src/shared/api/types/modules/jd-publish.ts', '上架 api 模块')
|
||||
assert.match(apiModule, /API_ENDPOINTS\.jdPublish\.onShelf/)
|
||||
assert.match(apiModule, /API_ENDPOINTS\.jdPublish\.markDelisted/)
|
||||
|
||||
const panel = read('src/pages/jd/JdOnShelfPanel.vue', '在架面板')
|
||||
assert.doesNotMatch(panel, /\/api\/jd-publish/, '面板不得裸拼后端 URL(落点必须走 api 模块)')
|
||||
assert.match(panel, /fetchJdOnShelf/)
|
||||
assert.match(panel, /markJdItemDelisted/)
|
||||
})
|
||||
|
||||
test('绊线:面板文案单出口——组件不硬拼「当前在架」,判据与界面读同一份', () => {
|
||||
const panel = read('src/pages/jd/JdOnShelfPanel.vue', '在架面板')
|
||||
assert.doesNotMatch(panel, /当前在架/, '余量文案必须经 quotaReadoutText 单出口')
|
||||
assert.match(panel, /quotaReadoutText/)
|
||||
assert.match(panel, /onShelfEmptyText/)
|
||||
assert.match(panel, /markDelistedNotice/)
|
||||
})
|
||||
|
||||
test('绊线:JdPublishTab 必须挂上在架面板(功能整面失踪类回退)', () => {
|
||||
const tab = read('src/pages/jd/JdPublishTab.vue', '上架页')
|
||||
assert.match(tab, /import JdOnShelfPanel from '@\/pages\/jd\/JdOnShelfPanel\.vue'/)
|
||||
assert.match(tab, /<JdOnShelfPanel \/>/)
|
||||
})
|
||||
@@ -0,0 +1,140 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import JdOnShelfPanel from '@/pages/jd/JdOnShelfPanel.vue'
|
||||
|
||||
/**
|
||||
* 在架商品面板 mount 判据(2026-11-25 额度改口径):余量读数、展开取数、
|
||||
* 标记已下架走确认框两臂+成功回执+重取列表。api 模块整体 mock——
|
||||
* 面板必须经 fetchJdOnShelf/markJdItemDelisted 出口(裸 URL 回退当场红)。
|
||||
*/
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
onShelf: vi.fn(),
|
||||
markDelisted: vi.fn(),
|
||||
confirm: vi.fn(),
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/types/modules/jd-publish', () => ({
|
||||
fetchJdOnShelf: api.onShelf,
|
||||
markJdItemDelisted: api.markDelisted,
|
||||
}))
|
||||
vi.mock('element-plus', async (importOriginal) => ({
|
||||
...await importOriginal<typeof import('element-plus')>(),
|
||||
ElMessage: { success: api.success, error: api.error },
|
||||
ElMessageBox: { confirm: api.confirm },
|
||||
}))
|
||||
|
||||
function pageVo(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
used: 2, limit: 5000, unlimited: false, total: 2,
|
||||
items: [
|
||||
{ itemId: 100, productId: 7, productCode: '100365361600', title: '收纳盒A', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:30:04' },
|
||||
{ itemId: 101, productId: 8, productCode: '100365355826', title: '纸巾盒B', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:21:29' },
|
||||
],
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
let wrapper: VueWrapper | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
})
|
||||
|
||||
async function mountPanel() {
|
||||
// 替身注册法与 jd-publish-dispatch.mount.test.ts 同族:分页替身+loading 指令空实现
|
||||
wrapper = mount(JdOnShelfPanel, {
|
||||
global: {
|
||||
stubs: { ElPagination: { emits: ['current-change'], template: '<div />' } },
|
||||
directives: { loading: () => undefined },
|
||||
},
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
it('默认收起不取数;展开后拉第一页并显余量读数', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
const w = await mountPanel()
|
||||
expect(api.onShelf).not.toHaveBeenCalled()
|
||||
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||||
expect(api.onShelf.mock.calls[0][0]).toBe(1)
|
||||
expect(api.onShelf.mock.calls[0][1]).toBe(20)
|
||||
expect(w.text()).toContain('当前在架 2/5000')
|
||||
expect(w.findAll('.on-shelf-row')).toHaveLength(2)
|
||||
expect(w.text()).toContain('收纳盒A')
|
||||
})
|
||||
|
||||
it('不限档显「不限」,绝不显「/0」坏数', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo({ used: 0, limit: 0, unlimited: true, total: 0, items: [] }))
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
expect(w.text()).toContain('当前在架 0/不限')
|
||||
expect(w.text()).not.toContain('/0')
|
||||
expect(w.text()).toContain('上架成功后的商品会出现在这里')
|
||||
})
|
||||
|
||||
it('额度到顶出琥珀提醒句', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo({ used: 5000, total: 5000 }))
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
expect(w.find('.on-shelf-warn').text()).toContain('额度已满')
|
||||
expect(w.find('.on-shelf-warn').text()).toContain('标记已下架')
|
||||
})
|
||||
|
||||
it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重取列表', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
api.confirm.mockResolvedValue(true)
|
||||
api.markDelisted.mockResolvedValue(null)
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.markDelisted).toHaveBeenCalledWith(100, true)
|
||||
expect(api.success).toHaveBeenCalledTimes(1)
|
||||
expect(String(api.success.mock.calls[0][0])).toContain('100365361600')
|
||||
// 标记成功后重取(腾额度读数当场回跳)
|
||||
expect(api.onShelf).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('确认框取消(reject 臂)不发起标记', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
api.confirm.mockRejectedValue('cancel')
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await w.findAll('.on-shelf-mark')[1].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.markDelisted).not.toHaveBeenCalled()
|
||||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('标记失败透出服务端原文(跨团队 403 等)', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
api.confirm.mockResolvedValue(true)
|
||||
api.markDelisted.mockRejectedValue(new Error('只能标记本团队(管理员及其名下员工)的上架商品'))
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.error).toHaveBeenCalledTimes(1)
|
||||
expect(String(api.error.mock.calls[0][0])).toContain('本团队')
|
||||
})
|
||||
Reference in New Issue
Block a user