feat(jd-admin): 2026-11-18 客户三条反馈闭环——公司超管收窄到名下+京东类目一级/二级可选中(IN 下推)+级联触发框 34px 对齐
【一、用户管理:公司超管「各自看各自名下」(backend-java AdminUserService)】
客户口径(11-18 截图:阿华66 公司超管看到了 admin 直建的 ssss):平台超管看所有,
其余公司超管只看自己名下。读侧 listUsers 公司超管分支由「本公司全部(role≠super_admin)」
改为 company_id=本公司 AND (id=本人 OR created_by_id=本人)——与组长档同一形状;
自己那行永远可见(保证能改自己密码/额度)。写侧 updateUser/deleteUser 公司超管分支
在「同公司」闸之外加同形「目标 created_by_id=本人」谓词,不留「列表看不见、API 照样改」
的洞(停用/改密/额度全走这条闸)。createUser 不动(新建天然落本人名下)。
口径为直接下级:组长再建的普通号归组长看,不在公司超管列表(如需整棵下级树另拍板)。
判据:AdminUserServiceCompanySuperAdminTest 改 1 增 5(名下可见谓词/超管档反向不收窄/
写侧越权 403 两支+本人建的可编辑);其余 admin 测试类夹具全用超管/组长档,核过不受影响。
【二、京东类目一级/二级可选中(前端展开+后端 IN,零表结构变更,用户拍板路线)】
后端:AdminJdProductController.page 的 category 参数改 List<String>(重复 query key 绑定,
参数名不变、单值形状照常);JdProductQueryService.Filter 逐项 trim/去空白/去重、空集合归
null=不过滤;JdProductMapper.xml productConds 类目谓词 eq→IN+foreach(仍 SQL 侧下推,
铁律 20 同形)。落库仍只有末级类目名,无 schema/迁移改动。
前端:jd-category-tree.ts 新增 jdCategoryAllNodes/jdCategorySearchNodes(搜索铺全层级)
+jdCategoryNamesUnder(path)(选中节点→自身+全部后代类目名集合,含自身因实际末级可能
就在这一级;路径失效回 null 兜单名)。JdCategoryCascader.vue:非末级行圆点点击=选中
(emit change 带名称路径)、行体/箭头仍下钻;选中态按路径比对(同名跨支不串);搜索
结果含一级/二级行。JdDatabasePage/jd-product-filter/jd-product-api:categoryPath 入筛选态,
序列化按子树展开集合,axios paramsSerializer indexes:false 出重复 category= 参数。
已知代价(路线自带、用户已选):不同父级下同名末级会随展开集合一起命中(B112-05 同口径)。
【三、样式(JdCategoryCascader.vue)】
触发框 min-height 42→34px+padding 5x10:main.css:245-248 全局密度收口把相邻 input/
el-select/.btn 压到 34,自绘 button 不在收口清单里才显高;非末级圆点不再永远空心。
【台账】source-pin-ledger.json 重录(UPDATE_SOURCE_PIN_BASELINE=1 官方口):本笔
jd-category-tree.test.ts 用例 6→8;同时把 2a8bdd7d 已提交未记账的
user-menu-tree-platform-filter.test.ts(8 例 0 钉 0 读点)一并登记——基线在该窗陈旧,
此处为台账记账、非卷码。
【验证】mvn -o test-compile rc=0;定向 mvn -o test(AdminUserService* 七类+
AdminJdProductControllerTest)rc=0;admin vue-tsc rc=0;node --test jd-category-tree/
jd-database-page/jd-product-group/cascader-position 全绿;vitest mount jd-database-page
44/44(含本笔新增一级/二级选中用例);ops _push_gate.py --fast overall=pass 四面绿
(首轮后管 readSource 格红=本笔用例数,重录基线后复跑绿)。
发版未做:jar+后管随下一窗口走既有流程;full 闸门未跑(模式 D 口径)。
This commit is contained in:
@@ -5,26 +5,31 @@
|
||||
*
|
||||
* 交互(京麦真机同款,2026-11-16 面板逐级点开取证):面板按点亮路径动态出栏——第一栏
|
||||
* 一级(3 个)、后续栏=点亮节点的 children(最深 4 栏);**非末级行点击=下钻**(推进
|
||||
* 路径)、**末级行(children 空)点击=选中**(radio 蓝,emit change→按 category_path
|
||||
* 等值过滤,后端契约零改动)。搜索框搜**树内全部末级**(名称或路径命中,行 title 带
|
||||
* 全路径);树外命中(已落库但京麦类目体系变更后的历史名)从 options 兜底段选,语义
|
||||
* 同旧版第三栏。「全部类目」行=清选;触发框已选时出 × 清除;面板外点透明遮罩关闭。
|
||||
* 路径)、**末级行(children 空)点击=选中**;2026-11-18 客户口径「一级/二级类目也要能
|
||||
* 选来搜索」:**非末级行的圆点点击=选中该节点**(emit change 带名称路径,页面按子树
|
||||
* 展开类目名集合下发,后端 IN 过滤;行体/箭头仍下钻)。搜索框搜**树内全部层级**
|
||||
* (一级/二级/末级都可选,名称或路径命中,行 title 带全路径);树外命中(已落库但京麦
|
||||
* 类目体系变更后的历史名)从 options 兜底段选,语义同旧版第三栏。「全部类目」行=清选;
|
||||
* 触发框已选时出 × 清除;面板外点透明遮罩关闭。
|
||||
* 零依赖自绘(radio 圆点/箭头都是 CSS),无 element 依赖。 */
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import {
|
||||
jdCategoryChildren,
|
||||
jdCategoryRoots,
|
||||
jdCategorySearchLeaves,
|
||||
jdCategorySearchNodes,
|
||||
type JdCategoryNode,
|
||||
} from './jd-category-tree.ts'
|
||||
import { clampPanelLeftX } from './jd-category-cascader-position.ts'
|
||||
|
||||
const props = defineProps<{
|
||||
/** 已落库末级类目全集(/categories 现算,页面传入)——只作**树外兜底**(搜索无树内
|
||||
/** 已落库类目全集(/categories 现算,页面传入)——只作**树外兜底**(搜索无树内
|
||||
* 命中时列出「已落库类目(树外历史)」段),不再默认铺第三栏。 */
|
||||
options?: { name: string; productCount: number }[]
|
||||
/** 当前选中末级类目名;'' = 全部类目。 */
|
||||
/** 当前选中类目名(末级或父级);'' = 全部类目。 */
|
||||
modelValue: string
|
||||
/** 当前选中节点的名称路径(从一级起);空/缺省=末级按名等值或树外行。
|
||||
* 2026-11-18 一级/二级可选中:同名跨支(吊带/背心等)靠路径区分选中态回显。 */
|
||||
selectedPath?: string[]
|
||||
groups?: { id: number; name: string; productCount: number }[]
|
||||
groupId?: string
|
||||
createVersion?: number
|
||||
@@ -33,7 +38,8 @@ const props = defineProps<{
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(event: 'change', value: string): void
|
||||
/** (类目名, 节点名称路径):末级/父级选中都带路径;树外兜底行与清选带 []。 */
|
||||
(event: 'change', value: string, path: string[]): void
|
||||
(event: 'group', value: string): void
|
||||
(event: 'create-group', value: string): void
|
||||
(event: 'delete-group', id: number): void
|
||||
@@ -74,9 +80,10 @@ function reposition(): void {
|
||||
}
|
||||
|
||||
const roots = jdCategoryRoots()
|
||||
/** 树内全部末级名集合(判定 options 哪些是「树外历史」)。 */
|
||||
const treeLeafNames = new Set(
|
||||
jdCategorySearchLeaves('').map((leaf) => leaf.name),
|
||||
/** 树内全部节点名集合(含非末级;判定 options 哪些是「树外历史」——11-18 起父级名
|
||||
* 也可选中过滤,历史行名只要树内有任何同名节点就走树内行,不再重复铺兜底段)。 */
|
||||
const treeNodeNames = new Set(
|
||||
jdCategorySearchNodes('').map((node) => node.name),
|
||||
)
|
||||
|
||||
/** 面板各栏内容:第 0 栏一级,第 i+1 栏=点亮路径前 i+1 个的 children(路径推进到
|
||||
@@ -91,12 +98,12 @@ const columns = computed<JdCategoryNode[][]>(() => {
|
||||
return cols
|
||||
})
|
||||
|
||||
/** 搜索激活=搜索词非空:面板切换成扁平末级结果列表。 */
|
||||
/** 搜索激活=搜索词非空:面板切换成扁平结果列表(2026-11-18 起含一级/二级)。 */
|
||||
const searching = computed(() => searchText.value.trim().length > 0)
|
||||
|
||||
/** 树内命中末级(名称或路径段命中)。 */
|
||||
const searchLeaves = computed(() =>
|
||||
searching.value ? jdCategorySearchLeaves(searchText.value) : [],
|
||||
/** 树内命中节点(全层级;名称或路径段命中)。 */
|
||||
const searchNodes = computed(() =>
|
||||
searching.value ? jdCategorySearchNodes(searchText.value) : [],
|
||||
)
|
||||
|
||||
/** 树外兜底:options 里不在树名集的行按搜索词过滤(历史行仍可选中过滤)。 */
|
||||
@@ -104,7 +111,7 @@ const fallbackOptions = computed(() => {
|
||||
if (!searching.value) return []
|
||||
const keyword = searchText.value.trim().toLowerCase()
|
||||
return (props.options ?? [])
|
||||
.filter((option) => !treeLeafNames.has(option.name))
|
||||
.filter((option) => !treeNodeNames.has(option.name))
|
||||
.filter((option) => option.name.toLowerCase().includes(keyword))
|
||||
})
|
||||
|
||||
@@ -132,29 +139,46 @@ function close(): void {
|
||||
activePath.value = []
|
||||
}
|
||||
|
||||
/** 非末级行点击=下钻;末级行点击=选中并收面板。 */
|
||||
/** 栏内节点的完整名称路径(下钻态:已点亮前缀+本节点名)。 */
|
||||
function nodePath(node: JdCategoryNode, depth: number): string[] {
|
||||
return [...activePath.value.slice(0, depth), node.name]
|
||||
}
|
||||
|
||||
/** 选中态回显按**路径**比对(同名跨支不串);树外兜底行没有路径,按名比对。 */
|
||||
function isSelected(path: string[]): boolean {
|
||||
const current = props.selectedPath ?? []
|
||||
return current.length === path.length && current.every((segment, i) => segment === path[i])
|
||||
}
|
||||
|
||||
/** 非末级行体/箭头点击=下钻;末级行点击=选中(带路径)。 */
|
||||
function pick(node: JdCategoryNode, depth: number): void {
|
||||
if (node.children && node.children.length) {
|
||||
activePath.value = [...activePath.value.slice(0, depth), node.name]
|
||||
activePath.value = nodePath(node, depth)
|
||||
return
|
||||
}
|
||||
emit('change', node.name)
|
||||
selectNode(node, depth)
|
||||
}
|
||||
|
||||
/** 圆点点击(任意层级)=选中该节点并收面板——2026-11-18 一级/二级类目可选中,
|
||||
* 页面按 jdCategoryNamesUnder(path) 展开子树类目名集合下发。 */
|
||||
function selectNode(node: JdCategoryNode, depth: number): void {
|
||||
emit('change', node.name, nodePath(node, depth))
|
||||
close()
|
||||
}
|
||||
|
||||
function pickAll(): void {
|
||||
emit('change', '')
|
||||
emit('change', '', [])
|
||||
close()
|
||||
}
|
||||
|
||||
/** 搜索结果行点击(树内末级或树外兜底行)=按名选中。 */
|
||||
function pickName(name: string): void {
|
||||
emit('change', name)
|
||||
/** 搜索结果行点击:树内行(含一级/二级)按路径选中;树外兜底行按名选中(path 空)。 */
|
||||
function pickName(name: string, path: string[]): void {
|
||||
emit('change', name, path)
|
||||
close()
|
||||
}
|
||||
|
||||
function clear(): void {
|
||||
emit('change', '')
|
||||
emit('change', '', [])
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -191,33 +215,34 @@ function clear(): void {
|
||||
<button type="button" :aria-label="`删除分类 ${group.name}`" @click.stop="emit('delete-group', group.id)">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 搜索态:树内末级命中+树外兜底段(扁平列表,行 title 带全路径)。 -->
|
||||
<!-- 搜索态:树内全层级命中(一级/二级/末级都可点选)+树外兜底段(扁平列表,行 title 带全路径)。 -->
|
||||
<template v-if="searching">
|
||||
<div class="cat-col cat-col-search">
|
||||
<div class="cat-search-row"><input v-model="searchText" type="text" class="cat-search" placeholder="搜索类目" /></div>
|
||||
<template v-if="searchLeaves.length || fallbackOptions.length">
|
||||
<template v-if="searchNodes.length || fallbackOptions.length">
|
||||
<div
|
||||
v-for="leaf in searchLeaves"
|
||||
:key="`tree-${leaf.path.join('/')}`"
|
||||
v-for="node in searchNodes"
|
||||
:key="`tree-${node.path.join('/')}`"
|
||||
class="cat-row"
|
||||
:class="{ active: modelValue === leaf.name }"
|
||||
:title="leaf.path.join(' > ')"
|
||||
@click="pickName(leaf.name)"
|
||||
:class="{ active: isSelected(node.path) }"
|
||||
:title="node.leaf ? node.path.join(' > ') : `${node.path.join(' > ')}(含下级,选中按整棵子树筛选)`"
|
||||
@click="pickName(node.name, node.path)"
|
||||
>
|
||||
<span class="cat-dot" :class="{ on: modelValue === leaf.name }" aria-hidden="true"></span>
|
||||
<span class="cat-name">{{ leaf.name }}</span>
|
||||
<span class="cat-path">{{ leaf.path.slice(0, -1).join(' › ') }}</span>
|
||||
<span class="cat-dot" :class="{ on: isSelected(node.path) }" aria-hidden="true"></span>
|
||||
<span class="cat-name">{{ node.name }}</span>
|
||||
<span v-if="!node.leaf" class="cat-arrow" aria-hidden="true">›</span>
|
||||
<span class="cat-path">{{ node.path.slice(0, -1).join(' › ') }}</span>
|
||||
</div>
|
||||
<div v-if="fallbackOptions.length" class="cat-seg">已落库类目(树外历史)</div>
|
||||
<div
|
||||
v-for="option in fallbackOptions"
|
||||
:key="`db-${option.name}`"
|
||||
class="cat-row"
|
||||
:class="{ active: modelValue === option.name }"
|
||||
:class="{ active: modelValue === option.name && !(selectedPath && selectedPath.length) }"
|
||||
:title="option.name"
|
||||
@click="pickName(option.name)"
|
||||
@click="pickName(option.name, [])"
|
||||
>
|
||||
<span class="cat-dot" :class="{ on: modelValue === option.name }" aria-hidden="true"></span>
|
||||
<span class="cat-dot" :class="{ on: modelValue === option.name && !(selectedPath && selectedPath.length) }" aria-hidden="true"></span>
|
||||
<span class="cat-name">{{ option.name }}</span>
|
||||
<span class="cat-count">{{ option.productCount }}</span>
|
||||
</div>
|
||||
@@ -250,11 +275,17 @@ function clear(): void {
|
||||
v-for="node in col"
|
||||
:key="`${depth}-${node.name}`"
|
||||
class="cat-row"
|
||||
:class="{ active: activePath[depth] === node.name || (depth === 0 && modelValue === node.name) }"
|
||||
:title="node.name"
|
||||
:class="{ active: activePath[depth] === node.name || isSelected(nodePath(node, depth)) }"
|
||||
:title="node.children && node.children.length ? `${node.name}(点行下钻,点圆点选中整棵子树)` : node.name"
|
||||
@click="pick(node, depth)"
|
||||
>
|
||||
<span class="cat-dot" aria-hidden="true"></span>
|
||||
<span
|
||||
class="cat-dot"
|
||||
:class="{ on: isSelected(nodePath(node, depth)) }"
|
||||
role="button"
|
||||
:aria-label="`选中 ${node.name}`"
|
||||
@click.stop="selectNode(node, depth)"
|
||||
></span>
|
||||
<span class="cat-name">{{ node.name }}</span>
|
||||
<span v-if="node.children && node.children.length" class="cat-arrow" aria-hidden="true">›</span>
|
||||
</div>
|
||||
@@ -273,14 +304,16 @@ function clear(): void {
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
}
|
||||
/* 触发框像素对齐页面 .form-group select(42 高/9 圆角/#cbd9e6 边框/#f8fbfd 底)。 */
|
||||
/* 触发框像素对齐筛选行实际渲染高度(2026-11-18 客户「输入框高了一些」):
|
||||
main.css 全局密度收口把 .form-group input/el-select/.btn 压到 34 高,自绘 button
|
||||
不在收口选择器清单里,这里同值对齐(34 高/5x10 padding/9 圆角/#cbd9e6 边框/#f8fbfd 底)。 */
|
||||
.cat-trigger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
min-height: 34px;
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
|
||||
@@ -210,6 +210,7 @@ async function load(): Promise<void> {
|
||||
productCode: filter.productCode,
|
||||
titleKeyword: filter.titleKeyword,
|
||||
category: filter.category,
|
||||
categoryPath: filter.categoryPath,
|
||||
groupId: filter.groupId,
|
||||
classified: filter.classified,
|
||||
ownerGroupId: ownerGroupId.value,
|
||||
@@ -235,10 +236,12 @@ function apply(): void {
|
||||
void load()
|
||||
}
|
||||
|
||||
/** 类目级联面板点末级即查:选完立刻按该类目过滤刷新(回第一页),同分组下拉口径;
|
||||
* 点「全部类目」/触发框 × = 清选重查。 */
|
||||
function onCategoryPicked(name: string): void {
|
||||
/** 类目级联面板选中即查:选完立刻按该类目过滤刷新(回第一页),同分组下拉口径;
|
||||
* 点「全部类目」/触发框 × = 清选重查。2026-11-18 一级/二级类目可选中:path 非空时
|
||||
* 序列化按子树展开类目名集合下发(后端 IN),末级/树外行 path 空=单名等值旧形状。 */
|
||||
function onCategoryPicked(name: string, path: string[]): void {
|
||||
filter.category = name
|
||||
filter.categoryPath = path
|
||||
apply()
|
||||
}
|
||||
|
||||
@@ -368,11 +371,13 @@ onMounted(async () => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>类目</label>
|
||||
<!-- 类目(京麦末级类目)京麦同款级联面板(2026-11-16 客户口径):一/二级为静态导航
|
||||
(采集链无层级数据),第三栏已落库末级+搜索,点行选中即查(回第一页)。 -->
|
||||
<!-- 类目(京麦授权类目树)京麦同款级联面板(2026-11-16 真树取证):点行下钻、
|
||||
末级点行选中;2026-11-18 客户口径「一级/二级也要能选来搜索」——任意层级点
|
||||
圆点选中,序列化按子树展开类目名集合下发(后端 IN),选中即查(回第一页)。 -->
|
||||
<JdCategoryCascader
|
||||
:options="categoryOptions"
|
||||
:model-value="filter.category"
|
||||
:selected-path="filter.categoryPath"
|
||||
tree-only
|
||||
@change="onCategoryPicked"
|
||||
/>
|
||||
|
||||
@@ -85,3 +85,71 @@ export function jdCategorySearchLeaves(keyword: string): JdCategoryLeafRef[] {
|
||||
leaf.path.some((segment) => segment.toLowerCase().includes(needle)),
|
||||
)
|
||||
}
|
||||
|
||||
/** 全树节点引用(含非末级)——2026-11-18 客户口径「一级/二级类目也要能选来搜索」:
|
||||
* 搜索面板从"只铺末级"扩成"铺全部层级",非末级行可选中=按子树展开集合过滤。 */
|
||||
export interface JdCategoryNodeRef {
|
||||
name: string
|
||||
value: string
|
||||
/** 从一级到本节点的名称路径(选中态回显与子树展开都按它定位)。 */
|
||||
path: string[]
|
||||
/** children 缺省/空=末级(落库 category_path 直接等值命中)。 */
|
||||
leaf: boolean
|
||||
}
|
||||
|
||||
export function jdCategoryAllNodes(): JdCategoryNodeRef[] {
|
||||
const out: JdCategoryNodeRef[] = []
|
||||
const walk = (nodes: JdCategoryNode[], prefix: string[]): void => {
|
||||
for (const node of nodes) {
|
||||
const path = [...prefix, node.name]
|
||||
const hasChildren = !!node.children && node.children.length > 0
|
||||
out.push({ name: node.name, value: node.value, path, leaf: !hasChildren })
|
||||
if (hasChildren) walk(node.children as JdCategoryNode[], path)
|
||||
}
|
||||
}
|
||||
walk(JD_CATEGORY_TREE, [])
|
||||
return out
|
||||
}
|
||||
|
||||
/** 全树节点按关键词过滤:名称或路径任一段命中(大小写不敏感 includes)。 */
|
||||
export function jdCategorySearchNodes(keyword: string): JdCategoryNodeRef[] {
|
||||
const needle = keyword.trim().toLowerCase()
|
||||
if (!needle) return jdCategoryAllNodes()
|
||||
return jdCategoryAllNodes().filter(
|
||||
(node) =>
|
||||
node.name.toLowerCase().includes(needle) ||
|
||||
node.path.some((segment) => segment.toLowerCase().includes(needle)),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中节点 → 下发后端的类目名集合(2026-11-18 前端展开+后端 IN 路线):
|
||||
* 返回该节点**自身+全部后代**的类目名(去重、层级序)。含自身是因为落库
|
||||
* `category_path` =京麦实际末级名,快照层级可能比实际深/浅——父级名本身也可能就是
|
||||
* 某批行的末级名(真机样本「艺考形体服」即三级节点名)。路径无效返回 null(调用方
|
||||
* 按单名等值兜底,语义同树外历史行)。
|
||||
*/
|
||||
export function jdCategoryNamesUnder(path: string[]): string[] | null {
|
||||
let level = JD_CATEGORY_TREE
|
||||
let target: JdCategoryNode | null = null
|
||||
for (const name of path) {
|
||||
const hit = level.find((node) => node.name === name)
|
||||
if (!hit) return null
|
||||
target = hit
|
||||
level = hit.children ?? []
|
||||
}
|
||||
if (!target) return null
|
||||
const out: string[] = []
|
||||
const seen = new Set<string>()
|
||||
const walk = (nodes: JdCategoryNode[]): void => {
|
||||
for (const node of nodes) {
|
||||
if (!seen.has(node.name)) {
|
||||
seen.add(node.name)
|
||||
out.push(node.name)
|
||||
}
|
||||
if (node.children && node.children.length) walk(node.children)
|
||||
}
|
||||
}
|
||||
walk([target])
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ export async function fetchJdProductList(
|
||||
productCode: params.productCode ?? '',
|
||||
titleKeyword: params.titleKeyword ?? '',
|
||||
category: params.category ?? '',
|
||||
categoryPath: params.categoryPath ?? [],
|
||||
groupId: params.groupId ?? '',
|
||||
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
@@ -37,7 +38,13 @@ export async function fetchJdProductList(
|
||||
params.pageSize,
|
||||
params.ownerGroupId ?? null,
|
||||
)
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, { params: query })
|
||||
// category 多值(父级展开集合)必须序列化成重复 `category=a&category=b`:axios 默认
|
||||
// 给数组加 `[]` 后缀,后端 @RequestParam("category") List<String> 认不到。
|
||||
// indexes:false = 无括号无下标的重复键(axios 1.x 官方口径)。
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, {
|
||||
params: query,
|
||||
paramsSerializer: { indexes: false },
|
||||
})
|
||||
return parseJdProductPage(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* 日期默认空字符串:同步台账是累计数据,默认当天会让首屏只剩今天同步的行
|
||||
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
||||
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
|
||||
import { jdCategoryNamesUnder } from './jd-category-tree.ts'
|
||||
|
||||
/** 每页条数默认 20(v1.4 §3.4),上限 100。 */
|
||||
export const JD_PRODUCT_PAGE_SIZE = 20
|
||||
@@ -28,8 +29,12 @@ export interface JdProductFilterState {
|
||||
productCode: string
|
||||
/** 标题关键字,空串不限。 */
|
||||
titleKeyword: string
|
||||
/** 类目(京麦末级类目名,等值过滤;选项来自 GET /categories),空串=全部类目。 */
|
||||
/** 类目(京麦类目名,末级或父级;选项来自级联面板),空串=全部类目。 */
|
||||
category: string
|
||||
/** 选中节点的名称路径(2026-11-18 一级/二级类目可选中):非空时序列化按
|
||||
* jdCategoryNamesUnder 展开为子树类目名集合下发(后端 IN);空=末级/树外行,
|
||||
* 按单名等值下发(旧形状)。 */
|
||||
categoryPath?: string[]
|
||||
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
|
||||
groupId: string
|
||||
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」,同日定默认卡未分类;
|
||||
@@ -49,7 +54,7 @@ export interface JdProductFilterState {
|
||||
export function createJdProductFilterState(): JdProductFilterState {
|
||||
// 分类状态出厂卡「未分类」(2026-11-17 用户口径「默认卡在未分类上就行」,2026-11-18
|
||||
// 加「全部」档后默认不动):首屏与「重置」都带 classified=false 查,全量走「全部」档。
|
||||
return { productCode: '', titleKeyword: '', category: '', groupId: '', classified: JD_PRODUCT_DEFAULT_CLASSIFIED, syncedFrom: '', syncedTo: '' }
|
||||
return { productCode: '', titleKeyword: '', category: '', categoryPath: [], groupId: '', classified: JD_PRODUCT_DEFAULT_CLASSIFIED, syncedFrom: '', syncedTo: '' }
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件。 */
|
||||
@@ -71,8 +76,9 @@ export interface JdProductQuery {
|
||||
page_size: number
|
||||
product_code?: string
|
||||
title_keyword?: string
|
||||
/** 京麦末级类目等值过滤(后端 JdProductQueryService.Filter.category)。 */
|
||||
category?: string
|
||||
/** 京麦类目名集合 IN 过滤(后端 JdProductQueryService.Filter.categories,
|
||||
* 2026-11-18 一级/二级类目可选中:父级展开为子树类目名集合;末级/树外=单元素)。 */
|
||||
category?: string[]
|
||||
/** 自定义分类 id(当前分组下的一个分类;V203 起按归属表 EXISTS 过滤)。 */
|
||||
group_id?: number
|
||||
/** 分类状态快筛(2026-11-17):true=已分类、false=未分类,缺省不下发=全部。
|
||||
@@ -91,6 +97,8 @@ export interface JdProductListParams {
|
||||
productCode?: string
|
||||
titleKeyword?: string
|
||||
category?: string
|
||||
/** 选中类目节点路径(见 JdProductFilterState.categoryPath;空=单名等值)。 */
|
||||
categoryPath?: string[]
|
||||
groupId?: string
|
||||
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
|
||||
classified?: string
|
||||
@@ -108,7 +116,14 @@ function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuer
|
||||
const titleKeyword = (state.titleKeyword || '').trim()
|
||||
if (titleKeyword) query.title_keyword = titleKeyword
|
||||
const category = (state.category || '').trim()
|
||||
if (category) query.category = category
|
||||
if (category) {
|
||||
// 2026-11-18 一级/二级类目可选中:带路径=按子树展开类目名集合(后端 IN);
|
||||
// 路径失效(树外历史名)回落单名等值集合——与旧 eq 语义逐字同形。
|
||||
const expanded = state.categoryPath && state.categoryPath.length
|
||||
? jdCategoryNamesUnder(state.categoryPath)
|
||||
: null
|
||||
query.category = expanded && expanded.length ? expanded : [category]
|
||||
}
|
||||
const groupId = Number.parseInt((state.groupId || '').trim(), 10)
|
||||
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
|
||||
// 分类状态快筛:只认两个显式档位,其余值(含脏值)按「全部」不下发——后端 classified
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
||||
"totals": {
|
||||
"files": 262,
|
||||
"cases": 1837,
|
||||
"files": 263,
|
||||
"cases": 1847,
|
||||
"pins": 460,
|
||||
"reads": 658
|
||||
},
|
||||
@@ -308,7 +308,7 @@
|
||||
"reads": 0
|
||||
},
|
||||
"jd-category-tree.test.ts": {
|
||||
"cases": 6,
|
||||
"cases": 8,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
@@ -1302,6 +1302,11 @@
|
||||
"pins": 2,
|
||||
"reads": 2
|
||||
},
|
||||
"user-menu-tree-platform-filter.test.ts": {
|
||||
"cases": 8,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"user-notice-chinese-only.test.ts": {
|
||||
"cases": 4,
|
||||
"pins": 0,
|
||||
|
||||
@@ -2,10 +2,13 @@ import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
JD_CATEGORY_TREE,
|
||||
jdCategoryAllNodes,
|
||||
jdCategoryChildren,
|
||||
jdCategoryLeaves,
|
||||
jdCategoryNamesUnder,
|
||||
jdCategoryRoots,
|
||||
jdCategorySearchLeaves,
|
||||
jdCategorySearchNodes,
|
||||
} from '../src/pages/jd/jd-category-tree.ts'
|
||||
|
||||
/** 京麦授权类目真树(2026-11-16 真机取证 getVenderLicenseCategory 快照;与用户端
|
||||
@@ -95,3 +98,37 @@ test('树数据快照不可空、value 全非空(取证 id 留档完整)', (
|
||||
assert.ok(leaf.value, `叶子 ${leaf.name} 必须带京麦类目 id`)
|
||||
}
|
||||
})
|
||||
|
||||
/** 2026-11-18 客户口径「一级/二级类目也要能选来搜索」:全层级节点+子树展开集合。 */
|
||||
test('全节点搜索:一级/二级/末级都在结果里,leaf 标记如实', () => {
|
||||
assert.equal(jdCategorySearchNodes('').length, jdCategoryAllNodes().length, '空词=全量节点')
|
||||
assert.ok(jdCategoryAllNodes().length > 250, '全节点数必须大于末级 250(含非末级)')
|
||||
const byName = jdCategorySearchNodes('女装')
|
||||
const women = byName.find((node) => node.name === '女装')
|
||||
assert.ok(women, '「女装」这个二级节点必须可搜到(旧版只铺末级,选不了它)')
|
||||
assert.equal(women!.leaf, false, '女装有子级=非末级')
|
||||
assert.deepEqual(women!.path, ['服饰内衣', '女装'], '路径从一级起(同名跨支靠它区分)')
|
||||
assert.ok(byName.some((node) => node.leaf), '末级命中照旧在')
|
||||
})
|
||||
|
||||
test('子树展开集合:含自身+全部后代名、去重、不越支;路径失效回 null', () => {
|
||||
const dress = jdCategoryNamesUnder(['服饰内衣', '女装', '连衣裙'])
|
||||
assert.ok(dress, '连衣裙路径有效')
|
||||
assert.ok(dress!.includes('连衣裙'), '含节点自身名(实际末级可能就在这一级)')
|
||||
assert.ok(dress!.includes('短袖连衣裙') && dress!.includes('长袖连衣裙') && dress!.includes('无袖连衣裙'))
|
||||
assert.ok(!dress!.includes('女装'), '只展开本节点子树,不带上父级')
|
||||
|
||||
const top = jdCategoryNamesUnder(['运动户外'])
|
||||
assert.ok(top!.includes('艺考形体服') && top!.includes('啦啦队服'), '一级展开覆盖全支')
|
||||
assert.ok(!top!.includes('女装'), '不越支')
|
||||
|
||||
const hanfu = jdCategoryNamesUnder(['服饰内衣', '女装', '汉服'])
|
||||
assert.ok(hanfu!.includes('汉服') && hanfu!.includes('汉服套装'), '非叶「汉服」展开含四级')
|
||||
|
||||
assert.equal(jdCategoryNamesUnder(['不存在', '的路径']), null, '路径失效回 null(调用方按单名兜底)')
|
||||
assert.equal(jdCategoryNamesUnder([]), null, '空路径回 null')
|
||||
|
||||
// 去重:同名跨支在**同一子树内**出现两次时集合不重复(唐装/短裤等在女装支内只有一个)。
|
||||
const women = jdCategoryNamesUnder(['服饰内衣', '女装'])!
|
||||
assert.equal(new Set(women).size, women.length, '展开集合内部去重')
|
||||
})
|
||||
|
||||
@@ -97,17 +97,30 @@ test('列表行价格:BigDecimal 的 JSON number 形状与字符串形状都
|
||||
assert.equal(jdPriceRange(missing), '', '两侧都空回空串(列表显示 -)')
|
||||
})
|
||||
|
||||
/** 类目筛选(2026-11-15):京麦末级类目等值过滤,空串不下发、非空透传 category。 */
|
||||
test('类目筛选参数序列化:空串不下发、非空下发 category(等值过滤)', async () => {
|
||||
/** 类目筛选(2026-11-15 末级等值;2026-11-18 一级/二级可选中=子树展开集合 IN):
|
||||
* 空串不下发;无路径=单元素集合(等值旧形状);带路径=jdCategoryNamesUnder 展开。 */
|
||||
test('类目筛选参数序列化:空串不下发、末级单值、父级展开子树集合', async () => {
|
||||
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
|
||||
await import('../src/pages/jd/jd-product-filter.ts')
|
||||
const empty = createJdProductFilterState()
|
||||
assert.equal('category' in toJdProductListParams(empty, 1, 20), false, '全部类目不下发 category')
|
||||
assert.equal(jdProductFilterActive(empty), false)
|
||||
|
||||
const filtered = { ...empty, category: ' 服饰内衣 ' }
|
||||
assert.equal(toJdProductListParams(filtered, 1, 20).category, '服饰内衣', '去空白透传(等值过滤)')
|
||||
assert.equal(jdProductFilterActive(filtered), true, '选中类目算激活筛选')
|
||||
const leaf = { ...empty, category: ' 艺考形体服 ' }
|
||||
assert.deepEqual(toJdProductListParams(leaf, 1, 20).category, ['艺考形体服'],
|
||||
'无路径=去空白单元素集合(等值旧形状,后端 IN 单值等价)')
|
||||
assert.equal(jdProductFilterActive(leaf), true, '选中类目算激活筛选')
|
||||
|
||||
const parent = { ...empty, category: '女装', categoryPath: ['服饰内衣', '女装'] }
|
||||
const expanded = toJdProductListParams(parent, 1, 20).category as string[]
|
||||
assert.ok(Array.isArray(expanded) && expanded.length > 20, '一级/二级选中=子树展开集合')
|
||||
assert.ok(expanded.includes('女装'), '集合含节点自身名(实际末级可能就在这一级)')
|
||||
assert.ok(expanded.includes('连衣裙') && expanded.includes('短袖连衣裙'), '含后代各级名')
|
||||
assert.ok(!expanded.includes('艺考形体服'), '不越出子树(艺考形体服在运动户外支)')
|
||||
|
||||
const stale = { ...empty, category: '已下架历史类目', categoryPath: ['不存在', '的路径'] }
|
||||
assert.deepEqual(toJdProductListParams(stale, 1, 20).category, ['已下架历史类目'],
|
||||
'路径失效(树外历史名)回落单名等值,不静默丢筛选')
|
||||
})
|
||||
|
||||
test('自定义分类使用 group_id,不发送分类状态参数', async () => {
|
||||
|
||||
@@ -608,6 +608,49 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.find('.cat-trigger').text()).toContain('腰带/腰链')
|
||||
})
|
||||
|
||||
it('一级/二级类目点圆点可选中即查(2026-11-18 客户口径「没办法选择一级跟二级类目」):入参带节点路径、行体仍下钻', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
|
||||
// 一级行体点击=仍下钻(旧语义不动);一级圆点点击=选中整棵一级子树。
|
||||
const firstCol = wrapper.findAll('.cat-col')[0]
|
||||
const apparelRow = firstCol.findAll('.cat-row').find((row) => row.text().includes('服饰内衣'))!
|
||||
await apparelRow.find('.cat-dot').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.cat-panel').exists()).toBe(false, '点圆点选中后面板收起')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({
|
||||
category: '服饰内衣',
|
||||
categoryPath: ['服饰内衣'],
|
||||
page: 1,
|
||||
}, '一级选中=带路径下发(序列化侧展开子树类目名集合)')
|
||||
expect(wrapper.find('.cat-trigger').text()).toContain('服饰内衣')
|
||||
|
||||
// 下钻两级后点二级圆点:路径带全前缀,同名跨支靠路径区分。
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
const col1 = wrapper.findAll('.cat-col')[0]
|
||||
await col1.findAll('.cat-row').find((row) => row.text().includes('服饰内衣'))!.trigger('click')
|
||||
const col2 = wrapper.findAll('.cat-col')[1]
|
||||
await col2.findAll('.cat-row').find((row) => row.text().includes('女装'))!.find('.cat-dot').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({
|
||||
category: '女装',
|
||||
categoryPath: ['服饰内衣', '女装'],
|
||||
page: 1,
|
||||
})
|
||||
|
||||
// 选中态回显:重新打开面板并下钻,被选节点(女装)的圆点是蓝芯(.cat-dot.on),
|
||||
// 其余行空心——11-16 旧形状里非末级行圆点永远空心、无法表达选中。
|
||||
await wrapper.find('.cat-trigger').trigger('click')
|
||||
const reopened1 = wrapper.findAll('.cat-col')[0]
|
||||
await reopened1.findAll('.cat-row').find((row) => row.text().includes('服饰内衣'))!.trigger('click')
|
||||
const reopened2 = wrapper.findAll('.cat-col')[1]
|
||||
const womenRow = reopened2.findAll('.cat-row').find((row) => row.text().includes('女装'))!
|
||||
expect(womenRow.find('.cat-dot').classes()).toContain('on', '二级选中态圆点回显')
|
||||
const menRow = reopened2.findAll('.cat-row').find((row) => row.text().includes('男装'))!
|
||||
expect(menRow.find('.cat-dot').classes()).not.toContain('on', '未选中行保持空心圆')
|
||||
})
|
||||
|
||||
it('类目级联搜索与清选(2026-11-16 真树重做):树内末级命中+树外兜底段;「全部类目」行/触发框 × 都能清选重查', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||
{ name: '艺考形体服', productCount: 120 },
|
||||
|
||||
+17
-2
@@ -112,9 +112,15 @@ public class AdminUserService {
|
||||
query.eq(AdminUserEntity::getCompanyId, companyIdFilter);
|
||||
}
|
||||
} else if (isCompanySuperAdmin) {
|
||||
// 公司超管看本公司全部账号(站点超管账号除外——那是平台自己的身份)
|
||||
// 2026-11-18 客户口径「admin 看所有,其余公司超管各自看各自名下的」:
|
||||
// 公司超管只看本人那行+自己直接创建(created_by_id=本人)的账号,
|
||||
// 本公司内由站点超管或其他组长建的行不再可见——与下面组长档同一形状。
|
||||
// 站点超管行本来就不可能落进这个谓词(ne 只是对脏数据的保险,保留)。
|
||||
Long selfId = currentUser.getId();
|
||||
query.eq(AdminUserEntity::getCompanyId, currentUser.getCompanyId())
|
||||
.ne(AdminUserEntity::getRole, "super_admin");
|
||||
.ne(AdminUserEntity::getRole, "super_admin")
|
||||
.and(w -> w.eq(AdminUserEntity::getId, selfId)
|
||||
.or(inner -> inner.eq(AdminUserEntity::getCreatedById, selfId)));
|
||||
if (!kw.isEmpty()) {
|
||||
query.like(AdminUserEntity::getUsername, kw);
|
||||
}
|
||||
@@ -441,6 +447,11 @@ public class AdminUserService {
|
||||
if (!currentUser.getCompanyId().equals(target.getCompanyId())) {
|
||||
throw new BusinessException(403, "只能编辑本公司名下的账号");
|
||||
}
|
||||
// 2026-11-18 与读侧「各自看各自名下」同口径:目标必须是自己直接创建的,
|
||||
// 否则就是「列表看不见、API 照样改」的洞(停用/改密/额度全走这条闸)。
|
||||
if (!currentUser.getId().equals(target.getCreatedById())) {
|
||||
throw new BusinessException(403, "只能编辑自己名下创建的账号");
|
||||
}
|
||||
}
|
||||
if ("super_admin".equals(wantRole)) {
|
||||
throw new BusinessException("不能将用户设为超级管理员");
|
||||
@@ -610,6 +621,10 @@ public class AdminUserService {
|
||||
if (!currentUser.getCompanyId().equals(target.getCompanyId())) {
|
||||
throw new BusinessException(403, "只能删除本公司名下的账号");
|
||||
}
|
||||
// 2026-11-18 与读侧/updateUser 同口径:只清退自己直接创建的账号
|
||||
if (!currentUser.getId().equals(target.getCreatedById())) {
|
||||
throw new BusinessException(403, "只能删除自己名下创建的账号");
|
||||
}
|
||||
}
|
||||
int affected = adminUserMapper.deleteById(uid);
|
||||
if (affected == 0) {
|
||||
|
||||
+4
-2
@@ -114,7 +114,9 @@ public class AdminJdProductController {
|
||||
@Parameter(description = "每页数量") @RequestParam(name = "page_size", defaultValue = PageDefaults.JD_PRODUCTS_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "商品编码(包含匹配)") @RequestParam(name = "product_code", required = false) String productCode,
|
||||
@Parameter(description = "标题关键词(包含匹配)") @RequestParam(name = "title_keyword", required = false) String titleKeyword,
|
||||
@Parameter(description = "类目(京麦末级类目名,eq)") @RequestParam(name = "category", required = false) String category,
|
||||
@Parameter(description = "类目(京麦类目名,多值 IN;2026-11-18 支持选一级/二级类目——"
|
||||
+ "前端把选中节点展开为其子树全部类目名,用重复 category 参数下发,单值形状照常工作)")
|
||||
@RequestParam(name = "category", required = false) List<String> categories,
|
||||
@Parameter(description = "自定义分类 id(类目面板「自定义分类」选中驱动)") @RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "当前数据权限分组 id(分类列/分类筛选按它取;缺省=作用域默认分组)")
|
||||
@RequestParam(name = "owner_group_id", required = false) Long ownerGroupId,
|
||||
@@ -136,7 +138,7 @@ public class AdminJdProductController {
|
||||
requireVisibleCategory(scope, groupId);
|
||||
}
|
||||
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
|
||||
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo, classified,
|
||||
productCode, titleKeyword, categories, groupId, syncedFrom, syncedTo, classified,
|
||||
scopedOwnerGroupId));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
/**
|
||||
* 后管只读页总数(Phase 5,v1.4):与 {@link #selectProductPage} 同一过滤面
|
||||
* (商品编码/标题关键词/类目/自定义分类/同步起止,全部 SQL 侧下推,铁律 20)。
|
||||
* {@code categories}(2026-11-18 一级/二级类目可选):类目名集合 IN,空/ null=不过滤;
|
||||
* 选父级时由前端展开为子树类目名集合下发,单值=原 eq 形状。
|
||||
* 公司维过滤已随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉
|
||||
* (数据全平台公共);{@code groupId} 为空或 ≤0=不过滤该面;
|
||||
* {@code ungrouped}/{@code grouped} 两档(未分类/已分类)已随同日口径
|
||||
@@ -55,7 +57,7 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
*/
|
||||
long countProducts(@Param("productCode") String productCode,
|
||||
@Param("titleKeyword") String titleKeyword,
|
||||
@Param("category") String category,
|
||||
@Param("categories") List<String> categories,
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo,
|
||||
@@ -96,7 +98,7 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
*/
|
||||
List<JdProductEntity> selectProductPage(@Param("productCode") String productCode,
|
||||
@Param("titleKeyword") String titleKeyword,
|
||||
@Param("category") String category,
|
||||
@Param("categories") List<String> categories,
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo,
|
||||
|
||||
+18
-9
@@ -78,7 +78,9 @@ public class JdProductQueryService {
|
||||
/**
|
||||
* 分页查询商品行({@code synced_at} 倒序)。
|
||||
*
|
||||
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq(2026-11-16 起
|
||||
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 IN(2026-11-18 起多值:
|
||||
* 选一级/二级类目由前端展开为子树类目名集合下发,单值=原 eq 形状;空集合=不过滤该面)、
|
||||
* 分组 eq(2026-11-16 起
|
||||
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)、分类状态档
|
||||
* {@code classified}(2026-11-17 用户口径「加个已分类和未分类的筛选」:true=当前分组下
|
||||
* 有分类、false=没有、null=全部;按 V203 归属表 EXISTS/NOT EXISTS 在 SQL 侧下推,
|
||||
@@ -89,7 +91,7 @@ public class JdProductQueryService {
|
||||
* 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p>
|
||||
*/
|
||||
public JdProductPageVo page(Long page, Long pageSize,
|
||||
String productCode, String titleKeyword, String category, Long groupId,
|
||||
String productCode, String titleKeyword, List<String> categories, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified, Long ownerGroupId) {
|
||||
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
|
||||
throw new BusinessException("开始时间不能晚于结束时间");
|
||||
@@ -97,14 +99,14 @@ public class JdProductQueryService {
|
||||
long safePage = page == null || page < 1 ? 1 : Math.min(page, MAX_PAGE);
|
||||
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
|
||||
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
|
||||
Filter filter = filter(productCode, titleKeyword, category,
|
||||
Filter filter = filter(productCode, titleKeyword, categories,
|
||||
groupId, syncedFrom, syncedTo, classified);
|
||||
long total = jdProductMapper.countProducts(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.titleKeyword(), filter.categories(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId);
|
||||
List<JdProductEntity> rows = total <= 0 ? List.of()
|
||||
: jdProductMapper.selectProductPage(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.titleKeyword(), filter.categories(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
|
||||
(safePage - 1) * safeSize, (int) safeSize);
|
||||
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
|
||||
@@ -228,18 +230,25 @@ public class JdProductQueryService {
|
||||
// ---------------------------------------------------------------- 过滤面
|
||||
|
||||
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘);
|
||||
* classified 原样直传(null=不过滤该面,2026-11-17 分类状态快筛)。 */
|
||||
* classified 原样直传(null=不过滤该面,2026-11-17 分类状态快筛);
|
||||
* categories 逐项 trim、去空白、去重,空集合归 null=不过滤该面(2026-11-18 一级/二级类目展开)。 */
|
||||
private record Filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId,
|
||||
List<String> categories, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
|
||||
}
|
||||
|
||||
private static Filter filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId,
|
||||
List<String> categories, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
|
||||
Long safeGroupId = groupId != null && groupId > 0 ? groupId : null;
|
||||
List<String> safeCategories = categories == null ? null : categories.stream()
|
||||
.map(JdProductQueryService::trimToNull)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
return new Filter(trimToNull(productCode), trimToNull(titleKeyword),
|
||||
trimToNull(category), safeGroupId, syncedFrom, syncedTo, classified);
|
||||
safeCategories == null || safeCategories.isEmpty() ? null : safeCategories,
|
||||
safeGroupId, syncedFrom, syncedTo, classified);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 列表/详情搬运
|
||||
|
||||
@@ -115,7 +115,13 @@
|
||||
<sql id="productConds">
|
||||
<if test="productCode != null and productCode != ''">AND p.product_code LIKE CONCAT('%', #{productCode}, '%')</if>
|
||||
<if test="titleKeyword != null and titleKeyword != ''">AND p.title LIKE CONCAT('%', #{titleKeyword}, '%')</if>
|
||||
<if test="category != null and category != ''">AND p.category_path = #{category}</if>
|
||||
<!-- 类目过滤(2026-11-18 一级/二级类目可选):单值=原 eq 形状;父级选中由前端展开为
|
||||
子树类目名集合,这里 IN 下推(铁律 20:谓词必须在 SQL 侧,不得 Java 侧对已取页 filter)。
|
||||
服务侧已逐项 trim/去空白/去重,空集合归 null 不进本分支。 -->
|
||||
<if test="categories != null and categories.size() > 0">
|
||||
AND p.category_path IN
|
||||
<foreach collection="categories" item="cat" open="(" separator="," close=")">#{cat}</foreach>
|
||||
</if>
|
||||
<if test="groupId != null and groupId > 0">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM biz_jd_product_group_assign a
|
||||
|
||||
+70
-3
@@ -172,7 +172,9 @@ class AdminUserServiceCompanySuperAdminTest {
|
||||
// ---------- 列表 ----------
|
||||
|
||||
@Test
|
||||
void companySuperAdminListsOwnCompanyWithoutSiteSuperAdmin() {
|
||||
void companySuperAdminOnlyListsOwnSubordinates() {
|
||||
// 2026-11-18 客户口径:公司超管只看「本人那行+自己直接创建的」,不再看本公司全部。
|
||||
// 判据形状:谓词必须同时出现 company_id、created_by_id 与 id=本人(读侧与组长档同形)。
|
||||
AdminUserEntity operator = user(9L, "company_super_admin", 2L, null);
|
||||
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
when(userMapper.selectCount(any())).thenReturn(0L);
|
||||
@@ -184,8 +186,27 @@ class AdminUserServiceCompanySuperAdminTest {
|
||||
ArgumentCaptor.forClass(LambdaQueryWrapper.class);
|
||||
verify(userMapper).selectCount(captor.capture());
|
||||
// 先碰一次 SqlSegment 才会铺出参数(MP 惯例)
|
||||
captor.getValue().getSqlSegment();
|
||||
assertThat(captor.getValue().getParamNameValuePairs().values()).contains(2L);
|
||||
String sql = captor.getValue().getSqlSegment();
|
||||
assertThat(sql).contains("company_id").contains("created_by_id");
|
||||
assertThat(captor.getValue().getParamNameValuePairs().values())
|
||||
.contains(2L) // 本公司
|
||||
.contains(9L); // 本人(id=本人 OR created_by_id=本人,两处同一值)
|
||||
}
|
||||
|
||||
@Test
|
||||
void siteSuperAdminListStillUnscopedBySubordinates() {
|
||||
// 反向保险:收窄只落在公司超管档——平台超管「看所有」,谓词里不得出现 created_by_id 强制项
|
||||
AdminUserEntity operator = user(1L, "super_admin", 1L, null);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectCount(any())).thenReturn(0L);
|
||||
when(userMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
service.listUsers(operator, 1, 15, null, null, null, null);
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper<AdminUserEntity>> captor =
|
||||
ArgumentCaptor.forClass(LambdaQueryWrapper.class);
|
||||
verify(userMapper).selectCount(captor.capture());
|
||||
assertThat(captor.getValue().getSqlSegment()).doesNotContain("created_by_id");
|
||||
}
|
||||
|
||||
// ---------- 编辑 ----------
|
||||
@@ -244,6 +265,52 @@ class AdminUserServiceCompanySuperAdminTest {
|
||||
.hasMessageContaining("只有超级管理员可以修改公司超级管理员");
|
||||
}
|
||||
|
||||
@Test
|
||||
void companySuperAdminCannotEditAccountCreatedByOthers() {
|
||||
// 2026-11-18 写侧与读侧同口径:本公司但由别人(组长8/站点超管)创建的账号,
|
||||
// 列表已不可见,API 也必须 403——不留「看不见但改得动」的洞。
|
||||
AdminUserEntity operator = user(9L, "company_super_admin", 1L, 2L);
|
||||
AdminUserEntity target = user(12L, "admin", 1L, 8L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
when(userMapper.selectById(12L)).thenReturn(target);
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setPassword("secret1");
|
||||
|
||||
assertThatThrownBy(() -> service.updateUser(operator, 12L, request))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("只能编辑自己名下创建的账号");
|
||||
verify(userMapper, never()).update(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void companySuperAdminCanEditOwnCreatedAdmin() {
|
||||
AdminUserEntity operator = user(9L, "company_super_admin", 1L, 2L);
|
||||
AdminUserEntity target = user(12L, "admin", 1L, 9L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
when(userMapper.selectById(12L)).thenReturn(target);
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setPassword("secret1");
|
||||
|
||||
service.updateUser(operator, 12L, request);
|
||||
|
||||
verify(userMapper).update(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void companySuperAdminCannotDeleteAccountCreatedByOthers() {
|
||||
AdminUserEntity operator = user(9L, "company_super_admin", 1L, 2L);
|
||||
AdminUserEntity target = user(12L, "normal", 1L, 8L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
when(userMapper.selectById(12L)).thenReturn(target);
|
||||
|
||||
assertThatThrownBy(() -> service.deleteUser(operator, 12L))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("只能删除自己名下创建的账号");
|
||||
verify(userMapper, never()).deleteById(12L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void companySuperAdminCannotDeleteCompanySuperAdminTarget() {
|
||||
AdminUserEntity operator = user(9L, "company_super_admin", 1L, 2L);
|
||||
|
||||
+36
-3
@@ -726,15 +726,48 @@ class AdminJdProductControllerTest {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null, null, null);
|
||||
verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null);
|
||||
verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null, 0L, 20);
|
||||
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", List.of(" 艺考形体服 "), 7L, null, null, null, null);
|
||||
verify(mapper).countProducts("SKU-1", "连衣裙", List.of("艺考形体服"), 7L, null, null, null, null);
|
||||
verify(mapper).selectProductPage("SKU-1", "连衣裙", List.of("艺考形体服"), 7L, null, null, null, null, 0L, 20);
|
||||
|
||||
service.page(1L, 20L, " ", null, null, 0L, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null, 0L, 20);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2026-11-18 一级/二级类目可选(前端展开子树类目名集合下发):
|
||||
* ① 服务侧逐项 trim、去空白、去重后进 mapper;全空白集合归 null=不过滤该面;
|
||||
* ② XML 绊线:类目谓词必须是 IN+foreach 下推(改回单值 eq 即红,铁律 20 同形)。
|
||||
*/
|
||||
@Test
|
||||
void 类目多值必须逐项归一并IN下推() throws IOException {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
|
||||
service.page(1L, 20L, null, null,
|
||||
java.util.Arrays.asList(" 女装 ", "女装", "", null, " 汉服/旗袍 "),
|
||||
null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, List.of("女装", "汉服/旗袍"),
|
||||
null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, null, List.of("女装", "汉服/旗袍"),
|
||||
null, null, null, null, null, 0L, 20);
|
||||
|
||||
// 全空白/空集合=不过滤该面(与「全部类目」清选同口径,不得下发空 IN)
|
||||
service.page(1L, 20L, null, null, java.util.Arrays.asList(" ", ""), null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null);
|
||||
|
||||
Path xml = findJdProductMapperXml();
|
||||
String xmlText = stripComments(Files.readString(xml)).replaceAll("(?s)<!--.*?-->", "");
|
||||
assertTrue(xmlText.contains("p.category_path IN"),
|
||||
"类目谓词必须是 IN 下推(2026-11-18 父级类目展开集合)");
|
||||
assertTrue(xmlText.contains("<foreach collection=\"categories\""),
|
||||
"IN 集合必须由 foreach 展开(拼串即红)");
|
||||
assertFalse(xmlText.contains("p.category_path = #{category}"),
|
||||
"改回单值 eq 即红——一级/二级类目展开会整体失效");
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):
|
||||
* ① classified+ownerGroupId 必须原样下传给 mapper(谓词在 XML 的 EXISTS/NOT EXISTS 段,
|
||||
|
||||
Reference in New Issue
Block a user