feat(京东数据库): 撤销按公司隔离回归全平台共享采集池+后管商品目录改京东平台类目平铺
客户口径(2026-11-26):「采集的数据可以重复被操作分类,大家一起采集,但分类后的 数据就自己看,所以会有数据副本」「被分类后按组 id 绑定拷贝数据副本,原来的数据 也要留着」。 - 可见口径:商品行全平台共享(2026-11-23 的按公司隔离整批撤销),读侧撤 companyId 谓词(列表/类目下拉/候选店铺/详情/导出),写侧撤 assertRowsInCompany 行级公司闸——越权由端点级 requireJdProductWrite(仅平台超管+公司超管)兜住。 「副本」落在 V203 归属行上:同一商品可多组各一条 owner_group_id,分类列/分类 筛选各看各的;原商品行一条不删不藏,别组分过类的在本组仍显示未分类、可再分。 - 用户端选品 pageInScope 不再按 companyId 收窄(只认可见分组下的归属行)。 - 后管左栏「商品目录」:授权类目树/内置花屿巷快照退役,改为 /categories 的 category_path 平铺(末级类目名+商品数),点行=末级名等值过滤;删 jd-category-tree.ts / jd-shop-category-api.ts 及其测试,JdDatabasePage 不再取树。 - 判据:AdminJdProductControllerTest 34、JdProductMapperSqlTest 5、 JdGroupShopServiceTest 10、JdProductQueryServiceUserPageTest 7 全绿; 后管 node --test 1963/vitest 250/vue-tsc rc=0。
This commit is contained in:
@@ -1,22 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 京东数据库页左侧栏(v1.6 蓝图 Phase 2,additive——页面接线随 Phase 5):
|
/** 京东数据库页左侧栏:
|
||||||
* 双 Tab=商品目录(京麦授权类目真树+计数徽标+展开折叠+树外类目组)/
|
* 双 Tab=商品目录(<b>京东平台类目平铺</b>:后端 `/categories` 的 DISTINCT `category_path`
|
||||||
* 店铺分类(当前数据权限分组的分类平铺+计数+新建分类+分类管理入口)。
|
* 末级类目名+商品数)/店铺分类(当前数据权限分组的分类平铺+计数+新建分类+分类管理入口)。
|
||||||
*
|
*
|
||||||
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本组件不发请求、
|
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本组件不发请求、
|
||||||
* 不 import api——mount 测试免 mock;内部状态只有双 Tab 切换、树展开/折叠与新建输入框。
|
* 不 import api——mount 测试免 mock;内部状态只有双 Tab 切换与新建输入框。
|
||||||
* 计数聚合走 jdCategoryCountTree(v1.6 Phase 1):节点徽标=自身名+子树叶和(与
|
*
|
||||||
* 「点节点 → 子树展开 IN 过滤」的命中集合同源)。树只渲染本店真有商品的类目分支
|
* 2026-11-26 客户口径(「京东分类是百分百有的,京东内分类就不需要」):商品目录改用
|
||||||
* (零命中整支剪掉,2026-11-24),树上挂不上的本店类目平铺/归组显示,点行=单名等值
|
* **京东平台类目**,不再依赖按店铺上报的授权类目树 `biz_jd_shop_category_tree`,也不再
|
||||||
* 旧形状(path 空数组交给页面回落)。 */
|
* 回落内置快照 `JD_CATEGORY_TREE`(那是 2026-11-16 一家店的历史取证,换店必整树零命中,
|
||||||
import { computed, nextTick, ref, watch } from 'vue'
|
* 此前靠「零命中剪枝+树外兜底组」打补丁)。平铺一层后点行=该末级类目名等值过滤,
|
||||||
import {
|
* 与后端 `p.category_path IN (...)` 单元素集合逐字同形。 */
|
||||||
JD_CATEGORY_TREE,
|
import { computed, ref } from 'vue'
|
||||||
jdCategoryCountTree,
|
|
||||||
jdCategoryPruneZero,
|
|
||||||
type JdCategoryCountedNode,
|
|
||||||
type JdCategoryNode,
|
|
||||||
} from './jd-category-tree.ts'
|
|
||||||
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
|
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
@@ -35,10 +30,6 @@ const props = withDefaults(defineProps<{
|
|||||||
selectedGroupId?: number | null
|
selectedGroupId?: number | null
|
||||||
/** 当前店铺筛选(v1.7 店铺名单点选;空/缺省=未按店铺过滤)。 */
|
/** 当前店铺筛选(v1.7 店铺名单点选;空/缺省=未按店铺过滤)。 */
|
||||||
selectedShopName?: string | null
|
selectedShopName?: string | null
|
||||||
/** 授权类目树(2026-11-23):页面从服务端取「已上报店铺并集」的真树传入;
|
|
||||||
* 缺省/空数组=回落内置快照(`JD_CATEGORY_TREE`,一家店的历史取证,
|
|
||||||
* 另由零命中剪枝兜住,不冒充本店类目)。 */
|
|
||||||
categoryTree?: JdCategoryNode[] | null
|
|
||||||
/** 类目计数行是否已取过(页面 loading 态投影;缺省/true=已就绪)。首帧未就绪时侧栏
|
/** 类目计数行是否已取过(页面 loading 态投影;缺省/true=已就绪)。首帧未就绪时侧栏
|
||||||
* 不画树:否则会先把回落快照整棵树(别店类目、徽标全 0、「全部商品 0」)画出来,计数
|
* 不画树:否则会先把回落快照整棵树(别店类目、徽标全 0、「全部商品 0」)画出来,计数
|
||||||
* 到达后再收成「本店无匹配」一行——用户肉眼看到一次「过一会变了」的闪变。 */
|
* 到达后再收成「本店无匹配」一行——用户肉眼看到一次「过一会变了」的闪变。 */
|
||||||
@@ -50,8 +41,8 @@ const props = withDefaults(defineProps<{
|
|||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
/** 选类目:树内节点带完整路径(页面按子树展开类目名集合 IN 下发);树外名
|
/** 选类目:京东平台类目末级名,path 恒为空数组(页面按单名集合 IN 下发);
|
||||||
* path=[](序列化回落单名等值);null=「全部商品」清选重查。 */
|
* null=「全部商品」清选重查。 */
|
||||||
(event: 'select-category', value: { name: string; path: string[] } | null): void
|
(event: 'select-category', value: { name: string; path: string[] } | null): void
|
||||||
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
|
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
|
||||||
(event: 'select-group', id: number | null): void
|
(event: 'select-group', id: number | null): void
|
||||||
@@ -78,196 +69,31 @@ const emit = defineEmits<{
|
|||||||
/** 左 Tab 内置展示态:出厂停在「商品目录」(首屏主筛选面)。 */
|
/** 左 Tab 内置展示态:出厂停在「商品目录」(首屏主筛选面)。 */
|
||||||
const activeTab = ref<'catalog' | 'custom'>('catalog')
|
const activeTab = ref<'catalog' | 'custom'>('catalog')
|
||||||
|
|
||||||
// ---------------- 计数聚合(Phase 1 纯函数) ----------------
|
// ---------------- 商品目录(京东平台类目平铺) ----------------
|
||||||
|
|
||||||
/** 生效的授权类目树:服务端真树优先,没有则回落到内置快照(一家店的历史取证)。 */
|
|
||||||
const activeTree = computed<JdCategoryNode[]>(() =>
|
|
||||||
(props.categoryTree && props.categoryTree.length ? props.categoryTree : JD_CATEGORY_TREE))
|
|
||||||
|
|
||||||
const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? [], activeTree.value))
|
|
||||||
|
|
||||||
/** 类目计数就绪(页面首帧未回时只留加载行,总数显示「—」)。 */
|
/** 类目计数就绪(页面首帧未回时只留加载行,总数显示「—」)。 */
|
||||||
const catalogReady = computed(() => props.categoriesReady !== false)
|
const catalogReady = computed(() => props.categoriesReady !== false)
|
||||||
|
|
||||||
/** 只渲染「本店真有商品」的类目分支(2026-11-24 客户口径「正确是一开始显示的那样,而不是
|
/** 「全部商品」徽标=全部计数行求和(有类目名的商品总数;无类目名的行不在任何类目筛选的
|
||||||
* 什么树兜底」):授权树里 count=0 的整支剪掉——落地后效果是
|
* 命中集里,不计进任何徽标)。 */
|
||||||
* - 本店商品名都在树上(如花屿巷旗舰店)⇒ 只显示命中分支,别店的空分支不出现;
|
|
||||||
* - 树与本店不同源(如家居日用店看花屿巷快照)⇒ 整树剪空 ⇒ 本店类目名平铺成一级列表,
|
|
||||||
* 既不再显示别店的服饰树,也不再出现「树外兜底」这种退化分组。
|
|
||||||
* 树内节点徽标本来就是子树去重和(jdCategoryCountTree 同源),剪枝只裁掉 count=0 且无子的节点。 */
|
|
||||||
const visibleRoots = computed(() => jdCategoryPruneZero(counted.value.roots))
|
|
||||||
|
|
||||||
/** 树之外的本店类目(授权树里对不上的名字);树被剪空时它们就是整列内容,故不摆分组头。 */
|
|
||||||
const extraIsSolo = computed(() => visibleRoots.value.length === 0)
|
|
||||||
/** 「全部商品」徽标=全部计数行求和(树内+树外=有类目名的商品总数;无类目名的行
|
|
||||||
* 不在任何类目筛选的命中集里,不计进任何徽标)。 */
|
|
||||||
const totalCount = computed(() =>
|
const totalCount = computed(() =>
|
||||||
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
|
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
|
||||||
|
|
||||||
/** 展开态:按路径串('/' 连接)记。出厂(无记忆)一级默认展开(二级可见);
|
/** 商品目录行:后端 `/categories` 已按类目名升序 DISTINCT,这里只归一脏数据
|
||||||
* v1.7 树增强:展开态持久化 localStorage `jd_db_cat_expand`(切页/重进不丢),损坏/不存在
|
* (空名/负计数),一列平铺——没有树、没有展开折叠、没有「树外兜底」分组。 */
|
||||||
* =按出厂态(宁可重展一级也不冒充用户记忆)。 */
|
const catalogRows = computed(() =>
|
||||||
const EXPAND_STORAGE_KEY = 'jd_db_cat_expand'
|
(props.categoryOptions ?? [])
|
||||||
|
.filter((row) => !!row.name && !!row.name.trim())
|
||||||
|
.map((row) => ({ name: row.name, productCount: row.productCount || 0 })))
|
||||||
|
|
||||||
/** 读展开记忆:合法字符串数组才采信;返回「键集+是否有记忆」两个值——空数组 `[]` 是
|
/** 点一行=按该末级类目名等值过滤(path 空数组,页面按单名集合下发,不静默丢筛选)。 */
|
||||||
* 用户主动「全部收起」的合法记忆,不得与「没存过」混为一谈(混了=全收起被重置成
|
function pickCatalogRow(name: string): void {
|
||||||
* 一级展开,用户意图被吞)。坏形状/不可读回无记忆。 */
|
|
||||||
function loadExpandedKeys(): { keys: Set<string>; stored: boolean } {
|
|
||||||
try {
|
|
||||||
const raw = localStorage.getItem(EXPAND_STORAGE_KEY)
|
|
||||||
if (raw === null) return { keys: new Set(), stored: false }
|
|
||||||
const parsed: unknown = JSON.parse(raw)
|
|
||||||
if (!Array.isArray(parsed)) return { keys: new Set(), stored: false }
|
|
||||||
return { keys: new Set(parsed.filter((value): value is string => typeof value === 'string')), stored: true }
|
|
||||||
} catch {
|
|
||||||
return { keys: new Set(), stored: false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialExpand = loadExpandedKeys()
|
|
||||||
const expanded = ref<Set<string>>(initialExpand.keys)
|
|
||||||
const expandKey = (path: string[]): string => path.join('/')
|
|
||||||
|
|
||||||
function persistExpanded(): void {
|
|
||||||
try {
|
|
||||||
localStorage.setItem(EXPAND_STORAGE_KEY, JSON.stringify([...expanded.value]))
|
|
||||||
} catch {
|
|
||||||
// 存储不可写(隐私模式/配额满)=展开态只活在本会话,树功能不受影响。
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 是否有持久化记忆:有(哪怕空集=全收起)=尊重记忆(不再补一级展开);无=树根到达时
|
|
||||||
* 补一级默认展开。注意 setup 时树数据通常还没到(页面先 scope 后列表),「一级默认展开」
|
|
||||||
* 必须挂树根 watch 而不是 init 直接遍历(旧写法 roots 为空什么也没加=默认展开从未真正生效)。 */
|
|
||||||
let hasStoredExpand = initialExpand.stored
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => visibleRoots.value,
|
|
||||||
(roots) => {
|
|
||||||
if (hasStoredExpand) return
|
|
||||||
// 树还没到(首帧计数空 / 整树被剪空)不置位:等真根到达时再补一级展开。
|
|
||||||
if (!roots.length) return
|
|
||||||
const next = new Set(expanded.value)
|
|
||||||
for (const root of roots) next.add(expandKey([root.name]))
|
|
||||||
// 补过一次就置位:之后类目重取不再补默认(用户中途收起的一级行不被重取展开回去)。
|
|
||||||
hasStoredExpand = true
|
|
||||||
if (next.size !== expanded.value.size) {
|
|
||||||
expanded.value = next
|
|
||||||
persistExpanded()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ immediate: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
// ---------------- 商品目录树:扁平渲染(深度缩进 + 祖先全展开才可见) ----------------
|
|
||||||
|
|
||||||
interface FlatNode {
|
|
||||||
node: JdCategoryCountedNode
|
|
||||||
path: string[]
|
|
||||||
depth: number
|
|
||||||
}
|
|
||||||
|
|
||||||
const flatTree = computed<FlatNode[]>(() => {
|
|
||||||
const out: FlatNode[] = []
|
|
||||||
const walk = (nodes: JdCategoryCountedNode[], depth: number, prefix: string[]): void => {
|
|
||||||
for (const node of nodes) {
|
|
||||||
const path = [...prefix, node.name]
|
|
||||||
out.push({ node, path, depth })
|
|
||||||
if (node.children.length && expanded.value.has(expandKey(path))) {
|
|
||||||
walk(node.children, depth + 1, path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
walk(visibleRoots.value, 0, [])
|
|
||||||
return out
|
|
||||||
})
|
|
||||||
|
|
||||||
function toggleExpand(path: string[]): void {
|
|
||||||
const key = expandKey(path)
|
|
||||||
const next = new Set(expanded.value)
|
|
||||||
if (next.has(key)) next.delete(key)
|
|
||||||
else next.add(key)
|
|
||||||
expanded.value = next
|
|
||||||
persistExpanded()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 全部展开(v1.7 树增强):把每个有子级的节点 path 全收进展开集(深树一次到底)。 */
|
|
||||||
function expandAll(): void {
|
|
||||||
const next = new Set<string>()
|
|
||||||
const walk = (nodes: JdCategoryCountedNode[], prefix: string[]): void => {
|
|
||||||
for (const node of nodes) {
|
|
||||||
const path = [...prefix, node.name]
|
|
||||||
if (node.children.length) {
|
|
||||||
next.add(expandKey(path))
|
|
||||||
walk(node.children, path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
walk(visibleRoots.value, [])
|
|
||||||
expanded.value = next
|
|
||||||
hasStoredExpand = true
|
|
||||||
persistExpanded()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 全部收起:清空展开集(一级也收,用户主动点了收起就是要全收)。 */
|
|
||||||
function collapseAll(): void {
|
|
||||||
expanded.value = new Set()
|
|
||||||
hasStoredExpand = true
|
|
||||||
persistExpanded()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 点树行=选中即筛;非末级行顺手展开(下钻感,与京麦列表筛选器同形;收起走箭头)。 */
|
|
||||||
function pickNode(node: FlatNode): void {
|
|
||||||
if (node.node.children.length && !expanded.value.has(expandKey(node.path))) {
|
|
||||||
toggleExpand(node.path)
|
|
||||||
}
|
|
||||||
emit('select-category', { name: node.node.name, path: node.path })
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 外部选中态(重置/清选/页面回显):展开选中节点的全部祖先,让它可见,并把选中行
|
|
||||||
* 滚进视口(v1.7 树增强;jsdom 无 scrollIntoView 自动跳过——测试不需要真滚)。
|
|
||||||
* immediate=页面带着已激活的类目筛选挂载侧栏时(如切换回本页),选中路径直接展开到位。 */
|
|
||||||
watch(
|
|
||||||
() => props.selectedCategory,
|
|
||||||
(selected) => {
|
|
||||||
if (!selected || !selected.path.length) return
|
|
||||||
const next = new Set(expanded.value)
|
|
||||||
for (let i = 1; i < selected.path.length; i++) {
|
|
||||||
next.add(expandKey(selected.path.slice(0, i)))
|
|
||||||
}
|
|
||||||
if (next.size !== expanded.value.size) {
|
|
||||||
expanded.value = next
|
|
||||||
persistExpanded()
|
|
||||||
}
|
|
||||||
void nextTick(() => {
|
|
||||||
const picked = document.querySelector('.jd-side-tree .jd-side-row.selected')
|
|
||||||
if (picked && typeof picked.scrollIntoView === 'function') {
|
|
||||||
picked.scrollIntoView({ block: 'nearest' })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
{ immediate: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
const isSelectedNode = (node: FlatNode): boolean => {
|
|
||||||
const selected = props.selectedCategory
|
|
||||||
if (!selected || selected.path.length !== node.path.length) return false
|
|
||||||
return selected.path.every((name, index) => name === node.path[index])
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- 树外类目组(树上挂不上的本店行,单名等值出口) ----------------
|
|
||||||
|
|
||||||
const extraOpen = ref(true)
|
|
||||||
|
|
||||||
function pickExtra(name: string): void {
|
|
||||||
// 树外名不进树:path 空数组=页面按「无路径」序列化(单名等值旧形状,不静默丢筛选)。
|
|
||||||
emit('select-category', { name, path: [] })
|
emit('select-category', { name, path: [] })
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSelectedExtra = (name: string): boolean => {
|
/** 选中回显:当前筛选的类目名与行名逐字相同即高亮。 */
|
||||||
const selected = props.selectedCategory
|
const isSelectedCatalogRow = (name: string): boolean =>
|
||||||
return !!selected && selected.path.length === 0 && selected.name === name
|
!!props.selectedCategory && props.selectedCategory.name === name
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- 店铺分类 Tab(当前分组分类平铺+店铺名单 v1.7) ----------------
|
// ---------------- 店铺分类 Tab(当前分组分类平铺+店铺名单 v1.7) ----------------
|
||||||
|
|
||||||
@@ -364,7 +190,8 @@ function cancelShopRename(): void {
|
|||||||
>店铺分类</button>
|
>店铺分类</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 商品目录:全部商品 + 京麦授权类目树(计数徽标)+ 树外类目组 -->
|
<!-- 商品目录(2026-11-26):全部商品 + 京东平台类目平铺(category_path 末级名+计数)。
|
||||||
|
不再依赖授权类目树/店铺内分类——客户口径「京东分类是百分百有的,京东内分类不需要」。 -->
|
||||||
<div v-show="activeTab === 'catalog'" class="jd-sidebar-body jd-side-catalog">
|
<div v-show="activeTab === 'catalog'" class="jd-sidebar-body jd-side-catalog">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -375,69 +202,25 @@ function cancelShopRename(): void {
|
|||||||
<span class="jd-side-name">全部商品</span>
|
<span class="jd-side-name">全部商品</span>
|
||||||
<span class="jd-side-count">{{ catalogReady ? totalCount : '—' }}</span>
|
<span class="jd-side-count">{{ catalogReady ? totalCount : '—' }}</span>
|
||||||
</button>
|
</button>
|
||||||
<!-- 类目计数未就绪(页面首帧):只留一行加载提示,不画整棵树——
|
<!-- 类目计数未就绪(页面首帧):只留一行加载提示,不画列表(先画空列表再跳成有数据会闪变)。 -->
|
||||||
否则会先显示回落快照的别店类目(徽标全 0),数据到达后再收树,肉眼一次闪变。 -->
|
|
||||||
<p v-if="!catalogReady" class="jd-side-loading">类目加载中…</p>
|
<p v-if="!catalogReady" class="jd-side-loading">类目加载中…</p>
|
||||||
<!-- 全部展开/收起(v1.7 树增强,对齐原型树控件):深树一次到底/一键收干净。
|
<div v-else class="jd-side-tree">
|
||||||
只对「真有命中的树」摆(整树被剪空时下面直接是本店类目平铺列表)。 -->
|
|
||||||
<div v-if="catalogReady && flatTree.length" class="jd-side-tree-ops">
|
|
||||||
<button type="button" aria-label="展开全部类目" @click="expandAll">全部展开</button>
|
|
||||||
<button type="button" aria-label="收起全部类目" @click="collapseAll">全部收起</button>
|
|
||||||
</div>
|
|
||||||
<!-- 授权树里「本店真有商品」的分支(2026-11-24 客户口径:正确是一开始显示的那棵树,
|
|
||||||
而不是树外兜底这种退化分组)。零命中的别店分支已由 jdCategoryPruneZero 剪掉,
|
|
||||||
整树剪空时这里不渲染,本店类目由下方平铺列表承担。 -->
|
|
||||||
<div class="jd-side-tree" v-show="catalogReady && flatTree.length">
|
|
||||||
<button
|
<button
|
||||||
v-for="flat in flatTree"
|
v-for="row in catalogRows"
|
||||||
:key="flat.path.join('/')"
|
:key="row.name"
|
||||||
type="button"
|
type="button"
|
||||||
class="jd-side-row"
|
class="jd-side-row depth-0"
|
||||||
:class="[`depth-${flat.depth}`, { selected: isSelectedNode(flat) }]"
|
:class="{ selected: isSelectedCatalogRow(row.name) }"
|
||||||
:title="flat.path.join(' / ')"
|
:title="row.name"
|
||||||
@click="pickNode(flat)"
|
@click="pickCatalogRow(row.name)"
|
||||||
>
|
>
|
||||||
<span
|
<span class="jd-side-leaf-dot" />
|
||||||
v-if="flat.node.children.length"
|
<span class="jd-side-name">{{ row.name }}</span>
|
||||||
class="jd-side-arrow"
|
<span class="jd-side-count">{{ row.productCount }}</span>
|
||||||
:class="{ open: expanded.has(flat.path.join('/')) }"
|
|
||||||
role="button"
|
|
||||||
:aria-label="`展开或收起 ${flat.node.name}`"
|
|
||||||
@click.stop="toggleExpand(flat.path)"
|
|
||||||
>▸</span>
|
|
||||||
<span v-else class="jd-side-leaf-dot" />
|
|
||||||
<span class="jd-side-name">{{ flat.node.name }}</span>
|
|
||||||
<span class="jd-side-count">{{ flat.node.count }}</span>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
<p v-if="!catalogRows.length" class="jd-side-empty">
|
||||||
<!-- 树外名(授权树里挂不上的本店类目):树被剪空时它们就是整列内容,直接铺成一级、
|
还没有采集到类目数据(先采集一次店铺即有)
|
||||||
不摆分组头;树有命中时仍收在「授权树外的类目」组里(可折叠,单名等值仍可选)。 -->
|
</p>
|
||||||
<div v-if="catalogReady && counted.extra.length" class="jd-side-extra" :class="{ 'jd-side-extra-solo': extraIsSolo }">
|
|
||||||
<button
|
|
||||||
v-if="!extraIsSolo"
|
|
||||||
type="button"
|
|
||||||
class="jd-side-row jd-side-extra-head"
|
|
||||||
:aria-expanded="extraOpen"
|
|
||||||
@click="extraOpen = !extraOpen"
|
|
||||||
>
|
|
||||||
<span class="jd-side-name">授权树外的类目</span>
|
|
||||||
<span class="jd-side-count">{{ counted.extraTotal }}</span>
|
|
||||||
</button>
|
|
||||||
<template v-if="extraIsSolo || extraOpen">
|
|
||||||
<button
|
|
||||||
v-for="row in counted.extra"
|
|
||||||
:key="row.name"
|
|
||||||
type="button"
|
|
||||||
class="jd-side-row"
|
|
||||||
:class="[{ 'depth-1': !extraIsSolo, selected: isSelectedExtra(row.name) }]"
|
|
||||||
:title="row.name"
|
|
||||||
@click="pickExtra(row.name)"
|
|
||||||
>
|
|
||||||
<span class="jd-side-leaf-dot" />
|
|
||||||
<span class="jd-side-name">{{ row.name }}</span>
|
|
||||||
<span class="jd-side-count">{{ row.productCount }}</span>
|
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -663,20 +446,6 @@ function cancelShopRename(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.jd-side-row.depth-1 { padding-left: 22px; }
|
.jd-side-row.depth-1 { padding-left: 22px; }
|
||||||
.jd-side-row.depth-2 { padding-left: 36px; }
|
|
||||||
.jd-side-row.depth-3 { padding-left: 50px; }
|
|
||||||
|
|
||||||
.jd-side-arrow {
|
|
||||||
width: 14px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
color: #909399;
|
|
||||||
transition: transform 0.15s;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jd-side-arrow.open {
|
|
||||||
transform: rotate(90deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.jd-side-leaf-dot {
|
.jd-side-leaf-dot {
|
||||||
width: 14px;
|
width: 14px;
|
||||||
@@ -712,44 +481,6 @@ function cancelShopRename(): void {
|
|||||||
background: #d9ecff;
|
background: #d9ecff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 树顶展开/收起操作行(v1.7 树增强):弱化小按钮,不与树行抢视觉。 */
|
|
||||||
.jd-side-tree-ops {
|
|
||||||
display: flex;
|
|
||||||
gap: 6px;
|
|
||||||
padding: 0 4px 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jd-side-tree-ops button {
|
|
||||||
padding: 2px 8px;
|
|
||||||
border: 1px solid #dcdfe6;
|
|
||||||
border-radius: 6px;
|
|
||||||
background: #fff;
|
|
||||||
color: #909399;
|
|
||||||
font-size: 12px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jd-side-tree-ops button:hover {
|
|
||||||
color: #409eff;
|
|
||||||
border-color: #c6e2ff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jd-side-extra {
|
|
||||||
margin-top: 4px;
|
|
||||||
border-top: 1px dashed #e4e7ed;
|
|
||||||
padding-top: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 树外名分组(授权树挂不上的本店类目):树被剪空时它就是主列表,不画上缘虚线。 */
|
|
||||||
.jd-side-extra-solo {
|
|
||||||
border-top: none;
|
|
||||||
padding-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jd-side-extra-head {
|
|
||||||
color: #909399;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jd-side-empty {
|
.jd-side-empty {
|
||||||
margin: 8px 4px;
|
margin: 8px 4px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
@@ -757,7 +488,7 @@ function cancelShopRename(): void {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 类目加载行(首帧未就绪占位):与空态同款弱化,不让整棵别店快照树先闪出来。 */
|
/* 类目加载行(首帧未就绪占位):与空态同款弱化,不让空列表先闪一下。 */
|
||||||
.jd-side-loading {
|
.jd-side-loading {
|
||||||
margin: 8px 4px;
|
margin: 8px 4px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ import {
|
|||||||
JD_PRODUCT_PAGE_SIZE_OPTIONS,
|
JD_PRODUCT_PAGE_SIZE_OPTIONS,
|
||||||
} from './jd-product-filter.ts'
|
} from './jd-product-filter.ts'
|
||||||
import { JD_PRODUCT_DEFAULT_SIZE, type JdProductItem } from './jd-product-model.ts'
|
import { JD_PRODUCT_DEFAULT_SIZE, type JdProductItem } from './jd-product-model.ts'
|
||||||
import { JD_CATEGORY_TREE, jdCategoryNamesUnder, type JdCategoryNode } from './jd-category-tree.ts'
|
|
||||||
import { fetchJdShopCategoryTree } from './jd-shop-category-api.ts'
|
|
||||||
import JdCategorySidebar from './JdCategorySidebar.vue'
|
import JdCategorySidebar from './JdCategorySidebar.vue'
|
||||||
import JdProductCard from './JdProductCard.vue'
|
import JdProductCard from './JdProductCard.vue'
|
||||||
import JdProductDetailModal from './JdProductDetailModal.vue'
|
import JdProductDetailModal from './JdProductDetailModal.vue'
|
||||||
@@ -127,9 +125,9 @@ const canManageCategories = computed(() => currentGroupOption.value?.editable ==
|
|||||||
* 弹窗右栏的勾选面 ⇒ 勾选面对「本组可写」放开,否则管理人员没有归类入口。 */
|
* 弹窗右栏的勾选面 ⇒ 勾选面对「本组可写」放开,否则管理人员没有归类入口。 */
|
||||||
const hasSelection = computed(() => canWriteProducts.value || canManageCategories.value)
|
const hasSelection = computed(() => canWriteProducts.value || canManageCategories.value)
|
||||||
|
|
||||||
/** 侧栏选中回显:类目(name+完整名称路径;树外名 path 空数组)与分类 id。 */
|
/** 侧栏选中回显:类目(京东平台末级类目名;path 恒空——平铺列表没有层级)与分类 id。 */
|
||||||
const selectedCategoryInfo = computed(() =>
|
const selectedCategoryInfo = computed(() =>
|
||||||
filter.category ? { name: filter.category, path: filter.categoryPath ?? [] } : null)
|
filter.category ? { name: filter.category, path: [] } : null)
|
||||||
const selectedGroupIdNum = computed(() => {
|
const selectedGroupIdNum = computed(() => {
|
||||||
const id = Number.parseInt(filter.groupId, 10)
|
const id = Number.parseInt(filter.groupId, 10)
|
||||||
return Number.isFinite(id) && id > 0 ? id : null
|
return Number.isFinite(id) && id > 0 ? id : null
|
||||||
@@ -164,17 +162,12 @@ const activeFilterChips = computed(() => {
|
|||||||
return chips
|
return chips
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 侧栏选类目:树内节点带完整路径(序列化按子树展开 IN 下发)、树外名 path 空=
|
/** 侧栏选类目(2026-11-26 客户口径「京东分类是百分百有的,京东内分类就不需要」):
|
||||||
* 单名等值旧形状;null=「全部商品」清选重查。选中即查(回第一页)。 */
|
* 左栏「商品目录」=后端 `/categories` 的 DISTINCT `category_path`(京麦末级类目名+计数),
|
||||||
|
* 点一行=按该末级类目名**等值**过滤(后端 `p.category_path IN (...)`,单元素集合);
|
||||||
|
* null=「全部商品」清选重查。不再有授权类目树/内置快照,也就没有父级展开集合。 */
|
||||||
function onSelectCategory(value: { name: string; path: string[] } | null): void {
|
function onSelectCategory(value: { name: string; path: string[] } | null): void {
|
||||||
filter.category = value?.name || ''
|
filter.category = value?.name || ''
|
||||||
filter.categoryPath = value?.path ?? []
|
|
||||||
// 父级点选的子树展开集合按**当前生效的树**算好存进过滤态(2026-11-23):树换成服务端
|
|
||||||
// 真树后,点「收纳用品」展开的就是真树的子类目名;filter 纯函数层不持有树,
|
|
||||||
// 避免「侧栏用真树、查询用快照树」两处各读一份。
|
|
||||||
filter.categoryNames = value && value.path.length
|
|
||||||
? (jdCategoryNamesUnder(value.path, activeCategoryTree.value) ?? undefined)
|
|
||||||
: undefined
|
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,28 +389,6 @@ async function loadCategoryOptions(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 服务端授权类目树(2026-11-23:客户端采集时按店铺上报、服务端并集)。
|
|
||||||
* null=还没取到或取不到 ⇒ 左栏回落内置快照(侧栏只渲染命中分支,零命中整支剪掉)。 */
|
|
||||||
const serverCategoryTree = ref<JdCategoryNode[] | null>(null)
|
|
||||||
|
|
||||||
/** 左栏实际生效的授权树:服务端真树优先,否则内置快照。
|
|
||||||
* 它同时是「父级点选展开集合」的口径源——树换了两处必须同源,不能各读各的。 */
|
|
||||||
const activeCategoryTree = computed<JdCategoryNode[]>(() =>
|
|
||||||
(serverCategoryTree.value && serverCategoryTree.value.length
|
|
||||||
? serverCategoryTree.value
|
|
||||||
: JD_CATEGORY_TREE))
|
|
||||||
|
|
||||||
/** 取授权类目树:失败静默回落快照(左栏不是首屏主功能,不占 loadFailure 提示,
|
|
||||||
* 与 loadCategoryOptions 同档兜底)。 */
|
|
||||||
async function loadShopCategoryTree(): Promise<void> {
|
|
||||||
try {
|
|
||||||
const result = await fetchJdShopCategoryTree()
|
|
||||||
serverCategoryTree.value = result.nodes.length ? result.nodes : null
|
|
||||||
} catch {
|
|
||||||
serverCategoryTree.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 切换「分组」下拉:分类筛选(属于上一组的分类)清空,分类选项换成本组,回第一页重取。
|
/** 切换「分组」下拉:分类筛选(属于上一组的分类)清空,分类选项换成本组,回第一页重取。
|
||||||
* 勾选集是按商品 id 记的(跨页累计),切组不清——归类的落点组随 ownerGroupId 走,
|
* 勾选集是按商品 id 记的(跨页累计),切组不清——归类的落点组随 ownerGroupId 走,
|
||||||
* 误跨组批量归类由归类对话框里的组名标注防住。 */
|
* 误跨组批量归类由归类对话框里的组名标注防住。 */
|
||||||
@@ -495,10 +466,6 @@ async function load(): Promise<void> {
|
|||||||
pageSize: pageSize.value,
|
pageSize: pageSize.value,
|
||||||
keyword: filter.keyword,
|
keyword: filter.keyword,
|
||||||
category: filter.category,
|
category: filter.category,
|
||||||
categoryPath: filter.categoryPath,
|
|
||||||
// 父级点选按当前生效树展开好的集合透传给查询(2026-11-25 断链修复:此前只存在
|
|
||||||
// 过滤态里没进 api 入参,列表查询退回快照树展开,真树≠快照时点开父级 0 条)。
|
|
||||||
categoryNames: filter.categoryNames,
|
|
||||||
shopName: filter.shopName,
|
shopName: filter.shopName,
|
||||||
groupId: filter.groupId,
|
groupId: filter.groupId,
|
||||||
classified: filter.classified,
|
classified: filter.classified,
|
||||||
@@ -675,7 +642,6 @@ onMounted(async () => {
|
|||||||
// 不要先发一条不带 owner_group_id 的列表请求再补,两次请求会落在不同默认组上)。
|
// 不要先发一条不带 owner_group_id 的列表请求再补,两次请求会落在不同默认组上)。
|
||||||
await loadCategoryScope()
|
await loadCategoryScope()
|
||||||
void loadCategoryOptions()
|
void loadCategoryOptions()
|
||||||
void loadShopCategoryTree()
|
|
||||||
await load()
|
await load()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -863,9 +829,10 @@ onMounted(async () => {
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div class="jd-body">
|
<div class="jd-body">
|
||||||
<!-- 左侧栏(v1.6 → v1.7 名单维度):商品目录(京麦授权类目树+计数徽标+树外类目)/
|
<!-- 左侧栏:商品目录(京东平台类目=/categories 的 category_path 平铺+计数徽标,
|
||||||
店铺分类(分类平铺+店铺名单展开/点选过滤/行内改名移除+添加店铺入口+新建+
|
2026-11-26 客户口径「京东分类百分百有,京东内分类不需要」)/店铺分类(分类平铺+
|
||||||
分类管理入口)。取数在页面,侧栏纯展示。 -->
|
店铺名单展开/点选过滤/行内改名移除+添加店铺入口+新建+分类管理入口)。
|
||||||
|
取数在页面,侧栏纯展示。 -->
|
||||||
<JdCategorySidebar
|
<JdCategorySidebar
|
||||||
:category-options="categoryOptions"
|
:category-options="categoryOptions"
|
||||||
:categories="groupOptions"
|
:categories="groupOptions"
|
||||||
@@ -873,7 +840,6 @@ onMounted(async () => {
|
|||||||
:selected-category="selectedCategoryInfo"
|
:selected-category="selectedCategoryInfo"
|
||||||
:selected-group-id="selectedGroupIdNum"
|
:selected-group-id="selectedGroupIdNum"
|
||||||
:selected-shop-name="filter.shopName"
|
:selected-shop-name="filter.shopName"
|
||||||
:category-tree="activeCategoryTree"
|
|
||||||
:categories-ready="categoryOptionsReady"
|
:categories-ready="categoryOptionsReady"
|
||||||
@select-category="onSelectCategory"
|
@select-category="onSelectCategory"
|
||||||
@select-group="onSelectGroup"
|
@select-group="onSelectGroup"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -28,10 +28,6 @@ export async function fetchJdProductList(
|
|||||||
{
|
{
|
||||||
keyword: params.keyword ?? '',
|
keyword: params.keyword ?? '',
|
||||||
category: params.category ?? '',
|
category: params.category ?? '',
|
||||||
categoryPath: params.categoryPath ?? [],
|
|
||||||
// 页面按当前生效树算好的子树展开集合必须透传(2026-11-25 断链修复):丢了它,
|
|
||||||
// 序列化层会拿内置快照树重展开,真树≠快照时父级点选退化成单名等值查 0 条。
|
|
||||||
categoryNames: params.categoryNames ?? [],
|
|
||||||
shopName: params.shopName ?? '',
|
shopName: params.shopName ?? '',
|
||||||
groupId: params.groupId ?? '',
|
groupId: params.groupId ?? '',
|
||||||
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
|
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
* 日期默认空字符串:同步台账是累计数据,默认当天会让首屏只剩今天同步的行
|
* 日期默认空字符串:同步台账是累计数据,默认当天会让首屏只剩今天同步的行
|
||||||
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
||||||
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
|
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
|
||||||
import { jdCategoryNamesUnder } from './jd-category-tree.ts'
|
|
||||||
|
|
||||||
/** 每页条数默认 50(v1.6 蓝图 Phase 1 新契约,商城款式一屏 50),上限 1000
|
/** 每页条数默认 50(v1.6 蓝图 Phase 1 新契约,商城款式一屏 50),上限 1000
|
||||||
* (v1.7 对齐原型档位 50/100/200/500/1000,与后端 MAX_PAGE_SIZE 逐字同步——契约
|
* (v1.7 对齐原型档位 50/100/200/500/1000,与后端 MAX_PAGE_SIZE 逐字同步——契约
|
||||||
@@ -47,17 +46,11 @@ export interface JdProductFilterState {
|
|||||||
/** 合并搜索词(v1.7 对齐原型:一个框同时搜商品编码与标题,OR 语义在后端 SQL)。
|
/** 合并搜索词(v1.7 对齐原型:一个框同时搜商品编码与标题,OR 语义在后端 SQL)。
|
||||||
* 旧 productCode/titleKeyword 两框随 v1.7 前端下线(后端参数保留兼容在飞请求)。 */
|
* 旧 productCode/titleKeyword 两框随 v1.7 前端下线(后端参数保留兼容在飞请求)。 */
|
||||||
keyword: string
|
keyword: string
|
||||||
/** 类目(京麦类目名,末级或父级;选项来自侧栏商品目录树),空串=全部类目。 */
|
/** 类目(京麦末级类目名=后端 `category_path` DISTINCT 值;选项来自侧栏商品目录平铺),
|
||||||
|
* 空串=全部类目。2026-11-26 客户口径「京东分类是百分百有的,京东内分类就不需要」:
|
||||||
|
* 只按末级类目名等值过滤,不再有「父级点选→子树展开集合」这一层(旧 categoryPath/
|
||||||
|
* categoryNames 两个字段随内置花屿巷快照树一并退役)。 */
|
||||||
category: string
|
category: string
|
||||||
/** 选中节点的名称路径(2026-11-18 一级/二级类目可选中):非空时序列化按
|
|
||||||
* jdCategoryNamesUnder 展开为子树类目名集合下发(后端 IN);空=末级/树外行,
|
|
||||||
* 按单名等值下发(旧形状)。 */
|
|
||||||
categoryPath?: string[]
|
|
||||||
/** 父级点选时按**当前生效授权树**展开好的类目名集合(2026-11-23):树可以是服务端
|
|
||||||
* 按店铺上报的真树,纯函数层不持有树,所以由页面在选中那一刻算好放在这里。
|
|
||||||
* 有值时优先于按内置快照展开的 `jdCategoryNamesUnder(categoryPath)`;
|
|
||||||
* 空/缺省=照旧按快照树展开(向后兼容旧调用与测试)。 */
|
|
||||||
categoryNames?: string[]
|
|
||||||
/** 店铺名(v1.7 店铺名单维度:侧栏点店铺行下发,精确 eq;空串不限)。 */
|
/** 店铺名(v1.7 店铺名单维度:侧栏点店铺行下发,精确 eq;空串不限)。 */
|
||||||
shopName: string
|
shopName: string
|
||||||
/** 分类 id 文本(侧栏店铺分类 Tab 里那一行),空串=全部分类。 */
|
/** 分类 id 文本(侧栏店铺分类 Tab 里那一行),空串=全部分类。 */
|
||||||
@@ -86,8 +79,6 @@ export function createJdProductFilterState(): JdProductFilterState {
|
|||||||
return {
|
return {
|
||||||
keyword: '',
|
keyword: '',
|
||||||
category: '',
|
category: '',
|
||||||
categoryPath: [],
|
|
||||||
categoryNames: [],
|
|
||||||
shopName: '',
|
shopName: '',
|
||||||
groupId: '',
|
groupId: '',
|
||||||
classified: JD_PRODUCT_DEFAULT_CLASSIFIED,
|
classified: JD_PRODUCT_DEFAULT_CLASSIFIED,
|
||||||
@@ -144,13 +135,6 @@ export interface JdProductListParams {
|
|||||||
pageSize: number
|
pageSize: number
|
||||||
keyword?: string
|
keyword?: string
|
||||||
category?: string
|
category?: string
|
||||||
/** 选中类目节点路径(见 JdProductFilterState.categoryPath;空=单名等值)。 */
|
|
||||||
categoryPath?: string[]
|
|
||||||
/** 页面按**当前生效树**(服务端真树优先)展开好的子树类目名集合(见
|
|
||||||
* JdProductFilterState.categoryNames)。2026-11-25 补:api 层此前没有这个字段,
|
|
||||||
* 页面算好的集合到不了序列化层,父级点选退回内置快照树重展开——真树≠快照时
|
|
||||||
* 展开失败退化成单名等值,「收纳用品 81」点开 0 条。序列化按它优先。 */
|
|
||||||
categoryNames?: string[]
|
|
||||||
shopName?: string
|
shopName?: string
|
||||||
groupId?: string
|
groupId?: string
|
||||||
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
|
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
|
||||||
@@ -173,16 +157,10 @@ function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuer
|
|||||||
if (keyword) query.keyword = keyword
|
if (keyword) query.keyword = keyword
|
||||||
const category = (state.category || '').trim()
|
const category = (state.category || '').trim()
|
||||||
if (category) {
|
if (category) {
|
||||||
// 2026-11-18 一级/二级类目可选中:带路径=按子树展开类目名集合(后端 IN);
|
// 末级类目名等值:单元素集合下发,后端 `p.category_path IN (...)` 单值等价 eq。
|
||||||
// 路径失效(树外历史名)回落单名等值集合——与旧 eq 语义逐字同形。
|
// 2026-11-26 起左栏商品目录=京东平台类目平铺(category_path DISTINCT),
|
||||||
// 2026-11-23:页面若已按服务端真树算好 categoryNames,直接用(两处口径同源,
|
// 不再有「父级点选→子树展开集合」这条链。
|
||||||
// 不再拿内置快照树重算一遍)。
|
query.category = [category]
|
||||||
const expanded = state.categoryNames && state.categoryNames.length
|
|
||||||
? state.categoryNames
|
|
||||||
: state.categoryPath && state.categoryPath.length
|
|
||||||
? jdCategoryNamesUnder(state.categoryPath)
|
|
||||||
: null
|
|
||||||
query.category = expanded && expanded.length ? expanded : [category]
|
|
||||||
}
|
}
|
||||||
const shopName = (state.shopName || '').trim()
|
const shopName = (state.shopName || '').trim()
|
||||||
if (shopName) query.shop_name = shopName
|
if (shopName) query.shop_name = shopName
|
||||||
@@ -248,8 +226,8 @@ export function jdOwnershipSelectValue(state: JdProductFilterState): string {
|
|||||||
/** 归属下拉选档 → 筛选态(原地改 state;调用方随后自行重查,本函数不发请求):
|
/** 归属下拉选档 → 筛选态(原地改 state;调用方随后自行重查,本函数不发请求):
|
||||||
* - `cat:<id>`=按分类查询:写 groupId、清状态档;店铺谓词一起清——店铺名单挂在分类下
|
* - `cat:<id>`=按分类查询:写 groupId、清状态档;店铺谓词一起清——店铺名单挂在分类下
|
||||||
* (v1.7 名单维度),换分类后旧店铺词是孤儿谓词(店铺全平台 DISTINCT,会命中别组分类
|
* (v1.7 名单维度),换分类后旧店铺词是孤儿谓词(店铺全平台 DISTINCT,会命中别组分类
|
||||||
* 下的同名店),与侧栏 onSelectGroup 同一条纪律;类目维(category/categoryPath)是
|
* 下的同名店),与侧栏 onSelectGroup 同一条纪律;类目维(category=京东平台末级类目名)
|
||||||
* 京麦树,独立维度不碰。
|
* 是独立维度,不碰。
|
||||||
* - ''/classified/ungrouped=状态档:写 classified、清 groupId;店铺词不属分类维度,
|
* - ''/classified/ungrouped=状态档:写 classified、清 groupId;店铺词不属分类维度,
|
||||||
* 与既有三档行为一致不动 shopName。
|
* 与既有三档行为一致不动 shopName。
|
||||||
* 脏值(未知前缀/非数字 id)按「全部」档兜底——不拿脏值冒充档位(classified 序列化同形)。 */
|
* 脏值(未知前缀/非数字 id)按「全部」档兜底——不拿脏值冒充档位(classified 序列化同形)。 */
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
/** 京麦授权类目树读取(2026-11-23):GET `/api/jd-shop-category-tree`。
|
|
||||||
*
|
|
||||||
* 数据来源=客户端采集窗口顺手收到的 `getVenderLicenseCategory`(按店铺上报、服务端并集),
|
|
||||||
* 与内置快照 `JD_CATEGORY_TREE`(2026-11-16 一家店的历史取证)**同形**——
|
|
||||||
* `{name, value, children}`,页面拿到后直接替换树数据源,计数/兜底/展开逻辑零改动。
|
|
||||||
*
|
|
||||||
* 失败/空一律返回空节点数组:页面据此回落内置快照(侧栏只渲染本店命中的分支,
|
|
||||||
* 零命中整支剪掉、树空就把本店类目平铺成一级),绝不让接口抖动把左栏变成错误块。 */
|
|
||||||
import { http } from '@/api/http'
|
|
||||||
import { unwrap } from '../../api/envelope.ts'
|
|
||||||
import { parseJdCategoryNodeTree, type JdCategoryNode } from './jd-category-tree.ts'
|
|
||||||
|
|
||||||
export { parseJdCategoryNodeTree }
|
|
||||||
|
|
||||||
export const JD_SHOP_CATEGORY_TREE_ENDPOINT = '/api/jd-shop-category-tree'
|
|
||||||
|
|
||||||
/** 已上报店铺(页面只用于「有没有真树」的判断与排查展示)。 */
|
|
||||||
export interface JdShopCategoryTreeShop {
|
|
||||||
shopId: string
|
|
||||||
shopName: string | null
|
|
||||||
capturedAt: string | null
|
|
||||||
nodeCount: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface JdShopCategoryTreeResult {
|
|
||||||
/** 并集森林;空数组=服务端还没有任何店铺上报过。 */
|
|
||||||
nodes: JdCategoryNode[]
|
|
||||||
shops: JdShopCategoryTreeShop[]
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 递归解析已在 `jd-category-tree.ts`(零依赖、node --test 可直测),这里只做请求与装配。 */
|
|
||||||
export async function fetchJdShopCategoryTree(): Promise<JdShopCategoryTreeResult> {
|
|
||||||
const { data } = await http.get<unknown>(JD_SHOP_CATEGORY_TREE_ENDPOINT)
|
|
||||||
const core = unwrap<unknown>(data)
|
|
||||||
if (!core || typeof core !== 'object') return { nodes: [], shops: [] }
|
|
||||||
const record = core as Record<string, unknown>
|
|
||||||
const shops: JdShopCategoryTreeShop[] = []
|
|
||||||
for (const raw of Array.isArray(record.shops) ? record.shops : []) {
|
|
||||||
if (!raw || typeof raw !== 'object') continue
|
|
||||||
const row = raw as Record<string, unknown>
|
|
||||||
const shopId = row.shopId == null ? '' : String(row.shopId).trim()
|
|
||||||
if (!shopId) continue
|
|
||||||
shops.push({
|
|
||||||
shopId,
|
|
||||||
shopName: typeof row.shopName === 'string' ? row.shopName : null,
|
|
||||||
capturedAt: typeof row.capturedAt === 'string' ? row.capturedAt : null,
|
|
||||||
nodeCount: typeof row.nodeCount === 'number' && Number.isFinite(row.nodeCount)
|
|
||||||
? Math.max(0, Math.floor(row.nodeCount))
|
|
||||||
: 0,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return { nodes: parseJdCategoryNodeTree(record.nodes), shops }
|
|
||||||
}
|
|
||||||
@@ -1,374 +0,0 @@
|
|||||||
import { test } from 'node:test'
|
|
||||||
import assert from 'node:assert/strict'
|
|
||||||
import {
|
|
||||||
JD_CATEGORY_TREE,
|
|
||||||
jdCategoryAllNodes,
|
|
||||||
jdCategoryChildren,
|
|
||||||
jdCategoryCountTree,
|
|
||||||
jdCategoryLeaves,
|
|
||||||
jdCategoryNamesUnder,
|
|
||||||
jdCategoryPruneZero,
|
|
||||||
jdCategoryRoots,
|
|
||||||
jdCategorySearchLeaves,
|
|
||||||
jdCategorySearchNodes,
|
|
||||||
parseJdCategoryNodeTree,
|
|
||||||
type JdCategoryCountedNode,
|
|
||||||
type JdCategoryNode,
|
|
||||||
} from '../src/pages/jd/jd-category-tree.ts'
|
|
||||||
|
|
||||||
/** 京麦授权类目真树(2026-11-16 真机取证 getVenderLicenseCategory 快照;与用户端
|
|
||||||
* frontend-vue 侧同数据两份正本,改树两边同轮同步)。判据钉的是取证读数:
|
|
||||||
* 3 个一级 / 250 个末级 / 最深 4 级 / 4 组同名跨支——改树先对取证数据(京麦面板
|
|
||||||
* 或 getVenderLicenseCategory 重抓),不得手改数字凑测试。 */
|
|
||||||
test('树形状=京麦授权类目真机读数:3 个一级、250 个末级、最深 4 级', () => {
|
|
||||||
const roots = jdCategoryRoots()
|
|
||||||
assert.deepEqual(
|
|
||||||
roots.map((node) => node.name),
|
|
||||||
['服饰内衣', '母婴', '运动户外'],
|
|
||||||
'一级就 3 个(京麦面板 2026-11-16 真机:该店铺授权经营类目,不得加回京东公开全量)',
|
|
||||||
)
|
|
||||||
assert.deepEqual(
|
|
||||||
roots.map((node) => node.value),
|
|
||||||
['1315', '1319', '1318'],
|
|
||||||
'一级类目 id 与取证响应逐字同',
|
|
||||||
)
|
|
||||||
const leaves = jdCategoryLeaves()
|
|
||||||
assert.equal(leaves.length, 250, '末级节点 250 个(取证读数)')
|
|
||||||
const maxDepth = Math.max(...leaves.map((leaf) => leaf.path.length))
|
|
||||||
assert.equal(maxDepth, 4, '树最深 4 级')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('服饰内衣二级与京麦面板逐字同源;逐级下钻到真机样本叶', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
jdCategoryChildren(['服饰内衣']).map((node) => node.name),
|
|
||||||
['服饰配件', '内衣', '女装', '男装', '定制服装/工装'],
|
|
||||||
'服饰内衣二级 5 个(京麦面板逐字)',
|
|
||||||
)
|
|
||||||
assert.deepEqual(
|
|
||||||
jdCategoryChildren(['服饰内衣', '服饰配件']).map((node) => node.name),
|
|
||||||
['腰带/腰链', '耳罩/耳包', '领带/领结/领带夹', '男士丝巾/围巾', '女士丝巾/围巾/披肩', '鸭舌帽',
|
|
||||||
'礼帽', '手套', '围巾/手套/帽子套装', '毛线帽', '遮阳帽', '棒球帽', '渔夫帽'],
|
|
||||||
'服饰配件三级 13 个(京麦面板 2026-11-16 截图逐字前 6 +取证快照全量)',
|
|
||||||
)
|
|
||||||
assert.deepEqual(
|
|
||||||
jdCategoryChildren(['服饰内衣', '服饰配件', '腰带/腰链']),
|
|
||||||
[],
|
|
||||||
'三级叶子 children 空(末级,可选中)',
|
|
||||||
)
|
|
||||||
assert.deepEqual(
|
|
||||||
jdCategoryChildren(['不存在的一级']),
|
|
||||||
[],
|
|
||||||
'未知路径回落空子级(面板该栏缺省)',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('落库末级名真机样本都在树内(category_path 等值过滤成立的前提)', () => {
|
|
||||||
const names = new Set(jdCategoryLeaves().map((leaf) => leaf.name))
|
|
||||||
for (const sample of ['艺考形体服', '啦啦队服', '拉丁舞服']) {
|
|
||||||
assert.ok(names.has(sample), `真机样本「${sample}」必须是树内末级(契约 E3 口径)`)
|
|
||||||
}
|
|
||||||
const yikao = jdCategoryLeaves().find((leaf) => leaf.name === '艺考形体服')
|
|
||||||
assert.ok(yikao, '艺考形体服在树内')
|
|
||||||
assert.equal(yikao!.path.length, 3, '艺考形体服是 level 3 节点(取证读数)')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('同名跨支叶子如实登记:4 组重名(同名行等值过滤一起命中,B112-05 口径)', () => {
|
|
||||||
const counts = new Map<string, number>()
|
|
||||||
for (const leaf of jdCategoryLeaves()) {
|
|
||||||
counts.set(leaf.name, (counts.get(leaf.name) ?? 0) + 1)
|
|
||||||
}
|
|
||||||
const dups = [...counts.entries()].filter(([, count]) => count > 1)
|
|
||||||
assert.deepEqual(
|
|
||||||
dups.map(([name]) => name).sort(),
|
|
||||||
['唐装', '吊带/背心', '短裤', '赠品'].sort(),
|
|
||||||
'重名集与取证读数逐字同(改树后这里红=重名集变了,须复核登记)。注:「汉服」两处节点中'
|
|
||||||
+ '一处带四级子级是非叶(点它会下钻),不构成末级重名。',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('搜索:按名称或路径段命中末级;空词返回全量', () => {
|
|
||||||
assert.equal(jdCategorySearchLeaves('').length, 250, '空词=全量末级')
|
|
||||||
const byName = jdCategorySearchLeaves('艺考')
|
|
||||||
assert.equal(byName.length, 1)
|
|
||||||
assert.equal(byName[0]!.name, '艺考形体服')
|
|
||||||
const byPath = jdCategorySearchLeaves('服饰配件')
|
|
||||||
assert.ok(byPath.length >= 13, '按路径段命中服饰配件全部末级')
|
|
||||||
assert.ok(byPath.every((leaf) => leaf.path.includes('服饰配件')))
|
|
||||||
assert.deepEqual(jdCategorySearchLeaves('不存在词xyz'), [])
|
|
||||||
})
|
|
||||||
|
|
||||||
test('树数据快照不可空、value 全非空(取证 id 留档完整)', () => {
|
|
||||||
assert.ok(JD_CATEGORY_TREE.length > 0)
|
|
||||||
for (const leaf of jdCategoryLeaves()) {
|
|
||||||
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, '展开集合内部去重')
|
|
||||||
})
|
|
||||||
|
|
||||||
/** v1.6 蓝图 Phase 1 备料:/categories 计数行 → 树形计数聚合(侧栏徽标的数据源)。 */
|
|
||||||
/** 按名称路径取计数节点(与 jdCategoryChildren 同构的测试侧寻路)。 */
|
|
||||||
const nodeAt = (roots: JdCategoryCountedNode[], path: string[]): JdCategoryCountedNode | null => {
|
|
||||||
let level = roots
|
|
||||||
let hit: JdCategoryCountedNode | null = null
|
|
||||||
for (const name of path) {
|
|
||||||
hit = level.find((node) => node.name === name) ?? null
|
|
||||||
if (!hit) return null
|
|
||||||
level = hit.children
|
|
||||||
}
|
|
||||||
return hit
|
|
||||||
}
|
|
||||||
|
|
||||||
test('计数聚合——节点徽标=自身名+子树叶和,与 jdCategoryNamesUnder 展开集合同源', () => {
|
|
||||||
const tree = jdCategoryCountTree([
|
|
||||||
{ name: '艺考形体服', productCount: 5 },
|
|
||||||
{ name: '啦啦队服', productCount: 3 },
|
|
||||||
{ name: '拉丁舞服', productCount: 2 },
|
|
||||||
{ name: '连衣裙', productCount: 7 },
|
|
||||||
{ name: '短袖连衣裙', productCount: 4 },
|
|
||||||
])
|
|
||||||
assert.equal(tree.extra.length, 0, '树内名字不进兜底组')
|
|
||||||
assert.equal(tree.extraTotal, 0)
|
|
||||||
|
|
||||||
const roots = tree.roots
|
|
||||||
assert.equal(roots.length, 3, '一级节点全量保留(无词条的一级也在)')
|
|
||||||
assert.deepEqual(
|
|
||||||
roots.map((node) => node.name),
|
|
||||||
['服饰内衣', '母婴', '运动户外'],
|
|
||||||
)
|
|
||||||
assert.equal(roots.find((node) => node.name === '母婴')!.count, 0, '无词条的一级归 0 不缺节点')
|
|
||||||
|
|
||||||
const sport = nodeAt(roots, ['运动户外'])!
|
|
||||||
assert.equal(sport.count, 10, '运动户外=艺考5+啦啦3+拉丁2')
|
|
||||||
assert.equal(sport.leaf, false)
|
|
||||||
const dance = nodeAt(roots, ['运动户外', '舞蹈体操鞋服/装备'])!
|
|
||||||
assert.equal(dance.count, 10, '二级下钻同和')
|
|
||||||
const yikao = nodeAt(roots, ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'])!
|
|
||||||
assert.equal(yikao.count, 5, '末级叶子=该名计数')
|
|
||||||
assert.equal(yikao.leaf, true, 'children 空=末级')
|
|
||||||
assert.deepEqual(yikao.children, [], '叶子 children 是空数组(UI 直接遍历不炸)')
|
|
||||||
|
|
||||||
const dress = nodeAt(roots, ['服饰内衣', '女装', '连衣裙'])!
|
|
||||||
assert.equal(dress.count, 11, '连衣裙=自身名7+短袖4(长袖/无袖无词条归 0)')
|
|
||||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 11, '女装只有连衣裙支有词条')
|
|
||||||
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 11, '一级汇总到根')
|
|
||||||
|
|
||||||
const dressLeaves = nodeAt(roots, ['服饰内衣', '女装', '连衣裙'])!.children.map((node) => node.name)
|
|
||||||
assert.deepEqual(dressLeaves, ['短袖连衣裙', '长袖连衣裙', '无袖连衣裙'], '子节点形状与静态树逐字同')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('计数聚合——父级名本身是落库末级名:计入自身节点(快照层级可能比实际浅)', () => {
|
|
||||||
const tree = jdCategoryCountTree([
|
|
||||||
{ name: '女装', productCount: 6 },
|
|
||||||
{ name: '短袖连衣裙', productCount: 1 },
|
|
||||||
])
|
|
||||||
const roots = tree.roots
|
|
||||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 7, '女装徽标=自身6+子树1')
|
|
||||||
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 7)
|
|
||||||
assert.equal(tree.extra.length, 0, '非叶名也是合法落库名,不进兜底组')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('计数聚合——同名跨支叶:两个分支都计入(点哪支都等值命中同一批行),父层去重不翻倍', () => {
|
|
||||||
const tree = jdCategoryCountTree([{ name: '短裤', productCount: 9 }])
|
|
||||||
const roots = tree.roots
|
|
||||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 9, '女装支的短裤叶如实计入')
|
|
||||||
assert.equal(nodeAt(roots, ['服饰内衣', '男装'])!.count, 9, '男装支的同名叶同计数(过滤语义非双计)')
|
|
||||||
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 9,
|
|
||||||
'父层子树按名字去重求和:展开集合里短裤只出现一次,徽标不得翻倍成 18')
|
|
||||||
assert.equal(tree.extra.length, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('计数聚合——树外兜底组:树上任何节点名都对不上的历史行单独归组', () => {
|
|
||||||
const tree = jdCategoryCountTree([
|
|
||||||
{ name: '已下架历史类目', productCount: 12 },
|
|
||||||
{ name: '另一个树外名', productCount: 8 },
|
|
||||||
{ name: '艺考形体服', productCount: 5 },
|
|
||||||
])
|
|
||||||
assert.deepEqual(
|
|
||||||
tree.extra.map((row) => row.name),
|
|
||||||
['已下架历史类目', '另一个树外名'],
|
|
||||||
'兜底组按入参顺序保留',
|
|
||||||
)
|
|
||||||
assert.deepEqual(
|
|
||||||
tree.extra.map((row) => row.productCount),
|
|
||||||
[12, 8],
|
|
||||||
)
|
|
||||||
assert.equal(tree.extraTotal, 20, '兜底组和=徽标直接用')
|
|
||||||
const sport = nodeAt(tree.roots, ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'])!
|
|
||||||
assert.equal(sport.count, 5, '树内行照常聚合,兜底不影响树形')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('计数聚合——脏值归一:空名跳过、非有限/负数归 0、前后空白截掉、同名多行求和', () => {
|
|
||||||
const tree = jdCategoryCountTree([
|
|
||||||
{ name: '', productCount: 5 },
|
|
||||||
{ name: ' ', productCount: 7 },
|
|
||||||
{ name: '短裤', productCount: Number.NaN },
|
|
||||||
{ name: '唐装', productCount: -3 },
|
|
||||||
{ name: ' 女装 ', productCount: 2 },
|
|
||||||
{ name: '女装', productCount: 3 },
|
|
||||||
{ name: '艺考形体服', productCount: '4' as unknown as number },
|
|
||||||
] as { name: string; productCount: number }[])
|
|
||||||
const roots = tree.roots
|
|
||||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 5, 'trim 后同名求和 2+3')
|
|
||||||
assert.equal(nodeAt(roots, ['服饰内衣', '男装'])!.count, 0, 'NaN/负数/空名都归 0 不记账')
|
|
||||||
assert.equal(tree.extra.length, 0, '空名词条不进兜底组')
|
|
||||||
assert.equal(tree.extraTotal, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('计数聚合——treeMatched 三态:树内有命中/整树零命中(别店快照树)/数据没到', () => {
|
|
||||||
// 树内任一节点有行 ⇒ true(正常店:库内类目名挂得上内置授权树)。
|
|
||||||
const matched = jdCategoryCountTree([{ name: '连衣裙', productCount: 3 }])
|
|
||||||
assert.equal(matched.treeMatched, true)
|
|
||||||
|
|
||||||
// 2026-11-23 活样本:家居日用店打开「花屿巷旗舰店」那份服饰授权快照树——库内
|
|
||||||
// 类目名一个都不在树上(收纳盒/收纳架全落兜底),树内节点全 0。
|
|
||||||
const foreign = jdCategoryCountTree([
|
|
||||||
{ name: '化妆品收纳盒', productCount: 260 },
|
|
||||||
{ name: '其他收纳架', productCount: 4 },
|
|
||||||
])
|
|
||||||
assert.equal(foreign.treeMatched, false, '整树零命中 ⇒ 侧栏收树、不拿别店的树冒充本店')
|
|
||||||
assert.equal(foreign.extra.length, 2)
|
|
||||||
assert.equal(foreign.extraTotal, 264)
|
|
||||||
assert.equal(foreign.roots.every((root) => root.count === 0), true)
|
|
||||||
|
|
||||||
// 数据没到(空输入)同样是 false,但兜底为空——侧栏靠剪枝后树为空 + extra 非空决定
|
|
||||||
// 怎么渲染(树空则本店类目平铺成一级列表),不靠 treeMatched 判「加载中」。
|
|
||||||
const empty = jdCategoryCountTree([])
|
|
||||||
assert.equal(empty.treeMatched, false)
|
|
||||||
assert.equal(empty.extra.length, 0)
|
|
||||||
|
|
||||||
// 树内名但计数 0(脏值/归一后)不算命中:徽标与命中集合必须同源。
|
|
||||||
const zero = jdCategoryCountTree([{ name: '连衣裙', productCount: 0 }])
|
|
||||||
assert.equal(zero.treeMatched, false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('计数聚合——空输入:全树 0、兜底组空(结构仍完整可渲染)', () => {
|
|
||||||
const tree = jdCategoryCountTree([])
|
|
||||||
assert.equal(tree.roots.length, 3)
|
|
||||||
assert.equal(tree.extra.length, 0)
|
|
||||||
assert.equal(tree.extraTotal, 0)
|
|
||||||
const total = tree.roots.reduce((sum, node) => sum + node.count, 0)
|
|
||||||
assert.equal(total, 0)
|
|
||||||
// 结构与静态树同形:一级孩子数与 jdCategoryChildren 逐一对齐。
|
|
||||||
for (const root of tree.roots) {
|
|
||||||
assert.deepEqual(
|
|
||||||
root.children.map((node) => node.name),
|
|
||||||
jdCategoryChildren([root.name]).map((node) => node.name),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// 非数组入参按空处理(运行期 resilience,JS 调用方传 null 不炸)。
|
|
||||||
const junk = jdCategoryCountTree(null as unknown as [])
|
|
||||||
assert.equal(junk.roots.length, 3)
|
|
||||||
assert.equal(junk.extraTotal, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('服务端授权树解析:与内置快照同形、空名节点丢自身保子级、非数组/超深归空', () => {
|
|
||||||
const parsed = parseJdCategoryNodeTree([
|
|
||||||
{ name: ' 收纳用品 ', value: '7001', children: [
|
|
||||||
{ name: '化妆品收纳盒', value: '7002' },
|
|
||||||
{ name: '', value: 'x', children: [{ name: '孤儿但保留', value: '7003' }] },
|
|
||||||
{ notAnObject: true },
|
|
||||||
] },
|
|
||||||
{ name: '厨房用品', value: 7004 },
|
|
||||||
])
|
|
||||||
assert.deepEqual(parsed, [
|
|
||||||
{ name: '收纳用品', value: '7001', children: [
|
|
||||||
{ name: '化妆品收纳盒', value: '7002' },
|
|
||||||
{ name: '孤儿但保留', value: '7003' },
|
|
||||||
] },
|
|
||||||
{ name: '厨房用品', value: '7004' },
|
|
||||||
], 'name trim、value 数字转串、空名节点自身丢弃但子级上提')
|
|
||||||
|
|
||||||
assert.deepEqual(parseJdCategoryNodeTree(null), [], '非数组按空处理(接口抖动不炸渲染)')
|
|
||||||
|
|
||||||
// 10 层脏数据:只留前 9 层(depth 0..8),第 10 层被护栏截断。
|
|
||||||
let deep: unknown = [{ name: 'L10', value: '10' }]
|
|
||||||
for (let i = 9; i >= 1; i--) {
|
|
||||||
deep = [{ name: 'L' + i, value: String(i), children: deep }]
|
|
||||||
}
|
|
||||||
assert.equal(JSON.stringify(parseJdCategoryNodeTree(deep)).includes('L10'), false,
|
|
||||||
'超过 8 层的脏数据不递归下去(护栏在解析层,不留给渲染层)')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('计数聚合——传入服务端真树:家居类目挂得上树、不再落兜底(2026-11-23 家居店活样本)', () => {
|
|
||||||
const homeTree: JdCategoryNode[] = [
|
|
||||||
{ name: '收纳用品', value: '7001', children: [
|
|
||||||
{ name: '化妆品收纳盒', value: '7002' },
|
|
||||||
{ name: '脏衣篓', value: '7003' },
|
|
||||||
] },
|
|
||||||
{ name: '厨房用品', value: '7101', children: [{ name: '其他收纳架', value: '7102' }] },
|
|
||||||
]
|
|
||||||
const counts = [
|
|
||||||
{ name: '化妆品收纳盒', productCount: 260 },
|
|
||||||
{ name: '其他收纳架', productCount: 4 },
|
|
||||||
]
|
|
||||||
const real = jdCategoryCountTree(counts, homeTree)
|
|
||||||
assert.equal(real.treeMatched, true, '真树有命中 ⇒ 侧栏不收树')
|
|
||||||
assert.equal(real.extra.length, 0, '家居类目全部挂得上真树,不再落树外兜底')
|
|
||||||
assert.equal(real.roots.length, 2)
|
|
||||||
assert.equal(nodeAt(real.roots, ['收纳用品', '化妆品收纳盒'])!.count, 260)
|
|
||||||
assert.equal(nodeAt(real.roots, ['收纳用品'])!.count, 260, '父级徽标=子树和')
|
|
||||||
assert.equal(nodeAt(real.roots, ['厨房用品'])!.count, 4)
|
|
||||||
|
|
||||||
// 同一批计数行套内置快照树 ⇒ 整树零命中(数据没错,是树不对——这就是本次修的那个形状)。
|
|
||||||
const snapshot = jdCategoryCountTree(counts)
|
|
||||||
assert.equal(snapshot.treeMatched, false)
|
|
||||||
assert.equal(snapshot.extraTotal, 264)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('剪枝——零命中的别店分支整支剪掉,整树剪空(2026-11-24 客户口径「要的是类目树,不是树外兜底」)', () => {
|
|
||||||
const foreign = jdCategoryCountTree([
|
|
||||||
{ name: '化妆品收纳盒', productCount: 260 },
|
|
||||||
{ name: '其他收纳架', productCount: 4 },
|
|
||||||
])
|
|
||||||
assert.equal(jdCategoryPruneZero(foreign.roots).length, 0,
|
|
||||||
'家居类目套服饰快照树 ⇒ 整树剪空,调用方把 extra 平铺成一级列表(不再有「本店无匹配」档)')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('剪枝——命中分支保留祖先链、重算 leaf,零命中兄弟支不出现', () => {
|
|
||||||
const counted = jdCategoryCountTree([{ name: '连衣裙', productCount: 7 }])
|
|
||||||
const pruned = jdCategoryPruneZero(counted.roots)
|
|
||||||
assert.deepEqual(pruned.map((node) => node.name), ['服饰内衣'], '只有服饰内衣这一支真有商品')
|
|
||||||
assert.equal(nodeAt(pruned, ['服饰内衣', '女装'])!.count, 7, '祖先链上徽标不变(子树去重和)')
|
|
||||||
const dress = nodeAt(pruned, ['服饰内衣', '女装', '连衣裙'])!
|
|
||||||
assert.equal(dress.leaf, true, '子级全被剪掉后重算 leaf(不再显示展开箭头)')
|
|
||||||
assert.equal(nodeAt(pruned, ['服饰内衣', '男装']), null, '零命中兄弟支剪掉')
|
|
||||||
assert.equal(nodeAt(pruned, ['母婴']), null, '整支零命中的一级剪掉')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('剪枝——空输入/异常入参回空数组(渲染层不炸)', () => {
|
|
||||||
assert.deepEqual(jdCategoryPruneZero([]), [])
|
|
||||||
assert.deepEqual(jdCategoryPruneZero(null as unknown as JdCategoryCountedNode[]), [])
|
|
||||||
})
|
|
||||||
@@ -97,9 +97,10 @@ test('列表行价格:BigDecimal 的 JSON number 形状与字符串形状都
|
|||||||
assert.equal(jdPriceRange(missing), '', '两侧都空回空串(列表显示 -)')
|
assert.equal(jdPriceRange(missing), '', '两侧都空回空串(列表显示 -)')
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 类目筛选(2026-11-15 末级等值;2026-11-18 一级/二级可选中=子树展开集合 IN):
|
/** 类目筛选(2026-11-26 客户口径「京东分类是百分百有的,京东内分类就不需要」):
|
||||||
* 空串不下发;无路径=单元素集合(等值旧形状);带路径=jdCategoryNamesUnder 展开。 */
|
* 左栏商品目录=京东平台类目(`category_path` DISTINCT 末级名)平铺,点行=单名等值;
|
||||||
test('类目筛选参数序列化:空串不下发、末级单值、父级展开子树集合', async () => {
|
* 空串不下发。旧「父级点选→按授权树/内置快照展开子树集合」那一层随之退役。 */
|
||||||
|
test('类目筛选参数序列化:空串不下发、选中末级类目=单元素集合(等值)', async () => {
|
||||||
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
|
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
|
||||||
await import('../src/pages/jd/jd-product-filter.ts')
|
await import('../src/pages/jd/jd-product-filter.ts')
|
||||||
const empty = createJdProductFilterState()
|
const empty = createJdProductFilterState()
|
||||||
@@ -108,45 +109,13 @@ test('类目筛选参数序列化:空串不下发、末级单值、父级展
|
|||||||
|
|
||||||
const leaf = { ...empty, category: ' 艺考形体服 ' }
|
const leaf = { ...empty, category: ' 艺考形体服 ' }
|
||||||
assert.deepEqual(toJdProductListParams(leaf, 1, 20).category, ['艺考形体服'],
|
assert.deepEqual(toJdProductListParams(leaf, 1, 20).category, ['艺考形体服'],
|
||||||
'无路径=去空白单元素集合(等值旧形状,后端 IN 单值等价)')
|
'末级类目名 trim 后单元素集合(后端 IN 单值等价 eq)')
|
||||||
assert.equal(jdProductFilterActive(leaf), true, '选中类目算激活筛选')
|
assert.equal(jdProductFilterActive(leaf), true, '选中类目算激活筛选')
|
||||||
|
|
||||||
const parent = { ...empty, category: '女装', categoryPath: ['服饰内衣', '女装'] }
|
// 历史「父级路径展开」字段已随内置快照树退役:带上也不影响序列化结果(不会凭空多出集合)。
|
||||||
const expanded = toJdProductListParams(parent, 1, 20).category as string[]
|
const legacy = { ...empty, category: '女装', categoryPath: ['服饰内衣', '女装'] }
|
||||||
assert.ok(Array.isArray(expanded) && expanded.length > 20, '一级/二级选中=子树展开集合')
|
assert.deepEqual(toJdProductListParams(legacy, 1, 20).category, ['女装'],
|
||||||
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, ['已下架历史类目'],
|
|
||||||
'路径失效(树外历史名)回落单名等值,不静默丢筛选')
|
|
||||||
})
|
|
||||||
|
|
||||||
/** 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 () => {
|
test('自定义分类使用 group_id,不发送分类状态参数', async () => {
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ import {
|
|||||||
jdOwnershipSelectValue,
|
jdOwnershipSelectValue,
|
||||||
toJdProductListParams,
|
toJdProductListParams,
|
||||||
} from '../src/pages/jd/jd-product-filter.ts'
|
} from '../src/pages/jd/jd-product-filter.ts'
|
||||||
import {
|
|
||||||
jdCategoryChildren,
|
|
||||||
jdCategoryRoots,
|
|
||||||
} from '../src/pages/jd/jd-category-tree.ts'
|
|
||||||
import {
|
import {
|
||||||
JD_PRODUCT_DEFAULT_SIZE,
|
JD_PRODUCT_DEFAULT_SIZE,
|
||||||
jdPriceRange,
|
jdPriceRange,
|
||||||
@@ -46,20 +42,6 @@ import {
|
|||||||
toJdProductItem,
|
toJdProductItem,
|
||||||
} from '../src/pages/jd/jd-product-model.ts'
|
} from '../src/pages/jd/jd-product-model.ts'
|
||||||
|
|
||||||
test('类目级联静态导航树——服饰内衣二级与京麦面板样本逐字同源,一级集非空且无重名', () => {
|
|
||||||
// 京麦面板真机样本(2026-11-16 客户截图):服饰内衣下就是这五个二级,改名即红。
|
|
||||||
assert.deepEqual(jdCategoryChildren(['服饰内衣']).map(node => node.name), ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
|
|
||||||
assert.deepEqual(jdCategoryChildren(['不存在的类目']), [], '未知一级回落空子级(面板不出第二栏)')
|
|
||||||
|
|
||||||
const roots = jdCategoryRoots().map(node => node.name)
|
|
||||||
assert.deepEqual(roots, ['服饰内衣', '母婴', '运动户外'], '一级导航与京麦授权类目一致')
|
|
||||||
assert.equal(new Set(roots).size, roots.length, '一级类目名不得重复')
|
|
||||||
for (const root of roots) {
|
|
||||||
const children = jdCategoryChildren([root]).map(node => node.name)
|
|
||||||
assert.equal(new Set(children).size, children.length, `${root} 的二级不得重复`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('京东列表参数——snake 形状:keyword/店铺/价格下发,旧编码标题两框停发、日期空白/非法不下发', () => {
|
test('京东列表参数——snake 形状:keyword/店铺/价格下发,旧编码标题两框停发、日期空白/非法不下发', () => {
|
||||||
const full = toJdProductListParams(
|
const full = toJdProductListParams(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* 京东数据库侧栏(JdCategorySidebar,v1.6 蓝图 Phase 2)的挂载契约。
|
* 京东数据库侧栏(JdCategorySidebar)的挂载契约。
|
||||||
*
|
*
|
||||||
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本文件零 api mock——
|
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本文件零 api mock——
|
||||||
* 钉的是「徽标数=点节点后列表命中的行数」(jdCategoryCountTree 同源)、双 Tab 切换、
|
* 钉的是双 Tab 切换、商品目录「京东平台类目平铺」口径(2026-11-26 客户口径「京东分类
|
||||||
* 点节点 emit 形状(树内带路径/树外兜底 path 空/全部商品 null)、可写档分档入口。
|
* 百分百有,京东内分类不需要」:平铺一层、点行=末级类目名等值、path 恒空、无授权树/
|
||||||
|
* 无内置快照/无「树外兜底」分组)、可写档分档入口。
|
||||||
*
|
*
|
||||||
* 跑法:`npx vitest run tests/mount/jd-category-sidebar.mount.test.ts`
|
* 跑法:`npx vitest run tests/mount/jd-category-sidebar.mount.test.ts`
|
||||||
*/
|
*/
|
||||||
@@ -63,250 +64,86 @@ function rowByText(scope: VueWrapper<Element>, text: string) {
|
|||||||
return row!
|
return row!
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
describe('商品目录 Tab(京东平台类目平铺,2026-11-26)', () => {
|
||||||
// v1.7 起展开态持久化 localStorage:用例间清掉防串台(出厂态=无记忆)。
|
it('出厂停在商品目录 Tab;「全部商品」徽标=计数行求和;一类目一行平铺(无树层级/无分组头)', () => {
|
||||||
localStorage.removeItem('jd_db_cat_expand')
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
|
|
||||||
it('出厂停在商品目录 Tab;徽标与 Phase 1 聚合同源(根=子树去重和、全部商品=计数行总和)', () => {
|
|
||||||
const wrapper = mountSidebar()
|
const wrapper = mountSidebar()
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
const all = catalog.get('.jd-side-all')
|
const all = catalog.get('.jd-side-all')
|
||||||
expect(all.text()).toContain('全部商品')
|
expect(all.text()).toContain('全部商品')
|
||||||
expect(all.text()).toContain('37', '全部商品徽标=5 条计数行求和(7+4+5+9+12)')
|
expect(all.text()).toContain('37', '全部商品徽标=5 条计数行求和(7+4+5+9+12)')
|
||||||
expect(rowByText(catalog, '服饰内衣').text()).toContain('20',
|
|
||||||
'服饰内衣根徽标=子树去重和(连衣裙7+短袖4+短裤9,短裤跨支同名只记一次)')
|
const rows = catalog.findAll('.jd-side-tree .jd-side-row')
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('母婴'))).toBe(false,
|
expect(rows.map((row) => row.findAll('.jd-side-name').at(0)!.text())).toEqual([
|
||||||
'零命中一级整支剪掉(2026-11-24:不显示本店没有的类目分支)')
|
'连衣裙',
|
||||||
expect(rowByText(catalog, '运动户外').text()).toContain('5')
|
'短袖连衣裙',
|
||||||
|
'艺考形体服',
|
||||||
|
'短裤',
|
||||||
|
'已下架历史类目',
|
||||||
|
], '按后端给的类目名顺序平铺,一行一个末级类目名')
|
||||||
|
expect(rows.map((row) => row.find('.jd-side-count').text())).toEqual(['7', '4', '5', '9', '12'],
|
||||||
|
'每行徽标=该类目的商品数(后端 productCount 原样)')
|
||||||
|
// 平铺形状:没有层级缩进类、没有箭头、没有「授权树外的类目」分组头、没有展开操作行。
|
||||||
|
expect(rows.every((row) => row.classes().includes('depth-0'))).toBe(true)
|
||||||
|
expect(catalog.find('.jd-side-arrow').exists()).toBe(false, '平铺列表没有展开箭头')
|
||||||
|
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '平铺列表没有展开/收起操作行')
|
||||||
|
expect(catalog.text()).not.toContain('授权树外的类目', '不再有树外兜底分组(客户口径:京东分类百分百有)')
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('一级默认展开(二级首屏可见);逐级展开后末级行点行 emit {name, path}', async () => {
|
it('点类目行 emit {name, path: []}(页面按单名集合 IN 下发);选中态按类目名高亮', async () => {
|
||||||
const wrapper = mountSidebar()
|
const wrapper = mountSidebar()
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
const women = rowByText(catalog, '女装')
|
await rowByText(catalog, '连衣裙').trigger('click')
|
||||||
expect(women.classes()).toContain('depth-1', '一级默认展开 ⇒ 二级行(depth-1 缩进)首屏可见')
|
|
||||||
// 末级艺考形体服在 depth-2:其父(舞蹈体操鞋服/装备)未展开时不可见。
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(false)
|
|
||||||
await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click')
|
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
const yikao = rowByText(catalog, '艺考形体服')
|
expect(wrapper.emitted('select-category')).toEqual([[{ name: '连衣裙', path: [] }]],
|
||||||
expect(yikao.classes()).toContain('depth-2', '艺考形体服是 level 3(depth 2 缩进)')
|
'平铺行不带路径:path 空=单名等值,与本页旧「树外名」同形')
|
||||||
await yikao.trigger('click')
|
|
||||||
await flushPromises()
|
await wrapper.setProps({ selectedCategory: { name: '短裤', path: [] } })
|
||||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '艺考形体服', path: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'] }]])
|
expect(rowByText(catalog, '短裤').classes()).toContain('selected')
|
||||||
|
expect(rowByText(catalog, '连衣裙').classes()).not.toContain('selected')
|
||||||
|
expect(catalog.get('.jd-side-all').classes()).not.toContain('selected', '选了类目就不再是全选态')
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('点二级节点 emit 完整路径(页面按子树展开 IN);箭头只折展不选中', async () => {
|
it('「全部商品」行 emit null(页面清类目筛选重查)', async () => {
|
||||||
const wrapper = mountSidebar()
|
const wrapper = mountSidebar()
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
// 女装行未展开时,其子行(连衣裙)不可见。
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false)
|
|
||||||
const women = rowByText(catalog, '女装')
|
|
||||||
await women.trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '女装', path: ['服饰内衣', '女装'] }]],
|
|
||||||
'点行=选中即筛,emit 完整名称路径')
|
|
||||||
// 点行顺手展开(下钻感):子行现在可见。
|
|
||||||
expect(wrapper.emitted('select-category')).toHaveLength(1)
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(true,
|
|
||||||
'非末级行点行后展开子级')
|
|
||||||
|
|
||||||
// 箭头(role=button, aria-label)只折展:点它不得触发 select-category。
|
|
||||||
const before = wrapper.emitted('select-category')?.length ?? 0
|
|
||||||
await catalog.get('[aria-label="展开或收起 女装"]').trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
expect(wrapper.emitted('select-category')?.length).toBe(before, '箭头点击不选中(click.stop 防冒泡)')
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false,
|
|
||||||
'再点箭头=收起(子行隐藏)')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('「全部商品」行 emit null(页面清类目筛选重查);挂载即带选中态时祖先自动展开并高亮', async () => {
|
|
||||||
const wrapper = mountSidebar({ selectedCategory: { name: '连衣裙', path: ['服饰内衣', '女装', '连衣裙'] } })
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
const dress = rowByText(catalog, '连衣裙')
|
|
||||||
expect(dress.classes()).toContain('selected', '外部选中态回显高亮')
|
|
||||||
expect(dress.classes()).toContain('depth-2', '挂载即带选中 ⇒ watch immediate 展开祖先(女装已展开,行可见)')
|
|
||||||
|
|
||||||
await wrapper.setProps({ selectedCategory: null })
|
|
||||||
expect(catalog.get('.jd-side-all').classes()).toContain('selected', 'null=全部商品高亮')
|
|
||||||
await catalog.get('.jd-side-all').trigger('click')
|
await catalog.get('.jd-side-all').trigger('click')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
expect(wrapper.emitted('select-category')).toEqual([[null]], '点全部商品=清选')
|
expect(wrapper.emitted('select-category')).toEqual([[null]])
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('全部展开/收起(v1.7 树增强):收起后二级行隐藏、展开后末级行直接可见', async () => {
|
it('挂载即带选中态:对应行直接高亮(平铺无祖先链,无需自动展开)', () => {
|
||||||
const wrapper = mountSidebar()
|
const wrapper = mountSidebar({ selectedCategory: { name: '已下架历史类目', path: [] } })
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
await catalog.get('[aria-label="收起全部类目"]').trigger('click')
|
expect(rowByText(catalog, '已下架历史类目').classes()).toContain('selected')
|
||||||
await flushPromises()
|
expect(catalog.get('.jd-side-all').classes()).not.toContain('selected')
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('女装'))).toBe(false,
|
|
||||||
'全部收起=一级也收(用户点了就是要收干净)')
|
|
||||||
|
|
||||||
await catalog.get('[aria-label="展开全部类目"]').trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(true,
|
|
||||||
'全部展开=末级行直接可见(一次到底)')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('展开态持久化:切换写入 localStorage `jd_db_cat_expand`;全收起存的是空数组(不是抹掉键)', async () => {
|
|
||||||
const wrapper = mountSidebar()
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
// 出厂态(一级默认展开)在树根到达时补齐并落盘。
|
|
||||||
const stored1 = JSON.parse(localStorage.getItem('jd_db_cat_expand') || 'null') as string[]
|
|
||||||
expect(Array.isArray(stored1)).toBe(true)
|
|
||||||
expect(stored1.length).toBeGreaterThan(0, '出厂一级展开态被记住')
|
|
||||||
|
|
||||||
await catalog.get('[aria-label="收起全部类目"]').trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
expect(JSON.parse(localStorage.getItem('jd_db_cat_expand') || '"bad"')).toEqual([],
|
|
||||||
'全收起=空数组记忆(下次挂载不再补一级展开)')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('挂载读记忆:预置空数组记忆=出厂不补一级展开(用户上次全收起的意图不被吞)', () => {
|
|
||||||
localStorage.setItem('jd_db_cat_expand', '[]')
|
|
||||||
const wrapper = mountSidebar()
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('女装'))).toBe(false,
|
|
||||||
'有记忆(哪怕空)就尊重记忆,不再补一级默认展开')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('挂载读记忆:预置展开记忆=深路径直接展开到位(切页/重进不丢)', () => {
|
|
||||||
localStorage.setItem('jd_db_cat_expand', JSON.stringify(['运动户外', '运动户外/舞蹈体操鞋服/装备']))
|
|
||||||
const wrapper = mountSidebar()
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(true,
|
|
||||||
'记忆里的展开键(含多级路径串)直接生效')
|
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('树外兜底组(树上对不上的历史行,单名等值出口)', () => {
|
describe('类目计数未就绪(首帧加载态)', () => {
|
||||||
it('兜底组头渲染计数和=extraTotal;行点击 emit {name, path:[]}(页面按单名等值回落)', async () => {
|
it('未就绪 ⇒ 只留加载行,不画列表(避免空列表先闪一下再跳成有数据)', () => {
|
||||||
const wrapper = mountSidebar()
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
const head = catalog.get('.jd-side-extra-head')
|
|
||||||
expect(head.text()).toContain('授权树外的类目', '树有命中时这一组的名字如实点名来处')
|
|
||||||
expect(head.text()).toContain('12', '兜底组头徽标=extraTotal(历史行求和)')
|
|
||||||
const extra = rowByText(catalog, '已下架历史类目')
|
|
||||||
await extra.trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '已下架历史类目', path: [] }]],
|
|
||||||
'树外名 path 空数组=无路径序列化(单名等值旧形状,不静默丢筛选)')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('全部是树内名时兜底组整体不渲染(不占一条空组)', () => {
|
|
||||||
const wrapper = mount(JdCategorySidebar, {
|
const wrapper = mount(JdCategorySidebar, {
|
||||||
props: {
|
props: {
|
||||||
categoryOptions: [{ name: '连衣裙', productCount: 7 }],
|
categoryOptions: CATEGORY_OPTIONS,
|
||||||
categories: CATEGORIES,
|
categories: CATEGORIES,
|
||||||
editable: true,
|
editable: true,
|
||||||
selectedCategory: null,
|
selectedCategory: null,
|
||||||
selectedGroupId: null,
|
selectedGroupId: null,
|
||||||
|
categoriesReady: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(wrapper.find('.jd-side-extra').exists()).toBe(false)
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('内置授权树与本店不同源(2026-11-24 客户口径:要的是类目树,不是「树外兜底」)', () => {
|
|
||||||
/** 活样本:库里只有家居收纳类目(家居日用数据库店的 474 件),内置树(花屿巷旗舰店的
|
|
||||||
* 服饰授权快照)节点全 0——旧行为照样渲染整棵服饰树(看着像「这家店卖女装」),
|
|
||||||
* 2026-11-23 一轮收成「本店无匹配」一行+全部落「树外兜底」(客户:「正确是一开始
|
|
||||||
* 显示的那棵树,而不是什么树兜底」)。现行口径:零命中分支整支剪掉,树空就把本店
|
|
||||||
* 类目平铺成一级列表——始终是一棵树,不出现别店类目、也不出现退化分组。 */
|
|
||||||
const FOREIGN_OPTIONS: JdProductCategoryOption[] = [
|
|
||||||
{ name: '化妆品收纳盒', productCount: 260 },
|
|
||||||
{ name: '其他收纳架', productCount: 4 },
|
|
||||||
]
|
|
||||||
|
|
||||||
function mountForeign(): VueWrapper<Element> {
|
|
||||||
return mount(JdCategorySidebar, {
|
|
||||||
props: {
|
|
||||||
categoryOptions: FOREIGN_OPTIONS,
|
|
||||||
categories: CATEGORIES,
|
|
||||||
editable: true,
|
|
||||||
selectedCategory: null,
|
|
||||||
selectedGroupId: null,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 树容器的 v-show 态:直接读 inline style(jsdom 的 getComputedStyle 有缓存,
|
|
||||||
* 同一元素二次切换后 isVisible() 仍回旧值——不拿它当判据)。 */
|
|
||||||
function treeDisplay(catalog: VueWrapper<Element>): string {
|
|
||||||
return (catalog.get('.jd-side-tree').element as HTMLElement).style.display
|
|
||||||
}
|
|
||||||
|
|
||||||
it('整树零命中 ⇒ 不渲染别店树,本店类目平铺成一级(无分组头、无「本店无匹配」行)', async () => {
|
|
||||||
const wrapper = mountForeign()
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
expect(treeDisplay(catalog)).toBe('none', '别店快照的服饰分支一件商品都没有 ⇒ 整树剪空')
|
expect(catalog.text()).toContain('类目加载中…')
|
||||||
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '没有树就不摆展开/收起')
|
expect(catalog.find('.jd-side-tree').exists()).toBe(false, '未就绪不画列表')
|
||||||
expect(catalog.find('.jd-side-extra-head').exists()).toBe(false,
|
expect(catalog.get('.jd-side-all').text()).toContain('—', '总数未就绪显示占位')
|
||||||
'本店类目就是整列内容,不再套「树外兜底」分组头')
|
|
||||||
expect(catalog.text()).not.toContain('服饰内衣', '别店类目一个都不露脸')
|
|
||||||
|
|
||||||
const extra = rowByText(catalog, '化妆品收纳盒')
|
|
||||||
expect(extra.classes()).not.toContain('depth-1', '平铺成本店一级类目(与树行同一层级)')
|
|
||||||
expect(extra.text()).toContain('260')
|
|
||||||
await extra.trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '化妆品收纳盒', path: [] }]],
|
|
||||||
'平铺行仍按单名等值出口(path 空数组=无路径序列化)')
|
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('树内有命中 ⇒ 只渲染命中分支(零命中的一级整支不出现)', () => {
|
it('数据到达(就绪)后同一实例切出列表与计数,加载行消失', async () => {
|
||||||
const wrapper = mountSidebar()
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
expect(treeDisplay(catalog)).not.toBe('none')
|
|
||||||
expect(rowByText(catalog, '服饰内衣').text()).toContain('20')
|
|
||||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('母婴'))).toBe(false,
|
|
||||||
'母婴支零命中 ⇒ 剪掉(不拿别店的空类目占屏)')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('传服务端真树(家居店):树上就是收纳类目、不同源判据不触发', () => {
|
|
||||||
const wrapper = mount(JdCategorySidebar, {
|
const wrapper = mount(JdCategorySidebar, {
|
||||||
props: {
|
|
||||||
categoryOptions: FOREIGN_OPTIONS,
|
|
||||||
categories: CATEGORIES,
|
|
||||||
editable: true,
|
|
||||||
selectedCategory: null,
|
|
||||||
selectedGroupId: null,
|
|
||||||
// 2026-11-23:客户端按店铺上报的授权树(形状与内置快照同款)。
|
|
||||||
categoryTree: [
|
|
||||||
{ name: '收纳用品', value: '7001', children: [{ name: '化妆品收纳盒', value: '7002' }] },
|
|
||||||
{ name: '厨房用品', value: '7101', children: [{ name: '其他收纳架', value: '7102' }] },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
expect(treeDisplay(catalog)).not.toBe('none', '真树直接渲染')
|
|
||||||
expect(rowByText(catalog, '收纳用品').text()).toContain('260', '计数徽标按真树聚合')
|
|
||||||
expect(catalog.find('.jd-side-extra').exists()).toBe(false, '所有类目都挂得上真树,无树外组')
|
|
||||||
expect(catalog.text()).not.toContain('服饰内衣', '内置快照树被服务端真树替换')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('类目计数未就绪(首帧加载态,2026-11-24)', () => {
|
|
||||||
/** 首帧真实形状:/categories 还没回(categoryOptions 空)、页面 loading 投影为 false。
|
|
||||||
* 旧行为会把回落快照整棵树先画出来(徽标全 0、「全部商品 0」),计数到达后再收成
|
|
||||||
* 「本店无匹配」一行——用户看到「原本这样过一会变那样」的闪变。 */
|
|
||||||
function mountLoading(): VueWrapper<Element> {
|
|
||||||
return mount(JdCategorySidebar, {
|
|
||||||
props: {
|
props: {
|
||||||
categoryOptions: [],
|
categoryOptions: [],
|
||||||
categories: CATEGORIES,
|
categories: CATEGORIES,
|
||||||
@@ -316,29 +153,21 @@ describe('类目计数未就绪(首帧加载态,2026-11-24)', () => {
|
|||||||
categoriesReady: false,
|
categoriesReady: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
it('未就绪 ⇒ 只留加载行,不先把内置快照整棵树画出来', () => {
|
|
||||||
const wrapper = mountLoading()
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
expect(catalog.get('.jd-side-loading').text()).toContain('加载中')
|
|
||||||
// 树容器 v-show 收起(jsdom 的 text() 仍含隐藏子树,判据只认 inline display)。
|
|
||||||
expect((catalog.get('.jd-side-tree').element as HTMLElement).style.display).toBe('none',
|
|
||||||
'首帧不得闪出别店快照树')
|
|
||||||
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '加载态不摆展开/收起')
|
|
||||||
expect(catalog.find('.jd-side-extra').exists()).toBe(false, '加载态不摆兜底组')
|
|
||||||
expect(catalog.get('.jd-side-all').text()).toContain('—', '总数未知时不冒充 0')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('数据到达(就绪)后同一实例切出树与计数,加载行消失', async () => {
|
|
||||||
const wrapper = mountLoading()
|
|
||||||
await wrapper.setProps({ categoryOptions: CATEGORY_OPTIONS, categoriesReady: true })
|
await wrapper.setProps({ categoryOptions: CATEGORY_OPTIONS, categoriesReady: true })
|
||||||
|
await flushPromises()
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
expect(catalog.find('.jd-side-loading').exists()).toBe(false)
|
expect(catalog.find('.jd-side-loading').exists()).toBe(false)
|
||||||
expect(catalog.get('.jd-side-all').text()).toContain('37')
|
expect(catalog.get('.jd-side-all').text()).toContain('37')
|
||||||
expect((catalog.get('.jd-side-tree').element as HTMLElement).style.display).not.toBe('none')
|
expect(catalog.findAll('.jd-side-tree .jd-side-row')).toHaveLength(5)
|
||||||
expect(catalog.text()).toContain('服饰内衣')
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('计数为空(从未采集过)⇒ 空态一句话,不是空白列表', () => {
|
||||||
|
const wrapper = mount(JdCategorySidebar, {
|
||||||
|
props: { categoryOptions: [], categories: [], editable: true, selectedCategory: null, selectedGroupId: null },
|
||||||
|
})
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
expect(catalog.get('.jd-side-empty').text()).toContain('还没有采集到类目数据')
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -404,13 +233,13 @@ describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () =>
|
|||||||
const writable = mount(JdCategorySidebar, {
|
const writable = mount(JdCategorySidebar, {
|
||||||
props: { categoryOptions: [], categories: [], editable: true, selectedCategory: null, selectedGroupId: null },
|
props: { categoryOptions: [], categories: [], editable: true, selectedCategory: null, selectedGroupId: null },
|
||||||
})
|
})
|
||||||
expect(writable.get('.jd-side-empty').text()).toBe('本组暂无分类,先新建一个')
|
expect(writable.get('.jd-side-custom').get('.jd-side-empty').text()).toBe('本组暂无分类,先新建一个')
|
||||||
writable.unmount()
|
writable.unmount()
|
||||||
|
|
||||||
const readonly = mount(JdCategorySidebar, {
|
const readonly = mount(JdCategorySidebar, {
|
||||||
props: { categoryOptions: [], categories: [], editable: false, selectedCategory: null, selectedGroupId: null },
|
props: { categoryOptions: [], categories: [], editable: false, selectedCategory: null, selectedGroupId: null },
|
||||||
})
|
})
|
||||||
expect(readonly.get('.jd-side-empty').text()).toBe('本组暂无分类')
|
expect(readonly.get('.jd-side-custom').get('.jd-side-empty').text()).toBe('本组暂无分类')
|
||||||
readonly.unmount()
|
readonly.unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -57,14 +57,8 @@ const groupApi = vi.hoisted(() => ({
|
|||||||
createShopGroup: vi.fn(),
|
createShopGroup: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// 京麦授权类目树(V215 真树)读取:默认空回执=页面回落内置快照;真树用例显式变形。
|
|
||||||
const shopTreeApi = vi.hoisted(() => ({
|
|
||||||
fetchJdShopCategoryTree: vi.fn(),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||||||
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
|
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 }))
|
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||||
|
|
||||||
function item(id: number, over: Record<string, unknown> = {}) {
|
function item(id: number, over: Record<string, unknown> = {}) {
|
||||||
@@ -114,9 +108,8 @@ function singleGroupScope(editable = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 类目计数夹具:与侧栏组件 mount 测试同源(树内连衣裙支+树外历史名),
|
/** 类目计数夹具:与侧栏组件 mount 测试同源。2026-11-26 起左栏商品目录=后端
|
||||||
* 树内路径以 jd-category-tree 真树为准:连衣裙=服饰内衣/女装/连衣裙、
|
* `/categories` 的 `category_path` 平铺(末级类目名+商品数),不再有类目树/路径。 */
|
||||||
* 艺考形体服=运动户外/舞蹈体操鞋服/装备/艺考形体服。 */
|
|
||||||
const CATEGORY_OPTIONS = [
|
const CATEGORY_OPTIONS = [
|
||||||
{ name: '连衣裙', productCount: 7 },
|
{ name: '连衣裙', productCount: 7 },
|
||||||
{ name: '艺考形体服', productCount: 5 },
|
{ name: '艺考形体服', productCount: 5 },
|
||||||
@@ -136,8 +129,6 @@ beforeEach(() => {
|
|||||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
||||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||||
// 真树默认「服务端还没人上报过」=页面回落内置快照(旧用例形状逐字不变)。
|
|
||||||
shopTreeApi.fetchJdShopCategoryTree.mockResolvedValue({ nodes: [], shops: [] })
|
|
||||||
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
|
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
|
||||||
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
|
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
|
||||||
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
||||||
@@ -328,49 +319,24 @@ describe('布局:筛选行+工具栏上移顶部通栏(2026-11-21 用户
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('侧栏商品目录(类目筛选迁移自级联面板)', () => {
|
describe('侧栏商品目录(京东平台类目平铺,2026-11-26)', () => {
|
||||||
it('授权类目树逐级下钻:一级行点行=选中即查(path 下发),末级点行单名/路径口径与级联面板等价', async () => {
|
it('类目行点选=末级类目名等值下发(category+path 空),「全部商品」清选重查', async () => {
|
||||||
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
||||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||||||
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith()
|
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith()
|
||||||
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
// 一级默认展开:二级「女装」首屏可见(侧栏与级联面板的关键差异——非末级也能直接选)。
|
// 一类目一行平铺:末级类目名直接点,不再有「一级/二级下钻」与展开箭头。
|
||||||
const women = sideRowBy(catalog, '女装')
|
expect(catalog.find('.jd-side-arrow').exists()).toBe(false, '平铺列表没有展开箭头')
|
||||||
expect(women.classes()).toContain('depth-1')
|
expect(catalog.findAll('.jd-side-tree .jd-side-row').length).toBeGreaterThan(0)
|
||||||
|
|
||||||
// 点二级=选中即查(2026-11-18 客户口径「没办法选择一级跟二级类目」的侧栏形状)。
|
|
||||||
await women.trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
let last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
|
||||||
expect(last).toMatchObject({ category: '女装', categoryPath: ['服饰内衣', '女装'], page: 1 },
|
|
||||||
'一级/二级点行=带完整路径下发(序列化按子树展开 IN)')
|
|
||||||
|
|
||||||
// 展开到末级再点末级:艺考形体服(运动户外支)。
|
|
||||||
await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
await sideRowBy(catalog, '艺考形体服').trigger('click')
|
await sideRowBy(catalog, '艺考形体服').trigger('click')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
const leaf = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||||
expect(last).toMatchObject({
|
expect(leaf).toMatchObject({ category: '艺考形体服', page: 1 },
|
||||||
category: '艺考形体服',
|
'末级类目名等值过滤(后端 category_path IN 单元素集合)')
|
||||||
categoryPath: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'],
|
expect('categoryPath' in leaf, '父级路径这一层已退役:api 入参不再有 categoryPath').toBe(false)
|
||||||
page: 1,
|
expect('categoryNames' in leaf, '子树展开集合同样退役:入参不再有 categoryNames').toBe(false)
|
||||||
}, '末级点行带完整名称路径(同名跨支靠路径区分)')
|
|
||||||
wrapper.unmount()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('树外类目组(已落库但京麦树里没有的历史名):点行单名等值下发;「全部商品」行清选重查', async () => {
|
|
||||||
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
|
||||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
|
||||||
|
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
|
||||||
// 授权树外的本店历史行收在单独一组(path 空数组=页面按无路径序列化单名等值)。
|
|
||||||
const extra = catalog.get('.jd-side-extra')
|
|
||||||
expect(extra.text()).toContain('授权树外的类目')
|
|
||||||
await extra.findAll('.jd-side-row').find((row) => row.text().includes('已下架历史类目'))!.trigger('click')
|
|
||||||
await flushPromises()
|
|
||||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '已下架历史类目', categoryPath: [] })
|
|
||||||
|
|
||||||
// 点「全部商品」行=清选重查(category 回空、query 层不下发,回第一页)。
|
// 点「全部商品」行=清选重查(category 回空、query 层不下发,回第一页)。
|
||||||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||||
@@ -378,44 +344,30 @@ describe('侧栏商品目录(类目筛选迁移自级联面板)', () => {
|
|||||||
await flushPromises()
|
await flushPromises()
|
||||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查')
|
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查')
|
||||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].categoryPath).toEqual([],
|
expect('categoryPath' in jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toBe(false)
|
||||||
'清选后路径回空数组(api 序列化层对空 category 不下发参数)')
|
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('服务端真树≠内置快照:点父级必须把按真树展开的 categoryNames 透传给列表查询(2026-11-25「收纳用品 81 点开 0 条」断链钉)', async () => {
|
it('2026-11-26:商品目录只读京东平台类目,页面不再取授权类目树(/jd-shop-category-tree)', 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([
|
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||||
{ name: '收纳盒', productCount: 23 },
|
{ name: '收纳盒', productCount: 23 },
|
||||||
{ name: '收纳篮', productCount: 14 },
|
{ name: '收纳篮', productCount: 14 },
|
||||||
{ name: '收纳架', productCount: 44 },
|
|
||||||
])
|
])
|
||||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||||||
|
|
||||||
|
// 客户口径「京东分类是百分百有的,京东内分类就不需要」:左栏直接是 category_path
|
||||||
|
// 平铺,不再有按店铺上报的授权树、也不再有内置花屿巷快照/树外兜底分组。
|
||||||
const catalog = wrapper.get('.jd-side-catalog')
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
// 徽标同源(真树聚合):父级 81=23+14+44,这条一直是对的,错的是过滤链。
|
expect(sideRowBy(catalog, '收纳盒').text()).toContain('23')
|
||||||
expect(sideRowBy(catalog, '收纳用品').text()).toContain('81')
|
expect(catalog.text()).not.toContain('授权树外的类目')
|
||||||
|
expect(catalog.text()).not.toContain('本店无匹配')
|
||||||
|
|
||||||
await sideRowBy(catalog, '收纳用品').trigger('click')
|
await sideRowBy(catalog, '收纳盒').trigger('click')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||||
expect(last).toMatchObject({ category: '收纳用品', categoryPath: ['收纳用品'], page: 1 })
|
expect(last).toMatchObject({ category: '收纳盒', page: 1 })
|
||||||
expect(last.categoryNames, '断链修复点:页面按真树展开的子树名集合必须进 api 入参').toBeDefined()
|
expect('categoryNames' in last, '不再有「页面按树展开的集合」这层:平铺行单名等值').toBe(false)
|
||||||
expect([...last.categoryNames].sort()).toEqual(['收纳架', '收纳盒', '收纳篮', '收纳用品'].sort(),
|
expect('categoryPath' in last, '也不再传类目路径').toBe(false)
|
||||||
'集合=节点自身+全部后代(与徽标计数同一棵树算出)')
|
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
+27
-47
@@ -72,14 +72,16 @@ import java.util.List;
|
|||||||
* (仅平台超管+公司超管放行,admin 与普通账号 403,见 {@code requireJdProductWrite});
|
* (仅平台超管+公司超管放行,admin 与普通账号 403,见 {@code requireJdProductWrite});
|
||||||
* 批量归类走 V203 的按组判(requireWritableGroup;2026-11-23 起 admin 对可见 jd 分组可写)。</p>
|
* 批量归类走 V203 的按组判(requireWritableGroup;2026-11-23 起 admin 对可见 jd 分组可写)。</p>
|
||||||
*
|
*
|
||||||
* <p><b>公司口径(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」)</b>:读侧零公司
|
* <p><b>数据可见口径(2026-11-26 客户口径「采集的数据可以重复被操作分类,大家一起采集,
|
||||||
* 维度——company_id 请求参数与 {@code superAdminScopedCompanyId} 谓词已随公共化收尾整批
|
* 但分类后的数据就自己看,所以会有数据副本」「被分类后按组 id 绑定拷贝数据副本,原来的数据
|
||||||
* 摘除(2026-11-15 定案「京东数据库不区分公司、属于公共的」的最后一截),行上的 company_id
|
* 也要留着」)</b>:商品行是<b>全平台共享的采集池</b>——读侧零公司维度,任何公司、任何组的
|
||||||
* 只剩「哪家公司客户端同步的」来源标记,不构成可见性边界;每个拿到本页菜单权限的管理员
|
* 账号都看到同一份采集数据;2026-11-23 加回的「公司与公司不能互看」按公司隔离整批撤销。
|
||||||
* (含站点超管)看到同一份全量公共库。详情与写侧(编辑/删除)同样没有公司维度:
|
* 分类的隔离落在 V203 归属行上(同一商品可多组各一条 {@code owner_group_id} 归属行,分类列/
|
||||||
* 写动作<b>只对超管级开放</b>(2026-11-23 客户口径「删除权限只有公司管理员有;
|
* 分类筛选各看各的)=客户说的「按组绑定一份副本」,<b>原商品行一条不删不藏</b>——别组分过类
|
||||||
* 管理人员只有分类权限」,见 {@code requireJdProductWrite}),
|
* 的商品在本组视角仍显示未分类、照样能再分一次、照样能上架,所以分类永远不会让任何管理员的
|
||||||
* 写侧端点的 company_id 传参已随 2026-11-15 公共化摘除。</p>
|
* 数据变少。不物理复制商品行(采集 upsert 唯一键/图片/SKU/上架选品都不跟随副本)。
|
||||||
|
* 写(编辑/删除/传图)仍只对超管级开放({@code requireJdProductWrite}),但不再按行上的
|
||||||
|
* {@code company_id} 收窄:共享池里看得见就能操作。</p>
|
||||||
*
|
*
|
||||||
* <p><b>v1.7(2026-11-21 对齐原型《商品数据商城》,用户拍板)</b>:恢复 CSV 导出
|
* <p><b>v1.7(2026-11-21 对齐原型《商品数据商城》,用户拍板)</b>:恢复 CSV 导出
|
||||||
* {@code POST /export}(按勾选 id,读闸 requireJdAccess,UTF-8 BOM+中文表头);
|
* {@code POST /export}(按勾选 id,读闸 requireJdAccess,UTF-8 BOM+中文表头);
|
||||||
@@ -113,12 +115,11 @@ public class AdminJdProductController {
|
|||||||
private final JdCategoryScopeService jdCategoryScopeService;
|
private final JdCategoryScopeService jdCategoryScopeService;
|
||||||
private final AdminAuthSupport adminAuthSupport;
|
private final AdminAuthSupport adminAuthSupport;
|
||||||
private final PermissionMenuService permissionMenuService;
|
private final PermissionMenuService permissionMenuService;
|
||||||
/** 公司隔离的唯一出口(2026-11-23):读侧 {@code readCompanyIdOrOwn}、写侧 {@code writeCompanyId}。 */
|
|
||||||
private final com.nanri.aiimage.common.service.DataReadScope dataReadScope;
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Operation(summary = "分页查询京东数据库商品", description = "公共库分页查询同步落表的京东商品;"
|
@Operation(summary = "分页查询京东数据库商品", description = "全平台共享采集池分页查询;"
|
||||||
+ "全平台公共、无公司维度(2026-11-16 摘公司 tab:公司维参数与超管筛选谓词已整批摘除)。")
|
+ "任何公司、任何组的账号看到同一份数据(2026-11-26 撤销按公司隔离)。"
|
||||||
|
+ "分类列按当前数据权限分组(owner_group_id)取,各看各的。")
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", content = @Content(schema = @Schema(implementation = JdProductPageVo.class)))
|
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "查询成功", content = @Content(schema = @Schema(implementation = JdProductPageVo.class)))
|
||||||
})
|
})
|
||||||
@@ -150,15 +151,11 @@ public class AdminJdProductController {
|
|||||||
@Parameter(description = "分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):"
|
@Parameter(description = "分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):"
|
||||||
+ "true=当前分组下有分类,false=未分类,缺省=全部;按 V203 归属表 SQL 侧下推")
|
+ "true=当前分组下有分类,false=未分类,缺省=全部;按 V203 归属表 SQL 侧下推")
|
||||||
@RequestParam(name = "classified", required = false) Boolean classified,
|
@RequestParam(name = "classified", required = false) Boolean classified,
|
||||||
@Parameter(description = "公司 id(仅平台超管有效;非超管一律按本公司过滤,传什么都不算)")
|
|
||||||
@RequestParam(name = "company_id", required = false) Long companyId,
|
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) {
|
if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) {
|
||||||
throw new BusinessException("页面版本已更新,请刷新页面后重新查询");
|
throw new BusinessException("页面版本已更新,请刷新页面后重新查询");
|
||||||
}
|
}
|
||||||
// 公司隔离(2026-11-23 客户口径「公司与公司之间不能互看」):非平台超管恒为本公司。
|
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator.user(), companyId);
|
|
||||||
JdCategoryScopeService.JdCategoryScope scope = jdCategoryScopeService.resolve(operator.user());
|
JdCategoryScopeService.JdCategoryScope scope = jdCategoryScopeService.resolve(operator.user());
|
||||||
Long scopedOwnerGroupId = jdCategoryScopeService.readGroupOrNull(scope, ownerGroupId);
|
Long scopedOwnerGroupId = jdCategoryScopeService.readGroupOrNull(scope, ownerGroupId);
|
||||||
if (groupId != null && groupId > 0) {
|
if (groupId != null && groupId > 0) {
|
||||||
@@ -166,7 +163,7 @@ public class AdminJdProductController {
|
|||||||
}
|
}
|
||||||
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
|
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
|
||||||
keyword, productCode, titleKeyword, categories, groupId, shopName, minPrice, maxPrice,
|
keyword, productCode, titleKeyword, categories, groupId, shopName, minPrice, maxPrice,
|
||||||
syncedFrom, syncedTo, classified, scopedOwnerGroupId, scopedCompanyId));
|
syncedFrom, syncedTo, classified, scopedOwnerGroupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
@@ -174,15 +171,12 @@ public class AdminJdProductController {
|
|||||||
description = "按勾选 id 导出(上限 1000,超限整批拒绝不静默截断);"
|
description = "按勾选 id 导出(上限 1000,超限整批拒绝不静默截断);"
|
||||||
+ "UTF-8 带 BOM + 中文表头(Excel 双击直开不乱码),列=商品编码/标题/价格下限/价格上限/"
|
+ "UTF-8 带 BOM + 中文表头(Excel 双击直开不乱码),列=商品编码/标题/价格下限/价格上限/"
|
||||||
+ "总库存/SKU数/信息分/品牌/货号/店铺/类目/状态/同步时间/主图。"
|
+ "总库存/SKU数/信息分/品牌/货号/店铺/类目/状态/同步时间/主图。"
|
||||||
+ "导出属读行为:走 requireJdAccess 菜单正门,不走商品行写闸。")
|
+ "导出属读行为:走 requireJdAccess 菜单正门,与列表同口径全平台共享。")
|
||||||
public ResponseEntity<byte[]> export(
|
public ResponseEntity<byte[]> export(
|
||||||
@Valid @RequestBody JdProductExportRequest body,
|
@Valid @RequestBody JdProductExportRequest body,
|
||||||
@Parameter(description = "公司 id(仅平台超管有效)")
|
|
||||||
@RequestParam(name = "company_id", required = false) Long companyId,
|
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator.user(), companyId);
|
byte[] bytes = jdProductQueryService.exportCsv(body.getIds());
|
||||||
byte[] bytes = jdProductQueryService.exportCsv(body.getIds(), scopedCompanyId);
|
|
||||||
log.info("[jd-product] 导出CSV operatorId={} requested={}", operator.id(), body.getIds().size());
|
log.info("[jd-product] 导出CSV operatorId={} requested={}", operator.id(), body.getIds().size());
|
||||||
String filename = "京东数据库-" + LocalDateTime.now().format(EXPORT_FILENAME_FORMATTER) + ".csv";
|
String filename = "京东数据库-" + LocalDateTime.now().format(EXPORT_FILENAME_FORMATTER) + ".csv";
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
@@ -194,33 +188,26 @@ public class AdminJdProductController {
|
|||||||
|
|
||||||
@GetMapping("/categories")
|
@GetMapping("/categories")
|
||||||
@Operation(summary = "类目筛选下拉数据源", description = "已落库行 DISTINCT 的 category_path"
|
@Operation(summary = "类目筛选下拉数据源", description = "已落库行 DISTINCT 的 category_path"
|
||||||
+ "(京麦末级类目名)+ 行数,按类目名排序;2026-11-23 起与列表同口径按行公司隔离"
|
+ "(京麦末级类目名)+ 行数,按类目名排序;与列表同口径全平台共享去重"
|
||||||
+ "(非平台超管只看本公司;平台超管可用 company_id 切公司)。")
|
+ "(2026-11-26 撤销按公司隔离)。")
|
||||||
public ApiResponse<List<JdProductCategoryVo>> categories(
|
public ApiResponse<List<JdProductCategoryVo>> categories(HttpServletRequest request) {
|
||||||
@Parameter(description = "公司 id(仅平台超管有效)")
|
requireJdAccess(request);
|
||||||
@RequestParam(name = "company_id", required = false) Long companyId,
|
return ApiResponse.success(jdProductQueryService.categories());
|
||||||
HttpServletRequest request) {
|
|
||||||
RequestOperator operator = requireJdAccess(request);
|
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator.user(), companyId);
|
|
||||||
return ApiResponse.success(jdProductQueryService.categories(scopedCompanyId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@Operation(summary = "商品详情", description = "主字段全量 + attr_json 属性分组(契约形状不识别时落空分组"
|
@Operation(summary = "商品详情", description = "主字段全量 + attr_json 属性分组(契约形状不识别时落空分组"
|
||||||
+ "并把原文放 attrJsonRaw 兜底,AC-7 未识别属性不丢弃)+ 已转存图片(100% 自有域名,AC-4)。"
|
+ "并把原文放 attrJsonRaw 兜底,AC-7 未识别属性不丢弃)+ 已转存图片(100% 自有域名,AC-4)。"
|
||||||
+ "公司隔离(2026-11-23):别公司的行按「商品不存在」拒绝,不泄露行是否存在。")
|
+ "2026-11-26:全平台共享,按 id 直取(列表里看得见就能点开)。")
|
||||||
public ApiResponse<JdProductDetailVo> detail(
|
public ApiResponse<JdProductDetailVo> detail(
|
||||||
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
||||||
@Parameter(description = "当前数据权限分组 id(分类字段按它取)")
|
@Parameter(description = "当前数据权限分组 id(分类字段按它取)")
|
||||||
@RequestParam(name = "owner_group_id", required = false) Long ownerGroupId,
|
@RequestParam(name = "owner_group_id", required = false) Long ownerGroupId,
|
||||||
@Parameter(description = "公司 id(仅平台超管有效)")
|
|
||||||
@RequestParam(name = "company_id", required = false) Long companyId,
|
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator.user(), companyId);
|
|
||||||
Long scopedOwnerGroupId = jdCategoryScopeService.readGroupOrNull(
|
Long scopedOwnerGroupId = jdCategoryScopeService.readGroupOrNull(
|
||||||
jdCategoryScopeService.resolve(operator.user()), ownerGroupId);
|
jdCategoryScopeService.resolve(operator.user()), ownerGroupId);
|
||||||
return ApiResponse.success(jdProductQueryService.detail(id, scopedOwnerGroupId, scopedCompanyId));
|
return ApiResponse.success(jdProductQueryService.detail(id, scopedOwnerGroupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@@ -234,13 +221,11 @@ public class AdminJdProductController {
|
|||||||
@Valid @RequestBody JdProductUpdateRequest body,
|
@Valid @RequestBody JdProductUpdateRequest body,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdProductWrite(request);
|
RequestOperator operator = requireJdProductWrite(request);
|
||||||
Long scopedCompanyId = dataReadScope.writeCompanyId(operator.user());
|
|
||||||
jdProductQueryService.assertRowsInCompany(List.of(id), scopedCompanyId);
|
|
||||||
Long updatedId = jdProductUpdateService.update(id, body);
|
Long updatedId = jdProductUpdateService.update(id, body);
|
||||||
log.info("[jd-product] 编辑商品 operatorId={} id={} title={}",
|
log.info("[jd-product] 编辑商品 operatorId={} id={} title={}",
|
||||||
operator.id(), updatedId, body.getTitle());
|
operator.id(), updatedId, body.getTitle());
|
||||||
// 返回刷新后的详情(前端保存后直接回填抽屉),复用详情同一查询出口。
|
// 返回刷新后的详情(前端保存后直接回填抽屉),复用详情同一查询出口。
|
||||||
return ApiResponse.success(jdProductQueryService.detail(updatedId, null, scopedCompanyId));
|
return ApiResponse.success(jdProductQueryService.detail(updatedId, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/{id}/images", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/{id}/images", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@@ -260,13 +245,11 @@ public class AdminJdProductController {
|
|||||||
@RequestParam(value = "replace_image_id", required = false) Long replaceImageId,
|
@RequestParam(value = "replace_image_id", required = false) Long replaceImageId,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdProductWrite(request);
|
RequestOperator operator = requireJdProductWrite(request);
|
||||||
Long scopedCompanyId = dataReadScope.writeCompanyId(operator.user());
|
|
||||||
jdProductQueryService.assertRowsInCompany(List.of(id), scopedCompanyId);
|
|
||||||
Long updatedId = jdProductUpdateService.uploadImage(id, file, imageType, attrName, replaceImageId);
|
Long updatedId = jdProductUpdateService.uploadImage(id, file, imageType, attrName, replaceImageId);
|
||||||
log.info("[jd-product] 上传图片 operatorId={} id={} replaceImageId={} imageType={}",
|
log.info("[jd-product] 上传图片 operatorId={} id={} replaceImageId={} imageType={}",
|
||||||
operator.id(), updatedId, replaceImageId, imageType);
|
operator.id(), updatedId, replaceImageId, imageType);
|
||||||
// 返回刷新后的详情(前端上传后直接回填抽屉图片区),复用详情同一查询出口。
|
// 返回刷新后的详情(前端上传后直接回填抽屉图片区),复用详情同一查询出口。
|
||||||
return ApiResponse.success(jdProductQueryService.detail(updatedId, null, scopedCompanyId));
|
return ApiResponse.success(jdProductQueryService.detail(updatedId, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@@ -277,7 +260,6 @@ public class AdminJdProductController {
|
|||||||
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdProductWrite(request);
|
RequestOperator operator = requireJdProductWrite(request);
|
||||||
jdProductQueryService.assertRowsInCompany(List.of(id), dataReadScope.writeCompanyId(operator.user()));
|
|
||||||
JdProductDeleteVo vo = jdProductDeleteService.delete(List.of(id));
|
JdProductDeleteVo vo = jdProductDeleteService.delete(List.of(id));
|
||||||
// 管理端破坏性动作必须留痕:谁、删了哪些行、桶里清了几个对象(同分组删除口径)。
|
// 管理端破坏性动作必须留痕:谁、删了哪些行、桶里清了几个对象(同分组删除口径)。
|
||||||
log.info("[jd-product] 删除商品 operatorId={} id={} deleted={} objectsDeleted={}",
|
log.info("[jd-product] 删除商品 operatorId={} id={} deleted={} objectsDeleted={}",
|
||||||
@@ -298,9 +280,8 @@ public class AdminJdProductController {
|
|||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
JdCategoryScopeService.JdCategoryScope scope = jdCategoryScopeService.resolve(operator.user());
|
JdCategoryScopeService.JdCategoryScope scope = jdCategoryScopeService.resolve(operator.user());
|
||||||
ShopManageGroupEntity target = jdCategoryScopeService.requireWritableGroup(scope, body.getOwnerGroupId());
|
ShopManageGroupEntity target = jdCategoryScopeService.requireWritableGroup(scope, body.getOwnerGroupId());
|
||||||
// 公司隔离(2026-11-23):商品行必须属于目标分组所在的公司——平台超管也不得把
|
// 2026-11-26:商品行是全平台共享采集池,行级公司闸整批撤销——任何公司采的商品都能
|
||||||
// A 公司采的商品归进 B 公司的分类(归类行带公司列,跨公司归类会让分类计数串公司)。
|
// 归进本组分类(客户口径「大家一起采集、各分各的」)。归属行公司列仍落 target 的公司。
|
||||||
jdProductQueryService.assertRowsInCompany(body.getIds(), target.getCompanyId());
|
|
||||||
int updated = jdProductUpdateService.assignGroup(target.getId(), target.getCompanyId(),
|
int updated = jdProductUpdateService.assignGroup(target.getId(), target.getCompanyId(),
|
||||||
body.getIds(), body.getGroupId(), operator.id());
|
body.getIds(), body.getGroupId(), operator.id());
|
||||||
// 管理端写动作必须留痕:谁、把多少行归到哪个组的哪个分类(null=移出分类)。
|
// 管理端写动作必须留痕:谁、把多少行归到哪个组的哪个分类(null=移出分类)。
|
||||||
@@ -316,7 +297,6 @@ public class AdminJdProductController {
|
|||||||
@Valid @RequestBody JdProductBatchDeleteRequest body,
|
@Valid @RequestBody JdProductBatchDeleteRequest body,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdProductWrite(request);
|
RequestOperator operator = requireJdProductWrite(request);
|
||||||
jdProductQueryService.assertRowsInCompany(body.getIds(), dataReadScope.writeCompanyId(operator.user()));
|
|
||||||
JdProductDeleteVo vo = jdProductDeleteService.delete(body.getIds());
|
JdProductDeleteVo vo = jdProductDeleteService.delete(body.getIds());
|
||||||
log.info("[jd-product] 批量删除商品 operatorId={} requested={} deleted={} objectsDeleted={} kept={}",
|
log.info("[jd-product] 批量删除商品 operatorId={} requested={} deleted={} objectsDeleted={} kept={}",
|
||||||
operator.id(), body.getIds().size(), vo.getDeleted(),
|
operator.id(), body.getIds().size(), vo.getDeleted(),
|
||||||
|
|||||||
+2
-6
@@ -72,8 +72,6 @@ public class AdminJdProductGroupController {
|
|||||||
private final JdCategoryScopeService jdCategoryScopeService;
|
private final JdCategoryScopeService jdCategoryScopeService;
|
||||||
private final AdminAuthSupport adminAuthSupport;
|
private final AdminAuthSupport adminAuthSupport;
|
||||||
private final PermissionMenuService permissionMenuService;
|
private final PermissionMenuService permissionMenuService;
|
||||||
/** 店铺候选的公司隔离出口(2026-11-23,与 AdminJdProductController 同一出口)。 */
|
|
||||||
private final com.nanri.aiimage.common.service.DataReadScope dataReadScope;
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Operation(summary = "分类列表(含分类下商品数)", description = "按「当前分组」返回分类,"
|
@Operation(summary = "分类列表(含分类下商品数)", description = "按「当前分组」返回分类,"
|
||||||
@@ -223,7 +221,7 @@ public class AdminJdProductGroupController {
|
|||||||
@GetMapping("/shops/available")
|
@GetMapping("/shops/available")
|
||||||
@Operation(summary = "可添加的店铺候选", description = "biz_jd_product.shop_name DISTINCT +"
|
@Operation(summary = "可添加的店铺候选", description = "biz_jd_product.shop_name DISTINCT +"
|
||||||
+ " 关键词包含匹配 + 排除指定分类已有名单(exclude_category_id);limit ≤ 200。"
|
+ " 关键词包含匹配 + 排除指定分类已有名单(exclude_category_id);limit ≤ 200。"
|
||||||
+ "2026-11-23 起按公司隔离:非平台超管只出本公司商品行的店铺名(公司之间不互看)。")
|
+ "2026-11-26 起与商品行同口径全平台去重(采集池共享,2026-11-23 的按公司隔离撤销)。")
|
||||||
public ApiResponse<List<String>> availableShops(
|
public ApiResponse<List<String>> availableShops(
|
||||||
@Parameter(description = "关键词(店铺名包含匹配)")
|
@Parameter(description = "关键词(店铺名包含匹配)")
|
||||||
@RequestParam(name = "keyword", required = false) String keyword,
|
@RequestParam(name = "keyword", required = false) String keyword,
|
||||||
@@ -237,9 +235,7 @@ public class AdminJdProductGroupController {
|
|||||||
if (excludeCategoryId != null && excludeCategoryId > 0) {
|
if (excludeCategoryId != null && excludeCategoryId > 0) {
|
||||||
requireReadableCategory(scope, jdProductGroupService.requireCategory(excludeCategoryId).getOwnerGroupId());
|
requireReadableCategory(scope, jdProductGroupService.requireCategory(excludeCategoryId).getOwnerGroupId());
|
||||||
}
|
}
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(operator.user(), null);
|
return ApiResponse.success(jdGroupShopService.availableShops(keyword, excludeCategoryId, limit));
|
||||||
return ApiResponse.success(jdGroupShopService.availableShops(keyword, excludeCategoryId, limit,
|
|
||||||
scopedCompanyId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 名单读闸:分类必须在本账号可见组内(同组普通号能看名单,越组 403)。 */
|
/** 名单读闸:分类必须在本账号可见组内(同组普通号能看名单,越组 403)。 */
|
||||||
|
|||||||
+5
-9
@@ -73,18 +73,14 @@ public class JdCollectController {
|
|||||||
@GetMapping("/categories")
|
@GetMapping("/categories")
|
||||||
@Operation(summary = "采集类目下拉数据源", description = "建单页类目多选面板的选项集:已落库行"
|
@Operation(summary = "采集类目下拉数据源", description = "建单页类目多选面板的选项集:已落库行"
|
||||||
+ " DISTINCT 的 category_path(京麦末级类目名)+ 行数,按类目名排序。与后管京东数据库"
|
+ " DISTINCT 的 category_path(京麦末级类目名)+ 行数,按类目名排序。与后管京东数据库"
|
||||||
+ "同一条 SQL(JdProductQueryService.categories)。<b>2026-11-23 起按公司隔离</b>:"
|
+ "同一条 SQL(JdProductQueryService.categories)。<b>2026-11-26 起全平台共享</b>:"
|
||||||
+ "只出本账号所属公司采集的行(公司与公司之间不互看);解析不出公司时回空集,不给全平台。"
|
+ "商品行是大家一起采集的共享池(客户口径「大家一起采集」),类目下拉是筛选词表、"
|
||||||
|
+ "不含任何账号数据,故不再按公司收窄(2026-11-23 的公司隔离撤销)。"
|
||||||
+ "边界:从未采集过的店铺/新类目不在集内(先全店采一次即有),页面选项空态不阻塞建单。")
|
+ "边界:从未采集过的店铺/新类目不在集内(先全店采一次即有),页面选项空态不阻塞建单。")
|
||||||
public ApiResponse<List<JdProductCategoryVo>> categories(HttpServletRequest httpRequest) {
|
public ApiResponse<List<JdProductCategoryVo>> categories(HttpServletRequest httpRequest) {
|
||||||
// 登录用户即可读:解析不出会话身份就 401(fail-closed,与建单同口径)。
|
// 登录用户即可读:解析不出会话身份就 401(fail-closed,与建单同口径)。
|
||||||
Long userId = adminAuthSupport.requireSessionOwnerUserId(httpRequest, null);
|
adminAuthSupport.requireSessionOwnerUserId(httpRequest, null);
|
||||||
Long companyId = jdCategoryScopeService.resolveByUserId(userId).companyId();
|
return ApiResponse.success(jdProductQueryService.categories());
|
||||||
if (companyId == null || companyId <= 0) {
|
|
||||||
// 公司读不出=看不到任何公司行;回空集而不是把全平台类目下发(隔离优先)。
|
|
||||||
return ApiResponse.success(List.of());
|
|
||||||
}
|
|
||||||
return ApiResponse.success(jdProductQueryService.categories(companyId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/groups")
|
@GetMapping("/groups")
|
||||||
|
|||||||
+5
-3
@@ -196,13 +196,15 @@ public class JdPublishController {
|
|||||||
// 形状照 JdCollectController 面板段同族:dashboard/history/delete 走 resolve,
|
// 形状照 JdCollectController 面板段同族:dashboard/history/delete 走 resolve,
|
||||||
// progressBatch 走 requireOwnershipUserId+filterOwnedTaskIds;products 按会话身份
|
// progressBatch 走 requireOwnershipUserId+filterOwnedTaskIds;products 按会话身份
|
||||||
// 解析可见数据权限分组、回归属行(2026-11-25 口径改:与分类下拉/徽标同源,同组同事
|
// 解析可见数据权限分组、回归属行(2026-11-25 口径改:与分类下拉/徽标同源,同组同事
|
||||||
// 采集的商品也能上架;跨公司/跨组看不到——见 JdProductQueryService#pageInScope)。
|
// 采集的商品也能上架;2026-11-26 起不再按公司收窄——商品行是全平台共享采集池,
|
||||||
|
// 只要归进了我可见的分组就能上架,见 JdProductQueryService#pageInScope)。
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
@GetMapping("/products")
|
@GetMapping("/products")
|
||||||
@Operation(summary = "用户端选品分页(可见分类作用域)", description = "「商品上架」页选品列表:回归当前"
|
@Operation(summary = "用户端选品分页(可见分类作用域)", description = "「商品上架」页选品列表:回归当前"
|
||||||
+ "账号<b>可见数据权限分组</b>下的分类归属商品行(与分类下拉/徽标同源同口径,2026-11-25 "
|
+ "账号<b>可见数据权限分组</b>下的分类归属商品行(与分类下拉/徽标同源同口径,2026-11-25 "
|
||||||
+ "口径改:同组同事采集的商品也能由你上架;跨公司、跨组一律看不到),可按自定义分类过滤"
|
+ "口径改:同组同事采集的商品也能由你上架;2026-11-26 起跨公司不再拦——商品行是全平台"
|
||||||
|
+ "共享采集池,分类只是各组自己那条归属行,不会让别人的数据变少),可按自定义分类过滤"
|
||||||
+ "(分类与可见组合成同一条 V203 归属表 EXISTS,SQL 侧下推)。")
|
+ "(分类与可见组合成同一条 V203 归属表 EXISTS,SQL 侧下推)。")
|
||||||
public ApiResponse<JdProductPageVo> products(
|
public ApiResponse<JdProductPageVo> products(
|
||||||
@Parameter(description = "自定义分类 id(不传=全部可见分类下商品)")
|
@Parameter(description = "自定义分类 id(不传=全部可见分类下商品)")
|
||||||
@@ -216,7 +218,7 @@ public class JdPublishController {
|
|||||||
publishPermissionSupport.assertCanPublish(userId);
|
publishPermissionSupport.assertCanPublish(userId);
|
||||||
JdCategoryScopeService.JdCategoryScope scope = jdCategoryScopeService.resolveByUserId(userId);
|
JdCategoryScopeService.JdCategoryScope scope = jdCategoryScopeService.resolveByUserId(userId);
|
||||||
return ApiResponse.success(jdProductQueryService.pageInScope(scope.visibleGroupIds(),
|
return ApiResponse.success(jdProductQueryService.pageInScope(scope.visibleGroupIds(),
|
||||||
scope.companyId(), categoryId, page, pageSize));
|
categoryId, page, pageSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
|
|||||||
+12
-17
@@ -62,15 +62,15 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
|||||||
* {@code classified}+{@code ownerGroupId}(2026-11-17 用户口径「加个已分类和未分类的筛选」):
|
* {@code classified}+{@code ownerGroupId}(2026-11-17 用户口径「加个已分类和未分类的筛选」):
|
||||||
* 按 V203 归属表 EXISTS/NOT EXISTS 快筛分类状态,NULL=不过滤;与 11-16 撤掉的旧
|
* 按 V203 归属表 EXISTS/NOT EXISTS 快筛分类状态,NULL=不过滤;与 11-16 撤掉的旧
|
||||||
* grouped/ungrouped(读已停用的 biz_jd_product.group_id 列)不是一回事。
|
* grouped/ungrouped(读已停用的 biz_jd_product.group_id 列)不是一回事。
|
||||||
* {@code companyId}(2026-11-23 客户口径「公司与公司之间不能互看」):行级公司谓词
|
* <b>可见口径(2026-11-26 客户口径「采集的数据可以重复被操作分类,大家一起采集,但分类后的
|
||||||
* {@code p.company_id = #{companyId}},由控制器经 {@code DataReadScope#readCompanyIdOrOwn}
|
* 数据就自己看,所以会有数据副本」)</b>:商品行<b>全平台共享</b>——读侧不设公司谓词,
|
||||||
* 算好传入——非平台超管恒为本公司,平台超管不带公司参数时为 {@code null}(=不筛)。
|
* 任何公司、任何组的账号都看到同一份采集数据(2026-11-23 的按公司隔离撤销)。
|
||||||
* {@code visibleGroupIds}(2026-11-25 客户实况「分类里有 3 个商品、选品列表 0 条」):
|
* 「副本」落在 V203 归属行上而非物理行:同一商品可以被多个组各自分类,每组一条
|
||||||
* 用户端「商品上架」的选品作用域=<b>当前账号可见的数据权限分组</b>下的分类归属行
|
* {@code biz_jd_product_group_assign(owner_group_id)} 行,分类列/分类筛选各看各的;
|
||||||
* (V203 {@code biz_jd_product_group_assign.owner_group_id IN (...)},与分类下拉同一份
|
* 别组分过类的商品在本组视角仍是「未分类」,可以再分一次。
|
||||||
* {@code JdCategoryScope#visibleGroupIds})——与分类徽标「N 个商品」同口径。非空时与
|
* {@code visibleGroupIds} 只服务用户端「商品上架」选品(V203 归属行作用域):非空时与
|
||||||
* {@code groupId} 合成<b>同一条</b> EXISTS(分类与可见组必须落在同一归属行,不拿别组
|
* {@code groupId} 合成<b>同一条</b> EXISTS(分类与可见组必须落在同一归属行,不拿别组
|
||||||
* 分类凑数);{@code null}/空=该面不过滤(后管只读页维持原口径不变)。
|
* 分类凑数);{@code null}=不设可见谓词(后管京东数据库:全平台共享行集)。
|
||||||
*/
|
*/
|
||||||
long countProducts(@Param("keyword") String keyword,
|
long countProducts(@Param("keyword") String keyword,
|
||||||
@Param("productCode") String productCode,
|
@Param("productCode") String productCode,
|
||||||
@@ -84,7 +84,6 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
|||||||
@Param("syncedTo") LocalDateTime syncedTo,
|
@Param("syncedTo") LocalDateTime syncedTo,
|
||||||
@Param("classified") Boolean classified,
|
@Param("classified") Boolean classified,
|
||||||
@Param("ownerGroupId") Long ownerGroupId,
|
@Param("ownerGroupId") Long ownerGroupId,
|
||||||
@Param("companyId") Long companyId,
|
|
||||||
@Param("visibleGroupIds") List<Long> visibleGroupIds);
|
@Param("visibleGroupIds") List<Long> visibleGroupIds);
|
||||||
|
|
||||||
// 2026-11-25 口径改造:旧「商品上架配额计数 countByUserIds(按 biz_jd_product 行数)」已删——
|
// 2026-11-25 口径改造:旧「商品上架配额计数 countByUserIds(按 biz_jd_product 行数)」已删——
|
||||||
@@ -126,7 +125,6 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
|||||||
@Param("syncedTo") LocalDateTime syncedTo,
|
@Param("syncedTo") LocalDateTime syncedTo,
|
||||||
@Param("classified") Boolean classified,
|
@Param("classified") Boolean classified,
|
||||||
@Param("ownerGroupId") Long ownerGroupId,
|
@Param("ownerGroupId") Long ownerGroupId,
|
||||||
@Param("companyId") Long companyId,
|
|
||||||
@Param("visibleGroupIds") List<Long> visibleGroupIds,
|
@Param("visibleGroupIds") List<Long> visibleGroupIds,
|
||||||
@Param("offset") long offset,
|
@Param("offset") long offset,
|
||||||
@Param("limit") int limit);
|
@Param("limit") int limit);
|
||||||
@@ -135,19 +133,16 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
|||||||
* 店铺名单「可添加候选」(v1.7,添加店铺弹窗源):{@code biz_jd_product.shop_name}
|
* 店铺名单「可添加候选」(v1.7,添加店铺弹窗源):{@code biz_jd_product.shop_name}
|
||||||
* DISTINCT + like + 排除指定分类已有名单(NOT IN 下推,铁律 20),按店铺名升序。
|
* DISTINCT + like + 排除指定分类已有名单(NOT IN 下推,铁律 20),按店铺名升序。
|
||||||
* {@code limit} 必须是服务侧钳制后的值(≤ {@code JdGroupShopService.MAX_AVAILABLE_LIMIT}),
|
* {@code limit} 必须是服务侧钳制后的值(≤ {@code JdGroupShopService.MAX_AVAILABLE_LIMIT}),
|
||||||
* mapper 不做第二次换算。{@code companyId}(2026-11-23):候选店铺也只能来自本公司
|
* mapper 不做第二次换算。候选店铺与商品行同口径:全平台共享(2026-11-26 撤销公司隔离)。
|
||||||
* 商品行,否则 A 公司能在候选里看到 B 公司的店铺名(口径见 {@link #countProducts})。
|
|
||||||
*/
|
*/
|
||||||
List<String> selectDistinctShopNames(@Param("keyword") String keyword,
|
List<String> selectDistinctShopNames(@Param("keyword") String keyword,
|
||||||
@Param("excludeNames") List<String> excludeNames,
|
@Param("excludeNames") List<String> excludeNames,
|
||||||
@Param("limit") int limit,
|
@Param("limit") int limit);
|
||||||
@Param("companyId") Long companyId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
|
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
|
||||||
* 已落库行的 DISTINCT {@code category_path}(=京麦末级类目名)+ 行数。
|
* 已落库行的 DISTINCT {@code category_path}(=京麦末级类目名)+ 行数。
|
||||||
* 2026-11-23 起按行公司隔离({@code companyId} 由 {@code DataReadScope#readCompanyIdOrOwn}
|
* 2026-11-26 起与列表同一口径:全平台共享去重(2026-11-23 的按公司隔离撤销)。
|
||||||
* 算好;平台超管不带公司参数时为 {@code null}=全平台去重)。
|
|
||||||
*/
|
*/
|
||||||
List<JdProductCategoryVo> selectProductCategories(@Param("companyId") Long companyId);
|
List<JdProductCategoryVo> selectProductCategories();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -7,9 +7,9 @@ import lombok.Data;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后管批量删除京东商品的请求体(v1.4 补口)。公司隔离不走 body——`company_id` 是请求参数,
|
* 后管批量删除京东商品的请求体(v1.4 补口)。2026-11-26 起商品行是全平台共享采集池,
|
||||||
* 由 `DataReadScope#readCompanyIdOrOwn` 统一收口(同本模块全部分页/导出/分组端点),
|
* 请求体只带 id 清单、不带公司维参数(2026-11-23 的公司隔离整批撤销,写侧由端点级
|
||||||
* 免得 body 里再出现一次"公司不传就当全公司"的假 tab 形状。
|
* 超管档 {@code requireJdProductWrite} 兜住)。
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "批量删除京东商品请求")
|
@Schema(description = "批量删除京东商品请求")
|
||||||
|
|||||||
+2
-2
@@ -14,8 +14,8 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* <p>主字段全量提交(保存即按本请求体覆写这几个列);三个可选块缺省=不动那一面:
|
* <p>主字段全量提交(保存即按本请求体覆写这几个列);三个可选块缺省=不动那一面:
|
||||||
* {@code attrGroups} 缺省不动属性、{@code skus} 缺省不动 SKU 价格库存、{@code deleteImageIds}
|
* {@code attrGroups} 缺省不动属性、{@code skus} 缺省不动 SKU 价格库存、{@code deleteImageIds}
|
||||||
* 缺省不删图。公司隔离不走 body——`company_id` 是请求参数,由
|
* 缺省不删图。2026-11-26 起商品行是全平台共享采集池,请求体里不带任何公司维参数
|
||||||
* {@code DataReadScope#readCompanyIdOrOwn} 统一收口(同本模块全部端点)。</p>
|
* (2026-11-23 的公司隔离整批撤销,写侧只由端点级超管档 {@code requireJdProductWrite} 兜住)。</p>
|
||||||
*
|
*
|
||||||
* <p>编辑保存后商品行 {@code manual_locked=1}(V199 人工编辑锁):采集回传的
|
* <p>编辑保存后商品行 {@code manual_locked=1}(V199 人工编辑锁):采集回传的
|
||||||
* upsert / 图片与 SKU 登记 / 覆盖清理对该行全部跳过,人工值不被京麦采集覆盖。</p>
|
* upsert / 图片与 SKU 登记 / 覆盖清理对该行全部跳过,人工值不被京麦采集覆盖。</p>
|
||||||
|
|||||||
+4
-6
@@ -165,16 +165,14 @@ public class JdGroupShopService {
|
|||||||
/**
|
/**
|
||||||
* 可添加候选(「添加店铺」弹窗源):{@code biz_jd_product.shop_name} DISTINCT +
|
* 可添加候选(「添加店铺」弹窗源):{@code biz_jd_product.shop_name} DISTINCT +
|
||||||
* like + 排除指定分类已有名单。SQL 侧下推(铁律 20 同形),limit 服务侧钳制。
|
* like + 排除指定分类已有名单。SQL 侧下推(铁律 20 同形),limit 服务侧钳制。
|
||||||
* {@code scopedCompanyId}(2026-11-23):候选同样按公司隔离——非平台超管为本公司 id
|
* 2026-11-26:与商品行同口径全平台去重(2026-11-23 的按公司隔离撤销——采集池共享,
|
||||||
* (经 {@code DataReadScope#readCompanyIdOrOwn} 算好),平台超管为空=全平台去重。
|
* 候选店铺也不该被公司切开)。
|
||||||
*/
|
*/
|
||||||
public List<String> availableShops(String keyword, Long excludeCategoryId, Integer limit,
|
public List<String> availableShops(String keyword, Long excludeCategoryId, Integer limit) {
|
||||||
Long scopedCompanyId) {
|
|
||||||
int safeLimit = limit == null || limit < 1 ? MAX_AVAILABLE_LIMIT : Math.min(limit, MAX_AVAILABLE_LIMIT);
|
int safeLimit = limit == null || limit < 1 ? MAX_AVAILABLE_LIMIT : Math.min(limit, MAX_AVAILABLE_LIMIT);
|
||||||
List<String> excludeNames = excludeCategoryId == null || excludeCategoryId <= 0
|
List<String> excludeNames = excludeCategoryId == null || excludeCategoryId <= 0
|
||||||
? List.of() : listShops(excludeCategoryId);
|
? List.of() : listShops(excludeCategoryId);
|
||||||
return jdProductMapper.selectDistinctShopNames(trimToNull(keyword), excludeNames, safeLimit,
|
return jdProductMapper.selectDistinctShopNames(trimToNull(keyword), excludeNames, safeLimit);
|
||||||
scopedCompanyId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- 业务规则
|
// ---------------------------------------------------------------- 业务规则
|
||||||
|
|||||||
+42
-59
@@ -39,10 +39,12 @@ import java.util.Map;
|
|||||||
* 先例:{@code page} 上限 {@link #MAX_PAGE}、{@code page_size} 上限 {@link #MAX_PAGE_SIZE},
|
* 先例:{@code page} 上限 {@link #MAX_PAGE}、{@code page_size} 上限 {@link #MAX_PAGE_SIZE},
|
||||||
* {@code page=Long.MAX_VALUE} 不会把乘积顶成负数生成 {@code LIMIT -N} 的 500 错。</p>
|
* {@code page=Long.MAX_VALUE} 不会把乘积顶成负数生成 {@code LIMIT -N} 的 500 错。</p>
|
||||||
*
|
*
|
||||||
* <p><b>公司口径(2026-11-16「删除掉公司 tab,参考品牌数据库」)</b>:读侧零公司维度——
|
* <p><b>公司口径(2026-11-16「删除掉公司 tab,参考品牌数据库」;2026-11-26 复核确认)</b>:
|
||||||
* 公司 tab 与 {@code superAdminScopedCompanyId} 谓词已随公共化收尾整批摘除,每个管理员
|
* 读侧零公司维度——公司 tab 与 {@code superAdminScopedCompanyId} 谓词已随公共化收尾整批
|
||||||
* (含站点超管)看到同一份全量公共库;行上的 {@code company_id} 列仍是"哪家公司客户端
|
* 摘除,每个管理员(含站点超管)看到同一份全量公共库;行上的 {@code company_id} 列仍是
|
||||||
* 同步的"来源标记,随详情下发但不构成可见性边界。详情本就按 id 直取。</p>
|
* "哪家公司客户端同步的"来源标记,随详情下发但不构成可见性边界。2026-11-23 曾按客户口径
|
||||||
|
* 加回按公司隔离,2026-11-26 客户重新定案「大家一起采集、分类后的数据各看各的(逻辑副本,
|
||||||
|
* 不复制商品行)」⇒ 公司隔离整批撤销,隔离只落在 V203 归属行上。</p>
|
||||||
*
|
*
|
||||||
* <p><b>详情 attr_json 解析(AC-7 未识别属性不丢弃)</b>:客户端实拍契约
|
* <p><b>详情 attr_json 解析(AC-7 未识别属性不丢弃)</b>:客户端实拍契约
|
||||||
* {@code {"tabs":[{"tab":"...","attrs":[{key,label,value}]}],"images":[...],"productCode":"..."}}——
|
* {@code {"tabs":[{"tab":"...","attrs":[{key,label,value}]}],"images":[...],"productCode":"..."}}——
|
||||||
@@ -103,16 +105,18 @@ public class JdProductQueryService {
|
|||||||
* 也必须是未分类」)。
|
* 也必须是未分类」)。
|
||||||
* 2026-11-16 撤掉的旧 ungrouped/grouped 两档读的是已停用的 biz_jd_product.group_id 列,
|
* 2026-11-16 撤掉的旧 ungrouped/grouped 两档读的是已停用的 biz_jd_product.group_id 列,
|
||||||
* 与本档不是一回事;独立「分类」筛选框的撤掉口径不变。
|
* 与本档不是一回事;独立「分类」筛选框的撤掉口径不变。
|
||||||
* <b>公司隔离(2026-11-23 客户口径「公司与公司之间不能互看」,推翻 11-16 公共库)</b>:
|
* <b>全平台共享(2026-11-26 客户口径「采集的数据可以重复被操作分类,大家一起采集,但
|
||||||
* {@code scopedCompanyId} 由控制器经 {@code DataReadScope#readCompanyIdOrOwn} 算好传入——
|
* 分类后的数据就自己看,所以会有数据副本」)</b>:读侧不设公司谓词——任何公司、任何组的
|
||||||
* 非平台超管恒为本公司,平台超管不带公司参数时为空(全平台)。谓词在 XML 的
|
* 账号都看到同一份采集池(2026-11-23 的「公司与公司不能互看」整批撤销)。
|
||||||
* {@code productConds} 里 SQL 侧下推(铁律 20)。</p>
|
* 「副本」落在 V203 归属行上:同一商品可被多个组各自分类,每组一条归属行,分类列
|
||||||
|
* ({@link #fillGroupNames})与分类筛选({@code groupId}/{@code classified})都按
|
||||||
|
* 「当前分组」取,各看各的;别组分过类的商品在本组视角仍是「未分类」,可以再分一次。
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public JdProductPageVo page(Long page, Long pageSize,
|
public JdProductPageVo page(Long page, Long pageSize,
|
||||||
String keyword, String productCode, String titleKeyword, List<String> categories,
|
String keyword, String productCode, String titleKeyword, List<String> categories,
|
||||||
Long groupId, String shopName, BigDecimal minPrice, BigDecimal maxPrice,
|
Long groupId, String shopName, BigDecimal minPrice, BigDecimal maxPrice,
|
||||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified, Long ownerGroupId,
|
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified, Long ownerGroupId) {
|
||||||
Long scopedCompanyId) {
|
|
||||||
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
|
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
|
||||||
throw new BusinessException("开始时间不能晚于结束时间");
|
throw new BusinessException("开始时间不能晚于结束时间");
|
||||||
}
|
}
|
||||||
@@ -128,13 +132,13 @@ public class JdProductQueryService {
|
|||||||
filter.titleKeyword(), filter.categories(), filter.groupId(), filter.shopName(),
|
filter.titleKeyword(), filter.categories(), filter.groupId(), filter.shopName(),
|
||||||
filter.minPrice(), filter.maxPrice(),
|
filter.minPrice(), filter.maxPrice(),
|
||||||
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
|
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
|
||||||
scopedCompanyId, null);
|
null);
|
||||||
List<JdProductEntity> rows = total <= 0 ? List.of()
|
List<JdProductEntity> rows = total <= 0 ? List.of()
|
||||||
: jdProductMapper.selectProductPage(filter.keyword(),
|
: jdProductMapper.selectProductPage(filter.keyword(),
|
||||||
filter.productCode(), filter.titleKeyword(), filter.categories(),
|
filter.productCode(), filter.titleKeyword(), filter.categories(),
|
||||||
filter.groupId(), filter.shopName(), filter.minPrice(), filter.maxPrice(),
|
filter.groupId(), filter.shopName(), filter.minPrice(), filter.maxPrice(),
|
||||||
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
|
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
|
||||||
scopedCompanyId, null,
|
null,
|
||||||
(safePage - 1) * safeSize, (int) safeSize);
|
(safePage - 1) * safeSize, (int) safeSize);
|
||||||
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
|
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
|
||||||
fillGroupNames(items, ownerGroupId);
|
fillGroupNames(items, ownerGroupId);
|
||||||
@@ -165,8 +169,13 @@ public class JdProductQueryService {
|
|||||||
*
|
*
|
||||||
* <p>可见分组为空=看不到任何分类归属行,直接回空页不查主表(防 {@code IN ()});
|
* <p>可见分组为空=看不到任何分类归属行,直接回空页不查主表(防 {@code IN ()});
|
||||||
* 页码/页宽钳制与 {@link #page} 同出口(MAX_PAGE/MAX_PAGE_SIZE,铁律 15)。</p>
|
* 页码/页宽钳制与 {@link #page} 同出口(MAX_PAGE/MAX_PAGE_SIZE,铁律 15)。</p>
|
||||||
|
*
|
||||||
|
* <p><b>2026-11-26 起不再按公司收窄</b>:后管京东数据库的商品行是全平台共享的采集池
|
||||||
|
* (「大家一起采集」),分类归属按组各看各的即可;用户端选品只认<b>可见分组下的归属行</b>
|
||||||
|
* (选品从分类进,未分类商品不进选品池),与公司维无关——同一商品被别家公司客户端采、
|
||||||
|
* 只要归进了我可见的分组,我照样能上架。</p>
|
||||||
*/
|
*/
|
||||||
public JdProductPageVo pageInScope(List<Long> visibleGroupIds, Long companyId,
|
public JdProductPageVo pageInScope(List<Long> visibleGroupIds,
|
||||||
Long categoryId, Long page, Long pageSize) {
|
Long categoryId, Long page, Long pageSize) {
|
||||||
long safePage = page == null || page < 1 ? 1 : Math.min(page, MAX_PAGE);
|
long safePage = page == null || page < 1 ? 1 : Math.min(page, MAX_PAGE);
|
||||||
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
|
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
|
||||||
@@ -182,11 +191,11 @@ public class JdProductQueryService {
|
|||||||
long safeCategoryId = categoryId != null && categoryId > 0 ? categoryId : 0L;
|
long safeCategoryId = categoryId != null && categoryId > 0 ? categoryId : 0L;
|
||||||
long total = jdProductMapper.countProducts(null, null, null, null,
|
long total = jdProductMapper.countProducts(null, null, null, null,
|
||||||
safeCategoryId, null, null, null, null, null, null, null,
|
safeCategoryId, null, null, null, null, null, null, null,
|
||||||
companyId, groupIds);
|
groupIds);
|
||||||
List<JdProductListItemVo> items = total <= 0 ? List.of()
|
List<JdProductListItemVo> items = total <= 0 ? List.of()
|
||||||
: jdProductMapper.selectProductPage(null, null, null, null,
|
: jdProductMapper.selectProductPage(null, null, null, null,
|
||||||
safeCategoryId, null, null, null, null, null, null, null,
|
safeCategoryId, null, null, null, null, null, null, null,
|
||||||
companyId, groupIds,
|
groupIds,
|
||||||
(safePage - 1) * safeSize, (int) safeSize)
|
(safePage - 1) * safeSize, (int) safeSize)
|
||||||
.stream().map(this::toListItem).toList();
|
.stream().map(this::toListItem).toList();
|
||||||
JdProductPageVo vo = new JdProductPageVo();
|
JdProductPageVo vo = new JdProductPageVo();
|
||||||
@@ -209,12 +218,11 @@ public class JdProductQueryService {
|
|||||||
/**
|
/**
|
||||||
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
|
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
|
||||||
* 已落库行 distinct 的 {@code category_path}(=京麦末级类目名,契约 §2.3 E3)
|
* 已落库行 distinct 的 {@code category_path}(=京麦末级类目名,契约 §2.3 E3)
|
||||||
* + 各自行数,按类目名排序。2026-11-23 起与列表同口径按行公司隔离
|
* + 各自行数,按类目名排序。2026-11-26 起与列表同口径全平台去重
|
||||||
* ({@code scopedCompanyId} 由控制器经 {@code DataReadScope#readCompanyIdOrOwn} 算好;
|
* (商品行是共享采集池,2026-11-23 的按公司隔离撤销)。
|
||||||
* 平台超管不带公司参数时为空=全平台去重,与用户端采集建单侧同一出口)。
|
|
||||||
*/
|
*/
|
||||||
public List<JdProductCategoryVo> categories(Long scopedCompanyId) {
|
public List<JdProductCategoryVo> categories() {
|
||||||
return jdProductMapper.selectProductCategories(scopedCompanyId);
|
return jdProductMapper.selectProductCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,10 +235,10 @@ public class JdProductQueryService {
|
|||||||
*
|
*
|
||||||
* <p>上限 {@link #MAX_EXPORT_IDS}(1000):超限整批拒绝不静默截断——用户以为导全了、
|
* <p>上限 {@link #MAX_EXPORT_IDS}(1000):超限整批拒绝不静默截断——用户以为导全了、
|
||||||
* 实际少导是交付事故;空勾选同样拒绝(前端按钮置灰是第一道,这里是兜底)。
|
* 实际少导是交付事故;空勾选同样拒绝(前端按钮置灰是第一道,这里是兜底)。
|
||||||
* 公司隔离(2026-11-23):勾选 id 里只要有一行不属于 {@code scopedCompanyId}(非平台超管
|
* 2026-11-26 起导出与列表同口径全平台共享:商品行是共享采集池,勾得到就能导
|
||||||
* 恒为本公司)就整批拒绝——导出是读行为,但静默少导/多导都是交付事故,不做部分导出。</p>
|
* (2026-11-23 的按公司拦截撤销)。</p>
|
||||||
*/
|
*/
|
||||||
public byte[] exportCsv(List<Long> ids, Long scopedCompanyId) {
|
public byte[] exportCsv(List<Long> ids) {
|
||||||
if (ids == null || ids.isEmpty()) {
|
if (ids == null || ids.isEmpty()) {
|
||||||
throw new BusinessException("请先勾选要导出的商品");
|
throw new BusinessException("请先勾选要导出的商品");
|
||||||
}
|
}
|
||||||
@@ -242,10 +250,6 @@ public class JdProductQueryService {
|
|||||||
throw new BusinessException("单次最多导出 " + MAX_EXPORT_IDS + " 个商品,请缩小勾选范围");
|
throw new BusinessException("单次最多导出 " + MAX_EXPORT_IDS + " 个商品,请缩小勾选范围");
|
||||||
}
|
}
|
||||||
List<JdProductEntity> rows = new ArrayList<>(jdProductMapper.selectBatchIds(uniqueIds));
|
List<JdProductEntity> rows = new ArrayList<>(jdProductMapper.selectBatchIds(uniqueIds));
|
||||||
if (scopedCompanyId != null && scopedCompanyId > 0
|
|
||||||
&& rows.stream().anyMatch(row -> !scopedCompanyId.equals(row.getCompanyId()))) {
|
|
||||||
throw new BusinessException(403, "无权导出其他公司的京东商品");
|
|
||||||
}
|
|
||||||
rows.sort(java.util.Comparator.comparing(JdProductEntity::getId,
|
rows.sort(java.util.Comparator.comparing(JdProductEntity::getId,
|
||||||
java.util.Comparator.nullsLast(java.util.Comparator.naturalOrder())));
|
java.util.Comparator.nullsLast(java.util.Comparator.naturalOrder())));
|
||||||
StringBuilder csv = new StringBuilder();
|
StringBuilder csv = new StringBuilder();
|
||||||
@@ -288,17 +292,17 @@ public class JdProductQueryService {
|
|||||||
/**
|
/**
|
||||||
* 商品详情(主字段全量 + attr_json 解析 + 已转存图片)。
|
* 商品详情(主字段全量 + attr_json 解析 + 已转存图片)。
|
||||||
*
|
*
|
||||||
* <p><b>公司隔离(2026-11-23 客户口径「公司与公司之间不能互看」)</b>:按 id 直取后
|
* <p><b>全平台共享(2026-11-26)</b>:按 id 直取、不再比公司——商品行是共享采集池,
|
||||||
* 再比 {@code scopedCompanyId}(非平台超管恒为本公司;平台超管为空=不限)。别公司的行
|
* 列表里看得见的就能点开(2026-11-23 的「别公司按商品不存在拒绝」撤销)。
|
||||||
* 按<b>「商品不存在」</b>拒绝——不返回 403,避免泄露行是否存在。attr_json 非契约形状/
|
* attr_json 非契约形状/解析异常时不抛 500:落空 {@code attrGroups}、原文进
|
||||||
* 解析异常时不抛 500:落空 {@code attrGroups}、原文进 {@code attrJsonRaw} 兜底(AC-7)。</p>
|
* {@code attrJsonRaw} 兜底(AC-7)。</p>
|
||||||
*/
|
*/
|
||||||
public JdProductDetailVo detail(Long id, Long ownerGroupId, Long scopedCompanyId) {
|
public JdProductDetailVo detail(Long id, Long ownerGroupId) {
|
||||||
if (id == null || id <= 0) {
|
if (id == null || id <= 0) {
|
||||||
throw new BusinessException("商品不存在");
|
throw new BusinessException("商品不存在");
|
||||||
}
|
}
|
||||||
JdProductEntity row = jdProductMapper.selectById(id);
|
JdProductEntity row = jdProductMapper.selectById(id);
|
||||||
if (row == null || !inCompany(row, scopedCompanyId)) {
|
if (row == null) {
|
||||||
throw new BusinessException("商品不存在");
|
throw new BusinessException("商品不存在");
|
||||||
}
|
}
|
||||||
JdProductDetailVo vo = new JdProductDetailVo();
|
JdProductDetailVo vo = new JdProductDetailVo();
|
||||||
@@ -596,34 +600,13 @@ public class JdProductQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写侧行级公司闸(2026-11-23):请求里的 id 只要有一行不属于 {@code scopedCompanyId}
|
* 写侧行级公司闸已随 2026-11-26「全平台共享采集池」口径<b>整批撤销</b>
|
||||||
* (非平台超管恒为本公司;平台超管为空=不限)就整批拒绝。不存在的 id 交给下游
|
* ({@code assertRowsInCompany} / {@code inCompany} 一并删除):商品行是大家共享采集的,
|
||||||
* 「商品不存在」语义,这里只管跨公司。
|
* 能看见就能操作;越权由端点级的超管档写闸({@code requireJdProductWrite}:仅平台超管+
|
||||||
|
* 公司超管)兜住,不再按行上的 {@code company_id} 收窄。
|
||||||
*
|
*
|
||||||
* <p>读侧藏起来的行仍然能删=静默删除,不是隔离;编辑/上传图片/删除/批量删除/批量归类
|
* <p>不存在的 id 仍由下游「商品不存在」语义处理。</p>
|
||||||
* 五个写口都必须在动手之前过这一道。</p>
|
|
||||||
*/
|
*/
|
||||||
public void assertRowsInCompany(List<Long> ids, Long scopedCompanyId) {
|
|
||||||
if (scopedCompanyId == null || scopedCompanyId <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<Long> uniqueIds = ids == null ? List.of()
|
|
||||||
: ids.stream().filter(id -> id != null && id > 0).distinct().toList();
|
|
||||||
if (uniqueIds.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (JdProductEntity row : jdProductMapper.selectBatchIds(uniqueIds)) {
|
|
||||||
if (!inCompany(row, scopedCompanyId)) {
|
|
||||||
throw new BusinessException(403, "无权操作其他公司的京东商品");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 行归属是否落在作用域公司内:作用域为空(平台超管)=不限,否则要求行上有同一公司值。 */
|
|
||||||
private static boolean inCompany(JdProductEntity row, Long scopedCompanyId) {
|
|
||||||
return scopedCompanyId == null || scopedCompanyId <= 0
|
|
||||||
|| (row.getCompanyId() != null && scopedCompanyId.equals(row.getCompanyId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String trimToNull(String value) {
|
private static String trimToNull(String value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|||||||
@@ -114,8 +114,10 @@
|
|||||||
group_id 过滤【V203 起按组隔离】:分类归属在 biz_jd_product_group_assign 的
|
group_id 过滤【V203 起按组隔离】:分类归属在 biz_jd_product_group_assign 的
|
||||||
(product_id, owner_group_id) 一行上,商品行自己的 group_id 列已停用(V201 清空),
|
(product_id, owner_group_id) 一行上,商品行自己的 group_id 列已停用(V201 清空),
|
||||||
故改 EXISTS 子查询;分类 id 自带归属组,不必再传 owner 维(行内谓词仍只这一处)。
|
故改 EXISTS 子查询;分类 id 自带归属组,不必再传 owner 维(行内谓词仍只这一处)。
|
||||||
公司维过滤随 2026-11-16「删除掉公司 tab,参考品牌数据库」撤掉(数据全平台公共;
|
<b>2026-11-26 客户口径</b>:「采集的数据可以重复被操作分类,大家一起采集,但分类后的
|
||||||
行 company_id 列仍是同步来源标记,不构成可见性边界)。
|
数据就自己看,所以会有数据副本」——商品行是全平台共享的采集池(2026-11-23 的按公司
|
||||||
|
隔离整批撤销),「副本」只体现在 V203 归属行上(同一商品多组各一条,各看各的分类),
|
||||||
|
不物理复制商品行。行 company_id 列仍是同步来源标记,不构成可见性边界。
|
||||||
sale_status 筛选随 2026-11-15 客户口径撤掉;店铺名过滤同日客户口径「店铺不需要」
|
sale_status 筛选随 2026-11-15 客户口径撤掉;店铺名过滤同日客户口径「店铺不需要」
|
||||||
同窗撤掉(前端筛选框与列下线;DB 列本身与详情/回传链不动)。
|
同窗撤掉(前端筛选框与列下线;DB 列本身与详情/回传链不动)。
|
||||||
全部走 #{} 占位符;offset/limit 必须是服务侧钳制后的值(铁律 15),mapper 不做第二次换算。 -->
|
全部走 #{} 占位符;offset/limit 必须是服务侧钳制后的值(铁律 15),mapper 不做第二次换算。 -->
|
||||||
@@ -192,12 +194,11 @@
|
|||||||
</if>
|
</if>
|
||||||
<if test="syncedFrom != null">AND p.synced_at >= #{syncedFrom}</if>
|
<if test="syncedFrom != null">AND p.synced_at >= #{syncedFrom}</if>
|
||||||
<if test="syncedTo != null">AND p.synced_at <= #{syncedTo}</if>
|
<if test="syncedTo != null">AND p.synced_at <= #{syncedTo}</if>
|
||||||
<!-- 公司隔离(2026-11-23 客户口径「公司与公司之间是不能互看的」,推翻 2026-11-16
|
<!-- 公司隔离(2026-11-23「公司与公司之间不能互看」)已于 2026-11-26 按客户口径撤销:
|
||||||
「公共库」定案):非平台超管钉本公司(controller 经 DataReadScope#readCompanyIdOrOwn
|
「采集的数据可以重复被操作分类,大家一起采集,但分类后的数据就自己看,所以会有
|
||||||
算好传入,非超管恒为本公司、请求带别家也不算);平台超管不带公司参数时为空=不筛。
|
数据副本」——商品行是全平台共享的采集池,读侧不设公司谓词;「副本」落在 V203 归属
|
||||||
谓词必须 SQL 侧下推(铁律 20),不得 Java 侧对已取页 filter。
|
行上(同一商品多组各一条),分类列/分类筛选各看各的。行上的 company_id 只剩
|
||||||
company_id 有值的行才可能被非超管看到——空值行只对平台超管可见(严格隔离)。 -->
|
「哪家公司客户端同步的」来源标记。 -->
|
||||||
<if test="companyId != null and companyId > 0">AND p.company_id = #{companyId}</if>
|
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<!-- 只读页总数(与 selectProductPage 同一过滤面)。 -->
|
<!-- 只读页总数(与 selectProductPage 同一过滤面)。 -->
|
||||||
@@ -226,13 +227,12 @@
|
|||||||
|
|
||||||
<!-- 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):已落库行
|
<!-- 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):已落库行
|
||||||
的 DISTINCT category_path(=京麦末级类目名,契约 §2.3 E3)+ 行数。
|
的 DISTINCT category_path(=京麦末级类目名,契约 §2.3 E3)+ 行数。
|
||||||
2026-11-23 起按行公司隔离(公司之间不能互看;平台超管不带公司参数时空=全平台去重)。
|
2026-11-26 起与列表同口径全平台去重(2026-11-23 的按公司隔离撤销:商品行是共享采集池)。
|
||||||
空类目行不进下拉。 -->
|
空类目行不进下拉。 -->
|
||||||
<select id="selectProductCategories" resultType="com.nanri.aiimage.modules.jd.model.vo.JdProductCategoryVo">
|
<select id="selectProductCategories" resultType="com.nanri.aiimage.modules.jd.model.vo.JdProductCategoryVo">
|
||||||
SELECT p.category_path AS name, COUNT(*) AS productCount
|
SELECT p.category_path AS name, COUNT(*) AS productCount
|
||||||
FROM biz_jd_product p
|
FROM biz_jd_product p
|
||||||
WHERE p.category_path IS NOT NULL AND p.category_path != ''
|
WHERE p.category_path IS NOT NULL AND p.category_path != ''
|
||||||
<if test="companyId != null and companyId > 0">AND p.company_id = #{companyId}</if>
|
|
||||||
GROUP BY p.category_path
|
GROUP BY p.category_path
|
||||||
ORDER BY p.category_path
|
ORDER BY p.category_path
|
||||||
</select>
|
</select>
|
||||||
@@ -240,12 +240,11 @@
|
|||||||
<!-- 店铺名单「可添加候选」(v1.7,添加店铺弹窗源):biz_jd_product.shop_name DISTINCT +
|
<!-- 店铺名单「可添加候选」(v1.7,添加店铺弹窗源):biz_jd_product.shop_name DISTINCT +
|
||||||
like + 排除指定分类已有名单(NOT IN 下推,铁律 20)。limit 是服务侧钳制后的值
|
like + 排除指定分类已有名单(NOT IN 下推,铁律 20)。limit 是服务侧钳制后的值
|
||||||
(≤ JdGroupShopService.MAX_AVAILABLE_LIMIT),mapper 不做第二次换算。
|
(≤ JdGroupShopService.MAX_AVAILABLE_LIMIT),mapper 不做第二次换算。
|
||||||
2026-11-23:候选店铺同样按公司隔离——A 公司不能在候选里看到 B 公司的店铺名。 -->
|
2026-11-26:候选店铺与商品行同口径全平台去重(公司隔离撤销)。 -->
|
||||||
<select id="selectDistinctShopNames" resultType="string">
|
<select id="selectDistinctShopNames" resultType="string">
|
||||||
SELECT DISTINCT p.shop_name
|
SELECT DISTINCT p.shop_name
|
||||||
FROM biz_jd_product p
|
FROM biz_jd_product p
|
||||||
WHERE p.shop_name IS NOT NULL AND p.shop_name != ''
|
WHERE p.shop_name IS NOT NULL AND p.shop_name != ''
|
||||||
<if test="companyId != null and companyId > 0">AND p.company_id = #{companyId}</if>
|
|
||||||
<if test="keyword != null and keyword != ''">AND p.shop_name LIKE CONCAT('%', #{keyword}, '%')</if>
|
<if test="keyword != null and keyword != ''">AND p.shop_name LIKE CONCAT('%', #{keyword}, '%')</if>
|
||||||
<if test="excludeNames != null and excludeNames.size() > 0">
|
<if test="excludeNames != null and excludeNames.size() > 0">
|
||||||
AND p.shop_name NOT IN
|
AND p.shop_name NOT IN
|
||||||
|
|||||||
+113
-157
@@ -97,15 +97,6 @@ class AdminJdProductControllerTest {
|
|||||||
private static final String COLUMN_KEY = "admin_jd_database";
|
private static final String COLUMN_KEY = "admin_jd_database";
|
||||||
private static final String ROUTE_PATH = "jd-center/database";
|
private static final String ROUTE_PATH = "jd-center/database";
|
||||||
|
|
||||||
/** 公司作用域桩:读/写都回 null(平台超管口径),让 controller 的 scopedCompanyId 走「不筛」分支。 */
|
|
||||||
private static com.nanri.aiimage.common.service.DataReadScope dataScopeMock() {
|
|
||||||
com.nanri.aiimage.common.service.DataReadScope scope =
|
|
||||||
mock(com.nanri.aiimage.common.service.DataReadScope.class);
|
|
||||||
when(scope.readCompanyIdOrOwn(any(), any())).thenReturn(null);
|
|
||||||
when(scope.writeCompanyId(any())).thenReturn(null);
|
|
||||||
return scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 用例里的「当前分组」:数据权限分组 10,归属公司 5。 */
|
/** 用例里的「当前分组」:数据权限分组 10,归属公司 5。 */
|
||||||
private static final long GROUP_ID = 10L;
|
private static final long GROUP_ID = 10L;
|
||||||
private static final long COMPANY_ID = 5L;
|
private static final long COMPANY_ID = 5L;
|
||||||
@@ -154,21 +145,25 @@ class AdminJdProductControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 读侧零公司维度_公司tab口径整批摘除() throws IOException {
|
void 读侧零公司维度_公司隔离与行级公司闸不得回流() throws IOException {
|
||||||
String source = stripComments(Files.readString(CONTROLLER));
|
String source = stripComments(Files.readString(CONTROLLER));
|
||||||
// 2026-11-23 客户口径「公司与公司之间是不能互看的」,推翻 2026-11-16「公共库」定案:
|
// 2026-11-26 客户口径「采集的数据可以重复被操作分类,大家一起采集,但分类后的数据就
|
||||||
// 读侧按行 company_id 隔离(非平台超管钉本公司),写侧再按行级公司闸兜住。
|
// 自己看,所以会有数据副本」「被分类后按组 id 绑定拷贝数据副本,原来的数据也要留着」:
|
||||||
assertTrue(source.contains("@RequestParam(name = \"company_id\""),
|
// 商品行是全平台共享采集池,读侧零公司维度;分类隔离只落 V203 归属行(owner_group_id)。
|
||||||
"company_id 请求参数必须在册(平台超管跨公司查看用;非超管传什么都不算)");
|
// 反向钉住:2026-11-23 加回的按公司隔离(company_id 参数 / readCompanyIdOrOwn /
|
||||||
assertTrue(source.contains("readCompanyIdOrOwn"),
|
// writeCompanyId / assertRowsInCompany)任何一处回流都判红。
|
||||||
"读侧必须经 DataReadScope#readCompanyIdOrOwn 算公司作用域(唯一出口,不许自己写 if)");
|
assertFalse(source.contains("@RequestParam(name = \"company_id\""),
|
||||||
assertTrue(source.contains("writeCompanyId"),
|
"company_id 请求参数必须摘除(商品行全平台共享,公司隔离已撤销)");
|
||||||
"写侧行级闸必须经 DataReadScope#writeCompanyId(编辑/传图/删除/批量删除)");
|
assertFalse(source.contains("readCompanyIdOrOwn"),
|
||||||
assertTrue(source.contains("assertRowsInCompany"),
|
"读侧不得再经 DataReadScope#readCompanyIdOrOwn 收窄(共享采集池)");
|
||||||
"编辑/传图/删除/批量删除/批量归类动手前必须过行级公司闸"
|
assertFalse(source.contains("writeCompanyId"),
|
||||||
+ "(读侧藏起来的行仍然能删=静默删除,不是隔离)");
|
"写侧不得再按行 company_id 收窄(共享池里看得见就能操作,越权由超管档写闸兜)");
|
||||||
|
assertFalse(source.contains("assertRowsInCompany"),
|
||||||
|
"行级公司闸必须整批摘除(分类不能减少任何账号的数据)");
|
||||||
assertFalse(source.contains("superAdminScopedCompanyId"),
|
assertFalse(source.contains("superAdminScopedCompanyId"),
|
||||||
"不得沿用 superAdminScopedCompanyId 旧形状(它只在超管身上收窄、非超管不过滤=公司互看)");
|
"不得沿用 superAdminScopedCompanyId 旧形状(它只在超管身上收窄、非超管不过滤=口径两套)");
|
||||||
|
assertTrue(source.contains("owner_group_id"),
|
||||||
|
"分类隔离保留在 owner_group_id(V203 归属行=客户说的「按组绑定副本」)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -176,7 +171,7 @@ class AdminJdProductControllerTest {
|
|||||||
String source = stripComments(Files.readString(CONTROLLER));
|
String source = stripComments(Files.readString(CONTROLLER));
|
||||||
for (String param : List.of("page_size", "product_code", "title_keyword", "keyword",
|
for (String param : List.of("page_size", "product_code", "title_keyword", "keyword",
|
||||||
"shop_name", "min_price", "max_price",
|
"shop_name", "min_price", "max_price",
|
||||||
"group_id", "owner_group_id", "synced_from", "synced_to", "company_id")) {
|
"group_id", "owner_group_id", "synced_from", "synced_to")) {
|
||||||
assertTrue(source.contains(param), "查询参数必须 snake_case:" + param);
|
assertTrue(source.contains(param), "查询参数必须 snake_case:" + param);
|
||||||
}
|
}
|
||||||
assertFalse(source.contains("@RequestParam(name = \"ungrouped\""));
|
assertFalse(source.contains("@RequestParam(name = \"ungrouped\""));
|
||||||
@@ -191,9 +186,10 @@ class AdminJdProductControllerTest {
|
|||||||
assertTrue(source.contains("@RequestParam(name = \"min_price\"")
|
assertTrue(source.contains("@RequestParam(name = \"min_price\"")
|
||||||
&& source.contains("@RequestParam(name = \"max_price\""),
|
&& source.contains("@RequestParam(name = \"max_price\""),
|
||||||
"价格区间参数 min_price/max_price 必须在册(v1.7 拍板)");
|
"价格区间参数 min_price/max_price 必须在册(v1.7 拍板)");
|
||||||
// 公司隔离(2026-11-23):company_id 在册(平台超管切公司);非超管由 readCompanyIdOrOwn 钉本公司。
|
// 公司隔离(2026-11-23)已于 2026-11-26 按客户口径撤销:商品行全平台共享,
|
||||||
assertTrue(source.contains("@RequestParam(name = \"company_id\""),
|
// company_id 请求参数不得回流(反向钉,见「读侧零公司维度」支)。
|
||||||
"company_id 请求参数必须在册(2026-11-23 公司与公司不能互看)");
|
assertFalse(source.contains("@RequestParam(name = \"company_id\""),
|
||||||
|
"company_id 请求参数必须摘除(共享采集池,2026-11-26 口径)");
|
||||||
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
|
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
|
||||||
assertFalse(source.contains("\"sale_status\""), "sale_status 筛选参数必须已删除,不得回潜");
|
assertFalse(source.contains("\"sale_status\""), "sale_status 筛选参数必须已删除,不得回潜");
|
||||||
// 店铺筛选 v1.7 复活(2026-11-21 拍板「店铺名单维度完整对齐」):精确 eq 配合 group_id;
|
// 店铺筛选 v1.7 复活(2026-11-21 拍板「店铺名单维度完整对齐」):精确 eq 配合 group_id;
|
||||||
@@ -306,7 +302,7 @@ class AdminJdProductControllerTest {
|
|||||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, deleteService, updateService, groupService, scopeService,
|
queryService, deleteService, updateService, groupService, scopeService,
|
||||||
authSupport, permissionMenuService, dataScopeMock());
|
authSupport, permissionMenuService);
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(9L);
|
operator.setId(9L);
|
||||||
@@ -327,10 +323,9 @@ class AdminJdProductControllerTest {
|
|||||||
// 读:菜单权限命中即放行(公共库一人一份全量)。
|
// 读:菜单权限命中即放行(公共库一人一份全量)。
|
||||||
JdProductPageVo pageVo = new JdProductPageVo();
|
JdProductPageVo pageVo = new JdProductPageVo();
|
||||||
pageVo.setItems(List.of());
|
pageVo.setItems(List.of());
|
||||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID, null))
|
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID))
|
||||||
.thenReturn(pageVo);
|
.thenReturn(pageVo);
|
||||||
assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null,
|
assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, null, request)
|
||||||
null, null, null, null, null, null, null, request)
|
|
||||||
.isSuccess(), "普通账号有菜单权限时读必须放行(读写分档只收窄写)");
|
.isSuccess(), "普通账号有菜单权限时读必须放行(读写分档只收窄写)");
|
||||||
|
|
||||||
// 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。
|
// 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。
|
||||||
@@ -374,7 +369,7 @@ class AdminJdProductControllerTest {
|
|||||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, deleteService, updateService, mock(JdProductGroupService.class),
|
queryService, deleteService, updateService, mock(JdProductGroupService.class),
|
||||||
mock(JdCategoryScopeService.class), authSupport, permissionMenuService, dataScopeMock());
|
mock(JdCategoryScopeService.class), authSupport, permissionMenuService);
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(9L);
|
operator.setId(9L);
|
||||||
@@ -434,7 +429,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||||
AdminJdProductGroupController controller = new AdminJdProductGroupController(
|
AdminJdProductGroupController controller = new AdminJdProductGroupController(
|
||||||
groupService, mock(JdGroupShopService.class), scopeService, authSupport, permissionMenuService, dataScopeMock());
|
groupService, mock(JdGroupShopService.class), scopeService, authSupport, permissionMenuService);
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(9L);
|
operator.setId(9L);
|
||||||
@@ -487,7 +482,7 @@ class AdminJdProductControllerTest {
|
|||||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), updateService, groupService,
|
queryService, mock(JdProductDeleteService.class), updateService, groupService,
|
||||||
scopeService, authSupport, permissionMenuService, dataScopeMock());
|
scopeService, authSupport, permissionMenuService);
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(9L);
|
operator.setId(9L);
|
||||||
@@ -531,7 +526,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
groupService, scopeService, authSupport, mock(PermissionMenuService.class), dataScopeMock());
|
groupService, scopeService, authSupport, mock(PermissionMenuService.class));
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
@@ -545,13 +540,11 @@ class AdminJdProductControllerTest {
|
|||||||
when(groupService.requireCategory(8L)).thenReturn(category(8L, 20L));
|
when(groupService.requireCategory(8L)).thenReturn(category(8L, 20L));
|
||||||
|
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> controller.page(1L, 20L, null, null, null, null, 8L, null, null, null,
|
() -> controller.page(1L, 20L, null, null, null, null, 8L, null, null, null, null, null, null, null, request));
|
||||||
null, null, null, null, null, request));
|
|
||||||
assertTrue(ex.getMessage().contains("无权查看该分组的分类"),
|
assertTrue(ex.getMessage().contains("无权查看该分组的分类"),
|
||||||
"跨组分类筛选必须 403 点名分组,不做空结果降级");
|
"跨组分类筛选必须 403 点名分组,不做空结果降级");
|
||||||
|
|
||||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(),
|
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
|
||||||
any(), any(), any(), any(), any(), any(), any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== 行为样本 =====================
|
// ===================== 行为样本 =====================
|
||||||
@@ -564,7 +557,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
groupService, scopeService, authSupport, mock(PermissionMenuService.class), dataScopeMock());
|
groupService, scopeService, authSupport, mock(PermissionMenuService.class));
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
@@ -579,14 +572,13 @@ class AdminJdProductControllerTest {
|
|||||||
pageVo.setTotal(0L);
|
pageVo.setTotal(0L);
|
||||||
pageVo.setPage(1L);
|
pageVo.setPage(1L);
|
||||||
pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT);
|
pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT);
|
||||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID, null))
|
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID))
|
||||||
.thenReturn(pageVo);
|
.thenReturn(pageVo);
|
||||||
|
|
||||||
// 请求面没有 company_id:任何授权身份看到的都是同一份全量;分类列按 owner_group_id 取。
|
// 请求面没有 company_id:任何授权身份看到的都是同一份全量;分类列按 owner_group_id 取。
|
||||||
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null,
|
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null, null, null, null, null, GROUP_ID, null, null, null, request);
|
||||||
null, null, null, null, GROUP_ID, null, null, null, null, request);
|
|
||||||
|
|
||||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID, null);
|
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID);
|
||||||
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
|
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
|
||||||
assertEquals(pageVo, response.getData());
|
assertEquals(pageVo, response.getData());
|
||||||
}
|
}
|
||||||
@@ -599,7 +591,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), scopeService, authSupport,
|
mock(JdProductGroupService.class), scopeService, authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
@@ -610,14 +602,12 @@ class AdminJdProductControllerTest {
|
|||||||
for (String value : List.of("true", "false", "")) {
|
for (String value : List.of("true", "false", "")) {
|
||||||
when(request.getParameter(name)).thenReturn(value);
|
when(request.getParameter(name)).thenReturn(value);
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> controller.page(1L, 20L, null, null, null, null, 7L, null, null, null,
|
() -> controller.page(1L, 20L, null, null, null, null, 7L, null, null, null, null, null, null, null, request));
|
||||||
null, null, null, null, null, request));
|
|
||||||
assertTrue(ex.getMessage().contains("刷新页面"));
|
assertTrue(ex.getMessage().contains("刷新页面"));
|
||||||
when(request.getParameter(name)).thenReturn(null);
|
when(request.getParameter(name)).thenReturn(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(),
|
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
|
||||||
any(), any(), any(), any(), any(), any(), any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -627,7 +617,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
@@ -637,11 +627,11 @@ class AdminJdProductControllerTest {
|
|||||||
JdProductCategoryVo row = new JdProductCategoryVo();
|
JdProductCategoryVo row = new JdProductCategoryVo();
|
||||||
row.setName("艺考形体服");
|
row.setName("艺考形体服");
|
||||||
row.setProductCount(85L);
|
row.setProductCount(85L);
|
||||||
when(queryService.categories(null)).thenReturn(List.of(row));
|
when(queryService.categories()).thenReturn(List.of(row));
|
||||||
|
|
||||||
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(null, request);
|
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(request);
|
||||||
|
|
||||||
verify(queryService).categories(null);
|
verify(queryService).categories();
|
||||||
assertEquals(Boolean.TRUE, response.isSuccess(), "类目下拉与列表同一鉴权正门(200 信封)");
|
assertEquals(Boolean.TRUE, response.isSuccess(), "类目下拉与列表同一鉴权正门(200 信封)");
|
||||||
assertEquals("艺考形体服", response.getData().get(0).getName(), "选项=已落库行的末级类目名(全平台去重)");
|
assertEquals("艺考形体服", response.getData().get(0).getName(), "选项=已落库行的末级类目名(全平台去重)");
|
||||||
assertEquals(85L, response.getData().get(0).getProductCount());
|
assertEquals(85L, response.getData().get(0).getProductCount());
|
||||||
@@ -655,7 +645,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), scopeService, authSupport,
|
mock(JdProductGroupService.class), scopeService, authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
@@ -667,13 +657,13 @@ class AdminJdProductControllerTest {
|
|||||||
when(scopeService.readGroupOrNull(scope, null)).thenReturn(GROUP_ID);
|
when(scopeService.readGroupOrNull(scope, null)).thenReturn(GROUP_ID);
|
||||||
JdProductDetailVo detailVo = new JdProductDetailVo();
|
JdProductDetailVo detailVo = new JdProductDetailVo();
|
||||||
detailVo.setId(11L);
|
detailVo.setId(11L);
|
||||||
when(queryService.detail(11L, GROUP_ID, null)).thenReturn(detailVo);
|
when(queryService.detail(11L, GROUP_ID)).thenReturn(detailVo);
|
||||||
|
|
||||||
ApiResponse<JdProductDetailVo> response = controller.detail(11L, null, null, request);
|
ApiResponse<JdProductDetailVo> response = controller.detail(11L, null, request);
|
||||||
|
|
||||||
// 公共库详情没有公司维度(DataReadScope 反向钉在结构判据支,2026-11-16 已整批摘除);
|
// 公共库详情没有公司维度(DataReadScope 反向钉在结构判据支,2026-11-16 已整批摘除);
|
||||||
// 分类字段按「当前分组」取(V203)。
|
// 分类字段按「当前分组」取(V203)。
|
||||||
verify(queryService).detail(11L, GROUP_ID, null);
|
verify(queryService).detail(11L, GROUP_ID);
|
||||||
assertEquals(Boolean.TRUE, response.isSuccess());
|
assertEquals(Boolean.TRUE, response.isSuccess());
|
||||||
assertEquals(detailVo, response.getData());
|
assertEquals(detailVo, response.getData());
|
||||||
}
|
}
|
||||||
@@ -686,7 +676,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, deleteService, mock(JdProductUpdateService.class),
|
queryService, deleteService, mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
@@ -715,7 +705,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, deleteService, mock(JdProductUpdateService.class),
|
queryService, deleteService, mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
|
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
@@ -736,24 +726,21 @@ class AdminJdProductControllerTest {
|
|||||||
void 查询服务分页钳制防溢出() {
|
void 查询服务分页钳制防溢出() {
|
||||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||||
JdProductQueryService service = queryService(mapper);
|
JdProductQueryService service = queryService(mapper);
|
||||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||||
any(), any(), any(), any(), isNull(), isNull())).thenReturn(1L);
|
|
||||||
|
|
||||||
// page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。
|
// page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。
|
||||||
service.page(0L, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
service.page(0L, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class);
|
ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class);
|
||||||
ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class);
|
ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class);
|
||||||
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), offset.capture(), limit.capture());
|
||||||
isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), offset.capture(), limit.capture());
|
|
||||||
assertEquals(0L, offset.getValue());
|
assertEquals(0L, offset.getValue());
|
||||||
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
|
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
|
||||||
|
|
||||||
// page=Long.MAX_VALUE / size=5000 ⇒ 钳到 10_000 页、1000 条(v1.7 上限);乘积 9_999_000 不得变负(铁律 15)。
|
// page=Long.MAX_VALUE / size=5000 ⇒ 钳到 10_000 页、1000 条(v1.7 上限);乘积 9_999_000 不得变负(铁律 15)。
|
||||||
service.page(Long.MAX_VALUE, 5000L, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
service.page(Long.MAX_VALUE, 5000L, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
ArgumentCaptor<Long> offsetMax = ArgumentCaptor.forClass(Long.class);
|
ArgumentCaptor<Long> offsetMax = ArgumentCaptor.forClass(Long.class);
|
||||||
ArgumentCaptor<Integer> limitMax = ArgumentCaptor.forClass(Integer.class);
|
ArgumentCaptor<Integer> limitMax = ArgumentCaptor.forClass(Integer.class);
|
||||||
verify(mapper, times(2)).selectProductPage(any(), any(), any(), any(), any(), any(),
|
verify(mapper, times(2)).selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull(), offsetMax.capture(), limitMax.capture());
|
||||||
any(), any(), any(), any(), any(), any(), isNull(), isNull(), offsetMax.capture(), limitMax.capture());
|
|
||||||
assertEquals(9_999_000L, offsetMax.getValue(), "(page-1)*page_size 最大 9_999_000,钳制后不得溢出变负");
|
assertEquals(9_999_000L, offsetMax.getValue(), "(page-1)*page_size 最大 9_999_000,钳制后不得溢出变负");
|
||||||
assertEquals(1000, limitMax.getValue(), "page_size 上限已随 v1.7 放宽到 1000(对齐原型档位)");
|
assertEquals(1000, limitMax.getValue(), "page_size 上限已随 v1.7 放宽到 1000(对齐原型档位)");
|
||||||
}
|
}
|
||||||
@@ -765,29 +752,23 @@ class AdminJdProductControllerTest {
|
|||||||
LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0);
|
LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0);
|
||||||
LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0);
|
LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0);
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> service.page(1L, 20L, null, null, null, null, null, null, null, null, from, to, null, null, null));
|
() -> service.page(1L, 20L, null, null, null, null, null, null, null, null, from, to, null, null));
|
||||||
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
|
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
|
||||||
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull());
|
||||||
any(), any(), any(), any(), isNull(), isNull());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 查询服务过滤面原样直传且空串归null() {
|
void 查询服务过滤面原样直传且空串归null() {
|
||||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||||
JdProductQueryService service = queryService(mapper);
|
JdProductQueryService service = queryService(mapper);
|
||||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||||
any(), any(), any(), any(), isNull(), isNull())).thenReturn(1L);
|
service.page(1L, 20L, null, " SKU-1 ", " 连衣裙 ", List.of(" 艺考形体服 "), 7L, null, null, null, null, null, null, null);
|
||||||
service.page(1L, 20L, null, " SKU-1 ", " 连衣裙 ", List.of(" 艺考形体服 "), 7L,
|
verify(mapper).countProducts(null, "SKU-1", "连衣裙", List.of("艺考形体服"), 7L, null, null, null, null, null, null, null, null);
|
||||||
null, null, null, null, null, null, null, null);
|
verify(mapper).selectProductPage(null, "SKU-1", "连衣裙", List.of("艺考形体服"), 7L, null, null, null, null, null, null, null, null, 0L, 20);
|
||||||
verify(mapper).countProducts(null, "SKU-1", "连衣裙", List.of("艺考形体服"), 7L,
|
|
||||||
null, null, null, null, null, null, null, null, null);
|
|
||||||
verify(mapper).selectProductPage(null, "SKU-1", "连衣裙", List.of("艺考形体服"), 7L,
|
|
||||||
null, null, null, null, null, null, null, null, null, 0L, 20);
|
|
||||||
|
|
||||||
service.page(1L, 20L, null, " ", null, null, 0L, null, null, null, null, null, null, null, null);
|
service.page(1L, 20L, null, " ", null, null, 0L, null, null, null, null, null, null, null);
|
||||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null,
|
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null, null, null, null, null, null, 0L, 20);
|
||||||
null, null, null, null, null, null, 0L, 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -799,21 +780,15 @@ class AdminJdProductControllerTest {
|
|||||||
void 类目多值必须逐项归一并IN下推() throws IOException {
|
void 类目多值必须逐项归一并IN下推() throws IOException {
|
||||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||||
JdProductQueryService service = queryService(mapper);
|
JdProductQueryService service = queryService(mapper);
|
||||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||||
any(), any(), any(), any(), isNull(), isNull())).thenReturn(1L);
|
|
||||||
|
|
||||||
service.page(1L, 20L, null, null, null,
|
service.page(1L, 20L, null, null, null, java.util.Arrays.asList(" 女装 ", "女装", "", null, " 汉服/旗袍 "), null, null, null, null, null, null, null, null);
|
||||||
java.util.Arrays.asList(" 女装 ", "女装", "", null, " 汉服/旗袍 "),
|
verify(mapper).countProducts(null, null, null, List.of("女装", "汉服/旗袍"), null, null, null, null, null, null, null, null, null);
|
||||||
null, null, null, null, null, null, null, null, null);
|
verify(mapper).selectProductPage(null, null, null, List.of("女装", "汉服/旗袍"), null, null, null, null, null, null, null, null, null, 0L, 20);
|
||||||
verify(mapper).countProducts(null, null, null, List.of("女装", "汉服/旗袍"),
|
|
||||||
null, null, null, null, null, null, null, null, null, null);
|
|
||||||
verify(mapper).selectProductPage(null, null, null, List.of("女装", "汉服/旗袍"),
|
|
||||||
null, null, null, null, null, null, null, null, null, null, 0L, 20);
|
|
||||||
|
|
||||||
// 全空白/空集合=不过滤该面(与「全部类目」清选同口径,不得下发空 IN)
|
// 全空白/空集合=不过滤该面(与「全部类目」清选同口径,不得下发空 IN)
|
||||||
service.page(1L, 20L, null, null, null, java.util.Arrays.asList(" ", ""),
|
service.page(1L, 20L, null, null, null, java.util.Arrays.asList(" ", ""), null, null, null, null, null, null, null, null);
|
||||||
null, null, null, null, null, null, null, null, null);
|
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
|
||||||
|
|
||||||
Path xml = findJdProductMapperXml();
|
Path xml = findJdProductMapperXml();
|
||||||
String xmlText = stripComments(Files.readString(xml)).replaceAll("(?s)<!--.*?-->", "");
|
String xmlText = stripComments(Files.readString(xml)).replaceAll("(?s)<!--.*?-->", "");
|
||||||
@@ -850,19 +825,14 @@ class AdminJdProductControllerTest {
|
|||||||
// ① 服务直传:classified 与 ownerGroupId 成对进 mapper(计数与分页同一过滤面)。
|
// ① 服务直传:classified 与 ownerGroupId 成对进 mapper(计数与分页同一过滤面)。
|
||||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||||
JdProductQueryService service = queryService(mapper);
|
JdProductQueryService service = queryService(mapper);
|
||||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||||
any(), any(), any(), any(), isNull(), isNull())).thenReturn(1L);
|
service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, Boolean.TRUE, GROUP_ID);
|
||||||
service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null,
|
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, true, GROUP_ID, null);
|
||||||
Boolean.TRUE, GROUP_ID, null);
|
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null, null, null, true, GROUP_ID, null, 0L, 20);
|
||||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, true, GROUP_ID, null, null);
|
|
||||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null,
|
|
||||||
null, null, true, GROUP_ID, null, null, 0L, 20);
|
|
||||||
|
|
||||||
service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null,
|
service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, Boolean.FALSE, GROUP_ID);
|
||||||
Boolean.FALSE, GROUP_ID, null);
|
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, false, GROUP_ID, null);
|
||||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, false, GROUP_ID, null, null);
|
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null, null, null, false, GROUP_ID, null, 0L, 20);
|
||||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null,
|
|
||||||
null, null, false, GROUP_ID, null, null, 0L, 20);
|
|
||||||
|
|
||||||
// ③ 控制器直传:classified 原样进服务(owner_group_id 仍按作用域收敛后的值)。
|
// ③ 控制器直传:classified 原样进服务(owner_group_id 仍按作用域收敛后的值)。
|
||||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||||
@@ -871,7 +841,7 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), scopeService, authSupport,
|
mock(JdProductGroupService.class), scopeService, authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
@@ -880,10 +850,8 @@ class AdminJdProductControllerTest {
|
|||||||
JdCategoryScopeService.JdCategoryScope scope = writableScope(GROUP_ID, COMPANY_ID);
|
JdCategoryScopeService.JdCategoryScope scope = writableScope(GROUP_ID, COMPANY_ID);
|
||||||
when(scopeService.resolve(operator)).thenReturn(scope);
|
when(scopeService.resolve(operator)).thenReturn(scope);
|
||||||
when(scopeService.readGroupOrNull(scope, null)).thenReturn(GROUP_ID);
|
when(scopeService.readGroupOrNull(scope, null)).thenReturn(GROUP_ID);
|
||||||
controller.page(1L, 20L, null, null, null, null, null, null, null, null, null, null,
|
controller.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, Boolean.TRUE, request);
|
||||||
null, Boolean.TRUE, null, request);
|
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null, null, null, Boolean.TRUE, GROUP_ID);
|
||||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null, null,
|
|
||||||
null, Boolean.TRUE, GROUP_ID, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -895,28 +863,22 @@ class AdminJdProductControllerTest {
|
|||||||
void 合并搜索价格区间店铺过滤归一后直传且价格倒挂拒绝() {
|
void 合并搜索价格区间店铺过滤归一后直传且价格倒挂拒绝() {
|
||||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||||
JdProductQueryService service = queryService(mapper);
|
JdProductQueryService service = queryService(mapper);
|
||||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||||
any(), any(), any(), any(), isNull(), isNull())).thenReturn(1L);
|
|
||||||
|
|
||||||
// ① 三件新面原样直传:keyword/shopName trim 归一,价格 BigDecimal 原样。
|
// ① 三件新面原样直传:keyword/shopName trim 归一,价格 BigDecimal 原样。
|
||||||
service.page(1L, 20L, " 连衣裙 ", null, null, null, 7L, " 测试店铺 ",
|
service.page(1L, 20L, " 连衣裙 ", null, null, null, 7L, " 测试店铺 ", new BigDecimal("100"), new BigDecimal("200"), null, null, null, null);
|
||||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null);
|
verify(mapper).countProducts("连衣裙", null, null, null, 7L, "测试店铺", new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null);
|
||||||
verify(mapper).countProducts("连衣裙", null, null, null, 7L, "测试店铺",
|
verify(mapper).selectProductPage("连衣裙", null, null, null, 7L, "测试店铺", new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null, 0L, 20);
|
||||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null, null);
|
|
||||||
verify(mapper).selectProductPage("连衣裙", null, null, null, 7L, "测试店铺",
|
|
||||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null, null, 0L, 20);
|
|
||||||
|
|
||||||
// ② 空白 keyword/shopName 归 null(不过滤该面)。
|
// ② 空白 keyword/shopName 归 null(不过滤该面)。
|
||||||
service.page(1L, 20L, " ", null, null, null, 0L, " ", null, null, null, null, null, null, null);
|
service.page(1L, 20L, " ", null, null, null, 0L, " ", null, null, null, null, null, null);
|
||||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
|
|
||||||
// ③ 价格倒挂按业务异常拒绝(同同步起止倒挂形状)。
|
// ③ 价格倒挂按业务异常拒绝(同同步起止倒挂形状)。
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> service.page(1L, 20L, null, null, null, null, null, null,
|
() -> service.page(1L, 20L, null, null, null, null, null, null, new BigDecimal("200"), new BigDecimal("100"), null, null, null, null));
|
||||||
new BigDecimal("200"), new BigDecimal("100"), null, null, null, null, null));
|
|
||||||
assertTrue(ex.getMessage().contains("价格区间最小值不能大于最大值"), "倒挂价格区间按业务异常拒绝");
|
assertTrue(ex.getMessage().contains("价格区间最小值不能大于最大值"), "倒挂价格区间按业务异常拒绝");
|
||||||
verify(mapper, times(2)).countProducts(any(), any(), any(), any(), any(), any(),
|
verify(mapper, times(2)).countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull());
|
||||||
any(), any(), any(), any(), any(), any(), isNull(), isNull());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -931,20 +893,20 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||||
byte[] csvBytes = "\uFEFF商品编码\r\nA123".getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
byte[] csvBytes = "\uFEFF商品编码\r\nA123".getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||||
when(queryService.exportCsv(List.of(11L, 12L), null)).thenReturn(csvBytes);
|
when(queryService.exportCsv(List.of(11L, 12L))).thenReturn(csvBytes);
|
||||||
|
|
||||||
JdProductExportRequest body = new JdProductExportRequest();
|
JdProductExportRequest body = new JdProductExportRequest();
|
||||||
body.setIds(List.of(11L, 12L));
|
body.setIds(List.of(11L, 12L));
|
||||||
ResponseEntity<byte[]> response = controller.export(body, null, request);
|
ResponseEntity<byte[]> response = controller.export(body, request);
|
||||||
|
|
||||||
verify(queryService).exportCsv(List.of(11L, 12L), null);
|
verify(queryService).exportCsv(List.of(11L, 12L));
|
||||||
assertEquals(200, response.getStatusCode().value(), "放行必须是 200 附件响应(非 ApiResponse 信封)");
|
assertEquals(200, response.getStatusCode().value(), "放行必须是 200 附件响应(非 ApiResponse 信封)");
|
||||||
assertTrue(response.getHeaders().getFirst("Content-Disposition").contains(".csv"),
|
assertTrue(response.getHeaders().getFirst("Content-Disposition").contains(".csv"),
|
||||||
"Content-Disposition 必须带 .csv 文件名(DownloadHeaderUtil 兜 ASCII 回退与 UTF-8 双名)");
|
"Content-Disposition 必须带 .csv 文件名(DownloadHeaderUtil 兜 ASCII 回退与 UTF-8 双名)");
|
||||||
@@ -961,14 +923,14 @@ class AdminJdProductControllerTest {
|
|||||||
AdminJdProductController controller = new AdminJdProductController(
|
AdminJdProductController controller = new AdminJdProductController(
|
||||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||||
mock(PermissionMenuService.class), dataScopeMock());
|
mock(PermissionMenuService.class));
|
||||||
AdminUserEntity operator = new AdminUserEntity();
|
AdminUserEntity operator = new AdminUserEntity();
|
||||||
operator.setId(7L);
|
operator.setId(7L);
|
||||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||||
// 服务侧限流是真源(服务级用例另钉 1001 拒绝);这里钉控制器原样透出业务异常、不吞成 500。
|
// 服务侧限流是真源(服务级用例另钉 1001 拒绝);这里钉控制器原样透出业务异常、不吞成 500。
|
||||||
when(queryService.exportCsv(any(), isNull()))
|
when(queryService.exportCsv(any()))
|
||||||
.thenThrow(new BusinessException("单次最多导出 1000 个商品,请缩小勾选范围"));
|
.thenThrow(new BusinessException("单次最多导出 1000 个商品,请缩小勾选范围"));
|
||||||
|
|
||||||
java.util.List<Long> oversized = new java.util.ArrayList<>();
|
java.util.List<Long> oversized = new java.util.ArrayList<>();
|
||||||
@@ -977,7 +939,7 @@ class AdminJdProductControllerTest {
|
|||||||
}
|
}
|
||||||
JdProductExportRequest body = new JdProductExportRequest();
|
JdProductExportRequest body = new JdProductExportRequest();
|
||||||
body.setIds(oversized);
|
body.setIds(oversized);
|
||||||
BusinessException ex = assertThrows(BusinessException.class, () -> controller.export(body, null, request));
|
BusinessException ex = assertThrows(BusinessException.class, () -> controller.export(body, request));
|
||||||
assertTrue(ex.getMessage().contains("1000"), "超限文案必须点名上限 1000");
|
assertTrue(ex.getMessage().contains("1000"), "超限文案必须点名上限 1000");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,7 +955,7 @@ class AdminJdProductControllerTest {
|
|||||||
second.setSyncedAt(LocalDateTime.of(2026, 11, 21, 9, 30));
|
second.setSyncedAt(LocalDateTime.of(2026, 11, 21, 9, 30));
|
||||||
when(mapper.selectBatchIds(List.of(2L, 1L))).thenReturn(List.of(second, first));
|
when(mapper.selectBatchIds(List.of(2L, 1L))).thenReturn(List.of(second, first));
|
||||||
|
|
||||||
byte[] bytes = service.exportCsv(List.of(2L, 1L), null);
|
byte[] bytes = service.exportCsv(List.of(2L, 1L));
|
||||||
String csv = new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
|
String csv = new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
|
||||||
assertTrue(csv.startsWith("\uFEFF"), "必须带 UTF-8 BOM(Excel 双击直开中文不乱码)");
|
assertTrue(csv.startsWith("\uFEFF"), "必须带 UTF-8 BOM(Excel 双击直开中文不乱码)");
|
||||||
@@ -1010,17 +972,17 @@ class AdminJdProductControllerTest {
|
|||||||
assertTrue(firstRow > 0 && secondRow > firstRow, "行分隔符存在");
|
assertTrue(firstRow > 0 && secondRow > firstRow, "行分隔符存在");
|
||||||
|
|
||||||
// 空勾选拒绝(前端按钮置灰是第一道,这里是兜底);超上限同样拒绝(少导是交付事故)。
|
// 空勾选拒绝(前端按钮置灰是第一道,这里是兜底);超上限同样拒绝(少导是交付事故)。
|
||||||
BusinessException empty = assertThrows(BusinessException.class, () -> service.exportCsv(List.of(), null));
|
BusinessException empty = assertThrows(BusinessException.class, () -> service.exportCsv(List.of()));
|
||||||
assertTrue(empty.getMessage().contains("请先勾选"));
|
assertTrue(empty.getMessage().contains("请先勾选"));
|
||||||
BusinessException invalid = assertThrows(BusinessException.class,
|
BusinessException invalid = assertThrows(BusinessException.class,
|
||||||
() -> service.exportCsv(java.util.Arrays.asList(0L, null), null));
|
() -> service.exportCsv(java.util.Arrays.asList(0L, null)));
|
||||||
assertTrue(invalid.getMessage().contains("请先勾选"));
|
assertTrue(invalid.getMessage().contains("请先勾选"));
|
||||||
|
|
||||||
java.util.List<Long> oversized = new java.util.ArrayList<>();
|
java.util.List<Long> oversized = new java.util.ArrayList<>();
|
||||||
for (long i = 1; i <= JdProductQueryService.MAX_EXPORT_IDS + 1; i++) {
|
for (long i = 1; i <= JdProductQueryService.MAX_EXPORT_IDS + 1; i++) {
|
||||||
oversized.add(i);
|
oversized.add(i);
|
||||||
}
|
}
|
||||||
BusinessException over = assertThrows(BusinessException.class, () -> service.exportCsv(oversized, null));
|
BusinessException over = assertThrows(BusinessException.class, () -> service.exportCsv(oversized));
|
||||||
assertTrue(over.getMessage().contains("1000"), "超限文案必须点名上限 1000");
|
assertTrue(over.getMessage().contains("1000"), "超限文案必须点名上限 1000");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1049,7 +1011,7 @@ class AdminJdProductControllerTest {
|
|||||||
image.setHeight(800);
|
image.setHeight(800);
|
||||||
when(imageMapper.selectList(any())).thenReturn(List.of(image));
|
when(imageMapper.selectList(any())).thenReturn(List.of(image));
|
||||||
|
|
||||||
JdProductDetailVo vo = service.detail(11L, null, null);
|
JdProductDetailVo vo = service.detail(11L, null);
|
||||||
|
|
||||||
assertEquals(2, vo.getAttrGroups().size(), "tabs 数组逐个映射成 attrGroups(groupName=tab 字段)");
|
assertEquals(2, vo.getAttrGroups().size(), "tabs 数组逐个映射成 attrGroups(groupName=tab 字段)");
|
||||||
assertEquals("商品基本信息", vo.getAttrGroups().get(0).getGroupName());
|
assertEquals("商品基本信息", vo.getAttrGroups().get(0).getGroupName());
|
||||||
@@ -1078,7 +1040,7 @@ class AdminJdProductControllerTest {
|
|||||||
JdProductEntity broken = productEntity(11L);
|
JdProductEntity broken = productEntity(11L);
|
||||||
broken.setAttrJson("{\"tabs\": [broken");
|
broken.setAttrJson("{\"tabs\": [broken");
|
||||||
when(mapper.selectById(11L)).thenReturn(broken);
|
when(mapper.selectById(11L)).thenReturn(broken);
|
||||||
JdProductDetailVo brokenVo = service.detail(11L, null, null);
|
JdProductDetailVo brokenVo = service.detail(11L, null);
|
||||||
assertTrue(brokenVo.getAttrGroups().isEmpty(), "解析异常落空 attrGroups,不抛 500(AC-7)");
|
assertTrue(brokenVo.getAttrGroups().isEmpty(), "解析异常落空 attrGroups,不抛 500(AC-7)");
|
||||||
assertEquals("{\"tabs\": [broken", brokenVo.getAttrJsonRaw(), "原文进 attrJsonRaw 兜底展示");
|
assertEquals("{\"tabs\": [broken", brokenVo.getAttrJsonRaw(), "原文进 attrJsonRaw 兜底展示");
|
||||||
|
|
||||||
@@ -1086,7 +1048,7 @@ class AdminJdProductControllerTest {
|
|||||||
JdProductEntity foreign = productEntity(11L);
|
JdProductEntity foreign = productEntity(11L);
|
||||||
foreign.setAttrJson("{\"attrs\":[{\"key\":\"x\",\"value\":\"y\"}]}");
|
foreign.setAttrJson("{\"attrs\":[{\"key\":\"x\",\"value\":\"y\"}]}");
|
||||||
when(mapper.selectById(11L)).thenReturn(foreign);
|
when(mapper.selectById(11L)).thenReturn(foreign);
|
||||||
JdProductDetailVo foreignVo = service.detail(11L, null, null);
|
JdProductDetailVo foreignVo = service.detail(11L, null);
|
||||||
assertTrue(foreignVo.getAttrGroups().isEmpty(), "非契约形状落空 attrGroups");
|
assertTrue(foreignVo.getAttrGroups().isEmpty(), "非契约形状落空 attrGroups");
|
||||||
assertEquals("{\"attrs\":[{\"key\":\"x\",\"value\":\"y\"}]}", foreignVo.getAttrJsonRaw(),
|
assertEquals("{\"attrs\":[{\"key\":\"x\",\"value\":\"y\"}]}", foreignVo.getAttrJsonRaw(),
|
||||||
"未识别属性不丢弃:原文兜底透出(AC-7)");
|
"未识别属性不丢弃:原文兜底透出(AC-7)");
|
||||||
@@ -1095,7 +1057,7 @@ class AdminJdProductControllerTest {
|
|||||||
JdProductEntity blank = productEntity(11L);
|
JdProductEntity blank = productEntity(11L);
|
||||||
blank.setAttrJson(null);
|
blank.setAttrJson(null);
|
||||||
when(mapper.selectById(11L)).thenReturn(blank);
|
when(mapper.selectById(11L)).thenReturn(blank);
|
||||||
JdProductDetailVo blankVo = service.detail(11L, null, null);
|
JdProductDetailVo blankVo = service.detail(11L, null);
|
||||||
assertTrue(blankVo.getAttrGroups().isEmpty());
|
assertTrue(blankVo.getAttrGroups().isEmpty());
|
||||||
assertNull(blankVo.getAttrJsonRaw());
|
assertNull(blankVo.getAttrJsonRaw());
|
||||||
}
|
}
|
||||||
@@ -1124,7 +1086,7 @@ class AdminJdProductControllerTest {
|
|||||||
brokenJson.setSaleAttrsJson("[{\"name\":");
|
brokenJson.setSaleAttrsJson("[{\"name\":");
|
||||||
when(skuMapper.selectList(any())).thenReturn(List.of(first, brokenJson));
|
when(skuMapper.selectList(any())).thenReturn(List.of(first, brokenJson));
|
||||||
|
|
||||||
JdProductDetailVo vo = service.detail(11L, null, null);
|
JdProductDetailVo vo = service.detail(11L, null);
|
||||||
|
|
||||||
assertEquals(2, vo.getSkus().size(), "京麦那 12 行矩阵按入库行下发(抽屉渲染的唯一来源)");
|
assertEquals(2, vo.getSkus().size(), "京麦那 12 行矩阵按入库行下发(抽屉渲染的唯一来源)");
|
||||||
JdProductDetailVo.SkuVo sku = vo.getSkus().get(0);
|
JdProductDetailVo.SkuVo sku = vo.getSkus().get(0);
|
||||||
@@ -1149,14 +1111,14 @@ class AdminJdProductControllerTest {
|
|||||||
JdProductEntity row = productEntity(11L);
|
JdProductEntity row = productEntity(11L);
|
||||||
row.setCompanyId(6L);
|
row.setCompanyId(6L);
|
||||||
when(mapper.selectById(11L)).thenReturn(row);
|
when(mapper.selectById(11L)).thenReturn(row);
|
||||||
assertNotNull(service.detail(11L, null, null));
|
assertNotNull(service.detail(11L, null));
|
||||||
|
|
||||||
// 行不存在 ⇒ 按「商品不存在」拒绝。
|
// 行不存在 ⇒ 按「商品不存在」拒绝。
|
||||||
when(mapper.selectById(11L)).thenReturn(null);
|
when(mapper.selectById(11L)).thenReturn(null);
|
||||||
BusinessException ex = assertThrows(BusinessException.class, () -> service.detail(11L, null, null));
|
BusinessException ex = assertThrows(BusinessException.class, () -> service.detail(11L, null));
|
||||||
assertTrue(ex.getMessage().contains("商品不存在"));
|
assertTrue(ex.getMessage().contains("商品不存在"));
|
||||||
// id 非法同样拒绝。
|
// id 非法同样拒绝。
|
||||||
assertThrows(BusinessException.class, () -> service.detail(0L, null, null));
|
assertThrows(BusinessException.class, () -> service.detail(0L, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1169,10 +1131,8 @@ class AdminJdProductControllerTest {
|
|||||||
|
|
||||||
JdProductEntity categorized = productEntity(1L);
|
JdProductEntity categorized = productEntity(1L);
|
||||||
JdProductEntity missing = productEntity(2L);
|
JdProductEntity missing = productEntity(2L);
|
||||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(2L);
|
||||||
any(), any(), any(), any(), isNull(), isNull())).thenReturn(2L);
|
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull(), anyLong(), anyInt())).thenReturn(List.of(categorized, missing));
|
||||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
|
||||||
any(), any(), any(), any(), isNull(), isNull(), anyLong(), anyInt())).thenReturn(List.of(categorized, missing));
|
|
||||||
when(assignMapper.selectList(any())).thenReturn(List.of(
|
when(assignMapper.selectList(any())).thenReturn(List.of(
|
||||||
assign(1L, GROUP_ID, 3L), assign(2L, GROUP_ID, 99L)));
|
assign(1L, GROUP_ID, 3L), assign(2L, GROUP_ID, 99L)));
|
||||||
JdProductGroupEntity category = new JdProductGroupEntity();
|
JdProductGroupEntity category = new JdProductGroupEntity();
|
||||||
@@ -1180,8 +1140,7 @@ class AdminJdProductControllerTest {
|
|||||||
category.setName("秋冬款");
|
category.setName("秋冬款");
|
||||||
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
|
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
|
||||||
|
|
||||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null,
|
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID);
|
||||||
null, null, null, GROUP_ID, null);
|
|
||||||
|
|
||||||
assertEquals(3L, vo.getItems().get(0).getGroupId(), "分类 id 取本组归属行");
|
assertEquals(3L, vo.getItems().get(0).getGroupId(), "分类 id 取本组归属行");
|
||||||
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集归属一次取齐分类名(无逐行查询)");
|
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集归属一次取齐分类名(无逐行查询)");
|
||||||
@@ -1196,13 +1155,10 @@ class AdminJdProductControllerTest {
|
|||||||
JdProductGroupAssignMapper assignMapper = mock(JdProductGroupAssignMapper.class);
|
JdProductGroupAssignMapper assignMapper = mock(JdProductGroupAssignMapper.class);
|
||||||
JdProductQueryService service = queryService(mapper, mock(JdProductImageMapper.class),
|
JdProductQueryService service = queryService(mapper, mock(JdProductImageMapper.class),
|
||||||
mock(JdProductSkuMapper.class), mock(JdProductGroupMapper.class), assignMapper);
|
mock(JdProductSkuMapper.class), mock(JdProductGroupMapper.class), assignMapper);
|
||||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||||
any(), any(), any(), any(), isNull(), isNull())).thenReturn(1L);
|
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull(), anyLong(), anyInt())).thenReturn(List.of(productEntity(1L)));
|
||||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
|
||||||
any(), any(), any(), any(), isNull(), isNull(), anyLong(), anyInt())).thenReturn(List.of(productEntity(1L)));
|
|
||||||
|
|
||||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null,
|
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||||
null, null, null, null, null);
|
|
||||||
|
|
||||||
assertNull(vo.getItems().get(0).getGroupId(), "不属于任何分组的账号:分类列一律空(未分类)");
|
assertNull(vo.getItems().get(0).getGroupId(), "不属于任何分组的账号:分类列一律空(未分类)");
|
||||||
assertNull(vo.getItems().get(0).getGroupName());
|
assertNull(vo.getItems().get(0).getGroupName());
|
||||||
@@ -1220,7 +1176,7 @@ class AdminJdProductControllerTest {
|
|||||||
|
|
||||||
// 本组(10)没归类:detail 的 selectOne 回 null ⇒ 分类字段空。
|
// 本组(10)没归类:detail 的 selectOne 回 null ⇒ 分类字段空。
|
||||||
when(assignMapper.selectOne(any())).thenReturn(null);
|
when(assignMapper.selectOne(any())).thenReturn(null);
|
||||||
JdProductDetailVo untouched = service.detail(11L, GROUP_ID, null);
|
JdProductDetailVo untouched = service.detail(11L, GROUP_ID);
|
||||||
assertNull(untouched.getGroupId(), "本组没归类=未分类,不拿别组的归属顶上");
|
assertNull(untouched.getGroupId(), "本组没归类=未分类,不拿别组的归属顶上");
|
||||||
assertNull(untouched.getGroupName());
|
assertNull(untouched.getGroupName());
|
||||||
|
|
||||||
@@ -1230,7 +1186,7 @@ class AdminJdProductControllerTest {
|
|||||||
category.setId(3L);
|
category.setId(3L);
|
||||||
category.setName("秋冬款");
|
category.setName("秋冬款");
|
||||||
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
|
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
|
||||||
JdProductDetailVo categorized = service.detail(11L, GROUP_ID, null);
|
JdProductDetailVo categorized = service.detail(11L, GROUP_ID);
|
||||||
assertEquals(3L, categorized.getGroupId());
|
assertEquals(3L, categorized.getGroupId());
|
||||||
assertEquals("秋冬款", categorized.getGroupName());
|
assertEquals("秋冬款", categorized.getGroupName());
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-9
@@ -114,21 +114,28 @@ class JdProductMapperSqlTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公司隔离(2026-11-23 客户口径「公司与公司之间不能互看」):四条读路径(列表/总数/
|
* 2026-11-26 客户口径(「采集的数据…大家一起采集」「不能因为被分类了导致数据少了」):
|
||||||
* 类目下拉/店铺候选)都必须能把 companyId 下推成 {@code p.company_id = ?};平台超管
|
* 商品行是全平台共享池,四条读路径(列表/总数/类目下拉/店铺候选)<b>一律不得出现
|
||||||
* (companyId 空)不得出现该谓词。漏一条=那条路径跨公司可见,且不会报错。
|
* {@code p.company_id}</b>——2026-11-23 的按公司隔离整批撤销。
|
||||||
|
* 「分类各看各的」由 V203 归属行 EXISTS 承担({@code visibleGroupIds}/{@code groupId}),
|
||||||
|
* 不靠藏商品行;漏一条谓词在本测试里当场红,符号还在也红(companyId 形参已删)。
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void 公司隔离谓词必须下推SQL() throws Exception {
|
void 商品行不设公司谓词_全平台共享SQL() throws Exception {
|
||||||
for (String id : java.util.List.of("countProducts", "selectProductPage",
|
for (String id : java.util.List.of("countProducts", "selectProductPage",
|
||||||
"selectProductCategories", "selectDistinctShopNames")) {
|
"selectProductCategories", "selectDistinctShopNames")) {
|
||||||
String sql = render(id, Map.of("companyId", 5L, "offset", 0L, "limit", 20));
|
String sql = render(id, Map.of("companyId", 5L, "offset", 0L, "limit", 20));
|
||||||
assertTrue(sql.contains("p.company_id = ?"),
|
// 只钉谓词形状:selectProductPage 的投影里仍有 p.company_id(实体字段映射,不是过滤条件)。
|
||||||
() -> id + " 少了公司隔离谓词(该路径会跨公司返回): " + sql);
|
assertFalse(sql.contains("p.company_id = ?"),
|
||||||
|
() -> id + " 仍带公司谓词(2026-11-26 已撤销公司隔离,商品行全平台共享): " + sql);
|
||||||
|
assertFalse(sql.contains("AND p.company_id"),
|
||||||
|
() -> id + " 仍把公司挂进 WHERE 串联(写法变了但口径不该回来): " + sql);
|
||||||
}
|
}
|
||||||
String bare = render("countProducts", Map.of("offset", 0L, "limit", 20));
|
// 归属行作用域不能被误删:后管列表(visibleGroupIds 空)之外的选品面仍走 V203 EXISTS。
|
||||||
assertFalse(bare.contains("company_id"),
|
String scoped = render("countProducts", Map.of("visibleGroupIds", java.util.List.of(11L, 12L),
|
||||||
() -> "平台超管(companyId 空)不得被钉死在某公司: " + bare);
|
"offset", 0L, "limit", 20));
|
||||||
|
assertTrue(scoped.contains("owner_group_id IN"),
|
||||||
|
() -> "可见分组作用域必须仍在(V203 归属行): " + scoped);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String render(String id) throws Exception {
|
private static String render(String id) throws Exception {
|
||||||
|
|||||||
+6
-6
@@ -202,19 +202,19 @@ class JdGroupShopServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void 可添加候选排除已有名单且limit钳制() {
|
void 可添加候选排除已有名单且limit钳制() {
|
||||||
when(shopMapper.selectList(any())).thenReturn(List.of(shopRow(1L, CATEGORY_ID, "已有店A")));
|
when(shopMapper.selectList(any())).thenReturn(List.of(shopRow(1L, CATEGORY_ID, "已有店A")));
|
||||||
when(productMapper.selectDistinctShopNames("旗", List.of("已有店A"), 200, null))
|
when(productMapper.selectDistinctShopNames("旗", List.of("已有店A"), 200))
|
||||||
.thenReturn(List.of("旗舷店"));
|
.thenReturn(List.of("旗舷店"));
|
||||||
|
|
||||||
assertEquals(List.of("旗舷店"),
|
assertEquals(List.of("旗舷店"),
|
||||||
service.availableShops(" 旗 ", CATEGORY_ID, null, null), "keyword trim 后下推;limit 缺省钳到 200");
|
service.availableShops(" 旗 ", CATEGORY_ID, null), "keyword trim 后下推;limit 缺省钳到 200");
|
||||||
|
|
||||||
// limit 钳制:500 请求 → 200(服务侧钳,mapper 不做第二次换算)。
|
// limit 钳制:500 请求 → 200(服务侧钳,mapper 不做第二次换算)。
|
||||||
service.availableShops(null, CATEGORY_ID, 500, null);
|
service.availableShops(null, CATEGORY_ID, 500);
|
||||||
verify(productMapper).selectDistinctShopNames(null, List.of("已有店A"), 200, null);
|
verify(productMapper).selectDistinctShopNames(null, List.of("已有店A"), 200);
|
||||||
|
|
||||||
// 不带排除分类:excludeNames 空清单(不生成 NOT IN);前两轮各查过一次名单表,共两次。
|
// 不带排除分类:excludeNames 空清单(不生成 NOT IN);前两轮各查过一次名单表,共两次。
|
||||||
when(productMapper.selectDistinctShopNames(null, List.of(), 50, null)).thenReturn(List.of("直接店"));
|
when(productMapper.selectDistinctShopNames(null, List.of(), 50)).thenReturn(List.of("直接店"));
|
||||||
assertEquals(List.of("直接店"), service.availableShops(null, null, 50, null));
|
assertEquals(List.of("直接店"), service.availableShops(null, null, 50));
|
||||||
verify(shopMapper, times(2)).selectList(any());
|
verify(shopMapper, times(2)).selectList(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+32
-39
@@ -81,16 +81,16 @@ class JdProductQueryServiceUserPageTest {
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** countProducts 的 14 个形参全 matcher(返回总数 1 行)。 */
|
/** countProducts 的 13 个形参全 matcher(返回总数 1 行)。 */
|
||||||
private void stubCount(long total) {
|
private void stubCount(long total) {
|
||||||
when(jdProductMapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(jdProductMapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||||
any(), any(), any(), any(), any(), any())).thenReturn(total);
|
any(), any(), any(), any(), any())).thenReturn(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** selectProductPage 的 16 个形参全 matcher。 */
|
/** selectProductPage 的 15 个形参全 matcher(含 offset/limit)。 */
|
||||||
private void stubPage(List<JdProductEntity> rows) {
|
private void stubPage(List<JdProductEntity> rows) {
|
||||||
when(jdProductMapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
when(jdProductMapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||||
any(), any(), any(), any(), any(), any(), org.mockito.ArgumentMatchers.anyLong(),
|
any(), any(), any(), any(), any(), org.mockito.ArgumentMatchers.anyLong(),
|
||||||
anyInt())).thenReturn(rows);
|
anyInt())).thenReturn(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,13 +99,13 @@ class JdProductQueryServiceUserPageTest {
|
|||||||
stubCount(1L);
|
stubCount(1L);
|
||||||
stubPage(List.of(product(11L)));
|
stubPage(List.of(product(11L)));
|
||||||
|
|
||||||
JdProductPageVo vo = service.pageInScope(List.of(11L, 12L), 2L, null, 1L, 20L);
|
JdProductPageVo vo = service.pageInScope(List.of(11L, 12L), null, 1L, 20L);
|
||||||
|
|
||||||
// 作用域全在 SQL 侧:可见组集合+公司进 mapper,owner_group_id 过滤由 XML 的 EXISTS 承担;
|
// 作用域全在 SQL 侧:可见组集合进 mapper,owner_group_id 过滤由 XML 的 EXISTS 承担;
|
||||||
// 这里恰好证明了「没有 user_id 条件」——旧实现按 user_id 过滤,同组同事采的商品恒 0 条。
|
// 这里恰好证明了「没有 user_id 条件」——旧实现按 user_id 过滤,同组同事采的商品恒 0 条。
|
||||||
verify(jdProductMapper).countProducts(isNull(), isNull(), isNull(), isNull(),
|
verify(jdProductMapper).countProducts(isNull(), isNull(), isNull(), isNull(),
|
||||||
eq(0L), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
eq(0L), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||||
eq(2L), eq(List.of(11L, 12L)));
|
eq(List.of(11L, 12L)));
|
||||||
assertThat(vo.getTotal()).isEqualTo(1L);
|
assertThat(vo.getTotal()).isEqualTo(1L);
|
||||||
assertThat(vo.getItems()).hasSize(1);
|
assertThat(vo.getItems()).hasSize(1);
|
||||||
assertThat(vo.getItems().get(0).getTitle()).isEqualTo("测试商品 11");
|
assertThat(vo.getItems().get(0).getTitle()).isEqualTo("测试商品 11");
|
||||||
@@ -117,27 +117,27 @@ class JdProductQueryServiceUserPageTest {
|
|||||||
void 分类过滤与可见组合成同一支谓词() {
|
void 分类过滤与可见组合成同一支谓词() {
|
||||||
stubCount(0L);
|
stubCount(0L);
|
||||||
|
|
||||||
JdProductPageVo vo = service.pageInScope(List.of(11L), 2L, 3L, 1L, 20L);
|
JdProductPageVo vo = service.pageInScope(List.of(11L), 3L, 1L, 20L);
|
||||||
|
|
||||||
verify(jdProductMapper).countProducts(isNull(), isNull(), isNull(), isNull(),
|
verify(jdProductMapper).countProducts(isNull(), isNull(), isNull(), isNull(),
|
||||||
eq(3L), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
eq(3L), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||||
eq(2L), eq(List.of(11L)));
|
eq(List.of(11L)));
|
||||||
assertThat(vo.getTotal()).isZero();
|
assertThat(vo.getTotal()).isZero();
|
||||||
assertThat(vo.getItems()).isEmpty();
|
assertThat(vo.getItems()).isEmpty();
|
||||||
verify(jdProductMapper, never()).selectProductPage(any(), any(), any(), any(), any(), any(),
|
verify(jdProductMapper, never()).selectProductPage(any(), any(), any(), any(), any(), any(),
|
||||||
any(), any(), any(), any(), any(), any(), any(), any(),
|
any(), any(), any(), any(), any(), any(), any(),
|
||||||
org.mockito.ArgumentMatchers.anyLong(), anyInt());
|
org.mockito.ArgumentMatchers.anyLong(), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 可见分组为空直接回空页不查主表() {
|
void 可见分组为空直接回空页不查主表() {
|
||||||
JdProductPageVo vo = service.pageInScope(List.of(), 2L, 3L, 1L, 20L);
|
JdProductPageVo vo = service.pageInScope(List.of(), 3L, 1L, 20L);
|
||||||
assertThat(vo.getTotal()).isZero();
|
assertThat(vo.getTotal()).isZero();
|
||||||
assertThat(vo.getItems()).isEmpty();
|
assertThat(vo.getItems()).isEmpty();
|
||||||
verify(jdProductMapper, never()).countProducts(any(), any(), any(), any(), any(), any(),
|
verify(jdProductMapper, never()).countProducts(any(), any(), any(), any(), any(), any(),
|
||||||
any(), any(), any(), any(), any(), any(), any(), any());
|
any(), any(), any(), any(), any(), any(), any());
|
||||||
|
|
||||||
JdProductPageVo nullScope = service.pageInScope(null, 2L, 3L, 1L, 20L);
|
JdProductPageVo nullScope = service.pageInScope(null, 3L, 1L, 20L);
|
||||||
assertThat(nullScope.getTotal()).as("作用域解析不出(null)同样回空页,不给全平台")
|
assertThat(nullScope.getTotal()).as("作用域解析不出(null)同样回空页,不给全平台")
|
||||||
.isZero();
|
.isZero();
|
||||||
}
|
}
|
||||||
@@ -146,51 +146,44 @@ class JdProductQueryServiceUserPageTest {
|
|||||||
void 页码页宽钳制_离谱页码不喂负下标() {
|
void 页码页宽钳制_离谱页码不喂负下标() {
|
||||||
stubCount(0L);
|
stubCount(0L);
|
||||||
|
|
||||||
JdProductPageVo zero = service.pageInScope(List.of(11L), 2L, null, 0L, 5000L);
|
JdProductPageVo zero = service.pageInScope(List.of(11L), null, 0L, 5000L);
|
||||||
assertThat(zero.getPage()).as("页码下限钳到 1").isEqualTo(1L);
|
assertThat(zero.getPage()).as("页码下限钳到 1").isEqualTo(1L);
|
||||||
assertThat(zero.getPageSize()).as("页宽上限钳到 1000(v1.7 对齐原型档位放宽,与后管只读页同出口)")
|
assertThat(zero.getPageSize()).as("页宽上限钳到 1000(v1.7 对齐原型档位放宽,与后管只读页同出口)")
|
||||||
.isEqualTo(1000L);
|
.isEqualTo(1000L);
|
||||||
|
|
||||||
JdProductPageVo huge = service.pageInScope(List.of(11L), 2L, null, Long.MAX_VALUE, 20L);
|
JdProductPageVo huge = service.pageInScope(List.of(11L), null, Long.MAX_VALUE, 20L);
|
||||||
assertThat(huge.getPage()).as("页码上限钳到 10000(乘积不溢出,铁律 15 同形)").isEqualTo(10000L);
|
assertThat(huge.getPage()).as("页码上限钳到 10000(乘积不溢出,铁律 15 同形)").isEqualTo(10000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公司隔离(2026-11-23 客户口径「公司与公司之间不能互看」):详情按行 company_id 校验,
|
* 2026-11-26 客户口径「采集的数据…大家一起采集」:商品行是全平台共享池,详情<b>不按公司过滤</b>——
|
||||||
* 别公司的行按「商品不存在」拒绝(不 403,不泄露行是否存在);平台超管(null)不限。
|
* 别公司采的行本账号同样能看到明细(2026-11-23 的按行 company_id 校验整批撤销)。
|
||||||
|
* 「分类后的数据各看各的」由 V203 归属行承担({@code fillCategory} 按当前分组取),不靠藏行。
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void 详情跨公司按商品不存在拒绝_本公司放行() {
|
void 详情不按公司过滤_别公司行同样可见() {
|
||||||
JdProductEntity row = product(31L);
|
JdProductEntity row = product(31L);
|
||||||
row.setCompanyId(5L);
|
row.setCompanyId(5L);
|
||||||
when(jdProductMapper.selectById(31L)).thenReturn(row);
|
when(jdProductMapper.selectById(31L)).thenReturn(row);
|
||||||
when(jdProductImageMapper.selectList(any())).thenReturn(List.of());
|
when(jdProductImageMapper.selectList(any())).thenReturn(List.of());
|
||||||
when(jdProductSkuMapper.selectList(any())).thenReturn(List.of());
|
when(jdProductSkuMapper.selectList(any())).thenReturn(List.of());
|
||||||
|
|
||||||
assertThat(service.detail(31L, null, 5L).getId()).as("本公司行正常返回").isEqualTo(31L);
|
assertThat(service.detail(31L, null).getId()).as("本公司行正常返回").isEqualTo(31L);
|
||||||
assertThat(service.detail(31L, null, null).getId()).as("平台超管不限公司").isEqualTo(31L);
|
assertThat(service.detail(31L, 99L).getId())
|
||||||
org.junit.jupiter.api.Assertions.assertThrows(
|
.as("别公司采集的行同样可见(全平台共享池),分类列按当前分组取").isEqualTo(31L);
|
||||||
com.nanri.aiimage.common.exception.BusinessException.class,
|
|
||||||
() -> service.detail(31L, null, 6L),
|
|
||||||
"别公司的行必须按「商品不存在」拒绝(不是 403,不泄露存在性)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写侧行级公司闸:请求 id 里只要有一行不属于作用域公司就整批拒绝;平台超管(null)不限。
|
* 写侧没有行级公司闸(2026-11-26):删/改/传图/归类的权限只由控制器的超管档写闸
|
||||||
* 读侧藏起来的行仍然能删=静默删除,不是隔离——编辑/传图/删除/批量删除/归类都走这一道。
|
* ({@code requireJdProductWrite})承担——「只有管理员能操作这些数据」。
|
||||||
|
* 这条钉的是「别再长出第二套按行公司过滤」:服务层对任意 company_id 的行一视同仁。
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void 写侧行级公司闸_跨公司整批拒绝_本公司与平台超管放行() {
|
void 写侧不设行级公司闸_权限只在控制器超管档() {
|
||||||
JdProductEntity own = product(41L);
|
assertThat(java.util.Arrays.stream(JdProductQueryService.class.getDeclaredMethods())
|
||||||
own.setCompanyId(5L);
|
.noneMatch(m -> m.getName().toLowerCase().contains("incompany")
|
||||||
when(jdProductMapper.selectBatchIds(List.of(41L))).thenReturn(List.of(own));
|
|| m.getName().toLowerCase().contains("rowsincompany")))
|
||||||
|
.as("服务层不得有按行公司校验的方法(2026-11-26 撤销公司隔离)").isTrue();
|
||||||
service.assertRowsInCompany(List.of(41L), 5L);
|
|
||||||
service.assertRowsInCompany(List.of(41L), null);
|
|
||||||
org.junit.jupiter.api.Assertions.assertThrows(
|
|
||||||
com.nanri.aiimage.common.exception.BusinessException.class,
|
|
||||||
() -> service.assertRowsInCompany(List.of(41L), 6L),
|
|
||||||
"别公司的行必须整批拒绝(静默删掉别家数据比报错更糟)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -203,14 +196,14 @@ class JdProductQueryServiceUserPageTest {
|
|||||||
when(jdProductImageMapper.selectList(any())).thenReturn(List.of());
|
when(jdProductImageMapper.selectList(any())).thenReturn(List.of());
|
||||||
when(jdProductSkuMapper.selectList(any())).thenReturn(List.of());
|
when(jdProductSkuMapper.selectList(any())).thenReturn(List.of());
|
||||||
|
|
||||||
com.nanri.aiimage.modules.jd.model.vo.JdProductDetailVo detail = service.detail(21L, null, null);
|
com.nanri.aiimage.modules.jd.model.vo.JdProductDetailVo detail = service.detail(21L, null);
|
||||||
assertThat(detail.getManualLocked()).as("详情 VO 带回人工锁").isEqualTo(1);
|
assertThat(detail.getManualLocked()).as("详情 VO 带回人工锁").isEqualTo(1);
|
||||||
|
|
||||||
JdProductEntity listRow = product(22L);
|
JdProductEntity listRow = product(22L);
|
||||||
listRow.setManualLocked(1);
|
listRow.setManualLocked(1);
|
||||||
stubCount(1L);
|
stubCount(1L);
|
||||||
stubPage(List.of(listRow));
|
stubPage(List.of(listRow));
|
||||||
JdProductPageVo page = service.pageInScope(List.of(11L), 2L, 3L, 1L, 20L);
|
JdProductPageVo page = service.pageInScope(List.of(11L), 3L, 1L, 20L);
|
||||||
assertThat(page.getItems().get(0).getManualLocked()).as("列表 VO 带回人工锁").isEqualTo(1);
|
assertThat(page.getItems().get(0).getManualLocked()).as("列表 VO 带回人工锁").isEqualTo(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user