fix(jd): 客户五截图排查窗三面修复——点父级类目0条断链、管理链上溯恒判异司、上架分类空态静默

① 后管:JdProductListParams 补 categoryNames 字段,load() 把页面按服务端真树展开好的
   子树名集合透传到序列化层(此前到不了,退回内置快照重展开失败→单名等值 IN→
   「收纳用品 81」点开 0 条)。计数与过滤从此同一棵树。回归:纯函数序列化 1 支+
   mount 真树≠快照点父级 1 支(反向验证:摘透传当场红);source-pin 台账逐格点名
   jd-database-page.test.ts cases 7→8。
② 后端:selectLedGroups 投影补 company_id——collectAncestorGroups 的「只继承同公司组」
   闸读的就是这列,缺列时每行恒 null、管理链上溯继承整段失效,「管理员名下所有普通
   员工都能看到分类」(2026-11-24 客户口径)在生产永不生效,普通账号分类页「本组暂无
   分类」、上架页下拉全空。SQL 契约格改钉新投影并记第三次缺列病灶(服务层 mock 夹具
   自带 companyId,行为测试照绿,只有本格拦得住回退;反向验证:删列 2 支当场红)。
③ 用户端:上架页分类空态点名——groupsEmpty 判据+两常量单出口(下拉 empty-text+
   块下琥珀动作句),不再静默空下拉+永久灰按钮。回归:mount 2 支(空态点名/非空
   不误报)+源码绊线 1 支(文案单出口)。

