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:
2026-11-25 22:35:43 +08:00
parent fce4c7322c
commit 934091b3d5
42 changed files with 1709 additions and 119 deletions
+99
View File
@@ -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 \/>/)
})