验证读数:后管 node --test 1984/vitest 259/vue-tsc rc=0;用户端 node --test 1136/
vitest 143/vue-tsc rc=0;后端 mvn -o test 整量 5843 例 0 失败 19 skip。
This commit is contained in:
2026-11-25 15:03:24 +08:00
parent 363f65c01a
commit a8d4b643f9
11 changed files with 148 additions and 8 deletions
@@ -496,6 +496,9 @@ async function load(): Promise<void> {
keyword: filter.keyword,
category: filter.category,
categoryPath: filter.categoryPath,
// 父级点选按当前生效树展开好的集合透传给查询(2026-11-25 断链修复:此前只存在
// 过滤态里没进 api 入参,列表查询退回快照树展开,真树≠快照时点开父级 0 条)。
categoryNames: filter.categoryNames,
shopName: filter.shopName,
groupId: filter.groupId,
classified: filter.classified,
@@ -29,6 +29,9 @@ export async function fetchJdProductList(
keyword: params.keyword ?? '',
category: params.category ?? '',
categoryPath: params.categoryPath ?? [],
// 页面按当前生效树算好的子树展开集合必须透传(2026-11-25 断链修复):丢了它,
// 序列化层会拿内置快照树重展开,真树≠快照时父级点选退化成单名等值查 0 条。
categoryNames: params.categoryNames ?? [],
shopName: params.shopName ?? '',
groupId: params.groupId ?? '',
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
@@ -146,6 +146,11 @@ export interface JdProductListParams {
category?: string
/** 选中类目节点路径(见 JdProductFilterState.categoryPath;空=单名等值)。 */
categoryPath?: string[]
/** 页面按**当前生效树**(服务端真树优先)展开好的子树类目名集合(见
* JdProductFilterState.categoryNames)。2026-11-25 补:api 层此前没有这个字段,
* 页面算好的集合到不了序列化层,父级点选退回内置快照树重展开——真树≠快照时
* 展开失败退化成单名等值,「收纳用品 81」点开 0 条。序列化按它优先。 */
categoryNames?: string[]
shopName?: string
groupId?: string
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
@@ -2,7 +2,7 @@
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
"totals": {
"files": 265,
"cases": 1866,
"cases": 1867,
"pins": 463,
"reads": 665
},
@@ -323,7 +323,7 @@
"reads": 0
},
"jd-database-page.test.ts": {
"cases": 7,
"cases": 8,
"pins": 0,
"reads": 0
},
@@ -123,6 +123,32 @@ test('类目筛选参数序列化:空串不下发、末级单值、父级展
'路径失效(树外历史名)回落单名等值,不静默丢筛选')
})
/** 2026-11-25 断链修复(客户实况「收纳用品 81 点开 0 条」):页面按**服务端真树**展开好的
* categoryNames 必须被序列化层直接采用——此前 api 入参没这个字段,集合到不了这里,
* 序列化退回内置快照树重展开;真树≠快照(家居店的类目不在花屿巷服饰快照上)时展开失败,
* 退化成单名等值 IN,而库里落的是叶子名 → 0 条。 */
test('类目筛选序列化优先采用页面算好的 categoryNames,不拿快照树重展开', async () => {
const { createJdProductFilterState, toJdProductListParams } = await import('../src/pages/jd/jd-product-filter.ts')
const empty = createJdProductFilterState()
const parent = { ...empty, category: '收纳用品', categoryPath: ['收纳用品'],
categoryNames: ['收纳用品', '收纳盒', '收纳篮', '收纳架'] }
assert.deepEqual(toJdProductListParams(parent, 1, 20).category,
['收纳用品', '收纳盒', '收纳篮', '收纳架'],
'categoryNames 有值=逐字下发,即便快照树重展开必然失败也不许退化')
// 对照旧形状:同样路径、无集合=快照展开失败 → 单名兜底(这正是实况 0 条的查询)。
const legacy = { ...empty, category: '收纳用品', categoryPath: ['收纳用品'] }
assert.deepEqual(toJdProductListParams(legacy, 1, 20).category, ['收纳用品'],
'无集合时保留快照展开失败回落单名的旧兜底(修复只加透传,不改兜底语义)')
// 空数组集合=视同缺省(末级点选/清选形状),走路径展开旧口径。
const leaf = { ...empty, category: '艺考形体服',
categoryPath: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'], categoryNames: [] }
assert.deepEqual(toJdProductListParams(leaf, 1, 20).category, ['艺考形体服'],
'空集合数组不冒充展开结果,仍走路径口径')
})
test('自定义分类使用 group_id,不发送分类状态参数', async () => {
const { createJdProductFilterState, toJdProductListParams } = await import('../src/pages/jd/jd-product-filter.ts')
const query = toJdProductListParams({ ...createJdProductFilterState(), groupId: '7' }, 1, 20)
@@ -57,8 +57,14 @@ const groupApi = vi.hoisted(() => ({
createShopGroup: vi.fn(),
}))
// 京麦授权类目树(V215 真树)读取:默认空回执=页面回落内置快照;真树用例显式变形。
const shopTreeApi = vi.hoisted(() => ({
fetchJdShopCategoryTree: vi.fn(),
}))
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
vi.mock('@/pages/jd/jd-shop-category-api.ts', () => shopTreeApi)
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
function item(id: number, over: Record<string, unknown> = {}) {
@@ -130,6 +136,8 @@ beforeEach(() => {
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
jdApi.fetchJdProductGroups.mockResolvedValue([])
jdApi.fetchJdProductCategories.mockResolvedValue([])
// 真树默认「服务端还没人上报过」=页面回落内置快照(旧用例形状逐字不变)。
shopTreeApi.fetchJdShopCategoryTree.mockResolvedValue({ nodes: [], shops: [] })
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
@@ -374,6 +382,42 @@ describe('侧栏商品目录(类目筛选迁移自级联面板)', () => {
'清选后路径回空数组(api 序列化层对空 category 不下发参数)')
wrapper.unmount()
})
it('服务端真树≠内置快照:点父级必须把按真树展开的 categoryNames 透传给列表查询(2026-11-25「收纳用品 81 点开 0 条」断链钉)', async () => {
// 真树=家居日用店授权树(收纳用品/收纳盒/收纳篮/收纳架),内置快照(花屿巷服饰)
// 里一个都没有——旧断链形状:页面算好集合但 api 入参丢字段,序列化退回快照展开
// 失败 → 单名等值 IN('收纳用品') → 库里只有叶子名 → 0 条。
shopTreeApi.fetchJdShopCategoryTree.mockResolvedValue({
nodes: [{
name: '收纳用品', value: '9001',
children: [
{ name: '收纳盒', value: '9002' },
{ name: '收纳篮', value: '9003' },
{ name: '收纳架', value: '9004' },
],
}],
shops: [{ shopId: '228346061', shopName: '家居日用数据库店', capturedAt: '2026-11-24 10:00:00', nodeCount: 4 }],
})
jdApi.fetchJdProductCategories.mockResolvedValue([
{ name: '收纳盒', productCount: 23 },
{ name: '收纳篮', productCount: 14 },
{ name: '收纳架', productCount: 44 },
])
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
const catalog = wrapper.get('.jd-side-catalog')
// 徽标同源(真树聚合):父级 81=23+14+44,这条一直是对的,错的是过滤链。
expect(sideRowBy(catalog, '收纳用品').text()).toContain('81')
await sideRowBy(catalog, '收纳用品').trigger('click')
await flushPromises()
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last).toMatchObject({ category: '收纳用品', categoryPath: ['收纳用品'], page: 1 })
expect(last.categoryNames, '断链修复点:页面按真树展开的子树名集合必须进 api 入参').toBeDefined()
expect([...last.categoryNames].sort()).toEqual(['收纳架', '收纳盒', '收纳篮', '收纳用品'].sort(),
'集合=节点自身+全部后代(与徽标计数同一棵树算出)')
wrapper.unmount()
})
})
describe('侧栏店铺分类(分类筛选迁移自下拉)', () => {
@@ -84,7 +84,11 @@
AND COALESCE(g.created_by_id, g.user_id) IS NOT NULL
</select>
<select id="selectLedGroups" resultType="com.nanri.aiimage.common.model.entity.ShopManageGroupEntity">
SELECT g.id AS id, g.group_name AS groupName, g.platform AS platform
<!-- company_id 不能省(2026-11-25 实录):JdCategoryScopeService.collectAncestorGroups 的
「只继承同公司组」闸读的就是这行的 getCompanyId()——缺列时每行恒 null、管理链上溯
继承整段失效,「管理员名下所有普通员工都能看到分类」(2026-11-24 客户口径)在生产
永不生效,普通账号分类页/上架页下拉全空。少 platform 是 2026-11-17 平台闸清空病灶。 -->
SELECT g.id AS id, g.group_name AS groupName, g.company_id AS companyId, g.platform AS platform
FROM biz_shop_manage_group g
WHERE g.created_by_id = #{operatorId} OR g.user_id = #{operatorId}
ORDER BY g.id ASC
@@ -29,6 +29,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* 清空</b>——平台超管在京东侧永远空作用域、空态直建口永远在、建完的组永远不显示
* (「建组建成功、界面永远不显示」的生产实录)。两条投影的判据一并钉进本格:
* 少 {@code company_id} 或少 {@code platform} 都直接红。
*
* <p>2026-11-25 同一条查询第三次缺列(这次是 {@code company_id}):
* {@code JdCategoryScopeService.collectAncestorGroups} 的「只继承同公司组」闸读组行的
* {@code getCompanyId()},而 {@code selectLedGroups} 没投影它 ⇒ 管理链上溯继承<b>恒判不同公司
* 整批丢弃</b>——「管理员名下所有普通员工都能看到分类」(2026-11-24 客户口径)在生产永不生效,
* 普通账号后管分类页「本组暂无分类」、用户端上架页分类下拉「无数据」、京东商品完全上不了架。
* 服务层单测 mock 夹具自带 companyId,行为测试照绿——这条投影回退只有本 SQL 格拦得住。</p>
*/
class ShopManageGroupScopeSqlTest {
@@ -47,14 +54,19 @@ class ShopManageGroupScopeSqlTest {
}
@Test
void 管理员档的组清单必须投影平台档() throws Exception {
void 管理员档的组清单必须投影平台档与归属公司() throws Exception {
String sql = render("selectLedGroups");
assertEquals("SELECT g.id AS id, g.group_name AS groupName, g.platform AS platform"
assertEquals("SELECT g.id AS id, g.group_name AS groupName, g.company_id AS companyId,"
+ " g.platform AS platform"
+ " FROM biz_shop_manage_group g WHERE g.created_by_id = ? OR g.user_id = ?"
+ " ORDER BY g.id ASC", sql,
"组长/普通号档走这条投影过平台闸:少 platform 则 jd 档组对非超管永远不可见"
+ "(与 selectAllGroups 同一批病灶,2026-11-17 实录)");
+ "(与 selectAllGroups 同一批病灶,2026-11-17 实录);少 company_id 则"
+ " collectAncestorGroups 的「只继承同公司组」闸对管理链上溯的组恒判不同公司"
+ "——上溯继承整段失效,「管理员名下所有普通员工都能看到分类」(2026-11-24"
+ " 客户口径)永不生效、普通账号分类页与上架页下拉全空(2026-11-25 客户实况)。"
+ "服务层 mock 夹具自带 companyId,行为测试照绿,只有本格拦得住这条投影回退");
}
private static String render(String id) throws Exception {
+15 -2
View File
@@ -84,6 +84,15 @@ async function loadGroups() {
}
}
// 分类空态点名(2026-11-25 客户实况「上架页分类无数据、也就上架不了」):拉完仍为空=
// 本账号可见分组里没有分类(/groups 按数据权限分组收窄,V203)。此前静默空下拉+
// 建单按钮永久置灰、零解释——现在点名「本分组暂无分类」与动作「找管理员在后台建分类」。
// 文案单出口两常量:下拉内空态(短)+块下说明(带动作句),mount/绊线测试按名钉。
const GROUPS_EMPTY_DROPDOWN_TEXT = '本分组暂无分类'
const GROUPS_EMPTY_HINT_TEXT =
'本分组暂无分类——请联系管理员在后台「京东数据库 → 店铺分类」创建分类并归入你的分组后再上架。'
const groupsEmpty = computed(() => !groupsLoading.value && groupOptions.value.length === 0)
// ---- 选品分页(owner 过滤在服务端;勾选跨页累计在本地 Map,翻页不清空)----
const PRODUCT_PAGE_SIZE = 12
const products = ref<JdPublishProductVo[]>([])
@@ -813,11 +822,13 @@ onUnmounted(() => {
<div class="category-block">
<span class="category-label">自定义分类</span>
<el-select v-model="selectedGroupId" placeholder="选择分类" class="shop-cat-select"
:loading="groupsLoading" @change="changeGroup">
:loading="groupsLoading" :empty-text="groupsEmpty ? GROUPS_EMPTY_DROPDOWN_TEXT : '无数据'"
@change="changeGroup">
<el-option v-for="group in groupOptions" :key="group.id"
:label="`${group.name}(${group.productCount ?? 0} 个商品)`" :value="group.id" />
</el-select>
<p class="category-hint">分类由管理员在后台「京东数据库」维护;列表只显示归属你账号的商品。</p>
<p v-if="groupsEmpty" class="category-hint category-hint--warn">{{ GROUPS_EMPTY_HINT_TEXT }}</p>
<p v-else class="category-hint">分类由管理员在后台「京东数据库」维护;列表只显示归属你账号的商品。</p>
</div>
<div class="product-block" v-loading="productsLoading">
@@ -942,6 +953,8 @@ onUnmounted(() => {
.category-block { margin-bottom: 16px; }
.category-label { display: block; margin-bottom: 8px; color: #c8d2e2; font-size: 13px; font-weight: 600; }
.category-hint { margin: 8px 0 0; color: #7f8ca3; font-size: 12px; line-height: 1.6; }
/* 分类空态点名用琥珀档:取 notification-bell 暗色档 --bell-warning 同值,和普通灰字说明区分开。 */
.category-hint--warn { color: #f0bb61; }
.shop-guard { padding: 10px 12px; border: 1px solid #2c3547; border-radius: 8px; background: #20283a; }
.shop-line { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 12px; line-height: 1.5; }
.shop-line__key { flex-shrink: 0; color: #7f8ca3; }
+12
View File
@@ -79,3 +79,15 @@ test('商品上架占位卡转正式:jd-publish 卡挂 /jd-publish 路由', ()
'jd-publish 卡须补 href 指向 /jd-publish(转正式)')
assert.ok(router.includes("path: '/jd-publish'"), 'router 缺 /jd-publish 路由')
})
// ---------------------------------------------------------- 分类空态点名(2026-11-25)
test('分类空态文案单出口:判据 computed+两常量定义存在,模板按名引用不内联第二份', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
assert.ok(tab.includes('const GROUPS_EMPTY_DROPDOWN_TEXT'), '下拉空态文案必须定义在常量单出口')
assert.ok(tab.includes('const GROUPS_EMPTY_HINT_TEXT'), '块下动作句文案必须定义在常量单出口')
assert.ok(tab.includes('const groupsEmpty = computed'),
'空态判据=拉取完成且集合为空(groupsLoading 结束+length===0),不许拿加载中也当空')
assert.ok(tab.includes('{{ GROUPS_EMPTY_HINT_TEXT }}') && tab.includes(':empty-text="groupsEmpty ? GROUPS_EMPTY_DROPDOWN_TEXT'),
'模板两处都必须引用常量——内联第二份文案就是口径漂移的开始')
})
@@ -432,3 +432,21 @@ it('京麦未登录时给登录指引,不静默建单', async () => {
expect(api.create).toHaveBeenCalledOnce()
expect(page.text()).toContain('京东任务正在运行')
})
it('分类拉回空=点名「本分组暂无分类」带动作句,不再静默空下拉+灰按钮(2026-11-25 客户实况)', async () => {
api.groups.mockResolvedValue([])
const page = await mountPage()
const warn = page.get('.category-hint--warn')
expect(warn.text()).toContain('本分组暂无分类')
expect(warn.text()).toContain('京东数据库 → 店铺分类')
// 原静态说明只在非空态出现(v-if/v-else 互斥,同屏双份即红)。
expect(page.text()).not.toContain('列表只显示归属你账号的商品')
// 空态下建单仍被硬闸禁用(既有 submitDisabled 口径),但界面此刻给得出原因。
expect(page.get('.collect-btn').attributes('disabled')).toBeDefined()
})
it('分类非空时不出空态告警(v-if 不成立,原静态说明照旧)', async () => {
const page = await mountPage()
expect(page.find('.category-hint--warn').exists()).toBe(false)
expect(page.text()).toContain('分类由管理员在后台「京东数据库」维护')
})