feat(jd): 京东数据库公共化——数据不区分公司、分组全平台一份(2026-11-15 用户定案)
This commit is contained in:
@@ -63,7 +63,9 @@ export const COMPANY_SCOPED_PAGES: readonly CompanyScopedPage[] = [
|
|||||||
// 外观专利无侵权数据(2026-11-10 v1.3):出表成功自动同步的只读明细,归属物化在行 company_id 列
|
// 外观专利无侵权数据(2026-11-10 v1.3):出表成功自动同步的只读明细,归属物化在行 company_id 列
|
||||||
// (V189,同店铺密钥形状)⇒ 后端正门 readCompanyIdOrOwn(超管显式传才收窄,非超管强制本公司)。
|
// (V189,同店铺密钥形状)⇒ 后端正门 readCompanyIdOrOwn(超管显式传才收窄,非超管强制本公司)。
|
||||||
{ menuKey: 'admin_appearance_patent_clean_items', apiFiles: ['src/pages/patent/appearance-patent-clean-api.ts'], pageFiles: ['src/pages/patent/AppearancePatentCleanItemsPage.vue'] },
|
{ menuKey: 'admin_appearance_patent_clean_items', apiFiles: ['src/pages/patent/appearance-patent-clean-api.ts'], pageFiles: ['src/pages/patent/AppearancePatentCleanItemsPage.vue'] },
|
||||||
// 京东数据库(2026-11-14 v1.4):京麦店铺商品采集落库的只读镜像,归属物化在行 company_id 列
|
// 京东数据库(2026-11-14 v1.4;2026-11-15 公共化改口径):京麦店铺商品采集落库的只读镜像,
|
||||||
// (V193,同外观专利 V189 形状)⇒ 后端正门 readCompanyIdOrOwn(超管显式传才收窄,非超管强制本公司)。
|
// 行 company_id 只剩"哪家公司客户端同步的"来源标记。数据公共(用户定案「不区分公司、属于
|
||||||
|
// 公共的」):详情/编辑/删除/分组管理不带公司维度;留在注册表里的理由是超管的公司 tab 筛选
|
||||||
|
// (=筛选管理员)仍作用于只读列表与类目下拉两个发送口,非超管没有这个筛选、看同一份全量。
|
||||||
{ menuKey: 'admin_jd_database', apiFiles: ['src/pages/jd/jd-product-api.ts'], pageFiles: ['src/pages/jd/JdDatabasePage.vue'] },
|
{ menuKey: 'admin_jd_database', apiFiles: ['src/pages/jd/jd-product-api.ts'], pageFiles: ['src/pages/jd/JdDatabasePage.vue'] },
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 京东数据库页(v1.4 Phase 5):公司隔离的京东商品库,筛选行(店铺/商品编码/标题关键字/
|
/** 京东数据库页(v1.4 Phase 5):公共的京东商品库(2026-11-15 用户定案「不区分公司、属于
|
||||||
* 分组/同步起止 date 对)+查询/重置/管理分组 + 自绘明细表(勾选列+点行开详情抽屉)
|
* 公共的」,分组同亚马逊口径全平台一份),筛选行(店铺/商品编码/标题关键字/分组/类目/
|
||||||
|
* 同步起止 date 对)+查询/重置/管理分组 + 自绘明细表(勾选列+点行开详情抽屉)
|
||||||
* + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。
|
* + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。
|
||||||
|
* 公司维度只剩超管的公司 tab(=筛选管理员,非超管没有这个筛选、看到同一份公共全量);
|
||||||
* 列表按京麦商品列表样式(2026-11-15 用户口径):店铺/分组前置为第 1/2 列;商品信息列=京麦同款
|
* 列表按京麦商品列表样式(2026-11-15 用户口径):店铺/分组前置为第 1/2 列;商品信息列=京麦同款
|
||||||
* 合并布局(主图+图下信息分+标题两行+商品编码/货号+SKU 数标签,编码带一键复制);类目/上架
|
* 合并布局(主图+图下信息分+标题两行+商品编码/货号+SKU 数标签,编码带一键复制);类目/上架
|
||||||
* 时间/京东创建/修改时间仍收详情抽屉基本信息(B104「详情显示全部属性」口径不变)。
|
* 时间/京东创建/修改时间仍收详情抽屉基本信息(B104「详情显示全部属性」口径不变)。
|
||||||
* 商品状态筛选框/列与导出按钮随 2026-11-15 客户口径「这两个不要/导出也不用」从前端下线
|
* 商品状态筛选框/列与导出按钮随 2026-11-15 客户口径「这两个不要/导出也不用」从前端下线
|
||||||
* (后端 sale_status 参数与 /export 端点保留;状态仍收详情抽屉)。
|
* (后端 sale_status 参数与 /export 端点保留;状态仍收详情抽屉)。
|
||||||
* 骨架像素复刻「外观专利数据库」页(panel-box + LoadFailureBar + 自绘 table + 旧式分页);
|
* 骨架像素复刻「外观专利数据库」页(panel-box + LoadFailureBar + 自绘 table + 旧式分页);
|
||||||
* 公司 tab 切换=清筛选重取(watch 体照外观专利页逐字形状);日期对护栏:起侧 max=止侧、
|
* 超管切公司 tab = 清筛选重取(watch 体照外观专利页逐字形状);日期对护栏:起侧 max=止侧、
|
||||||
* 止侧 min=起侧、两侧 @change 用 orderedPair 把倒挂交换回来(clampJdSyncedRange 照 clampDatePair)。
|
* 止侧 min=起侧、两侧 @change 用 orderedPair 把倒挂交换回来(clampJdSyncedRange 照 clampDatePair)。
|
||||||
* 日期初值故意留空:同步数据是累计集,默认当天会让首屏只剩今天同步的行
|
* 日期初值故意留空:同步数据是累计集,默认当天会让首屏只剩今天同步的行
|
||||||
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
|
||||||
@@ -44,9 +46,11 @@ const total = ref(0)
|
|||||||
const page = ref(1)
|
const page = ref(1)
|
||||||
const pageSize = ref(20)
|
const pageSize = ref(20)
|
||||||
const filter = reactive(createJdProductFilterState())
|
const filter = reactive(createJdProductFilterState())
|
||||||
/** 分组下拉选项:公司 tab 切换时重取;选项失败不拦列表,只回空下拉(可见「全部分组」)。 */
|
/** 分组下拉选项:分组全平台一份(公共),进页取一次即可;选项失败不拦列表,只回空下拉
|
||||||
|
* (可见「全部分组」)。 */
|
||||||
const groupOptions = ref<JdProductGroup[]>([])
|
const groupOptions = ref<JdProductGroup[]>([])
|
||||||
/** 类目下拉选项(京麦末级类目):同分组口径——公司隔离取数、失败静默回空。 */
|
/** 类目下拉选项(京麦末级类目):与当前行集同源(超管切公司 tab 时按 tab 收窄重取、
|
||||||
|
* 普通行集全量);失败静默回空。 */
|
||||||
const categoryOptions = ref<JdProductCategoryOption[]>([])
|
const categoryOptions = ref<JdProductCategoryOption[]>([])
|
||||||
/** 分组管理弹窗与详情抽屉。 */
|
/** 分组管理弹窗与详情抽屉。 */
|
||||||
const groupDialogVisible = ref(false)
|
const groupDialogVisible = ref(false)
|
||||||
@@ -84,7 +88,7 @@ const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.v
|
|||||||
/** 分组选项失败静默回空——分组只是筛选项,不该让它把首屏行集一起拖死。 */
|
/** 分组选项失败静默回空——分组只是筛选项,不该让它把首屏行集一起拖死。 */
|
||||||
async function loadGroupOptions(): Promise<void> {
|
async function loadGroupOptions(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
groupOptions.value = await fetchJdProductGroups(companyTab.requestCompanyId)
|
groupOptions.value = await fetchJdProductGroups()
|
||||||
} catch {
|
} catch {
|
||||||
groupOptions.value = []
|
groupOptions.value = []
|
||||||
}
|
}
|
||||||
@@ -219,7 +223,7 @@ async function removeMany(picked: JdProductItem[], message: string): Promise<voi
|
|||||||
if (!ok) return
|
if (!ok) return
|
||||||
deleting.value = true
|
deleting.value = true
|
||||||
try {
|
try {
|
||||||
const receipt = await deleteJdProducts(picked.map((row) => row.id), companyTab.requestCompanyId)
|
const receipt = await deleteJdProducts(picked.map((row) => row.id))
|
||||||
showAdminFeedback(`已删除 ${receipt.deleted} 个商品,清理 ${receipt.objectsDeleted} 个图片文件` +
|
showAdminFeedback(`已删除 ${receipt.deleted} 个商品,清理 ${receipt.objectsDeleted} 个图片文件` +
|
||||||
(receipt.objectsKept ? `(${receipt.objectsKept} 个共用图片保留)` : ''), 'success')
|
(receipt.objectsKept ? `(${receipt.objectsKept} 个共用图片保留)` : ''), 'success')
|
||||||
selectedIds.value = new Set()
|
selectedIds.value = new Set()
|
||||||
@@ -233,9 +237,10 @@ async function removeMany(picked: JdProductItem[], message: string): Promise<voi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切公司 = 重新取数:店铺/编码/关键字/类目/分组是上一家选中的值,在新一家的行集里筛不出东西,
|
// 超管切公司 tab = 重新取数:店铺/编码/关键字/类目/日期是按行集筛的自由值,在另一家的
|
||||||
// 必须一起清,分组/类目选项也按新公司重取(选项集是公司隔离的)。
|
// 行集里筛不出东西,必须一起清(分组全平台一份,groupId 与公司维度正交、不清);
|
||||||
watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void loadCategoryOptions(); void load() })
|
// 类目选项与行集同源,按新 tab 重取;分组选项是全局的、进页取一次即可。
|
||||||
|
watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadCategoryOptions(); void load() })
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
void loadGroupOptions()
|
void loadGroupOptions()
|
||||||
@@ -389,19 +394,16 @@ onMounted(() => {
|
|||||||
<JdProductDetailDrawer
|
<JdProductDetailDrawer
|
||||||
:item="detailItem"
|
:item="detailItem"
|
||||||
:visible="detailVisible"
|
:visible="detailVisible"
|
||||||
:company-id="companyTab.requestCompanyId"
|
|
||||||
@close="closeDetail"
|
@close="closeDetail"
|
||||||
/>
|
/>
|
||||||
<JdProductEditDrawer
|
<JdProductEditDrawer
|
||||||
:item="editItem"
|
:item="editItem"
|
||||||
:visible="editVisible"
|
:visible="editVisible"
|
||||||
:company-id="companyTab.requestCompanyId"
|
|
||||||
@close="closeEdit"
|
@close="closeEdit"
|
||||||
@saved="onEditSaved"
|
@saved="onEditSaved"
|
||||||
/>
|
/>
|
||||||
<JdProductGroupDialog
|
<JdProductGroupDialog
|
||||||
:visible="groupDialogVisible"
|
:visible="groupDialogVisible"
|
||||||
:company-id="companyTab.requestCompanyId"
|
|
||||||
@close="groupDialogVisible = false"
|
@close="groupDialogVisible = false"
|
||||||
@changed="onGroupChanged"
|
@changed="onGroupChanged"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* 基本信息=商品全部字段(B104:列表只摆部分字段,类目/信息分/SKU 数/上架时间/京东创建/
|
* 基本信息=商品全部字段(B104:列表只摆部分字段,类目/信息分/SKU 数/上架时间/京东创建/
|
||||||
* 修改时间/店铺/分组都在这里看)。
|
* 修改时间/店铺/分组都在这里看)。
|
||||||
* 图片点击放大预览用自绘 modal-mask(先例:RecordsHistoryPage 的 thumb + modal-mask +
|
* 图片点击放大预览用自绘 modal-mask(先例:RecordsHistoryPage 的 thumb + modal-mask +
|
||||||
* 原图新标签;不用 element-plus)。数据由本组件按 (id, companyId) 自取,失败条内提示可重试。 */
|
* 原图新标签;不用 element-plus)。数据由本组件按 id 自取(公共库无公司维度),失败条内提示可重试。 */
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import { fetchJdProductDetail } from './jd-product-api.ts'
|
import { fetchJdProductDetail } from './jd-product-api.ts'
|
||||||
import type {
|
import type {
|
||||||
@@ -20,7 +20,6 @@ import { requestErrorMessage } from '../../api/envelope.ts'
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
item: JdProductItem | null
|
item: JdProductItem | null
|
||||||
visible: boolean
|
visible: boolean
|
||||||
companyId: number | null
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{ (event: 'close'): void }>()
|
const emit = defineEmits<{ (event: 'close'): void }>()
|
||||||
@@ -82,7 +81,7 @@ async function loadDetail(): Promise<void> {
|
|||||||
skus.value = []
|
skus.value = []
|
||||||
attrJsonRaw.value = ''
|
attrJsonRaw.value = ''
|
||||||
try {
|
try {
|
||||||
const detail = await fetchJdProductDetail(item.id, props.companyId)
|
const detail = await fetchJdProductDetail(item.id)
|
||||||
attrGroups.value = detail.attrGroups
|
attrGroups.value = detail.attrGroups
|
||||||
images.value = detail.images
|
images.value = detail.images
|
||||||
skus.value = detail.skus
|
skus.value = detail.skus
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
item: JdProductItem | null
|
item: JdProductItem | null
|
||||||
visible: boolean
|
visible: boolean
|
||||||
companyId: number | null
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'saved'): void }>()
|
const emit = defineEmits<{ (event: 'close'): void; (event: 'saved'): void }>()
|
||||||
@@ -97,8 +96,8 @@ async function loadDetail(): Promise<void> {
|
|||||||
saveError.value = ''
|
saveError.value = ''
|
||||||
try {
|
try {
|
||||||
const [detail, groups] = await Promise.all([
|
const [detail, groups] = await Promise.all([
|
||||||
fetchJdProductDetail(item.id, props.companyId),
|
fetchJdProductDetail(item.id),
|
||||||
fetchJdProductGroups(props.companyId).catch(() => [] as JdProductGroup[]),
|
fetchJdProductGroups().catch(() => [] as JdProductGroup[]),
|
||||||
])
|
])
|
||||||
groupOptions.value = groups
|
groupOptions.value = groups
|
||||||
const row = detail.item
|
const row = detail.item
|
||||||
@@ -172,7 +171,7 @@ async function save(): Promise<void> {
|
|||||||
}))
|
}))
|
||||||
: null,
|
: null,
|
||||||
deleteImageIds: deleteImageIds.value.size ? [...deleteImageIds.value] : null,
|
deleteImageIds: deleteImageIds.value.size ? [...deleteImageIds.value] : null,
|
||||||
}, props.companyId)
|
})
|
||||||
// 保存成功:用返回的刷新详情直接回填(图片行集已扣掉删掉的行、计数已刷新)。
|
// 保存成功:用返回的刷新详情直接回填(图片行集已扣掉删掉的行、计数已刷新)。
|
||||||
form.value.title = detail.item.title
|
form.value.title = detail.item.title
|
||||||
form.value.brand = detail.item.brand
|
form.value.brand = detail.item.brand
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { requestErrorMessage } from '../../api/envelope.ts'
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
visible: boolean
|
visible: boolean
|
||||||
companyId: number | null
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void }>()
|
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void }>()
|
||||||
@@ -38,7 +37,7 @@ async function loadGroups(): Promise<void> {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
errorText.value = ''
|
errorText.value = ''
|
||||||
try {
|
try {
|
||||||
groups.value = await fetchJdProductGroups(props.companyId)
|
groups.value = await fetchJdProductGroups()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorText.value = requestErrorMessage(error) || '分组列表加载失败'
|
errorText.value = requestErrorMessage(error) || '分组列表加载失败'
|
||||||
groups.value = []
|
groups.value = []
|
||||||
@@ -57,10 +56,10 @@ async function submitCreate(): Promise<void> {
|
|||||||
creating.value = true
|
creating.value = true
|
||||||
errorText.value = ''
|
errorText.value = ''
|
||||||
try {
|
try {
|
||||||
await createJdProductGroup({ name, sortOrder: Math.floor(createSortOrder.value) || 0 }, props.companyId)
|
await createJdProductGroup({ name, sortOrder: Math.floor(createSortOrder.value) || 0 })
|
||||||
createName.value = ''
|
createName.value = ''
|
||||||
createSortOrder.value = 0
|
createSortOrder.value = 0
|
||||||
groups.value = sortGroups(await fetchJdProductGroups(props.companyId))
|
groups.value = sortGroups(await fetchJdProductGroups())
|
||||||
emit('changed')
|
emit('changed')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorText.value = requestErrorMessage(error) || '新建分组失败'
|
errorText.value = requestErrorMessage(error) || '新建分组失败'
|
||||||
@@ -86,9 +85,9 @@ async function submitRename(group: JdProductGroup): Promise<void> {
|
|||||||
saving.value = true
|
saving.value = true
|
||||||
errorText.value = ''
|
errorText.value = ''
|
||||||
try {
|
try {
|
||||||
await updateJdProductGroup(group.id, { name, sortOrder: group.sortOrder }, props.companyId)
|
await updateJdProductGroup(group.id, { name, sortOrder: group.sortOrder })
|
||||||
cancelRename()
|
cancelRename()
|
||||||
groups.value = sortGroups(await fetchJdProductGroups(props.companyId))
|
groups.value = sortGroups(await fetchJdProductGroups())
|
||||||
emit('changed')
|
emit('changed')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorText.value = requestErrorMessage(error) || '改名失败'
|
errorText.value = requestErrorMessage(error) || '改名失败'
|
||||||
@@ -103,8 +102,8 @@ async function removeGroup(group: JdProductGroup): Promise<void> {
|
|||||||
saving.value = true
|
saving.value = true
|
||||||
errorText.value = ''
|
errorText.value = ''
|
||||||
try {
|
try {
|
||||||
await deleteJdProductGroup(group.id, props.companyId)
|
await deleteJdProductGroup(group.id)
|
||||||
groups.value = sortGroups(await fetchJdProductGroups(props.companyId))
|
groups.value = sortGroups(await fetchJdProductGroups())
|
||||||
emit('changed')
|
emit('changed')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorText.value = requestErrorMessage(error) || '删除分组失败'
|
errorText.value = requestErrorMessage(error) || '删除分组失败'
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
/** 京东数据库查询适配(v1.4 Phase 5):GET /api/admin/jd-products + 删除(DELETE /{id} +
|
/** 京东数据库查询适配(v1.4 Phase 5):GET /api/admin/jd-products + 删除(DELETE /{id} +
|
||||||
* POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
|
* POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
|
||||||
* 只读列表+删除+分组管理:公司 tab 的值由本发送口从原始入参自己下传
|
* 公司口径(2026-11-15 用户定案「京东数据库不区分公司、属于公共的」):公共库只有两个
|
||||||
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。
|
* 公司维度出口——只读列表与类目下拉把公司 tab 的值下传(仅超管生效=筛选管理员);
|
||||||
* 导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export 端点保留)。 */
|
* 详情/编辑/删除/分组管理全平台一份,不收 company_id(后端写侧也没有公司维度)。
|
||||||
|
* 取值口形状由 company-tab-wiring 护栏钉住。导出发送口已随 2026-11-15 客户口径
|
||||||
|
* 「导出也不用」从前端下线(后端 /export 端点保留)。 */
|
||||||
import { http } from '@/api/http'
|
import { http } from '@/api/http'
|
||||||
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
||||||
import {
|
import {
|
||||||
@@ -39,14 +41,12 @@ export async function fetchJdProductList(
|
|||||||
return parseJdProductPage(data)
|
return parseJdProductPage(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 详情:GET /api/admin/jd-products/{id}(信封 data=主字段 + attrGroups + attrJsonRaw + images)。 */
|
/** 详情:GET /api/admin/jd-products/{id}(信封 data=主字段 + attrGroups + attrJsonRaw + images)。
|
||||||
|
* 公共库无公司维度,按 id 直取。 */
|
||||||
export async function fetchJdProductDetail(
|
export async function fetchJdProductDetail(
|
||||||
id: number,
|
id: number,
|
||||||
companyId: number | null,
|
|
||||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||||
const query: Record<string, number> = {}
|
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`)
|
||||||
if (companyId != null) query.company_id = companyId
|
|
||||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, { params: query })
|
|
||||||
return parseJdProductDetail(data)
|
return parseJdProductDetail(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,18 +59,16 @@ export interface JdProductDeleteResult {
|
|||||||
objectsSkipped: number
|
objectsSkipped: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除是先删桶、全成功才删库行(后端 JdProductDeleteService);失败文案原样抛给页面。 */
|
/** 删除是先删桶、全成功才删库行(后端 JdProductDeleteService);失败文案原样抛给页面。
|
||||||
|
* 公共库写侧无公司维度(2026-11-15 用户定案)。 */
|
||||||
export async function deleteJdProducts(
|
export async function deleteJdProducts(
|
||||||
ids: number[],
|
ids: number[],
|
||||||
companyId: number | null,
|
|
||||||
): Promise<JdProductDeleteResult> {
|
): Promise<JdProductDeleteResult> {
|
||||||
const query: Record<string, number> = {}
|
|
||||||
if (companyId != null) query.company_id = companyId
|
|
||||||
if (ids.length === 1) {
|
if (ids.length === 1) {
|
||||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_ENDPOINT}/${ids[0]}`, { params: query })
|
const { data } = await http.delete<unknown>(`${JD_PRODUCT_ENDPOINT}/${ids[0]}`)
|
||||||
return unwrap<JdProductDeleteResult>(data)
|
return unwrap<JdProductDeleteResult>(data)
|
||||||
}
|
}
|
||||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-delete`, { ids }, { params: query })
|
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-delete`, { ids })
|
||||||
return unwrap<JdProductDeleteResult>(data)
|
return unwrap<JdProductDeleteResult>(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,17 +90,14 @@ export interface JdProductUpdatePayload {
|
|||||||
deleteImageIds: number[] | null
|
deleteImageIds: number[] | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑保存(PUT + company_id 作 query,照 deleteJdProducts 形状):主字段保存即置
|
/** 编辑保存(PUT):主字段保存即置人工编辑锁(V199 manual_locked=1,后续采集不再覆盖该行);
|
||||||
* 人工编辑锁(V199 manual_locked=1,后续采集不再覆盖该行);失败文案原样抛给抽屉红条。
|
* 失败文案原样抛给抽屉红条。公共库写侧无公司维度。返回刷新后的详情(与
|
||||||
* 返回刷新后的详情(与 fetchJdProductDetail 同一信封),抽屉用它回填。 */
|
* fetchJdProductDetail 同一信封),抽屉用它回填。 */
|
||||||
export async function updateJdProduct(
|
export async function updateJdProduct(
|
||||||
id: number,
|
id: number,
|
||||||
payload: JdProductUpdatePayload,
|
payload: JdProductUpdatePayload,
|
||||||
companyId: number | null,
|
|
||||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||||
const query: Record<string, number> = {}
|
const { data } = await http.put<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, payload)
|
||||||
if (companyId != null) query.company_id = companyId
|
|
||||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, payload, { params: query })
|
|
||||||
return parseJdProductDetail(data)
|
return parseJdProductDetail(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,11 +128,10 @@ function numberOr(value: unknown, fallback: number): number {
|
|||||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : fallback
|
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 分组下拉/管理列表;失败由页面自己兜(分组只是筛选项,不拦首屏行集)。 */
|
/** 分组下拉/管理列表(分组 2026-11-15 起全平台一份,不带公司维度);失败由页面自己兜
|
||||||
export async function fetchJdProductGroups(companyId: number | null): Promise<JdProductGroup[]> {
|
* (分组只是筛选项,不拦首屏行集)。 */
|
||||||
const query: Record<string, number> = {}
|
export async function fetchJdProductGroups(): Promise<JdProductGroup[]> {
|
||||||
if (companyId != null) query.company_id = companyId
|
const { data } = await http.get<unknown>(JD_PRODUCT_GROUP_ENDPOINT)
|
||||||
const { data } = await http.get<unknown>(JD_PRODUCT_GROUP_ENDPOINT, { params: query })
|
|
||||||
const core = unwrap<unknown>(data)
|
const core = unwrap<unknown>(data)
|
||||||
if (!Array.isArray(core)) return []
|
if (!Array.isArray(core)) return []
|
||||||
const out: JdProductGroup[] = []
|
const out: JdProductGroup[] = []
|
||||||
@@ -182,13 +176,11 @@ export async function fetchJdProductCategories(
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 新建分组;重名等业务失败把后端中文文案抛回(页面直接展示)。 */
|
/** 新建分组(公共库无公司维度);重名等业务失败把后端中文文案抛回(页面直接展示)。 */
|
||||||
export async function createJdProductGroup(
|
export async function createJdProductGroup(
|
||||||
payload: JdProductGroupPayload,
|
payload: JdProductGroupPayload,
|
||||||
companyId: number | null,
|
|
||||||
): Promise<JdProductGroup | null> {
|
): Promise<JdProductGroup | null> {
|
||||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||||
if (companyId != null) body.company_id = companyId
|
|
||||||
const { data } = await http.post<unknown>(JD_PRODUCT_GROUP_ENDPOINT, body)
|
const { data } = await http.post<unknown>(JD_PRODUCT_GROUP_ENDPOINT, body)
|
||||||
return groupDataOf<JdProductGroup | null>(data)
|
return groupDataOf<JdProductGroup | null>(data)
|
||||||
}
|
}
|
||||||
@@ -197,18 +189,14 @@ export async function createJdProductGroup(
|
|||||||
export async function updateJdProductGroup(
|
export async function updateJdProductGroup(
|
||||||
id: number,
|
id: number,
|
||||||
payload: JdProductGroupPayload,
|
payload: JdProductGroupPayload,
|
||||||
companyId: number | null,
|
|
||||||
): Promise<JdProductGroup | null> {
|
): Promise<JdProductGroup | null> {
|
||||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||||
if (companyId != null) body.company_id = companyId
|
|
||||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, body)
|
const { data } = await http.put<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, body)
|
||||||
return groupDataOf<JdProductGroup | null>(data)
|
return groupDataOf<JdProductGroup | null>(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除分组;业务失败文案同上。 */
|
/** 删除分组;业务失败文案同上。 */
|
||||||
export async function deleteJdProductGroup(id: number, companyId: number | null): Promise<void> {
|
export async function deleteJdProductGroup(id: number): Promise<void> {
|
||||||
const query: Record<string, number> = {}
|
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`)
|
||||||
if (companyId != null) query.company_id = companyId
|
|
||||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, { params: query })
|
|
||||||
groupDataOf<unknown>(data)
|
groupDataOf<unknown>(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,20 +132,15 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
|
|||||||
// 500 够得着自己、够不到隔壁(对平用例逐处从真文件重算,注释过期即红)。
|
// 500 够得着自己、够不到隔壁(对平用例逐处从真文件重算,注释过期即红)。
|
||||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items 无侵权只读列表' },
|
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items 无侵权只读列表' },
|
||||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'exportAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/export 导出(2026-11-11 客户需求「数据得导出来」,与列表共用同一过滤面)' },
|
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'exportAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/export 导出(2026-11-11 客户需求「数据得导出来」,与列表共用同一过滤面)' },
|
||||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):京麦店铺商品采集落库的只读镜像,归属物化在行
|
// ↓ 批次 8(2026-11-14 v1.4 京东数据库;2026-11-15 公共化改口径):京麦店铺商品采集落库的
|
||||||
// company_id 列(V193,同外观专利 V189 形状)⇒ 后端正门 readCompanyIdOrOwn。
|
// 只读镜像,行 company_id 只剩"哪家公司客户端同步的"来源标记。2026-11-15 用户定案
|
||||||
// 导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export 端点保留,
|
// 「京东数据库不区分公司、属于公共的」「分组和亚马逊功能一样」⇒ 详情/编辑/删除/分组管理
|
||||||
// 前端发送口撤,重上时从 git 历史找回发送行再登记——同批次 7 主管两口的先例)。
|
// 的 6 个 company_id 发送口整批撤下(后端写侧同窗摘掉公司谓词,重上时从 git 历史找回);
|
||||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /jd-products 京东数据库只读列表' },
|
// 留下的两个公司维度出口=只读列表与类目下拉(仅超管生效=筛选管理员,普通管理员没有
|
||||||
// ↓ 同文件其余 6 个发送口(payload 形签名,塞键行与列表口不同形):详情/删除/分组列表/
|
// 这个筛选)。导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export
|
||||||
// 类目列表/删分组都在 2026-11-14 v1.4 就带 company_id 下传,编辑口(2026-11-15 行级编辑,
|
// 端点保留,前端发送口撤,重上时从 git 历史找回发送行再登记——同批次 7 主管两口的先例)。
|
||||||
// PUT 保存、V199 人工编辑锁)同形状——6 处塞键行逐字同行走一组,一函数一钉对平。
|
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /jd-products 京东数据库只读列表(超管公司 tab 筛选=筛选管理员)' },
|
||||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductDetail', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-products/{id} 详情抽屉取数' },
|
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductCategories', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-products/categories 类目下拉(选项集与超管当前 tab 行集同源)' },
|
||||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'deleteJdProducts', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'DELETE /jd-products/{id} 与 POST batch-delete 删除' },
|
|
||||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductGroups', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-product-groups 分组下拉/管理列表' },
|
|
||||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductCategories', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-products/categories 类目下拉' },
|
|
||||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'deleteJdProductGroup', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'DELETE /jd-product-groups/{id} 删分组' },
|
|
||||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'updateJdProduct', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'PUT /jd-products/{id} 行级编辑保存(V199 人工编辑锁)' },
|
|
||||||
]
|
]
|
||||||
|
|
||||||
/** 任务看板那 5 处(1b ④ 那条用例按文件筛它们,沿用旧名字不漂;表只有一份,不会漂出两个口径)。 */
|
/** 任务看板那 5 处(1b ④ 那条用例按文件筛它们,沿用旧名字不漂;表只有一份,不会漂出两个口径)。 */
|
||||||
@@ -369,8 +364,11 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
|||||||
// ⚠ 分母是本轮实扫的表条数(批次 1 的 5 + 批次 2 的 7 + 批次 3 的 4 + 批次 4 的 1 + 批次 5 的 1 + 批次 6 的 3;
|
// ⚠ 分母是本轮实扫的表条数(批次 1 的 5 + 批次 2 的 7 + 批次 3 的 4 + 批次 4 的 1 + 批次 5 的 1 + 批次 6 的 3;
|
||||||
// 批次 2 原 12 条里的品牌库 1 条 + 商品类目 4 条随 2026-10-06「这两页退回全平台共享」摘掉)。
|
// 批次 2 原 12 条里的品牌库 1 条 + 商品类目 4 条随 2026-10-06「这两页退回全平台共享」摘掉)。
|
||||||
// 这条只防"整表被摘空/被改窄",逐处脱管由下面两条(对平闸门 + 窗口对平)负责。
|
// 这条只防"整表被摘空/被改窄",逐处脱管由下面两条(对平闸门 + 窗口对平)负责。
|
||||||
assert.ok(SEND_POINTS.length >= 32,
|
// 2026-11-15 京东数据库公共化(用户定案「不区分公司、属于公共的」):批次 8 的详情/删除/
|
||||||
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权列表/导出 2 条 + 主管聚合 1 条 + 按主管删除 1 条 + 批次 8 v1.4 京东数据库列表/详情/删除/分组/类目/删分组/编辑 7 条(导出口 2026-11-15 随客户口径下线)= 32 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
// 分组列表/删分组/编辑 5 条 company_id 发送口随公司谓词整批撤下(后端写侧同窗摘),批次 8
|
||||||
|
// 只剩列表/类目两条(超管筛选管理员)⇒ 32 → 27。
|
||||||
|
assert.ok(SEND_POINTS.length >= 27,
|
||||||
|
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权列表/导出 2 条 + 主管聚合 1 条 + 按主管删除 1 条 + 批次 8 v1.4 京东数据库列表/类目 2 条(详情/删除/分组/删分组/编辑 5 口随 2026-11-15 公共化撤、导出口随客户口径下线)= 27 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
||||||
for (const p of SEND_POINTS) {
|
for (const p of SEND_POINTS) {
|
||||||
const shape = pointShape(p)
|
const shape = pointShape(p)
|
||||||
const compliant = pointCompliant(p)
|
const compliant = pointCompliant(p)
|
||||||
@@ -759,14 +757,15 @@ const WATCH_BODY_PINS: ReadonlyArray<{
|
|||||||
{ file: 'src/pages/patent/appearance-patent-clean-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
{ file: 'src/pages/patent/appearance-patent-clean-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):店铺/商品编码/标题是按行集筛的自由文本,分组/类目
|
// ↓ 批次 8(2026-11-14 v1.4 京东数据库;2026-11-15 公共化改口径):店铺/商品编码/标题是
|
||||||
// 选项集是公司隔离的(/jd-product-groups、/jd-products/categories 带 company_id)⇒ 上一家的
|
// 按行集筛的自由文本,类目选项集与超管当前 tab 的行集同源 ⇒ 上一家的筛选值与 category
|
||||||
// 筛选值与 groupId/category 在新一家的行集/选项集里不存在,切 tab 必清且选项重取;页码回 1 同外观专利页。
|
// 在新一家的行集/选项集里不存在,切 tab 必清且类目选项重取;页码回 1 同外观专利页。
|
||||||
|
// 分组 2026-11-15 起全平台一份(公共),groupId 与公司维度正交——不清、选项也不随 tab 重取。
|
||||||
{
|
{
|
||||||
file: 'src/pages/jd/JdDatabasePage.vue',
|
file: 'src/pages/jd/JdDatabasePage.vue',
|
||||||
token: "filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void loadCategoryOptions(); void load()",
|
token: "filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadCategoryOptions(); void load()",
|
||||||
why: '店铺/商品编码/标题是按行集筛的自由文本,上一家的值在新一家的行里不存在 ⇒ 切 tab 后首屏被筛成「暂无商品」,'
|
why: '店铺/商品编码/标题是按行集筛的自由文本,上一家的值在新一家的行里不存在 ⇒ 切 tab 后首屏被筛成「暂无商品」,'
|
||||||
+ '而输入框还显示着上一家填的值;分组/类目选项集是公司隔离的,上一家选的 groupId/category 在新一家的选项里不存在,'
|
+ '而输入框还显示着上一家填的值;类目选项集与超管当前 tab 的行集同源,上一家选的 category 在新一家的选项里不存在,'
|
||||||
+ '同罪必清且选项重取;页码回 1 是因为新一家的行数更少,末尾的 void load() 才让切 tab 真的换数据',
|
+ '同罪必清且选项重取;页码回 1 是因为新一家的行数更少,末尾的 void load() 才让切 tab 真的换数据',
|
||||||
premise: [
|
premise: [
|
||||||
{ file: 'src/pages/jd/jd-product-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
{ file: 'src/pages/jd/jd-product-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
||||||
|
|||||||
@@ -148,12 +148,12 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(wrapper.find('.drawer').exists()).toBe(false, '删除按钮 @click.stop,点它不开详情抽屉')
|
expect(wrapper.find('.drawer').exists()).toBe(false, '删除按钮 @click.stop,点它不开详情抽屉')
|
||||||
expect(confirmMock).toHaveBeenCalledTimes(1, '删除必须过二次确认')
|
expect(confirmMock).toHaveBeenCalledTimes(1, '删除必须过二次确认')
|
||||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(0, '确认弹窗取消时不发删除请求')
|
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(0, '确认弹窗取消时不发删除请求')
|
||||||
// 确认后:deleteJdProducts 按公司 tab 下传(id, companyId)。
|
// 确认后:deleteJdProducts 按 id 直删(公共库写侧无公司维度,2026-11-15 公共化)。
|
||||||
confirmMock.mockResolvedValue(true)
|
confirmMock.mockResolvedValue(true)
|
||||||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||||||
await wrapper.findAll('tbody tr')[0].findAll('td')[10].findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
await wrapper.findAll('tbody tr')[0].findAll('td')[10].findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1], 1)
|
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('操作列编辑按钮防冒泡且打开编辑抽屉(抽屉自取详情回填,2026-11-15 行级编辑)', async () => {
|
it('操作列编辑按钮防冒泡且打开编辑抽屉(抽屉自取详情回填,2026-11-15 行级编辑)', async () => {
|
||||||
@@ -186,8 +186,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
await flushPromises()
|
await flushPromises()
|
||||||
expect(wrapper.find('.drawer').exists()).toBe(true, '编辑抽屉打开')
|
expect(wrapper.find('.drawer').exists()).toBe(true, '编辑抽屉打开')
|
||||||
expect(wrapper.text()).toContain('编辑商品', '抽屉标题点商品')
|
expect(wrapper.text()).toContain('编辑商品', '抽屉标题点商品')
|
||||||
// 抽屉按 (id, companyId) 自取详情回填。
|
// 抽屉按 id 自取详情回填(公共库详情无公司维度)。
|
||||||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1, 1)
|
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
|
||||||
// 编辑抽屉的保存提示文案点名人工编辑锁后果(用户保存前看得见「采集不再覆盖」)。
|
// 编辑抽屉的保存提示文案点名人工编辑锁后果(用户保存前看得见「采集不再覆盖」)。
|
||||||
expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)')
|
expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)')
|
||||||
})
|
})
|
||||||
@@ -255,7 +255,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
{ id: 8, name: '乙组', sortOrder: 1, productCount: 1 },
|
{ id: 8, name: '乙组', sortOrder: 1, productCount: 1 },
|
||||||
])
|
])
|
||||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(1)
|
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith()
|
||||||
|
|
||||||
const groupSelect = wrapper.find('select')
|
const groupSelect = wrapper.find('select')
|
||||||
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
|
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
|
||||||
@@ -330,7 +330,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1, '下线导出不影响列表首屏')
|
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1, '下线导出不影响列表首屏')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('点行打开详情抽屉:按 (id, companyId) 取详情,attrGroups 分块渲染', async () => {
|
it('点行打开详情抽屉:按 id 取详情(公共库无公司维度),attrGroups 分块渲染', async () => {
|
||||||
jdApi.fetchJdProductDetail.mockImplementation(() =>
|
jdApi.fetchJdProductDetail.mockImplementation(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
item: item(1),
|
item: item(1),
|
||||||
@@ -349,7 +349,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
|
|
||||||
expect(wrapper.find('.drawer-mask').exists()).toBe(true)
|
expect(wrapper.find('.drawer-mask').exists()).toBe(true)
|
||||||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledTimes(1)
|
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledTimes(1)
|
||||||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1, 1)
|
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
|
||||||
expect(wrapper.find('.drawer-mask').text()).toContain('基本信息')
|
expect(wrapper.find('.drawer-mask').text()).toContain('基本信息')
|
||||||
expect(wrapper.find('.drawer-mask').text()).toContain('规格')
|
expect(wrapper.find('.drawer-mask').text()).toContain('规格')
|
||||||
expect(wrapper.find('.drawer-mask').text()).toContain('容量')
|
expect(wrapper.find('.drawer-mask').text()).toContain('容量')
|
||||||
@@ -419,7 +419,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(wrapper.find('.drawer-mask').text()).toContain('暂无 SKU 矩阵')
|
expect(wrapper.find('.drawer-mask').text()).toContain('暂无 SKU 矩阵')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('删除:勾选两行点删除 → 二次确认点名数量与桶清理 → 批量端点带 (ids, companyId),成功后刷新并清勾选', async () => {
|
it('删除:勾选两行点删除 → 二次确认点名数量与桶清理 → 批量端点按 id 直删(公共库无公司维度),成功后刷新并清勾选', async () => {
|
||||||
jdApi.deleteJdProducts.mockResolvedValue({ deleted: 2, imagesDeleted: 18, objectsDeleted: 16, objectsKept: 2, objectsSkipped: 0 })
|
jdApi.deleteJdProducts.mockResolvedValue({ deleted: 2, imagesDeleted: 18, objectsDeleted: 16, objectsKept: 2, objectsSkipped: 0 })
|
||||||
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 })
|
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 })
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(options.danger).toBe(true)
|
expect(options.danger).toBe(true)
|
||||||
|
|
||||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(1)
|
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(1)
|
||||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1, 2], 1)
|
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1, 2])
|
||||||
expect(document.body.textContent).toContain('已删除 2 个商品')
|
expect(document.body.textContent).toContain('已删除 2 个商品')
|
||||||
expect(document.body.textContent).toContain('2 个共用图片保留', '共用对象计数要透出到反馈')
|
expect(document.body.textContent).toContain('2 个共用图片保留', '共用对象计数要透出到反馈')
|
||||||
// 成功后重取列表并清勾选:工具栏按钮消失。
|
// 成功后重取列表并清勾选:工具栏按钮消失。
|
||||||
@@ -480,9 +480,9 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
expect(wrapper.find('.group-modal').exists()).toBe(true)
|
expect(wrapper.find('.group-modal').exists()).toBe(true)
|
||||||
// 打开弹窗 = 拉一次分组列表(第 2 次:首屏已拉过一次)
|
// 打开弹窗 = 拉一次分组列表(第 2 次:首屏已拉过一次;分组全平台一份、不带公司维度)
|
||||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
|
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
|
||||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(1)
|
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith()
|
||||||
|
|
||||||
// 模拟分组管理里删了一个分组:emit changed → 页面刷新分组下拉与列表(回第一页)
|
// 模拟分组管理里删了一个分组:emit changed → 页面刷新分组下拉与列表(回第一页)
|
||||||
wrapper.findComponent(JdProductGroupDialog).vm.$emit('changed')
|
wrapper.findComponent(JdProductGroupDialog).vm.$emit('changed')
|
||||||
@@ -492,7 +492,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, companyId: 1 })
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, companyId: 1 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径)', async () => {
|
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径;分组公共不清)', async () => {
|
||||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||||
@@ -510,10 +510,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(last.companyId).toBe(2)
|
expect(last.companyId).toBe(2)
|
||||||
expect(last.shopName).toBe('', '切公司必须清掉上一家的店铺名')
|
expect(last.shopName).toBe('', '切公司必须清掉上一家的店铺名')
|
||||||
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
|
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
|
||||||
expect(last.groupId).toBe('', '切公司必须清掉上一家选的分组')
|
expect(last.groupId).toBe('7', '分组全平台一份(公共),groupId 与公司维度正交——切 tab 不清')
|
||||||
expect(last).not.toHaveProperty('category', '切公司必须清掉上一家选的类目')
|
expect(last).not.toHaveProperty('category', '切公司必须清掉上一家选的类目')
|
||||||
expect(last.page).toBe(1)
|
expect(last.page).toBe(1)
|
||||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(2)
|
// 分组选项是全局的:切 tab 不重取(首屏那一次之后就不再增长),且任何一次拉取都不带公司维度。
|
||||||
|
for (const call of jdApi.fetchJdProductGroups.mock.calls) {
|
||||||
|
expect(call).toEqual([], '分组选项是全局的,任何一次拉取都不带公司维度')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||||||
|
|||||||
+32
-41
@@ -57,10 +57,13 @@ import java.util.List;
|
|||||||
* 非超管菜单权限(column_key/route_path 双匹配)。菜单行由 V196 只插 columns 不预授权
|
* 非超管菜单权限(column_key/route_path 双匹配)。菜单行由 V196 只插 columns 不预授权
|
||||||
* ⇒ 默认仅 super_admin 可见可访问,其余角色由超管在权限页手工勾授后才放行。</p>
|
* ⇒ 默认仅 super_admin 可见可访问,其余角色由超管在权限页手工勾授后才放行。</p>
|
||||||
*
|
*
|
||||||
* <p>公司隔离正门是 {@code readCompanyIdOrOwn}(同外观专利只读页/店铺密钥的表形状:
|
* <p><b>公司口径(2026-11-15 用户定案「京东数据库不区分公司、属于公共的」)</b>:行上的
|
||||||
* 归属物化在行 company_id 列、可见集不靠账号/分组)——超管显式传才收窄、不传全量;
|
* company_id 只剩「哪家公司客户端同步的」来源标记,不再构成可见性边界——读侧全公共;
|
||||||
* 非超管强制本公司(忽略请求传参)。{@code superAdminScopedCompanyId} 对非超管返回 null
|
* 唯一保留的公司维度是<b>站点超管</b>的公司 tab 筛选({@code superAdminScopedCompanyId}:
|
||||||
* =按行 company_id 列查询时把整张表交给每一家(该方法 javadoc 点名的越权形状),不走那道门。</p>
|
* 超管显式传 company_id 才收窄,非超管传什么都不收),也就是「管理员没有这个筛选、
|
||||||
|
* 超管可以筛选管理员」。详情与写侧(编辑/删除)没有公司维度:任何拿到本页菜单权限的
|
||||||
|
* 管理员对全部公共行可编辑可删除(同商品类目「谁都能改」的 2026-10-06 定案形状),
|
||||||
|
* 请求里的 company_id 传参已随公共化从写侧端点摘除。</p>
|
||||||
*
|
*
|
||||||
* <p>导出端点已随 2026-11-15 客户口径「导出也不用」整段下线(控制器/服务/mapper 参数一起删);
|
* <p>导出端点已随 2026-11-15 客户口径「导出也不用」整段下线(控制器/服务/mapper 参数一起删);
|
||||||
* {@code sale_status} 查询参数同窗撤掉(商品状态筛选框已从前端下线)。DB 列
|
* {@code sale_status} 查询参数同窗撤掉(商品状态筛选框已从前端下线)。DB 列
|
||||||
@@ -70,7 +73,7 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequestMapping("/api/admin/jd-products")
|
@RequestMapping("/api/admin/jd-products")
|
||||||
@Tag(name = "京东数据库", description = "后管京东店铺商品库:分页查询、详情、编辑与删除,按分公司隔离。")
|
@Tag(name = "京东数据库", description = "后管京东店铺商品库:分页查询、详情、编辑与删除。数据全平台公共,仅超管可按公司(同步来源)筛选。")
|
||||||
public class AdminJdProductController {
|
public class AdminJdProductController {
|
||||||
|
|
||||||
private static final String COLUMN_KEY = "admin_jd_database";
|
private static final String COLUMN_KEY = "admin_jd_database";
|
||||||
@@ -84,8 +87,8 @@ public class AdminJdProductController {
|
|||||||
private final DataReadScope dataReadScope;
|
private final DataReadScope dataReadScope;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Operation(summary = "分页查询京东数据库商品", description = "按分公司隔离分页查询同步落表的京东商品;"
|
@Operation(summary = "分页查询京东数据库商品", description = "公共库分页查询同步落表的京东商品;"
|
||||||
+ "company_id 只对站点超管生效(显式传才收窄,不传全量),非超管强制本公司。")
|
+ "company_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)))
|
||||||
})
|
})
|
||||||
@@ -105,39 +108,36 @@ public class AdminJdProductController {
|
|||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
AdminUserEntity user = operator.user();
|
||||||
// 公司隔离正门是 readCompanyIdOrOwn(同外观专利只读页口径):超管显式传才收窄、
|
// 公司维度只剩超管的公司 tab 筛选(superAdminScopedCompanyId):超管显式传才收窄,
|
||||||
// 不传全量;非超管强制本公司(忽略请求传参)。
|
// 非超管传什么都不收——公共库对每一家管理员都是同一份全量。
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(user, companyId);
|
||||||
return ApiResponse.success(jdProductQueryService.page(page, pageSize, scopedCompanyId, shopName,
|
return ApiResponse.success(jdProductQueryService.page(page, pageSize, scopedCompanyId, shopName,
|
||||||
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo));
|
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/categories")
|
@GetMapping("/categories")
|
||||||
@Operation(summary = "类目筛选下拉数据源", description = "本公司已落库行 DISTINCT 的 category_path"
|
@Operation(summary = "类目筛选下拉数据源", description = "已落库行 DISTINCT 的 category_path"
|
||||||
+ "(京麦末级类目名)+ 行数,按类目名排序;company_id 只对站点超管生效(显式传才收窄,"
|
+ "(京麦末级类目名)+ 行数,按类目名排序;company_id 只对站点超管生效(显式传才收窄="
|
||||||
+ "不传全量),非超管强制本公司。")
|
+ "选项集与超管当前公司 tab 的行集同源),非超管传什么都不收(全量)。")
|
||||||
public ApiResponse<List<JdProductCategoryVo>> categories(
|
public ApiResponse<List<JdProductCategoryVo>> categories(
|
||||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
AdminUserEntity user = operator.user();
|
||||||
// 类目下拉与列表同走 readCompanyIdOrOwn 正门:选项集永远和页签能看到的公司行集同源。
|
// 类目下拉与列表同走超管筛选口径:选项集永远和当前请求能看到的行集同源。
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(user, companyId);
|
||||||
return ApiResponse.success(jdProductQueryService.categories(scopedCompanyId));
|
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)。"
|
||||||
+ "公司隔离与列表同门:越界 id 按不存在拒绝。")
|
+ "公共库无公司维度:按 id 直取,越界 id 按不存在拒绝。")
|
||||||
public ApiResponse<JdProductDetailVo> detail(
|
public ApiResponse<JdProductDetailVo> detail(
|
||||||
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
return ApiResponse.success(jdProductQueryService.detail(id));
|
||||||
// 详情同样过公司隔离正门:超管不传 company_id = 全量可见;非超管恒为本公司(服务按它收口)。
|
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, null);
|
|
||||||
return ApiResponse.success(jdProductQueryService.detail(id, scopedCompanyId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@@ -148,16 +148,13 @@ public class AdminJdProductController {
|
|||||||
public ApiResponse<JdProductDetailVo> update(
|
public ApiResponse<JdProductDetailVo> update(
|
||||||
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
||||||
@Valid @RequestBody JdProductUpdateRequest body,
|
@Valid @RequestBody JdProductUpdateRequest body,
|
||||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
Long updatedId = jdProductUpdateService.update(id, body);
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
log.info("[jd-product] 编辑商品 operatorId={} id={} title={}",
|
||||||
Long updatedId = jdProductUpdateService.update(id, body, scopedCompanyId);
|
operator.id(), updatedId, body.getTitle());
|
||||||
log.info("[jd-product] 编辑商品 operatorId={} companyId={} id={} title={}",
|
|
||||||
operator.id(), scopedCompanyId, updatedId, body.getTitle());
|
|
||||||
// 返回刷新后的详情(前端保存后直接回填抽屉),复用详情同一查询出口。
|
// 返回刷新后的详情(前端保存后直接回填抽屉),复用详情同一查询出口。
|
||||||
return ApiResponse.success(jdProductQueryService.detail(updatedId, scopedCompanyId));
|
return ApiResponse.success(jdProductQueryService.detail(updatedId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@@ -166,31 +163,25 @@ public class AdminJdProductController {
|
|||||||
+ "任何对象删不掉就整批拒绝、一行库行都不动。越界 id 按不存在拒绝。")
|
+ "任何对象删不掉就整批拒绝、一行库行都不动。越界 id 按不存在拒绝。")
|
||||||
public ApiResponse<JdProductDeleteVo> delete(
|
public ApiResponse<JdProductDeleteVo> delete(
|
||||||
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
@Parameter(description = "商品行 id") @PathVariable("id") Long id,
|
||||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
JdProductDeleteVo vo = jdProductDeleteService.delete(List.of(id));
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
|
||||||
JdProductDeleteVo vo = jdProductDeleteService.delete(List.of(id), scopedCompanyId);
|
|
||||||
// 管理端破坏性动作必须留痕:谁、删了哪些行、桶里清了几个对象(同分组删除口径)。
|
// 管理端破坏性动作必须留痕:谁、删了哪些行、桶里清了几个对象(同分组删除口径)。
|
||||||
log.info("[jd-product] 删除商品 operatorId={} companyId={} id={} deleted={} objectsDeleted={}",
|
log.info("[jd-product] 删除商品 operatorId={} id={} deleted={} objectsDeleted={}",
|
||||||
operator.id(), scopedCompanyId, id, vo.getDeleted(), vo.getObjectsDeleted());
|
operator.id(), id, vo.getDeleted(), vo.getObjectsDeleted());
|
||||||
return ApiResponse.success(vo);
|
return ApiResponse.success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/batch-delete")
|
@PostMapping("/batch-delete")
|
||||||
@Operation(summary = "批量删除京东商品", description = "与单行删除同一出口(先删桶对象、全成功才删库行);"
|
@Operation(summary = "批量删除京东商品", description = "与单行删除同一出口(先删桶对象、全成功才删库行);"
|
||||||
+ "单次最多 200 个,id 里有一行不存在或不属于当前公司则整批拒绝(不做部分删除)。")
|
+ "单次最多 200 个,id 里有一行不存在则整批拒绝(不做部分删除)。")
|
||||||
public ApiResponse<JdProductDeleteVo> batchDelete(
|
public ApiResponse<JdProductDeleteVo> batchDelete(
|
||||||
@Valid @RequestBody JdProductBatchDeleteRequest body,
|
@Valid @RequestBody JdProductBatchDeleteRequest body,
|
||||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
JdProductDeleteVo vo = jdProductDeleteService.delete(body.getIds());
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
log.info("[jd-product] 批量删除商品 operatorId={} requested={} deleted={} objectsDeleted={} kept={}",
|
||||||
JdProductDeleteVo vo = jdProductDeleteService.delete(body.getIds(), scopedCompanyId);
|
operator.id(), body.getIds().size(), vo.getDeleted(),
|
||||||
log.info("[jd-product] 批量删除商品 operatorId={} companyId={} requested={} deleted={} objectsDeleted={} kept={}",
|
|
||||||
operator.id(), scopedCompanyId, body.getIds().size(), vo.getDeleted(),
|
|
||||||
vo.getObjectsDeleted(), vo.getObjectsKept());
|
vo.getObjectsDeleted(), vo.getObjectsKept());
|
||||||
return ApiResponse.success(vo);
|
return ApiResponse.success(vo);
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-35
@@ -5,7 +5,6 @@ import com.nanri.aiimage.common.exception.BusinessException;
|
|||||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||||
import com.nanri.aiimage.common.service.DataReadScope;
|
|
||||||
import com.nanri.aiimage.modules.jd.model.dto.JdProductGroupSaveRequest;
|
import com.nanri.aiimage.modules.jd.model.dto.JdProductGroupSaveRequest;
|
||||||
import com.nanri.aiimage.modules.jd.model.vo.JdProductGroupVo;
|
import com.nanri.aiimage.modules.jd.model.vo.JdProductGroupVo;
|
||||||
import com.nanri.aiimage.modules.jd.service.JdProductGroupService;
|
import com.nanri.aiimage.modules.jd.service.JdProductGroupService;
|
||||||
@@ -24,7 +23,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -32,19 +30,20 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 后管「京东数据库」分组管理(v1.4 Phase 5,R4):新建 / 改名 / 删除 / 下拉列表。
|
* 后管「京东数据库」分组管理(v1.4 Phase 5,R4):新建 / 改名 / 删除 / 下拉列表。
|
||||||
*
|
*
|
||||||
* <p>京东数据库专属分组(不是店铺管理的分组集):按公司隔离(唯一键
|
* <p>京东数据库专属分组(不是店铺管理的分组集):<b>2026-11-15 用户定案公共化</b>——
|
||||||
* {@code uk_company_group_name});删除分组不删商品——商品行 {@code group_id} 置 NULL
|
* 与品牌数据库(亚马逊)的分组同形状,全平台一份、不分公司(唯一键 {@code uk_group_name},
|
||||||
* (AC-8,事务两步落 {@code JdProductGroupService})。</p>
|
* V200 退键);删除分组不删商品——商品行 {@code group_id} 置 NULL(AC-8,事务两步落
|
||||||
|
* {@code JdProductGroupService})。实体上遗留的 company_id 列只是历史归属标记,读写两侧
|
||||||
|
* 都不再引用,新行按 DEFAULT 0 落「平台公共」。</p>
|
||||||
*
|
*
|
||||||
* <p>鉴权与 {@code AdminJdProductController} 同款私有闸(同一 column_key/route_path):
|
* <p>鉴权与 {@code AdminJdProductController} 同款私有闸(同一 column_key/route_path):
|
||||||
* 普通授权用户可读写分组(AC-9),默认仅 super_admin;公司隔离正门同样是
|
* 普通授权用户可读写分组(AC-9),默认仅 super_admin。</p>
|
||||||
* {@code readCompanyIdOrOwn}——超管显式传才收窄,非超管强制本公司。</p>
|
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequestMapping("/api/admin/jd-product-groups")
|
@RequestMapping("/api/admin/jd-product-groups")
|
||||||
@Tag(name = "京东数据库分组", description = "京东商品自定义分组管理:按公司隔离的列表/新建/改名/删除,删除不删商品(脱组)。")
|
@Tag(name = "京东数据库分组", description = "京东商品自定义分组管理:全平台一份(公共库),列表/新建/改名/删除,删除不删商品(脱组)。")
|
||||||
public class AdminJdProductGroupController {
|
public class AdminJdProductGroupController {
|
||||||
|
|
||||||
private static final String COLUMN_KEY = "admin_jd_database";
|
private static final String COLUMN_KEY = "admin_jd_database";
|
||||||
@@ -53,49 +52,35 @@ public class AdminJdProductGroupController {
|
|||||||
private final JdProductGroupService jdProductGroupService;
|
private final JdProductGroupService jdProductGroupService;
|
||||||
private final AdminAuthSupport adminAuthSupport;
|
private final AdminAuthSupport adminAuthSupport;
|
||||||
private final PermissionMenuService permissionMenuService;
|
private final PermissionMenuService permissionMenuService;
|
||||||
private final DataReadScope dataReadScope;
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Operation(summary = "分组列表(含组内商品数)", description = "按公司隔离返回全部分组,按 sort_order, id 升序;"
|
@Operation(summary = "分组列表(含组内商品数)", description = "全平台全部分组,按 sort_order, id 升序;"
|
||||||
+ "company_id 只对站点超管生效(显式传才收窄,不传全量),非超管强制本公司。"
|
|
||||||
+ "productCount 为读侧现算列(分组下拉展示用)。")
|
+ "productCount 为读侧现算列(分组下拉展示用)。")
|
||||||
public ApiResponse<List<JdProductGroupVo>> list(
|
public ApiResponse<List<JdProductGroupVo>> list(HttpServletRequest request) {
|
||||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
requireJdAccess(request);
|
||||||
HttpServletRequest request) {
|
return ApiResponse.success(jdProductGroupService.list());
|
||||||
RequestOperator operator = requireJdAccess(request);
|
|
||||||
AdminUserEntity user = operator.user();
|
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
|
||||||
return ApiResponse.success(jdProductGroupService.list(scopedCompanyId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@Operation(summary = "新建分组", description = "同公司重名按业务错误拒绝(409),不落库;"
|
@Operation(summary = "新建分组", description = "重名按业务错误拒绝(409),不落库;公共库无公司归属。")
|
||||||
+ "归属公司走公司隔离正门(站点超管必须显式传 company_id)。")
|
|
||||||
public ApiResponse<Long> create(
|
public ApiResponse<Long> create(
|
||||||
@Valid @RequestBody JdProductGroupSaveRequest body,
|
@Valid @RequestBody JdProductGroupSaveRequest body,
|
||||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
Long id = jdProductGroupService.create(body.getName(), body.getSortOrder());
|
||||||
// 超管不传 company_id 时 scopedCompanyId 为空 ⇒ 服务侧拒绝(分组必须归属一家公司)。
|
log.info("[jd-product-group] 新建分组 operatorId={} groupId={}", operator.id(), id);
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
|
||||||
Long id = jdProductGroupService.create(scopedCompanyId, body.getName(), body.getSortOrder());
|
|
||||||
log.info("[jd-product-group] 新建分组 operatorId={} companyId={} groupId={}",
|
|
||||||
operator.id(), scopedCompanyId, id);
|
|
||||||
return ApiResponse.success(id);
|
return ApiResponse.success(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@Operation(summary = "分组改名/改排序", description = "越界 id(不属于本公司)按不存在拒绝;"
|
@Operation(summary = "分组改名/改排序", description = "越界 id(不存在)按不存在拒绝;"
|
||||||
+ "改成本公司已有名字按业务错误拒绝(409)。")
|
+ "改成已有名字按业务错误拒绝(409)。")
|
||||||
public ApiResponse<Boolean> rename(
|
public ApiResponse<Boolean> rename(
|
||||||
@Parameter(description = "分组 id") @PathVariable("id") Long id,
|
@Parameter(description = "分组 id") @PathVariable("id") Long id,
|
||||||
@Valid @RequestBody JdProductGroupSaveRequest body,
|
@Valid @RequestBody JdProductGroupSaveRequest body,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
jdProductGroupService.rename(id, body.getName(), body.getSortOrder());
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, null);
|
|
||||||
jdProductGroupService.rename(id, scopedCompanyId, body.getName(), body.getSortOrder());
|
|
||||||
log.info("[jd-product-group] 分组改名 operatorId={} groupId={}", operator.id(), id);
|
log.info("[jd-product-group] 分组改名 operatorId={} groupId={}", operator.id(), id);
|
||||||
return ApiResponse.success(Boolean.TRUE);
|
return ApiResponse.success(Boolean.TRUE);
|
||||||
}
|
}
|
||||||
@@ -107,9 +92,7 @@ public class AdminJdProductGroupController {
|
|||||||
@Parameter(description = "分组 id") @PathVariable("id") Long id,
|
@Parameter(description = "分组 id") @PathVariable("id") Long id,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
RequestOperator operator = requireJdAccess(request);
|
RequestOperator operator = requireJdAccess(request);
|
||||||
AdminUserEntity user = operator.user();
|
int detached = jdProductGroupService.delete(id);
|
||||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, null);
|
|
||||||
int detached = jdProductGroupService.delete(id, scopedCompanyId);
|
|
||||||
// 管理端破坏性动作必须留痕:谁、删了哪个分组、脱组了多少商品。
|
// 管理端破坏性动作必须留痕:谁、删了哪个分组、脱组了多少商品。
|
||||||
log.info("[jd-product-group] 删除分组 operatorId={} groupId={} detached={}",
|
log.info("[jd-product-group] 删除分组 operatorId={} groupId={} detached={}",
|
||||||
operator.id(), id, detached);
|
operator.id(), id, detached);
|
||||||
|
|||||||
+6
-5
@@ -10,9 +10,10 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* 京东商品自定义分组({@code biz_jd_product_group},V195,v1.4)。
|
* 京东商品自定义分组({@code biz_jd_product_group},V195,v1.4)。
|
||||||
*
|
*
|
||||||
* <p>京东数据库专属分组(R4):按公司隔离(唯一键 {@code uk_company_group_name}),
|
* <p>京东数据库专属分组(R4):<b>2026-11-15 起全平台一份</b>(唯一键 {@code uk_group_name},
|
||||||
* 可新建/改名/删除;删除分组不删商品——商品行 {@code group_id} 置 NULL(AC-8)。
|
* V200 退掉按公司的 {@code uk_company_group_name});可新建/改名/删除;删除分组不删商品——
|
||||||
* 简单单表 CRUD 走 BaseMapper + wrapper(SqlLayering 惯例),无 XML。</p>
|
* 商品行 {@code group_id} 置 NULL(AC-8)。简单单表 CRUD 走 BaseMapper + wrapper
|
||||||
|
* (SqlLayering 惯例),无 XML。</p>
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@TableName("biz_jd_product_group")
|
@TableName("biz_jd_product_group")
|
||||||
@@ -20,9 +21,9 @@ public class JdProductGroupEntity {
|
|||||||
|
|
||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
/** 归属分公司(分组按公司隔离,R4)。 */
|
/** 历史归属公司(V195~V199 按公司隔离时代遗留,公共化后读写两侧不再引用;新行 DEFAULT 0=平台公共)。 */
|
||||||
private Long companyId;
|
private Long companyId;
|
||||||
/** 分组名(同公司内唯一)。 */
|
/** 分组名(全平台唯一)。 */
|
||||||
private String name;
|
private String name;
|
||||||
/** 下拉展示顺序。 */
|
/** 下拉展示顺序。 */
|
||||||
private Integer sortOrder;
|
private Integer sortOrder;
|
||||||
|
|||||||
+14
-13
@@ -34,9 +34,12 @@ import java.util.Set;
|
|||||||
* {@code biz_jd_product_image} 里有没有别的商品引用它;有就保留,计入 {@code objectsKept}。</li>
|
* {@code biz_jd_product_image} 里有没有别的商品引用它;有就保留,计入 {@code objectsKept}。</li>
|
||||||
* <li><b>只删自己前缀内的 key</b>:key 不以 {@code aiimage.jd.oss.key-prefix} 开头的行只留 WARN、
|
* <li><b>只删自己前缀内的 key</b>:key 不以 {@code aiimage.jd.oss.key-prefix} 开头的行只留 WARN、
|
||||||
* 不动手(防早期脏数据把删除扩到别的桶前缀上),计入 {@code objectsSkipped}。</li>
|
* 不动手(防早期脏数据把删除扩到别的桶前缀上),计入 {@code objectsSkipped}。</li>
|
||||||
* <li><b>归属先判、整批拒绝</b>:id 里有一行不存在或不属于当前公司 ⇒ 整批不删(不做部分删除,
|
* <li><b>存在先判、整批拒绝</b>:id 里有一行不存在 ⇒ 整批不删(不做部分删除),
|
||||||
* 也不泄露越界行的存在性),文案点明"本次未删除任何数据"。</li>
|
* 文案点明"本次未删除任何数据"。</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>公共库无公司维度(2026-11-15 用户定案「京东数据库不区分公司」):删除按 id 直判存在性,
|
||||||
|
* 不再按行 company_id 收口。</p>
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -68,10 +71,10 @@ public class JdProductDeleteService {
|
|||||||
@Value("${aiimage.jd.oss.key-prefix:jd-products/}")
|
@Value("${aiimage.jd.oss.key-prefix:jd-products/}")
|
||||||
private String keyPrefix;
|
private String keyPrefix;
|
||||||
|
|
||||||
/** 删除给定商品(含 SKU、图片登记行与桶内对象);见类注释的三条边界。 */
|
/** 删除给定商品(含 SKU、图片登记行与桶内对象);见类注释的三条边界。公共库无公司维度(2026-11-15 用户定案)。 */
|
||||||
public JdProductDeleteVo delete(List<Long> requestedIds, Long scopedCompanyId) {
|
public JdProductDeleteVo delete(List<Long> requestedIds) {
|
||||||
List<Long> ids = normalizeIds(requestedIds);
|
List<Long> ids = normalizeIds(requestedIds);
|
||||||
List<JdProductEntity> scopedRows = requireScopedRows(ids, scopedCompanyId);
|
List<JdProductEntity> scopedRows = requireExistingRows(ids);
|
||||||
List<JdProductImageEntity> images = imageRowsOf(ids);
|
List<JdProductImageEntity> images = imageRowsOf(ids);
|
||||||
Set<String> ownedKeys = new LinkedHashSet<>();
|
Set<String> ownedKeys = new LinkedHashSet<>();
|
||||||
Set<String> foreignKeys = new LinkedHashSet<>();
|
Set<String> foreignKeys = new LinkedHashSet<>();
|
||||||
@@ -103,8 +106,8 @@ public class JdProductDeleteService {
|
|||||||
vo.setObjectsDeleted(purged);
|
vo.setObjectsDeleted(purged);
|
||||||
vo.setObjectsKept(ownedKeys.size() - purged);
|
vo.setObjectsKept(ownedKeys.size() - purged);
|
||||||
vo.setObjectsSkipped(foreignKeys.size());
|
vo.setObjectsSkipped(foreignKeys.size());
|
||||||
log.info("[{}] 删除完成 companyId={} productIds={} deleted={} images={} objectsDeleted={} kept={} skipped={}",
|
log.info("[{}] 删除完成 productIds={} deleted={} images={} objectsDeleted={} kept={} skipped={}",
|
||||||
LOG_TAG, scopedCompanyId, ids, deleted, images.size(), purged, vo.getObjectsKept(),
|
LOG_TAG, ids, deleted, images.size(), purged, vo.getObjectsKept(),
|
||||||
foreignKeys.size());
|
foreignKeys.size());
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
@@ -130,15 +133,13 @@ public class JdProductDeleteService {
|
|||||||
return new ArrayList<>(unique);
|
return new ArrayList<>(unique);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 归属闸:行必须都在(且都在当前公司可见面内),否则整批拒绝——不做部分删除。返回归属校验通过的行(供删除成功后登记忽略三元组)。 */
|
/** 存在闸:行必须都在,否则整批拒绝——不做部分删除。返回实读到的行(供删除成功后登记忽略三元组)。 */
|
||||||
private List<JdProductEntity> requireScopedRows(List<Long> ids, Long scopedCompanyId) {
|
private List<JdProductEntity> requireExistingRows(List<Long> ids) {
|
||||||
boolean scoped = scopedCompanyId != null && scopedCompanyId > 0;
|
|
||||||
List<JdProductEntity> rows = jdProductMapper.selectList(new LambdaQueryWrapper<JdProductEntity>()
|
List<JdProductEntity> rows = jdProductMapper.selectList(new LambdaQueryWrapper<JdProductEntity>()
|
||||||
.in(JdProductEntity::getId, ids)
|
.in(JdProductEntity::getId, ids));
|
||||||
.eq(scoped, JdProductEntity::getCompanyId, scopedCompanyId));
|
|
||||||
if (rows.size() != ids.size()) {
|
if (rows.size() != ids.size()) {
|
||||||
throw new BusinessException("有 " + (ids.size() - rows.size())
|
throw new BusinessException("有 " + (ids.size() - rows.size())
|
||||||
+ " 个商品不存在或不属于当前公司,请刷新后重试(本次未删除任何数据)");
|
+ " 个商品不存在,请刷新后重试(本次未删除任何数据)");
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-35
@@ -21,17 +21,14 @@ import java.util.List;
|
|||||||
* <p>分组表是简单单表,CRUD 全走 BaseMapper + wrapper(SqlLayering 惯例,无 XML)。
|
* <p>分组表是简单单表,CRUD 全走 BaseMapper + wrapper(SqlLayering 惯例,无 XML)。
|
||||||
* 业务规则:</p>
|
* 业务规则:</p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><b>按公司隔离</b>:所有读写都带 {@code companyId} 面;越界 id(行不存在或
|
* <li><b>全平台一份(2026-11-15 用户定案「分组和亚马逊功能一样」=与品牌数据库的
|
||||||
* {@code company_id} 与传入公司不符)一律按「分组不存在」拒绝,不泄露存在性。</li>
|
* 全平台共享同形状)</b>:读写都不带公司维度;实体遗留的 {@code company_id} 列只是
|
||||||
* <li><b>同公司重名拒绝</b>(唯一键 {@code uk_company_group_name}):先查后插给可读的
|
* V195~V199 按公司隔离时代的历史值,新行由 DEFAULT 0 落「平台公共」。</li>
|
||||||
|
* <li><b>全局重名拒绝</b>(唯一键 {@code uk_group_name},V200 退键):先查后插给可读的
|
||||||
* 409 业务错误,不拿 DB 异常撞 500;改名时排除自身再查。</li>
|
* 409 业务错误,不拿 DB 异常撞 500;改名时排除自身再查。</li>
|
||||||
* <li><b>删除两步一事务</b>(AC-8):先把该组商品 {@code biz_jd_product.group_id} 置 NULL
|
* <li><b>删除两步一事务</b>(AC-8):先把该组商品 {@code biz_jd_product.group_id} 置 NULL
|
||||||
* (商品不删,脱组即成「未分组」),再删分组行——同一事务,失败一起回滚。</li>
|
* (商品不删,脱组即成「未分组」),再删分组行——同一事务,失败一起回滚。</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
|
||||||
* <p>{@code companyId} 由控制器经 {@code DataReadScope#readCompanyIdOrOwn} 算好传入:
|
|
||||||
* {@code null} = 超管没选公司(rename/delete 放行、create 没有「没选公司」语义——
|
|
||||||
* 分组必须归属一家公司,直接拒绝),正数=该公司(非超管恒为自己的公司)。</p>
|
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -45,10 +42,8 @@ public class JdProductGroupService {
|
|||||||
* {@code productCount} 用 {@code JdProductMapper} BaseMapper selectCount wrapper
|
* {@code productCount} 用 {@code JdProductMapper} BaseMapper selectCount wrapper
|
||||||
* 按 {@code group_id} 统计(分组下拉展示用)。
|
* 按 {@code group_id} 统计(分组下拉展示用)。
|
||||||
*/
|
*/
|
||||||
public List<JdProductGroupVo> list(Long scopedCompanyId) {
|
public List<JdProductGroupVo> list() {
|
||||||
LambdaQueryWrapper<JdProductGroupEntity> query = new LambdaQueryWrapper<JdProductGroupEntity>()
|
LambdaQueryWrapper<JdProductGroupEntity> query = new LambdaQueryWrapper<JdProductGroupEntity>()
|
||||||
.eq(scopedCompanyId != null && scopedCompanyId > 0,
|
|
||||||
JdProductGroupEntity::getCompanyId, scopedCompanyId)
|
|
||||||
.orderByAsc(JdProductGroupEntity::getSortOrder)
|
.orderByAsc(JdProductGroupEntity::getSortOrder)
|
||||||
.orderByAsc(JdProductGroupEntity::getId);
|
.orderByAsc(JdProductGroupEntity::getId);
|
||||||
List<JdProductGroupVo> items = new ArrayList<>();
|
List<JdProductGroupVo> items = new ArrayList<>();
|
||||||
@@ -65,15 +60,11 @@ public class JdProductGroupService {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 新建分组:同公司重名(trim 后)按 409 业务错误拒绝,不落库。 */
|
/** 新建分组:重名(trim 后)按 409 业务错误拒绝,不落库;company_id 不写(DB DEFAULT 0=平台公共)。 */
|
||||||
public Long create(Long scopedCompanyId, String name, Integer sortOrder) {
|
public Long create(String name, Integer sortOrder) {
|
||||||
if (scopedCompanyId == null || scopedCompanyId <= 0) {
|
|
||||||
throw new BusinessException(400, "创建分组必须指定公司");
|
|
||||||
}
|
|
||||||
String safeName = requireName(name);
|
String safeName = requireName(name);
|
||||||
requireNameFree(scopedCompanyId, safeName, null);
|
requireNameFree(safeName, null);
|
||||||
JdProductGroupEntity group = new JdProductGroupEntity();
|
JdProductGroupEntity group = new JdProductGroupEntity();
|
||||||
group.setCompanyId(scopedCompanyId);
|
|
||||||
group.setName(safeName);
|
group.setName(safeName);
|
||||||
group.setSortOrder(sortOrder == null ? 0 : sortOrder);
|
group.setSortOrder(sortOrder == null ? 0 : sortOrder);
|
||||||
jdProductGroupMapper.insert(group);
|
jdProductGroupMapper.insert(group);
|
||||||
@@ -81,10 +72,10 @@ public class JdProductGroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 改名/改排序:越界 id 拒绝,重名(排除自身)拒绝。 */
|
/** 改名/改排序:越界 id 拒绝,重名(排除自身)拒绝。 */
|
||||||
public void rename(Long id, Long scopedCompanyId, String name, Integer sortOrder) {
|
public void rename(Long id, String name, Integer sortOrder) {
|
||||||
String safeName = requireName(name);
|
String safeName = requireName(name);
|
||||||
JdProductGroupEntity group = requireOwnedGroup(id, scopedCompanyId);
|
JdProductGroupEntity group = requireExistingGroup(id);
|
||||||
requireNameFree(group.getCompanyId(), safeName, group.getId());
|
requireNameFree(safeName, group.getId());
|
||||||
group.setName(safeName);
|
group.setName(safeName);
|
||||||
if (sortOrder != null) {
|
if (sortOrder != null) {
|
||||||
group.setSortOrder(sortOrder);
|
group.setSortOrder(sortOrder);
|
||||||
@@ -99,11 +90,10 @@ public class JdProductGroupService {
|
|||||||
* @return 实际脱组的商品行数(前端拿它做「已解挂 N 个商品」的反馈,不猜)
|
* @return 实际脱组的商品行数(前端拿它做「已解挂 N 个商品」的反馈,不猜)
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public int delete(Long id, Long scopedCompanyId) {
|
public int delete(Long id) {
|
||||||
JdProductGroupEntity group = requireOwnedGroup(id, scopedCompanyId);
|
JdProductGroupEntity group = requireExistingGroup(id);
|
||||||
int detached = jdProductMapper.update(null, new LambdaUpdateWrapper<JdProductEntity>()
|
int detached = jdProductMapper.update(null, new LambdaUpdateWrapper<JdProductEntity>()
|
||||||
.set(JdProductEntity::getGroupId, null)
|
.set(JdProductEntity::getGroupId, null)
|
||||||
.eq(JdProductEntity::getCompanyId, group.getCompanyId())
|
|
||||||
.eq(JdProductEntity::getGroupId, group.getId()));
|
.eq(JdProductEntity::getGroupId, group.getId()));
|
||||||
jdProductGroupMapper.deleteById(group.getId());
|
jdProductGroupMapper.deleteById(group.getId());
|
||||||
return detached;
|
return detached;
|
||||||
@@ -119,31 +109,25 @@ public class JdProductGroupService {
|
|||||||
return name.trim();
|
return name.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** 分组行存在校验:不存在一律按「分组不存在」拒绝。 */
|
||||||
* 分组行归属校验:不存在 / 公司不符(越界 id)一律按「分组不存在」拒绝——
|
private JdProductGroupEntity requireExistingGroup(Long id) {
|
||||||
* 越界探测拿到的与 id 不存在是同一种响应,不泄露跨公司行的存在性。
|
|
||||||
* {@code scopedCompanyId} 为空=超管没选公司、跨公司放行。
|
|
||||||
*/
|
|
||||||
private JdProductGroupEntity requireOwnedGroup(Long id, Long scopedCompanyId) {
|
|
||||||
if (id == null || id <= 0) {
|
if (id == null || id <= 0) {
|
||||||
throw new BusinessException("分组不存在");
|
throw new BusinessException("分组不存在");
|
||||||
}
|
}
|
||||||
JdProductGroupEntity group = jdProductGroupMapper.selectById(id);
|
JdProductGroupEntity group = jdProductGroupMapper.selectById(id);
|
||||||
if (group == null || (scopedCompanyId != null && scopedCompanyId > 0
|
if (group == null) {
|
||||||
&& !scopedCompanyId.equals(group.getCompanyId()))) {
|
|
||||||
throw new BusinessException("分组不存在");
|
throw new BusinessException("分组不存在");
|
||||||
}
|
}
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 同公司重名拒绝(409):{@code excludeId} 非空=改名时排除自身。 */
|
/** 全局重名拒绝(409):{@code excludeId} 非空=改名时排除自身。 */
|
||||||
private void requireNameFree(Long companyId, String name, Long excludeId) {
|
private void requireNameFree(String name, Long excludeId) {
|
||||||
Long count = jdProductGroupMapper.selectCount(new LambdaQueryWrapper<JdProductGroupEntity>()
|
Long count = jdProductGroupMapper.selectCount(new LambdaQueryWrapper<JdProductGroupEntity>()
|
||||||
.eq(JdProductGroupEntity::getCompanyId, companyId)
|
|
||||||
.eq(JdProductGroupEntity::getName, name)
|
.eq(JdProductGroupEntity::getName, name)
|
||||||
.ne(excludeId != null, JdProductGroupEntity::getId, excludeId));
|
.ne(excludeId != null, JdProductGroupEntity::getId, excludeId));
|
||||||
if (count != null && count > 0) {
|
if (count != null && count > 0) {
|
||||||
throw new BusinessException(409, "同公司下已存在同名分组:" + name);
|
throw new BusinessException(409, "已存在同名分组:" + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-19
@@ -35,9 +35,10 @@ 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>公司隔离</b>:{@code scopedCompanyId} 由控制器经 {@code DataReadScope#readCompanyIdOrOwn}
|
* <p><b>公司口径(2026-11-15 公共化)</b>:{@code scopedCompanyId} 由控制器经
|
||||||
* 算好传入——{@code null} = 超管没选公司、查全量;正数 = 只查该公司(非超管恒为自己的公司)。
|
* {@code DataReadScope#superAdminScopedCompanyId} 算好传入——只有站点超管显式传 company_id
|
||||||
* 详情同样按它收口:行 {@code company_id} 与公司隔离范围不符按不存在拒绝(不泄露跨公司行的存在性)。</p>
|
* (公司 tab 筛选)才是正数,其余请求(含全部非超管)恒为 {@code null} = 全量;详情没有
|
||||||
|
* 公司维度,按 id 直取。</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":"..."}}——
|
||||||
@@ -106,8 +107,9 @@ public class JdProductQueryService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
|
* 类目筛选下拉数据源(2026-11-15 用户口径「京麦的类目也要同步过来后台」):
|
||||||
* 本公司已落库行 distinct 的 {@code category_path}(=京麦末级类目名,契约 §2.3 E3)
|
* 已落库行 distinct 的 {@code category_path}(=京麦末级类目名,契约 §2.3 E3)
|
||||||
* + 各自行数,按类目名排序。公司隔离与分页同门(控制器经 {@code readCompanyIdOrOwn} 传入)。
|
* + 各自行数,按类目名排序。公司口径与分页同门(控制器经 {@code superAdminScopedCompanyId} 传入,
|
||||||
|
* {@code null} = 全量公共选项集)。
|
||||||
*/
|
*/
|
||||||
public List<JdProductCategoryVo> categories(Long scopedCompanyId) {
|
public List<JdProductCategoryVo> categories(Long scopedCompanyId) {
|
||||||
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
|
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
|
||||||
@@ -117,17 +119,16 @@ public class JdProductQueryService {
|
|||||||
/**
|
/**
|
||||||
* 商品详情(主字段全量 + attr_json 解析 + 已转存图片)。
|
* 商品详情(主字段全量 + attr_json 解析 + 已转存图片)。
|
||||||
*
|
*
|
||||||
* <p>公司隔离与分页同门:{@code scopedCompanyId} 非空且与行 {@code company_id} 不符时按
|
* <p>公共库无公司维度(2026-11-15 用户定案「京东数据库不区分公司」):按 id 直取,
|
||||||
* 不存在拒绝——不泄露跨公司行的存在性(越界 id 探测拿到的与 id 不存在是同一种响应)。
|
* 越界 id 按不存在拒绝。attr_json 非契约形状/解析异常时不抛 500:落空 {@code attrGroups}、
|
||||||
* attr_json 非契约形状/解析异常时不抛 500:落空 {@code attrGroups}、原文进
|
* 原文进 {@code attrJsonRaw} 兜底(AC-7)。</p>
|
||||||
* {@code attrJsonRaw} 兜底(AC-7)。</p>
|
|
||||||
*/
|
*/
|
||||||
public JdProductDetailVo detail(Long id, Long scopedCompanyId) {
|
public JdProductDetailVo detail(Long id) {
|
||||||
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 || !companyVisible(row.getCompanyId(), scopedCompanyId)) {
|
if (row == null) {
|
||||||
throw new BusinessException("商品不存在");
|
throw new BusinessException("商品不存在");
|
||||||
}
|
}
|
||||||
JdProductDetailVo vo = new JdProductDetailVo();
|
JdProductDetailVo vo = new JdProductDetailVo();
|
||||||
@@ -181,14 +182,6 @@ public class JdProductQueryService {
|
|||||||
trimToNull(category), safeGroupId, syncedFrom, syncedTo);
|
trimToNull(category), safeGroupId, syncedFrom, syncedTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 超管不选公司(scopedCompanyId=null)=全量可见;正数=只看该公司。 */
|
|
||||||
private static boolean companyVisible(Long rowCompanyId, Long scopedCompanyId) {
|
|
||||||
if (scopedCompanyId == null || scopedCompanyId <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return scopedCompanyId.equals(rowCompanyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------- 列表/详情搬运
|
// ---------------------------------------------------------------- 列表/详情搬运
|
||||||
|
|
||||||
/** 行值原样搬运(读侧不加工),groupName 由 {@link #fillGroupNames} 批量补齐。 */
|
/** 行值原样搬运(读侧不加工),groupName 由 {@link #fillGroupNames} 批量补齐。 */
|
||||||
|
|||||||
+8
-16
@@ -35,9 +35,9 @@ import java.util.Set;
|
|||||||
* <p>三条块语义:</p>
|
* <p>三条块语义:</p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><b>主字段全量提交</b>:标题/品牌/类目/货号/价格区间/总库存/状态/分组按请求体覆写;
|
* <li><b>主字段全量提交</b>:标题/品牌/类目/货号/价格区间/总库存/状态/分组按请求体覆写;
|
||||||
* 分组 id 归属必须与商品行同公司(防跨公司挂组)。保存即置 {@code manual_locked=1}(V199
|
* 分组 id 必须真实存在(分组 2026-11-15 起全平台一份,无公司维度)。保存即置
|
||||||
* 人工编辑锁)——采集回传的 upsert / 图片与 SKU 登记 / 覆盖清理对锁定的行全部跳过,
|
* {@code manual_locked=1}(V199 人工编辑锁)——采集回传的 upsert / 图片与 SKU 登记 /
|
||||||
* 人工值不被重爬覆盖。</li>
|
* 覆盖清理对锁定的行全部跳过,人工值不被重爬覆盖。</li>
|
||||||
* <li><b>可选块缺省不动</b>:{@code attrGroups} 缺省不动属性;提交时只重建 attr_json 的
|
* <li><b>可选块缺省不动</b>:{@code attrGroups} 缺省不动属性;提交时只重建 attr_json 的
|
||||||
* {@code tabs} 段、<b>保留原 JSON 其它顶层键</b>(images/productCode 等,铁律 30 形状:
|
* {@code tabs} 段、<b>保留原 JSON 其它顶层键</b>(images/productCode 等,铁律 30 形状:
|
||||||
* 不整份覆写别人的键);原文解析不出(attrJsonRaw 兜底行)则明确拒绝,不让编辑静默丢原文。
|
* 不整份覆写别人的键);原文解析不出(attrJsonRaw 兜底行)则明确拒绝,不让编辑静默丢原文。
|
||||||
@@ -80,15 +80,15 @@ public class JdProductUpdateService {
|
|||||||
/**
|
/**
|
||||||
* 编辑保存,返回商品行 id(控制器用它回读刷新后的详情 VO)。
|
* 编辑保存,返回商品行 id(控制器用它回读刷新后的详情 VO)。
|
||||||
*
|
*
|
||||||
* <p>公司隔离与详情同门:行 company_id 与范围不符按不存在拒绝(不泄露越界行存在性)。</p>
|
* <p>公共库无公司维度(2026-11-15 用户定案):任何拿到本页菜单权限的管理员可编辑全部行。</p>
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long update(Long id, JdProductUpdateRequest body, Long scopedCompanyId) {
|
public Long update(Long id, JdProductUpdateRequest body) {
|
||||||
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 || !companyVisible(row.getCompanyId(), scopedCompanyId)) {
|
if (row == null) {
|
||||||
throw new BusinessException("商品不存在");
|
throw new BusinessException("商品不存在");
|
||||||
}
|
}
|
||||||
validateBody(body);
|
validateBody(body);
|
||||||
@@ -96,8 +96,8 @@ public class JdProductUpdateService {
|
|||||||
Long groupId = body.getGroupId();
|
Long groupId = body.getGroupId();
|
||||||
if (groupId != null) {
|
if (groupId != null) {
|
||||||
JdProductGroupEntity group = jdProductGroupMapper.selectById(groupId);
|
JdProductGroupEntity group = jdProductGroupMapper.selectById(groupId);
|
||||||
if (group == null || !row.getCompanyId().equals(group.getCompanyId())) {
|
if (group == null) {
|
||||||
throw new BusinessException("分组不存在或不属于当前公司,请刷新分组后重试");
|
throw new BusinessException("分组不存在,请刷新分组后重试");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,14 +186,6 @@ public class JdProductUpdateService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 超管不选公司(scopedCompanyId=null)=全量可编辑;正数=只可编辑该公司行。 */
|
|
||||||
private static boolean companyVisible(Long rowCompanyId, Long scopedCompanyId) {
|
|
||||||
if (scopedCompanyId == null || scopedCompanyId <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return scopedCompanyId.equals(rowCompanyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------- 属性重建(只重建 tabs 段,其余顶层键保留) ----------
|
// ---------- 属性重建(只重建 tabs 段,其余顶层键保留) ----------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+163
@@ -0,0 +1,163 @@
|
|||||||
|
-- =============================================================
|
||||||
|
-- 迁移 V200__jd_product_group_shared_across_companies
|
||||||
|
-- 需求:2026-11-15 用户定案「京东数据库不区分公司、属于公共的」「分组就是和亚马逊功能一样」
|
||||||
|
-- 前版:V195(京东分组表按公司一套,uk_company_group_name)
|
||||||
|
--
|
||||||
|
-- 1. 变更目的:把「京东数据库」分组 biz_jd_product_group 的唯一键从"公司+名"退回【全平台】
|
||||||
|
-- 键,与同批 jar 里已经摘掉公司谓词的读写侧对齐(分组挂到 AdminJdProductGroupController /
|
||||||
|
-- JdProductGroupService,读写两侧都不再引用 company_id)。不退这一刀的后果不是"看不到",
|
||||||
|
-- 是"写不进去":新代码的 INSERT 不带 company_id(实体字段不再赋值),旧键 (company_id, name)
|
||||||
|
-- 在功能上"暂时还能用"——但它把第 2 家公司将来建的同名分组挡在同一行里,而这一版之后
|
||||||
|
-- 系统里根本不存在"哪一家的分组"这个概念,键里留着公司维度就是一把没有对照物的锁。
|
||||||
|
--
|
||||||
|
-- 2. 口径:
|
||||||
|
-- uk_company_group_name(company_id, name) -> uk_group_name(name)
|
||||||
|
-- 键名复用 V151__rule_tables_shared_across_companies 的退键纪律(先加全局键、再摘公司键,
|
||||||
|
-- 中间任一步失败时至少还有一个唯一键在守并发)。
|
||||||
|
-- 同名组归并:V195 上线(2026-11-14)以来各公司可建同名组;退全局键前必须先归并——
|
||||||
|
-- 每个分组名保留最小 id 一行,其余行的商品(biz_jd_product.group_id)改挂到保留行,
|
||||||
|
-- 再删除多余组行。临时表 _v200_group_map(old_id, keep_id) 只记"要删的行"。
|
||||||
|
-- 【company_id 列不 DROP】(V151 第 6 段同一理由):上一版 jar 的读写两侧还带着
|
||||||
|
-- company_id(实体字段 + insert 列清单),删列与换键同批必然在混合窗口里打断旧 jar。
|
||||||
|
-- 本版只把 DEFAULT 补上(NOT NULL DEFAULT 0):新 jar 的 INSERT 不带这一列,
|
||||||
|
-- 靠 DEFAULT 0 落「平台公共」;历史行保留原公司号,只作"哪家客户端同步的"溯源标记。
|
||||||
|
-- 【CompanyDefaultGuard 不登记本表】:该哨兵只盯"仍然按公司写"的表;本表自本版起
|
||||||
|
-- 读写两侧都不分公司,喊"去摘 DEFAULT"会让人把唯一能兜住 NOT NULL 的默认值摘掉(1364)。
|
||||||
|
--
|
||||||
|
-- 3. 影响表与数据量:分组行数=公司数×用户自建组数(十级量级),归并扫描毫秒级;
|
||||||
|
-- 商品侧 UPDATE 只动 group_id 指向被归并行的那部分(通常 0 行)。任何形态都在毫秒级,
|
||||||
|
-- ADD UNIQUE 仍钉 ALGORITHM = INPLACE, LOCK = NONE,不给"顺手退化成交换锁"留机会。
|
||||||
|
--
|
||||||
|
-- 4. 可重跑性:归并段只在 uk_company_group_name 仍存在时执行;四条 DDL 都先查
|
||||||
|
-- information_schema 再 PREPARE(V145 首例写法),重跑逐条 no-op。
|
||||||
|
--
|
||||||
|
-- 5. 回滚(人工补丁,写成注释以免落在 Flyway 扫描路径里被当迁移执行):
|
||||||
|
-- ALTER TABLE biz_jd_product_group ADD UNIQUE KEY uk_company_group_name (company_id, name);
|
||||||
|
-- ALTER TABLE biz_jd_product_group DROP INDEX uk_group_name;
|
||||||
|
-- ALTER TABLE biz_jd_product_group MODIFY COLUMN company_id BIGINT NOT NULL
|
||||||
|
-- COMMENT '归属分公司(分组按公司隔离,R4)';
|
||||||
|
-- (jar 必须先回到带公司谓词的那版,否则"键按公司、代码不分公司"会让第 2 家建出
|
||||||
|
-- 与第 1 家同键的行;归并掉的组行不可自动找回,回滚前先备份。)
|
||||||
|
-- =============================================================
|
||||||
|
|
||||||
|
SET @db_name = DATABASE();
|
||||||
|
|
||||||
|
-- ---------- 1. 同名组归并(只在公司键仍在时执行;每组保留最小 id) ----------
|
||||||
|
|
||||||
|
SET @v200_old_uk := (SELECT COUNT(DISTINCT INDEX_NAME) FROM information_schema.STATISTICS
|
||||||
|
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'biz_jd_product_group' AND INDEX_NAME = 'uk_company_group_name');
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS _v200_group_map (
|
||||||
|
old_id BIGINT NOT NULL PRIMARY KEY,
|
||||||
|
keep_id BIGINT NOT NULL
|
||||||
|
) ENGINE = InnoDB;
|
||||||
|
|
||||||
|
-- 重复执行前先清空(Flyway 重跑整个文件时临时表可能已存在)。
|
||||||
|
DELETE FROM _v200_group_map;
|
||||||
|
|
||||||
|
-- 每个分组名保留最小 id;其余行进归并映射。
|
||||||
|
INSERT INTO _v200_group_map (old_id, keep_id)
|
||||||
|
SELECT g.id, keep.first_id
|
||||||
|
FROM biz_jd_product_group g
|
||||||
|
JOIN (
|
||||||
|
SELECT name, MIN(id) AS first_id
|
||||||
|
FROM biz_jd_product_group
|
||||||
|
GROUP BY name
|
||||||
|
HAVING COUNT(*) > 1
|
||||||
|
) dup ON dup.name = g.name
|
||||||
|
JOIN (
|
||||||
|
SELECT name, MIN(id) AS first_id
|
||||||
|
FROM biz_jd_product_group
|
||||||
|
GROUP BY name
|
||||||
|
) keep ON keep.name = g.name
|
||||||
|
WHERE g.id <> keep.first_id
|
||||||
|
AND @v200_old_uk > 0;
|
||||||
|
|
||||||
|
-- 商品改挂保留组(只动指向被归并行的 group_id)。
|
||||||
|
UPDATE biz_jd_product p
|
||||||
|
JOIN _v200_group_map m ON p.group_id = m.old_id
|
||||||
|
SET p.group_id = m.keep_id;
|
||||||
|
|
||||||
|
-- 删除被归并的组行。
|
||||||
|
DELETE g FROM biz_jd_product_group g
|
||||||
|
JOIN _v200_group_map m ON g.id = m.old_id;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS _v200_group_map;
|
||||||
|
|
||||||
|
-- ---------- 2. 分组表:先加全局键 ----------
|
||||||
|
|
||||||
|
SET @idx_exists := (SELECT COUNT(DISTINCT INDEX_NAME) FROM information_schema.STATISTICS
|
||||||
|
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'biz_jd_product_group' AND INDEX_NAME = 'uk_group_name');
|
||||||
|
SET @sql := IF(@idx_exists = 0,
|
||||||
|
'ALTER TABLE `biz_jd_product_group` ADD UNIQUE KEY `uk_group_name` (`name`), ALGORITHM = INPLACE, LOCK = NONE',
|
||||||
|
'SELECT 1');
|
||||||
|
PREPARE stmt FROM @sql;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
-- ---------- 3. 分组表:再摘公司键 ----------
|
||||||
|
|
||||||
|
SET @idx_exists := (SELECT COUNT(DISTINCT INDEX_NAME) FROM information_schema.STATISTICS
|
||||||
|
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'biz_jd_product_group' AND INDEX_NAME = 'uk_company_group_name');
|
||||||
|
SET @sql := IF(@idx_exists > 0,
|
||||||
|
'ALTER TABLE `biz_jd_product_group` DROP INDEX `uk_company_group_name`, ALGORITHM = INPLACE, LOCK = NONE',
|
||||||
|
'SELECT 1');
|
||||||
|
PREPARE stmt FROM @sql;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
-- ---------- 4. 摘按公司取全量的二级索引(读侧已不按 company_id 筛) ----------
|
||||||
|
|
||||||
|
SET @idx_exists := (SELECT COUNT(DISTINCT INDEX_NAME) FROM information_schema.STATISTICS
|
||||||
|
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'biz_jd_product_group' AND INDEX_NAME = 'idx_company');
|
||||||
|
SET @sql := IF(@idx_exists > 0,
|
||||||
|
'ALTER TABLE `biz_jd_product_group` DROP INDEX `idx_company`, ALGORITHM = INPLACE, LOCK = NONE',
|
||||||
|
'SELECT 1');
|
||||||
|
PREPARE stmt FROM @sql;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
-- ---------- 5. company_id 补 DEFAULT 0(新 INSERT 不带这一列,靠它满足 NOT NULL) ----------
|
||||||
|
|
||||||
|
SET @col_default := (SELECT COLUMN_DEFAULT FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'biz_jd_product_group' AND COLUMN_NAME = 'company_id');
|
||||||
|
SET @v200_needs_default := (@col_default IS NULL OR (@col_default <> '0' AND @col_default <> 'NULL'));
|
||||||
|
SET @sql := IF(@v200_needs_default,
|
||||||
|
'ALTER TABLE `biz_jd_product_group` MODIFY COLUMN `company_id` BIGINT NOT NULL DEFAULT 0 COMMENT ''历史归属公司(V195~V199 按公司隔离时代遗留;2026-11-15 公共化后读写两侧不再引用,新行 0=平台公共)''',
|
||||||
|
'SELECT 1');
|
||||||
|
PREPARE stmt FROM @sql;
|
||||||
|
EXECUTE stmt;
|
||||||
|
DEALLOCATE PREPARE stmt;
|
||||||
|
|
||||||
|
-- =============================================================
|
||||||
|
-- 验证 SQL(迁移后在库上执行,必须有人实跑,不许只看启动日志的 Successfully applied)
|
||||||
|
--
|
||||||
|
-- SELECT TABLE_NAME, INDEX_NAME, GROUP_CONCAT(CONCAT(COLUMN_NAME,'@',SEQ_IN_INDEX) ORDER BY SEQ_IN_INDEX) AS cols
|
||||||
|
-- FROM information_schema.STATISTICS
|
||||||
|
-- WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'biz_jd_product_group' AND NON_UNIQUE = 0
|
||||||
|
-- GROUP BY TABLE_NAME, INDEX_NAME;
|
||||||
|
-- -> 期望恰好两行:PRIMARY(id)、uk_group_name(name@1);
|
||||||
|
-- uk_company_group_name / idx_company 必须不在结果里。
|
||||||
|
--
|
||||||
|
-- SELECT COUNT(*) AS dup_group_names FROM (
|
||||||
|
-- SELECT name FROM biz_jd_product_group GROUP BY name HAVING COUNT(*) > 1 LIMIT 1
|
||||||
|
-- ) t;
|
||||||
|
-- -> 期望 0(第 2 步 ADD UNIQUE 能建起的前提)。
|
||||||
|
--
|
||||||
|
-- SELECT COUNT(*) AS orphan_group_products FROM biz_jd_product p
|
||||||
|
-- LEFT JOIN biz_jd_product_group g ON g.id = p.group_id
|
||||||
|
-- WHERE p.group_id IS NOT NULL AND g.id IS NULL;
|
||||||
|
-- -> 期望 0:归并后没有商品还挂着已删除的组行。
|
||||||
|
--
|
||||||
|
-- SHOW COLUMNS FROM biz_jd_product_group LIKE 'company_id';
|
||||||
|
-- -> 期望 Null = NO、Default = 0。本版【故意保留列】:旧 jar 的读写两侧还引用它。
|
||||||
|
--
|
||||||
|
-- INSERT IGNORE 在退回全局键后(事务内跑完回滚,只插 ZZTEST 前缀):
|
||||||
|
-- START TRANSACTION;
|
||||||
|
-- INSERT INTO biz_jd_product_group (name) VALUES ('ZZTESTGROUP0001');
|
||||||
|
-- INSERT INTO biz_jd_product_group (name) VALUES ('ZZTESTGROUP0001');
|
||||||
|
-- SELECT COUNT(*) AS one_row FROM biz_jd_product_group WHERE name = 'ZZTESTGROUP0001';
|
||||||
|
-- ROLLBACK;
|
||||||
|
-- -> 期望 one_row = 1:同名第二次被 IGNORE 掉 = 键真的回到全平台一档,且
|
||||||
|
-- company_id 由 DEFAULT 0 兜住(新 INSERT 不带这一列)。
|
||||||
|
-- =============================================================
|
||||||
+44
-43
@@ -48,14 +48,16 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* v1.4 Phase 5:后管「京东数据库」只读接口(列表/详情)与分组管理入口。
|
* v1.4 Phase 5:后管「京东数据库」只读接口(列表/详情)与分组管理入口。
|
||||||
*
|
*
|
||||||
* <p>结构判据(照 {@code AdminAppearancePatentCleanItemsControllerTest} 双形态):
|
* <p>结构判据(照 {@code AdminAppearancePatentCleanItemsControllerTest} 双形态):
|
||||||
* 端点只读、鉴权 seam、公司隔离正门、snake 参数带默认值、SQL 只落 XML;
|
* 端点只读、鉴权 seam、公司口径(读侧只剩超管筛选 superAdminScopedCompanyId,公共库不走
|
||||||
* 行为样本:mock HttpServletRequest 把 company 参数交给 readCompanyIdOrOwn 并装进 200 信封、
|
* readCompanyIdOrOwn)、snake 参数带默认值、SQL 只落 XML;
|
||||||
|
* 行为样本:mock HttpServletRequest 把 company 参数交给 superAdminScopedCompanyId 并装进 200 信封、
|
||||||
* 分页钳制 offset/limit(page=Long.MAX_VALUE 不得负,铁律 15)、详情 attr_json
|
* 分页钳制 offset/limit(page=Long.MAX_VALUE 不得负,铁律 15)、详情 attr_json
|
||||||
* tabs→attrGroups 解析与非法形状兜底(AC-7)。
|
* tabs→attrGroups 解析与非法形状兜底(AC-7)。
|
||||||
* 导出端点与 sale_status 筛选参数已随 2026-11-15 客户口径整段下线(反向钉住防回潜)。</p>
|
* 导出端点与 sale_status 筛选参数已随 2026-11-15 客户口径整段下线(反向钉住防回潜)。</p>
|
||||||
@@ -109,13 +111,14 @@ class AdminJdProductControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 公司隔离走readCompanyIdOrOwn() throws IOException {
|
void 公司口径只剩超管筛选_公共库不走readCompanyIdOrOwn() throws IOException {
|
||||||
String source = stripComments(Files.readString(CONTROLLER));
|
String source = stripComments(Files.readString(CONTROLLER));
|
||||||
assertTrue(source.contains("DataReadScope"), "公司隔离唯一出口是 DataReadScope");
|
assertTrue(source.contains("DataReadScope"), "公司维度唯一出口是 DataReadScope");
|
||||||
assertTrue(source.contains("readCompanyIdOrOwn"),
|
assertTrue(source.contains("superAdminScopedCompanyId"),
|
||||||
"读侧必须走 readCompanyIdOrOwn:超管显式传才收窄,非超管强制本公司");
|
"读侧(列表/类目)必须走 superAdminScopedCompanyId:只有站点超管显式传 company_id 才收窄"
|
||||||
assertFalse(source.contains("superAdminScopedCompanyId"),
|
+ "(公司 tab 筛选管理员),其余请求全量(2026-11-15 用户定案「京东数据库不区分公司、属于公共的」)");
|
||||||
"不得走 superAdminScopedCompanyId:它对非超管返回 null=按行 company_id 查询时把整张表交给每一家");
|
assertFalse(source.contains("readCompanyIdOrOwn"),
|
||||||
|
"不得走 readCompanyIdOrOwn:它对非超管强制本公司,公共库对每一家管理员都是同一份全量");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -169,7 +172,7 @@ class AdminJdProductControllerTest {
|
|||||||
// ===================== 行为样本 =====================
|
// ===================== 行为样本 =====================
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 控制器把公司参数交给readCompanyIdOrOwn并把结果装进200信封() {
|
void 控制器把公司参数交给superAdminScopedCompanyId并把结果装进200信封() {
|
||||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||||
@@ -183,8 +186,8 @@ class AdminJdProductControllerTest {
|
|||||||
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");
|
||||||
// 超管显式传 company_id=5 ⇒ 正门把 5 交出来(不传时正门给 null=全量,同一行为样本家族)。
|
// 超管显式传 company_id=5 ⇒ 超管筛选把 5 交出来(不传时给 null=全量,同一行为样本家族)。
|
||||||
when(dataReadScope.readCompanyIdOrOwn(operator, 5L)).thenReturn(5L);
|
when(dataReadScope.superAdminScopedCompanyId(operator, 5L)).thenReturn(5L);
|
||||||
JdProductPageVo pageVo = new JdProductPageVo();
|
JdProductPageVo pageVo = new JdProductPageVo();
|
||||||
pageVo.setItems(List.of());
|
pageVo.setItems(List.of());
|
||||||
pageVo.setTotal(0L);
|
pageVo.setTotal(0L);
|
||||||
@@ -195,14 +198,14 @@ class AdminJdProductControllerTest {
|
|||||||
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null, null,
|
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null, null,
|
||||||
null, null, 5L, request);
|
null, null, 5L, request);
|
||||||
|
|
||||||
verify(dataReadScope).readCompanyIdOrOwn(operator, 5L);
|
verify(dataReadScope).superAdminScopedCompanyId(operator, 5L);
|
||||||
verify(queryService).page(1L, 20L, 5L, null, null, null, null, null, null, null);
|
verify(queryService).page(1L, 20L, 5L, null, null, null, null, null, null, null);
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 类目下拉端点走同一正门并回选项集() {
|
void 类目下拉端点走同一超管筛选口径并回选项集() {
|
||||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||||
DataReadScope dataReadScope = mock(DataReadScope.class);
|
DataReadScope dataReadScope = mock(DataReadScope.class);
|
||||||
@@ -215,8 +218,7 @@ class AdminJdProductControllerTest {
|
|||||||
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");
|
||||||
// 非超管正门强制本公司:即使请求带别的 company_id 也按返回值收口(同一行为样本家族)。
|
when(dataReadScope.superAdminScopedCompanyId(operator, 5L)).thenReturn(5L);
|
||||||
when(dataReadScope.readCompanyIdOrOwn(operator, 5L)).thenReturn(5L);
|
|
||||||
JdProductCategoryVo row = new JdProductCategoryVo();
|
JdProductCategoryVo row = new JdProductCategoryVo();
|
||||||
row.setName("艺考形体服");
|
row.setName("艺考形体服");
|
||||||
row.setProductCount(85L);
|
row.setProductCount(85L);
|
||||||
@@ -224,7 +226,7 @@ class AdminJdProductControllerTest {
|
|||||||
|
|
||||||
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(5L, request);
|
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(5L, request);
|
||||||
|
|
||||||
verify(dataReadScope).readCompanyIdOrOwn(operator, 5L);
|
verify(dataReadScope).superAdminScopedCompanyId(operator, 5L);
|
||||||
verify(queryService).categories(5L);
|
verify(queryService).categories(5L);
|
||||||
assertEquals(Boolean.TRUE, response.isSuccess(), "类目下拉与列表同一鉴权正门(200 信封)");
|
assertEquals(Boolean.TRUE, response.isSuccess(), "类目下拉与列表同一鉴权正门(200 信封)");
|
||||||
assertEquals("艺考形体服", response.getData().get(0).getName(), "选项=已落库行的末级类目名");
|
assertEquals("艺考形体服", response.getData().get(0).getName(), "选项=已落库行的末级类目名");
|
||||||
@@ -232,7 +234,7 @@ class AdminJdProductControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 控制器详情走同一鉴权正门并回详情() {
|
void 控制器详情走同一鉴权正门并回详情且不问公司() {
|
||||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||||
DataReadScope dataReadScope = mock(DataReadScope.class);
|
DataReadScope dataReadScope = mock(DataReadScope.class);
|
||||||
@@ -245,22 +247,21 @@ class AdminJdProductControllerTest {
|
|||||||
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");
|
||||||
// 详情不收 company 参数:超管不传=全量可见;非超管由正门强制本公司(服务按返回值收口)。
|
|
||||||
when(dataReadScope.readCompanyIdOrOwn(operator, null)).thenReturn(null);
|
|
||||||
JdProductDetailVo detailVo = new JdProductDetailVo();
|
JdProductDetailVo detailVo = new JdProductDetailVo();
|
||||||
detailVo.setId(11L);
|
detailVo.setId(11L);
|
||||||
when(queryService.detail(11L, null)).thenReturn(detailVo);
|
when(queryService.detail(11L)).thenReturn(detailVo);
|
||||||
|
|
||||||
ApiResponse<JdProductDetailVo> response = controller.detail(11L, request);
|
ApiResponse<JdProductDetailVo> response = controller.detail(11L, request);
|
||||||
|
|
||||||
verify(dataReadScope).readCompanyIdOrOwn(operator, null);
|
// 公共库详情没有公司维度:DataReadScope 不参与(防有人把公司收口接回来)。
|
||||||
verify(queryService).detail(11L, null);
|
verifyNoInteractions(dataReadScope);
|
||||||
|
verify(queryService).detail(11L);
|
||||||
assertEquals(Boolean.TRUE, response.isSuccess());
|
assertEquals(Boolean.TRUE, response.isSuccess());
|
||||||
assertEquals(detailVo, response.getData());
|
assertEquals(detailVo, response.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 删除端点走同一正门并把服务回执装进200信封() {
|
void 删除端点按公共库直判存在并把服务回执装进200信封() {
|
||||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||||
JdProductDeleteService deleteService = mock(JdProductDeleteService.class);
|
JdProductDeleteService deleteService = mock(JdProductDeleteService.class);
|
||||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||||
@@ -274,17 +275,17 @@ class AdminJdProductControllerTest {
|
|||||||
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");
|
||||||
when(dataReadScope.readCompanyIdOrOwn(operator, 5L)).thenReturn(5L);
|
|
||||||
JdProductDeleteVo receipt = new JdProductDeleteVo();
|
JdProductDeleteVo receipt = new JdProductDeleteVo();
|
||||||
receipt.setDeleted(1);
|
receipt.setDeleted(1);
|
||||||
receipt.setObjectsDeleted(9);
|
receipt.setObjectsDeleted(9);
|
||||||
receipt.setObjectsKept(2);
|
receipt.setObjectsKept(2);
|
||||||
when(deleteService.delete(List.of(11L), 5L)).thenReturn(receipt);
|
when(deleteService.delete(List.of(11L))).thenReturn(receipt);
|
||||||
|
|
||||||
ApiResponse<JdProductDeleteVo> response = controller.delete(11L, 5L, request);
|
ApiResponse<JdProductDeleteVo> response = controller.delete(11L, request);
|
||||||
|
|
||||||
verify(dataReadScope).readCompanyIdOrOwn(operator, 5L);
|
// 公共库写侧没有公司维度:不收 company_id、DataReadScope 不参与。
|
||||||
verify(deleteService).delete(List.of(11L), 5L);
|
verifyNoInteractions(dataReadScope);
|
||||||
|
verify(deleteService).delete(List.of(11L));
|
||||||
assertEquals(Boolean.TRUE, response.isSuccess());
|
assertEquals(Boolean.TRUE, response.isSuccess());
|
||||||
assertEquals(9, response.getData().getObjectsDeleted());
|
assertEquals(9, response.getData().getObjectsDeleted());
|
||||||
}
|
}
|
||||||
@@ -304,14 +305,13 @@ class AdminJdProductControllerTest {
|
|||||||
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");
|
||||||
when(dataReadScope.readCompanyIdOrOwn(operator, null)).thenReturn(5L);
|
when(deleteService.delete(List.of(11L, 12L)))
|
||||||
when(deleteService.delete(List.of(11L, 12L), 5L))
|
.thenThrow(new BusinessException("有 1 个商品不存在,请刷新后重试(本次未删除任何数据)"));
|
||||||
.thenThrow(new BusinessException("有 1 个商品不存在或不属于当前公司,请刷新后重试(本次未删除任何数据)"));
|
|
||||||
|
|
||||||
JdProductBatchDeleteRequest body = new JdProductBatchDeleteRequest();
|
JdProductBatchDeleteRequest body = new JdProductBatchDeleteRequest();
|
||||||
body.setIds(List.of(11L, 12L));
|
body.setIds(List.of(11L, 12L));
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> controller.batchDelete(body, null, request));
|
() -> controller.batchDelete(body, request));
|
||||||
assertTrue(ex.getMessage().contains("本次未删除任何数据"), "整批拒绝的语义必须到界面");
|
assertTrue(ex.getMessage().contains("本次未删除任何数据"), "整批拒绝的语义必须到界面");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +402,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, 5L);
|
JdProductDetailVo vo = service.detail(11L);
|
||||||
|
|
||||||
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());
|
||||||
@@ -433,7 +433,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, 5L);
|
JdProductDetailVo brokenVo = service.detail(11L);
|
||||||
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 兜底展示");
|
||||||
|
|
||||||
@@ -441,7 +441,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, 5L);
|
JdProductDetailVo foreignVo = service.detail(11L);
|
||||||
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)");
|
||||||
@@ -450,7 +450,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, 5L);
|
JdProductDetailVo blankVo = service.detail(11L);
|
||||||
assertTrue(blankVo.getAttrGroups().isEmpty());
|
assertTrue(blankVo.getAttrGroups().isEmpty());
|
||||||
assertNull(blankVo.getAttrJsonRaw());
|
assertNull(blankVo.getAttrJsonRaw());
|
||||||
}
|
}
|
||||||
@@ -482,7 +482,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, 5L);
|
JdProductDetailVo vo = service.detail(11L);
|
||||||
|
|
||||||
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);
|
||||||
@@ -499,23 +499,24 @@ class AdminJdProductControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 详情公司越界按不存在拒绝() {
|
void 详情按公共库直取_缺失按不存在拒绝() {
|
||||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||||
JdProductQueryService service = new JdProductQueryService(mapper, mock(JdProductImageMapper.class),
|
JdProductQueryService service = new JdProductQueryService(mapper, mock(JdProductImageMapper.class),
|
||||||
mock(com.nanri.aiimage.modules.jd.mapper.JdProductSkuMapper.class),
|
mock(com.nanri.aiimage.modules.jd.mapper.JdProductSkuMapper.class),
|
||||||
mock(com.nanri.aiimage.modules.jd.mapper.JdProductGroupMapper.class));
|
mock(com.nanri.aiimage.modules.jd.mapper.JdProductGroupMapper.class));
|
||||||
|
|
||||||
|
// 公共库(2026-11-15 用户定案):详情没有公司维度,别家公司时代的行照样可读。
|
||||||
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));
|
||||||
|
|
||||||
// 非超管(scopedCompanyId=5):行属公司 6 ⇒ 按「商品不存在」拒绝,不泄露跨公司行的存在性。
|
// 行不存在 ⇒ 按「商品不存在」拒绝。
|
||||||
BusinessException ex = assertThrows(BusinessException.class, () -> service.detail(11L, 5L));
|
when(mapper.selectById(11L)).thenReturn(null);
|
||||||
|
BusinessException ex = assertThrows(BusinessException.class, () -> service.detail(11L));
|
||||||
assertTrue(ex.getMessage().contains("商品不存在"));
|
assertTrue(ex.getMessage().contains("商品不存在"));
|
||||||
// 超管不选公司(null)=全量可见。
|
|
||||||
assertNotNull(service.detail(11L, null));
|
|
||||||
// id 非法同样拒绝。
|
// id 非法同样拒绝。
|
||||||
assertThrows(BusinessException.class, () -> service.detail(0L, null));
|
assertThrows(BusinessException.class, () -> service.detail(0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+21
-32
@@ -37,9 +37,10 @@ import static org.mockito.Mockito.when;
|
|||||||
* 京东商品删除编排判据(用户口径「后台删除数据的时候也要把桶对应的文件删除」)。
|
* 京东商品删除编排判据(用户口径「后台删除数据的时候也要把桶对应的文件删除」)。
|
||||||
*
|
*
|
||||||
* <p>钉四件事:①<b>先删桶、全成功才删库行</b>——桶失败时库行删除出口必须零调用
|
* <p>钉四件事:①<b>先删桶、全成功才删库行</b>——桶失败时库行删除出口必须零调用
|
||||||
* (库行先消失就再没人知道该删哪些 key,对象成永久孤儿);②共用对象不删(同公司
|
* (库行先消失就再没人知道该删哪些 key,对象成永久孤儿);②共用对象不删(同内容同 key,
|
||||||
* 同内容同 key,删一个商品的图不能把别的商品搞裂图);③归属先判、越界整批拒绝
|
* 删一个商品的图不能把别的商品搞裂图);③存在先判、缺失整批拒绝(不做部分删除);
|
||||||
* (不做部分删除);④前缀外的 key 不动手(只留 WARN),防脏数据把删除扩到别的桶前缀。</p>
|
* ④前缀外的 key 不动手(只留 WARN),防脏数据把删除扩到别的桶前缀。
|
||||||
|
* 公共库无公司维度(2026-11-15 用户定案):删除按 id 直判存在性,不再按 company_id 收口。</p>
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class JdProductDeleteServiceTest {
|
class JdProductDeleteServiceTest {
|
||||||
@@ -93,7 +94,7 @@ class JdProductDeleteServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void 先删桶_全成功才删库行() {
|
void 先删桶_全成功才删库行() {
|
||||||
givenOwnedRows(List.of(11L));
|
givenOwnedRows(List.of(11L));
|
||||||
// selectList 依次被调:①商品归属闸 ②图片行取数 ③共用性回查(mock 不看 wrapper 条件,
|
// selectList 依次被调:①商品存在闸 ②图片行取数 ③共用性回查(mock 不看 wrapper 条件,
|
||||||
// 所以回查那次显式给空——没人引用这张图,才能真的删)。
|
// 所以回查那次显式给空——没人引用这张图,才能真的删)。
|
||||||
when(jdProductMapper.selectList(any())).thenReturn(List.of(productRow(11L)));
|
when(jdProductMapper.selectList(any())).thenReturn(List.of(productRow(11L)));
|
||||||
when(jdProductImageMapper.selectList(any()))
|
when(jdProductImageMapper.selectList(any()))
|
||||||
@@ -101,7 +102,7 @@ class JdProductDeleteServiceTest {
|
|||||||
.thenReturn(List.of());
|
.thenReturn(List.of());
|
||||||
when(jdProductRowDeleteService.deleteRows(List.of(11L))).thenReturn(1);
|
when(jdProductRowDeleteService.deleteRows(List.of(11L))).thenReturn(1);
|
||||||
|
|
||||||
JdProductDeleteVo vo = service.delete(List.of(11L), COMPANY_ID);
|
JdProductDeleteVo vo = service.delete(List.of(11L));
|
||||||
|
|
||||||
// 顺序:removeObject 先于 deleteRows。
|
// 顺序:removeObject 先于 deleteRows。
|
||||||
var inOrder = org.mockito.Mockito.inOrder(ossStorageService, jdProductRowDeleteService);
|
var inOrder = org.mockito.Mockito.inOrder(ossStorageService, jdProductRowDeleteService);
|
||||||
@@ -120,7 +121,7 @@ class JdProductDeleteServiceTest {
|
|||||||
doThrow(new RuntimeException("oss 5xx"))
|
doThrow(new RuntimeException("oss 5xx"))
|
||||||
.when(ossStorageService).removeObject(anyString(), anyString());
|
.when(ossStorageService).removeObject(anyString(), anyString());
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.delete(List.of(11L), COMPANY_ID))
|
assertThatThrownBy(() -> service.delete(List.of(11L)))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("本次未删除任何数据");
|
.hasMessageContaining("本次未删除任何数据");
|
||||||
|
|
||||||
@@ -130,14 +131,14 @@ class JdProductDeleteServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void 被其他商品共用的对象保留不删() {
|
void 被其他商品共用的对象保留不删() {
|
||||||
givenOwnedRows(List.of(11L));
|
givenOwnedRows(List.of(11L));
|
||||||
// selectList 依次被调:①商品归属闸 ②图片行取数 ③按 key 反查别的商品的共用性回查
|
// selectList 依次被调:①商品存在闸 ②图片行取数 ③按 key 反查别的商品的共用性回查
|
||||||
//(回查返回 99 号商品也引用同一 key ⇒ 保留)。
|
//(回查返回 99 号商品也引用同一 key ⇒ 保留)。
|
||||||
when(jdProductImageMapper.selectList(any()))
|
when(jdProductImageMapper.selectList(any()))
|
||||||
.thenReturn(List.of(image(11L, "jd-products/5/shared.jpg")))
|
.thenReturn(List.of(image(11L, "jd-products/5/shared.jpg")))
|
||||||
.thenReturn(List.of(image(99L, "jd-products/5/shared.jpg")));
|
.thenReturn(List.of(image(99L, "jd-products/5/shared.jpg")));
|
||||||
when(jdProductRowDeleteService.deleteRows(List.of(11L))).thenReturn(1);
|
when(jdProductRowDeleteService.deleteRows(List.of(11L))).thenReturn(1);
|
||||||
|
|
||||||
JdProductDeleteVo vo = service.delete(List.of(11L), COMPANY_ID);
|
JdProductDeleteVo vo = service.delete(List.of(11L));
|
||||||
|
|
||||||
verify(ossStorageService, never()).removeObject(anyString(), anyString());
|
verify(ossStorageService, never()).removeObject(anyString(), anyString());
|
||||||
assertThat(vo.getObjectsDeleted()).isZero();
|
assertThat(vo.getObjectsDeleted()).isZero();
|
||||||
@@ -147,17 +148,22 @@ class JdProductDeleteServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void 越界或缺失的行整批拒绝_不做部分删除() {
|
void 存在闸不分公司_缺失的行整批拒绝_不做部分删除() {
|
||||||
// 请求 2 行,归属闸只找到 1 行(另一行不存在/不属于本公司)。
|
// 公共库(2026-11-15 用户定案):存在闸 wrapper 不带 company_id 谓词,任何公司的行都可删。
|
||||||
|
// 请求 2 行,存在闸只找到 1 行(另一行不存在)⇒ 整批拒绝。
|
||||||
JdProductEntity row = new JdProductEntity();
|
JdProductEntity row = new JdProductEntity();
|
||||||
row.setId(11L);
|
row.setId(11L);
|
||||||
row.setCompanyId(COMPANY_ID);
|
row.setCompanyId(COMPANY_ID);
|
||||||
when(jdProductMapper.selectList(any(Wrapper.class))).thenReturn(List.of(row));
|
when(jdProductMapper.selectList(any(Wrapper.class))).thenReturn(List.of(row));
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.delete(List.of(11L, 12L), COMPANY_ID))
|
assertThatThrownBy(() -> service.delete(List.of(11L, 12L)))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("本次未删除任何数据");
|
.hasMessageContaining("本次未删除任何数据");
|
||||||
|
|
||||||
|
ArgumentCaptor<Wrapper<JdProductEntity>> captor = ArgumentCaptor.forClass(Wrapper.class);
|
||||||
|
verify(jdProductMapper).selectList(captor.capture());
|
||||||
|
assertThat(captor.getValue().getSqlSegment()).doesNotContain("company_id");
|
||||||
|
|
||||||
verify(ossStorageService, never()).removeObject(anyString(), anyString());
|
verify(ossStorageService, never()).removeObject(anyString(), anyString());
|
||||||
verify(jdProductRowDeleteService, never()).deleteRows(any());
|
verify(jdProductRowDeleteService, never()).deleteRows(any());
|
||||||
}
|
}
|
||||||
@@ -169,7 +175,7 @@ class JdProductDeleteServiceTest {
|
|||||||
image(11L, "nanri-ai-images/legacy.jpg")));
|
image(11L, "nanri-ai-images/legacy.jpg")));
|
||||||
when(jdProductRowDeleteService.deleteRows(List.of(11L))).thenReturn(1);
|
when(jdProductRowDeleteService.deleteRows(List.of(11L))).thenReturn(1);
|
||||||
|
|
||||||
JdProductDeleteVo vo = service.delete(List.of(11L), COMPANY_ID);
|
JdProductDeleteVo vo = service.delete(List.of(11L));
|
||||||
|
|
||||||
verify(ossStorageService, never()).removeObject(anyString(), anyString());
|
verify(ossStorageService, never()).removeObject(anyString(), anyString());
|
||||||
assertThat(vo.getObjectsSkipped()).isEqualTo(1);
|
assertThat(vo.getObjectsSkipped()).isEqualTo(1);
|
||||||
@@ -178,10 +184,10 @@ class JdProductDeleteServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 空清单与超上限都在入口拒绝() {
|
void 空清单与超上限都在入口拒绝() {
|
||||||
assertThatThrownBy(() -> service.delete(List.of(), COMPANY_ID))
|
assertThatThrownBy(() -> service.delete(List.of()))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("请先选择");
|
.hasMessageContaining("请先选择");
|
||||||
assertThatThrownBy(() -> service.delete(null, COMPANY_ID))
|
assertThatThrownBy(() -> service.delete(null))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("请先选择");
|
.hasMessageContaining("请先选择");
|
||||||
|
|
||||||
@@ -189,28 +195,11 @@ class JdProductDeleteServiceTest {
|
|||||||
for (long id = 1; id <= JdProductDeleteService.MAX_BATCH + 1; id++) {
|
for (long id = 1; id <= JdProductDeleteService.MAX_BATCH + 1; id++) {
|
||||||
tooMany.add(id);
|
tooMany.add(id);
|
||||||
}
|
}
|
||||||
assertThatThrownBy(() -> service.delete(tooMany, COMPANY_ID))
|
assertThatThrownBy(() -> service.delete(tooMany))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("200");
|
.hasMessageContaining("200");
|
||||||
|
|
||||||
verify(jdProductMapper, times(0)).selectList(any());
|
verify(jdProductMapper, times(0)).selectList(any());
|
||||||
verify(jdProductRowDeleteService, never()).deleteRows(any());
|
verify(jdProductRowDeleteService, never()).deleteRows(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
void 非超管按本公司收口_越公司行不可见() {
|
|
||||||
// scopedCompanyId=5:归属闸 wrapper 带 company_id=5 ⇒ 别家行查不到 ⇒ 整批拒绝。
|
|
||||||
JdProductEntity row = new JdProductEntity();
|
|
||||||
row.setId(11L);
|
|
||||||
row.setCompanyId(6L);
|
|
||||||
when(jdProductMapper.selectList(any(Wrapper.class))).thenReturn(List.of());
|
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.delete(List.of(11L), COMPANY_ID))
|
|
||||||
.isInstanceOf(BusinessException.class);
|
|
||||||
|
|
||||||
ArgumentCaptor<Wrapper<JdProductEntity>> captor = ArgumentCaptor.forClass(Wrapper.class);
|
|
||||||
verify(jdProductMapper).selectList(captor.capture());
|
|
||||||
assertThat(captor.getValue().getSqlSegment()).contains("company_id");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-55
@@ -11,7 +11,7 @@ import com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity;
|
|||||||
import com.nanri.aiimage.modules.jd.model.vo.JdProductGroupVo;
|
import com.nanri.aiimage.modules.jd.model.vo.JdProductGroupVo;
|
||||||
import com.nanri.aiimage.testutil.UpdateWrapperProbe;
|
import com.nanri.aiimage.testutil.UpdateWrapperProbe;
|
||||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
@@ -35,9 +35,10 @@ import static org.mockito.Mockito.when;
|
|||||||
/**
|
/**
|
||||||
* v1.4 Phase 5(R4/AC-8/AC-9):京东商品自定义分组业务规则。
|
* v1.4 Phase 5(R4/AC-8/AC-9):京东商品自定义分组业务规则。
|
||||||
*
|
*
|
||||||
* <p>判据:同公司重名拒绝不落库(409)、删除先把商品 group_id 置 NULL 再删分组行
|
* <p>判据(2026-11-15 用户定案「分组和亚马逊功能一样」=全平台一份,V200 退键后的服务形状):
|
||||||
* (事务两步,AC-8)、越公司 id 操作按不存在拒绝(不泄露存在性)、productCount
|
* 全局重名拒绝不落库(409)、删除先把商品 group_id 置 NULL 再删分组行(事务两步,AC-8,
|
||||||
* 读侧现算统计(分组下拉展示用)。</p>
|
* 且脱组谓词不带 company_id)、越界 id 操作按不存在拒绝、company_id 列读写两侧都不再引用
|
||||||
|
* (新行不带公司,DB DEFAULT 0 兜底)、productCount 读侧现算统计(分组下拉展示用)。</p>
|
||||||
*/
|
*/
|
||||||
class JdProductGroupServiceTest {
|
class JdProductGroupServiceTest {
|
||||||
|
|
||||||
@@ -45,29 +46,30 @@ class JdProductGroupServiceTest {
|
|||||||
private final JdProductMapper productMapper = mock(JdProductMapper.class);
|
private final JdProductMapper productMapper = mock(JdProductMapper.class);
|
||||||
private final JdProductGroupService service = new JdProductGroupService(groupMapper, productMapper);
|
private final JdProductGroupService service = new JdProductGroupService(groupMapper, productMapper);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeAll
|
||||||
void initTableInfo() {
|
static void initTableInfo() {
|
||||||
// 探针要读 LambdaUpdateWrapper 的 SET/WHERE 段:裸单测 JVM 里 lambda 列缓存不初始化就解析不了,
|
// 探针要读 LambdaUpdateWrapper 的 SET/WHERE 段:裸单测 JVM 里 lambda 列缓存不初始化就解析不了,
|
||||||
// AccountExpiryServiceTest 同款(无 GlobalConfig 下 underCamel=false,列名归一由探针兜)。
|
// AccountExpiryServiceTest 同款(无 GlobalConfig 下 underCamel=false,列名归一由探针兜)。
|
||||||
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""),
|
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||||
JdProductEntity.class);
|
TableInfoHelper.initTableInfo(assistant, JdProductEntity.class);
|
||||||
|
TableInfoHelper.initTableInfo(assistant, JdProductGroupEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== 新建 =====================
|
// ===================== 新建 =====================
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 新建同公司重名拒绝且不落库() {
|
void 新建重名拒绝且不落库() {
|
||||||
when(groupMapper.selectCount(any())).thenReturn(1L);
|
when(groupMapper.selectCount(any())).thenReturn(1L);
|
||||||
|
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> service.create(5L, " 秋冬款 ", 2));
|
() -> service.create(" 秋冬款 ", 2));
|
||||||
assertEquals(409, ex.getCode(), "重名冲突=409(语义正确的资源冲突码,仓内 DeviceLogService 有先例)");
|
assertEquals(409, ex.getCode(), "重名冲突=409(语义正确的资源冲突码,仓内 DeviceLogService 有先例)");
|
||||||
assertTrue(ex.getMessage().contains("同名分组"), "重名必须给可读文案,不拿 DB 唯一键异常撞 500");
|
assertTrue(ex.getMessage().contains("同名分组"), "重名必须给可读文案,不拿 DB 唯一键异常撞 500");
|
||||||
verify(groupMapper, never()).insert(any(JdProductGroupEntity.class));
|
verify(groupMapper, never()).insert(any(JdProductGroupEntity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 新建成功落公司归属与归一名() {
|
void 新建成功落归一名与排序且不带公司() {
|
||||||
when(groupMapper.selectCount(any())).thenReturn(0L);
|
when(groupMapper.selectCount(any())).thenReturn(0L);
|
||||||
when(groupMapper.insert(any(JdProductGroupEntity.class))).thenAnswer(invocation -> {
|
when(groupMapper.insert(any(JdProductGroupEntity.class))).thenAnswer(invocation -> {
|
||||||
JdProductGroupEntity group = invocation.getArgument(0);
|
JdProductGroupEntity group = invocation.getArgument(0);
|
||||||
@@ -75,25 +77,21 @@ class JdProductGroupServiceTest {
|
|||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Long id = service.create(5L, " 秋冬款 ", 2);
|
Long id = service.create(" 秋冬款 ", 2);
|
||||||
|
|
||||||
assertEquals(9L, id);
|
assertEquals(9L, id);
|
||||||
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
||||||
verify(groupMapper).insert(captor.capture());
|
verify(groupMapper).insert(captor.capture());
|
||||||
JdProductGroupEntity saved = captor.getValue();
|
JdProductGroupEntity saved = captor.getValue();
|
||||||
assertEquals(5L, saved.getCompanyId(), "归属公司来自隔离正门的 scopedCompanyId,不是请求体");
|
assertNull(saved.getCompanyId(), "公共库新行不带公司(实体字段不赋值,DB DEFAULT 0=平台公共)");
|
||||||
assertEquals("秋冬款", saved.getName(), "名字 trim 后落库");
|
assertEquals("秋冬款", saved.getName(), "名字 trim 后落库");
|
||||||
assertEquals(2, saved.getSortOrder());
|
assertEquals(2, saved.getSortOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 新建缺公司或空名直接拒绝() {
|
void 新建空名直接拒绝() {
|
||||||
// 超管没选公司(scopedCompanyId=null)=分组没有归属公司,直接拒绝。
|
|
||||||
BusinessException noCompany = assertThrows(BusinessException.class,
|
|
||||||
() -> service.create(null, "秋冬款", null));
|
|
||||||
assertEquals(400, noCompany.getCode());
|
|
||||||
BusinessException blankName = assertThrows(BusinessException.class,
|
BusinessException blankName = assertThrows(BusinessException.class,
|
||||||
() -> service.create(5L, " ", null));
|
() -> service.create(" ", null));
|
||||||
assertEquals(400, blankName.getCode());
|
assertEquals(400, blankName.getCode());
|
||||||
verifyNoInteractions(groupMapper);
|
verifyNoInteractions(groupMapper);
|
||||||
}
|
}
|
||||||
@@ -102,7 +100,7 @@ class JdProductGroupServiceTest {
|
|||||||
void 新建排序缺省归零() {
|
void 新建排序缺省归零() {
|
||||||
when(groupMapper.selectCount(any())).thenReturn(0L);
|
when(groupMapper.selectCount(any())).thenReturn(0L);
|
||||||
|
|
||||||
service.create(5L, "默认排序", null);
|
service.create("默认排序", null);
|
||||||
|
|
||||||
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
||||||
verify(groupMapper).insert(captor.capture());
|
verify(groupMapper).insert(captor.capture());
|
||||||
@@ -112,34 +110,32 @@ class JdProductGroupServiceTest {
|
|||||||
// ===================== 改名 =====================
|
// ===================== 改名 =====================
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 改名越公司id按不存在拒绝() {
|
void 改名不存在按不存在拒绝() {
|
||||||
JdProductGroupEntity group = groupEntity(1L, 6L, "别家的组");
|
when(groupMapper.selectById(1L)).thenReturn(null);
|
||||||
when(groupMapper.selectById(1L)).thenReturn(group);
|
|
||||||
|
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> service.rename(1L, 5L, "新名字", null));
|
() -> service.rename(1L, "新名字", null));
|
||||||
assertTrue(ex.getMessage().contains("分组不存在"),
|
assertTrue(ex.getMessage().contains("分组不存在"));
|
||||||
"越界 id 与 id 不存在是同一种响应,不泄露跨公司行的存在性");
|
|
||||||
verify(groupMapper, never()).updateById(any(JdProductGroupEntity.class));
|
verify(groupMapper, never()).updateById(any(JdProductGroupEntity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 改名重名拒绝且不落库() {
|
void 改名重名拒绝且不落库() {
|
||||||
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, 5L, "旧名"));
|
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, "旧名"));
|
||||||
when(groupMapper.selectCount(any())).thenReturn(1L);
|
when(groupMapper.selectCount(any())).thenReturn(1L);
|
||||||
|
|
||||||
BusinessException ex = assertThrows(BusinessException.class,
|
BusinessException ex = assertThrows(BusinessException.class,
|
||||||
() -> service.rename(1L, 5L, "已有名", 3));
|
() -> service.rename(1L, "已有名", 3));
|
||||||
assertEquals(409, ex.getCode());
|
assertEquals(409, ex.getCode());
|
||||||
verify(groupMapper, never()).updateById(any(JdProductGroupEntity.class));
|
verify(groupMapper, never()).updateById(any(JdProductGroupEntity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 改名成功带归一名与排序() {
|
void 改名成功带归一名与排序() {
|
||||||
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, 5L, "旧名"));
|
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, "旧名"));
|
||||||
when(groupMapper.selectCount(any())).thenReturn(0L);
|
when(groupMapper.selectCount(any())).thenReturn(0L);
|
||||||
|
|
||||||
service.rename(1L, 5L, " 新名 ", 7);
|
service.rename(1L, " 新名 ", 7);
|
||||||
|
|
||||||
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
||||||
verify(groupMapper).updateById(captor.capture());
|
verify(groupMapper).updateById(captor.capture());
|
||||||
@@ -149,10 +145,10 @@ class JdProductGroupServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 改名排序不传保持原值() {
|
void 改名排序不传保持原值() {
|
||||||
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, 5L, "旧名"));
|
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, "旧名"));
|
||||||
when(groupMapper.selectCount(any())).thenReturn(0L);
|
when(groupMapper.selectCount(any())).thenReturn(0L);
|
||||||
|
|
||||||
service.rename(1L, 5L, "只改名", null);
|
service.rename(1L, "只改名", null);
|
||||||
|
|
||||||
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
ArgumentCaptor<JdProductGroupEntity> captor = ArgumentCaptor.forClass(JdProductGroupEntity.class);
|
||||||
verify(groupMapper).updateById(captor.capture());
|
verify(groupMapper).updateById(captor.capture());
|
||||||
@@ -163,29 +159,31 @@ class JdProductGroupServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 删除先把商品组置NULL再删分组行() {
|
void 删除先把商品组置NULL再删分组行() {
|
||||||
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, 5L, "秋冬款"));
|
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, "秋冬款"));
|
||||||
when(productMapper.update(any(), any(Wrapper.class))).thenReturn(3);
|
when(productMapper.update(any(), any(Wrapper.class))).thenReturn(3);
|
||||||
|
|
||||||
int detached = service.delete(1L, 5L);
|
int detached = service.delete(1L);
|
||||||
|
|
||||||
assertEquals(3, detached, "返回实际脱组的商品行数(前端拿它做反馈,不猜)");
|
assertEquals(3, detached, "返回实际脱组的商品行数(前端拿它做反馈,不猜)");
|
||||||
ArgumentCaptor<Wrapper<JdProductEntity>> wrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
|
ArgumentCaptor<Wrapper<JdProductEntity>> wrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
|
||||||
verify(productMapper).update(any(), wrapperCaptor.capture());
|
verify(productMapper).update(any(), wrapperCaptor.capture());
|
||||||
// 置 NULL 语义必须落在 SET group_id=NULL(商品保留,脱组即「未分组」),且限定本公司该组。
|
// 置 NULL 语义必须落在 SET group_id=NULL(商品保留,脱组即「未分组」)。
|
||||||
var setValues = UpdateWrapperProbe.setValues(wrapperCaptor.getValue());
|
var setValues = UpdateWrapperProbe.setValues(wrapperCaptor.getValue());
|
||||||
assertTrue(setValues.containsKey("group_id") && setValues.get("group_id") == null,
|
assertTrue(setValues.containsKey("group_id") && setValues.get("group_id") == null,
|
||||||
"删除分组必须把商品 group_id 置 NULL(SET group_id=NULL),不是删商品行:实得 " + setValues);
|
"删除分组必须把商品 group_id 置 NULL(SET group_id=NULL),不是删商品行:实得 " + setValues);
|
||||||
|
// 公共库:脱组谓词只限定该组,不带 company_id。
|
||||||
var whereEq = UpdateWrapperProbe.whereEq(wrapperCaptor.getValue());
|
var whereEq = UpdateWrapperProbe.whereEq(wrapperCaptor.getValue());
|
||||||
assertEquals(5L, ((Number) whereEq.get("company_id")).longValue(), "脱组必须限定本公司");
|
|
||||||
assertEquals(1L, ((Number) whereEq.get("group_id")).longValue(), "脱组必须限定该组");
|
assertEquals(1L, ((Number) whereEq.get("group_id")).longValue(), "脱组必须限定该组");
|
||||||
|
assertTrue(!whereEq.containsKey("company_id"),
|
||||||
|
"分组公共化后脱组谓词不得再带 company_id:实得 " + whereEq);
|
||||||
verify(groupMapper).deleteById(1L);
|
verify(groupMapper).deleteById(1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 删除越公司id拒绝且一个字节都不写() {
|
void 删除不存在拒绝且一个字节都不写() {
|
||||||
when(groupMapper.selectById(1L)).thenReturn(groupEntity(1L, 6L, "别家的组"));
|
when(groupMapper.selectById(1L)).thenReturn(null);
|
||||||
|
|
||||||
assertThrows(BusinessException.class, () -> service.delete(1L, 5L));
|
assertThrows(BusinessException.class, () -> service.delete(1L));
|
||||||
verifyNoInteractions(productMapper);
|
verifyNoInteractions(productMapper);
|
||||||
verify(groupMapper, never()).deleteById(anyLong());
|
verify(groupMapper, never()).deleteById(anyLong());
|
||||||
}
|
}
|
||||||
@@ -194,22 +192,23 @@ class JdProductGroupServiceTest {
|
|||||||
void 删除分组不存在直接拒绝() {
|
void 删除分组不存在直接拒绝() {
|
||||||
when(groupMapper.selectById(404L)).thenReturn(null);
|
when(groupMapper.selectById(404L)).thenReturn(null);
|
||||||
|
|
||||||
assertThrows(BusinessException.class, () -> service.delete(404L, null));
|
assertThrows(BusinessException.class, () -> service.delete(404L));
|
||||||
verifyNoInteractions(productMapper);
|
verifyNoInteractions(productMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== 列表(productCount 统计) =====================
|
// ===================== 列表(productCount 统计) =====================
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 列表按排序返回且productCount现算() {
|
@SuppressWarnings("unchecked")
|
||||||
JdProductGroupEntity first = groupEntity(2L, 5L, "晚出厂");
|
void 列表全平台一份不带公司谓词且productCount现算() {
|
||||||
|
JdProductGroupEntity first = groupEntity(2L, "晚出厂");
|
||||||
first.setSortOrder(0);
|
first.setSortOrder(0);
|
||||||
JdProductGroupEntity second = groupEntity(1L, 5L, "早出厂");
|
JdProductGroupEntity second = groupEntity(1L, "早出厂");
|
||||||
second.setSortOrder(1);
|
second.setSortOrder(1);
|
||||||
when(groupMapper.selectList(any())).thenReturn(List.of(first, second));
|
when(groupMapper.selectList(any())).thenReturn(List.of(first, second));
|
||||||
when(productMapper.selectCount(any())).thenReturn(12L, 0L);
|
when(productMapper.selectCount(any())).thenReturn(12L, 0L);
|
||||||
|
|
||||||
List<JdProductGroupVo> items = service.list(5L);
|
List<JdProductGroupVo> items = service.list();
|
||||||
|
|
||||||
assertEquals(2, items.size());
|
assertEquals(2, items.size());
|
||||||
assertEquals("晚出厂", items.get(0).getName(), "selectList 的排序由 wrapper 决定,服务不重排");
|
assertEquals("晚出厂", items.get(0).getName(), "selectList 的排序由 wrapper 决定,服务不重排");
|
||||||
@@ -218,24 +217,20 @@ class JdProductGroupServiceTest {
|
|||||||
assertEquals(1, items.get(1).getSortOrder());
|
assertEquals(1, items.get(1).getSortOrder());
|
||||||
verify(productMapper, times(2)).selectCount(any());
|
verify(productMapper, times(2)).selectCount(any());
|
||||||
assertNotNull(items.get(0).getCreatedAt());
|
assertNotNull(items.get(0).getCreatedAt());
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
// 公共库:列表 wrapper 不带 company_id 谓词(历史行的 company_id 只是溯源标记)。
|
||||||
void 列表超管不选公司查全量() {
|
ArgumentCaptor<Wrapper<JdProductGroupEntity>> captor = ArgumentCaptor.forClass(Wrapper.class);
|
||||||
when(groupMapper.selectList(any())).thenReturn(List.of());
|
verify(groupMapper).selectList(captor.capture());
|
||||||
|
assertTrue(!captor.getValue().getSqlSegment().contains("company_id"),
|
||||||
List<JdProductGroupVo> items = service.list(null);
|
"分组列表不得再按公司过滤(2026-11-15 公共化):实得 " + captor.getValue().getSqlSegment());
|
||||||
|
|
||||||
assertTrue(items.isEmpty());
|
|
||||||
verify(groupMapper).selectList(any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- 助手
|
// ---------------------------------------------------------------- 助手
|
||||||
|
|
||||||
private static JdProductGroupEntity groupEntity(long id, long companyId, String name) {
|
private static JdProductGroupEntity groupEntity(long id, String name) {
|
||||||
JdProductGroupEntity group = new JdProductGroupEntity();
|
JdProductGroupEntity group = new JdProductGroupEntity();
|
||||||
group.setId(id);
|
group.setId(id);
|
||||||
group.setCompanyId(companyId);
|
group.setCompanyId(5L);
|
||||||
group.setName(name);
|
group.setName(name);
|
||||||
group.setSortOrder(3);
|
group.setSortOrder(3);
|
||||||
group.setCreatedAt(LocalDateTime.of(2026, 11, 14, 10, 0));
|
group.setCreatedAt(LocalDateTime.of(2026, 11, 14, 10, 0));
|
||||||
|
|||||||
+30
-21
@@ -42,9 +42,9 @@ import static org.mockito.Mockito.when;
|
|||||||
/**
|
/**
|
||||||
* 后管「编辑京东商品」编排判据(PUT /api/admin/jd-products/{id},2026-11-15 用户口径)。
|
* 后管「编辑京东商品」编排判据(PUT /api/admin/jd-products/{id},2026-11-15 用户口径)。
|
||||||
*
|
*
|
||||||
* <p>钉六件事:①归属闸(越界 id 按不存在拒绝,零写);②主字段全量保存即置人工编辑锁
|
* <p>钉六件事:①存在闸(行不存在按不存在拒绝,零写;公共库无公司维度);②主字段全量保存即置人工编辑锁
|
||||||
* {@code manual_locked=1}(V199——没有这个锁,编辑会被下一次采集 upsert 覆盖回去);
|
* {@code manual_locked=1}(V199——没有这个锁,编辑会被下一次采集 upsert 覆盖回去);
|
||||||
* ③分组归属校验(跨公司挂组拒绝);④属性重建只覆写 attr_json 的 {@code tabs} 段、
|
* ③分组存在校验(分组 2026-11-15 起全平台一份,挂组只认存在性);④属性重建只覆写 attr_json 的 {@code tabs} 段、
|
||||||
* images/productCode 等其它顶层键原样保留(铁律 30 形状),原文形状不识别时拒绝而不是静默重写;
|
* images/productCode 等其它顶层键原样保留(铁律 30 形状),原文形状不识别时拒绝而不是静默重写;
|
||||||
* ⑤SKU 按 (productId, skuId) 匹配改价改库存,缺失 skuId 拒绝;⑥删图=先删桶、共用对象保留、
|
* ⑤SKU 按 (productId, skuId) 匹配改价改库存,缺失 skuId 拒绝;⑥删图=先删桶、共用对象保留、
|
||||||
* image_count 按表实数刷新。</p>
|
* image_count 按表实数刷新。</p>
|
||||||
@@ -124,18 +124,19 @@ class JdProductUpdateServiceTest {
|
|||||||
// ---------- 判据 ----------
|
// ---------- 判据 ----------
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 归属闸_越界或不存在按不存在拒绝且零写() {
|
void 行不存在按不存在拒绝_公共库跨公司行可编辑() {
|
||||||
|
// 公共库(2026-11-15 用户定案):行存在即可编辑,company_id 只是同步来源标记。
|
||||||
JdProductEntity otherCompany = productRow();
|
JdProductEntity otherCompany = productRow();
|
||||||
otherCompany.setCompanyId(99L);
|
otherCompany.setCompanyId(99L);
|
||||||
when(jdProductMapper.selectById(PRODUCT_ID)).thenReturn(otherCompany);
|
when(jdProductMapper.selectById(PRODUCT_ID)).thenReturn(otherCompany);
|
||||||
|
when(jdProductMapper.update(isNull(), any(Wrapper.class))).thenReturn(1);
|
||||||
|
assertThat(service.update(PRODUCT_ID, mainFieldsOnly())).isEqualTo(PRODUCT_ID);
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, mainFieldsOnly(), COMPANY_ID))
|
// 行不存在 ⇒ 按不存在拒绝,零写。
|
||||||
|
when(jdProductMapper.selectById(PRODUCT_ID)).thenReturn(null);
|
||||||
|
assertThatThrownBy(() -> service.update(PRODUCT_ID, mainFieldsOnly()))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("商品不存在");
|
.hasMessageContaining("商品不存在");
|
||||||
verify(jdProductMapper, never()).update(isNull(), any(Wrapper.class));
|
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, mainFieldsOnly(), COMPANY_ID))
|
|
||||||
.isInstanceOf(BusinessException.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -143,7 +144,7 @@ class JdProductUpdateServiceTest {
|
|||||||
givenOwnedRow();
|
givenOwnedRow();
|
||||||
when(jdProductMapper.update(isNull(), any(Wrapper.class))).thenReturn(1);
|
when(jdProductMapper.update(isNull(), any(Wrapper.class))).thenReturn(1);
|
||||||
|
|
||||||
Long id = service.update(PRODUCT_ID, mainFieldsOnly(), COMPANY_ID);
|
Long id = service.update(PRODUCT_ID, mainFieldsOnly());
|
||||||
|
|
||||||
assertThat(id).isEqualTo(PRODUCT_ID);
|
assertThat(id).isEqualTo(PRODUCT_ID);
|
||||||
Map<String, Object> values = capturedSetValues();
|
Map<String, Object> values = capturedSetValues();
|
||||||
@@ -159,19 +160,27 @@ class JdProductUpdateServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 分组必须属于本公司() {
|
void 分组必须存在_公共组无公司维度() {
|
||||||
givenOwnedRow();
|
givenOwnedRow();
|
||||||
JdProductUpdateRequest body = mainFieldsOnly();
|
JdProductUpdateRequest body = mainFieldsOnly();
|
||||||
body.setGroupId(7L);
|
body.setGroupId(7L);
|
||||||
|
// 分组 2026-11-15 起全平台一份:别家时代建的组(company_id=99)照样能挂。
|
||||||
JdProductGroupEntity group = new JdProductGroupEntity();
|
JdProductGroupEntity group = new JdProductGroupEntity();
|
||||||
group.setId(7L);
|
group.setId(7L);
|
||||||
group.setCompanyId(99L);
|
group.setCompanyId(99L);
|
||||||
when(jdProductGroupMapper.selectById(7L)).thenReturn(group);
|
when(jdProductGroupMapper.selectById(7L)).thenReturn(group);
|
||||||
|
when(jdProductMapper.update(isNull(), any(Wrapper.class))).thenReturn(1);
|
||||||
|
assertThat(service.update(PRODUCT_ID, body)).isEqualTo(PRODUCT_ID);
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, body, COMPANY_ID))
|
// 分组不存在 ⇒ 拒绝且零写。
|
||||||
|
JdProductUpdateRequest ghost = mainFieldsOnly();
|
||||||
|
ghost.setGroupId(404L);
|
||||||
|
when(jdProductGroupMapper.selectById(404L)).thenReturn(null);
|
||||||
|
assertThatThrownBy(() -> service.update(PRODUCT_ID, ghost))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("分组不存在或不属于当前公司");
|
.hasMessageContaining("分组不存在");
|
||||||
verify(jdProductMapper, never()).update(isNull(), any(Wrapper.class));
|
// update 只剩成功挂组那 1 次:ghost 分支零写点(同用例前半段已成功写过一次,不能按 never 数)。
|
||||||
|
verify(jdProductMapper, org.mockito.Mockito.times(1)).update(isNull(), any(Wrapper.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -188,7 +197,7 @@ class JdProductUpdateServiceTest {
|
|||||||
group.setAttrs(List.of(attr));
|
group.setAttrs(List.of(attr));
|
||||||
body.setAttrGroups(List.of(group));
|
body.setAttrGroups(List.of(group));
|
||||||
|
|
||||||
service.update(PRODUCT_ID, body, COMPANY_ID);
|
service.update(PRODUCT_ID, body);
|
||||||
|
|
||||||
Map<String, Object> values = capturedSetValues();
|
Map<String, Object> values = capturedSetValues();
|
||||||
// 新 JSON 里有重建后的 tabs(新属性值落进去了),且 images/productCode 原样保留(铁律 30)
|
// 新 JSON 里有重建后的 tabs(新属性值落进去了),且 images/productCode 原样保留(铁律 30)
|
||||||
@@ -206,7 +215,7 @@ class JdProductUpdateServiceTest {
|
|||||||
JdProductUpdateRequest body = mainFieldsOnly();
|
JdProductUpdateRequest body = mainFieldsOnly();
|
||||||
body.setAttrGroups(List.of(new JdProductUpdateRequest.AttrGroupDto()));
|
body.setAttrGroups(List.of(new JdProductUpdateRequest.AttrGroupDto()));
|
||||||
|
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, body, COMPANY_ID))
|
assertThatThrownBy(() -> service.update(PRODUCT_ID, body))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("属性原文形状不识别");
|
.hasMessageContaining("属性原文形状不识别");
|
||||||
verify(jdProductMapper, never()).update(isNull(), any(Wrapper.class));
|
verify(jdProductMapper, never()).update(isNull(), any(Wrapper.class));
|
||||||
@@ -228,7 +237,7 @@ class JdProductUpdateServiceTest {
|
|||||||
edit.setPrice(new BigDecimal("199.00"));
|
edit.setPrice(new BigDecimal("199.00"));
|
||||||
edit.setStock(88);
|
edit.setStock(88);
|
||||||
body.setSkus(List.of(edit));
|
body.setSkus(List.of(edit));
|
||||||
service.update(PRODUCT_ID, body, COMPANY_ID);
|
service.update(PRODUCT_ID, body);
|
||||||
|
|
||||||
ArgumentCaptor<Wrapper<JdProductSkuEntity>> captor = ArgumentCaptor.forClass(Wrapper.class);
|
ArgumentCaptor<Wrapper<JdProductSkuEntity>> captor = ArgumentCaptor.forClass(Wrapper.class);
|
||||||
verify(jdProductSkuMapper).update(isNull(), captor.capture());
|
verify(jdProductSkuMapper).update(isNull(), captor.capture());
|
||||||
@@ -242,7 +251,7 @@ class JdProductUpdateServiceTest {
|
|||||||
ghost.setSkuId("ghost-sku");
|
ghost.setSkuId("ghost-sku");
|
||||||
ghost.setPrice(BigDecimal.ONE);
|
ghost.setPrice(BigDecimal.ONE);
|
||||||
bad.setSkus(List.of(ghost));
|
bad.setSkus(List.of(ghost));
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, bad, COMPANY_ID))
|
assertThatThrownBy(() -> service.update(PRODUCT_ID, bad))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("SKU 行不存在");
|
.hasMessageContaining("SKU 行不存在");
|
||||||
}
|
}
|
||||||
@@ -266,14 +275,14 @@ class JdProductUpdateServiceTest {
|
|||||||
|
|
||||||
JdProductUpdateRequest body = mainFieldsOnly();
|
JdProductUpdateRequest body = mainFieldsOnly();
|
||||||
body.setDeleteImageIds(List.of(1L, 2L));
|
body.setDeleteImageIds(List.of(1L, 2L));
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, body, COMPANY_ID))
|
assertThatThrownBy(() -> service.update(PRODUCT_ID, body))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("本次未删除任何数据");
|
.hasMessageContaining("本次未删除任何数据");
|
||||||
|
|
||||||
// 修正归属:只删 1L;同 key 被别的商品引用 ⇒ 对象保留、只删登记行、计数刷新
|
// 修正归属:只删 1L;同 key 被别的商品引用 ⇒ 对象保留、只删登记行、计数刷新
|
||||||
JdProductUpdateRequest fixed = mainFieldsOnly();
|
JdProductUpdateRequest fixed = mainFieldsOnly();
|
||||||
fixed.setDeleteImageIds(List.of(1L));
|
fixed.setDeleteImageIds(List.of(1L));
|
||||||
service.update(PRODUCT_ID, fixed, COMPANY_ID);
|
service.update(PRODUCT_ID, fixed);
|
||||||
|
|
||||||
verify(ossStorageService, never()).removeObject(eq("jd-products"), eq("jd-products/5/aaa.jpg"));
|
verify(ossStorageService, never()).removeObject(eq("jd-products"), eq("jd-products/5/aaa.jpg"));
|
||||||
verify(jdProductImageMapper).delete(any(Wrapper.class));
|
verify(jdProductImageMapper).delete(any(Wrapper.class));
|
||||||
@@ -288,13 +297,13 @@ class JdProductUpdateServiceTest {
|
|||||||
JdProductUpdateRequest badPrice = mainFieldsOnly();
|
JdProductUpdateRequest badPrice = mainFieldsOnly();
|
||||||
badPrice.setPriceMin(new BigDecimal("100"));
|
badPrice.setPriceMin(new BigDecimal("100"));
|
||||||
badPrice.setPriceMax(new BigDecimal("50"));
|
badPrice.setPriceMax(new BigDecimal("50"));
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, badPrice, COMPANY_ID))
|
assertThatThrownBy(() -> service.update(PRODUCT_ID, badPrice))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("价格区间下限不能大于上限");
|
.hasMessageContaining("价格区间下限不能大于上限");
|
||||||
|
|
||||||
JdProductUpdateRequest badStock = mainFieldsOnly();
|
JdProductUpdateRequest badStock = mainFieldsOnly();
|
||||||
badStock.setStockTotal(-1);
|
badStock.setStockTotal(-1);
|
||||||
assertThatThrownBy(() -> service.update(PRODUCT_ID, badStock, COMPANY_ID))
|
assertThatThrownBy(() -> service.update(PRODUCT_ID, badStock))
|
||||||
.isInstanceOf(BusinessException.class)
|
.isInstanceOf(BusinessException.class)
|
||||||
.hasMessageContaining("总库存不能为负数");
|
.hasMessageContaining("总库存不能为负数");
|
||||||
verify(jdProductMapper, never()).update(isNull(), any(Wrapper.class));
|
verify(jdProductMapper, never()).update(isNull(), any(Wrapper.class));
|
||||||
|
|||||||
Reference in New Issue
Block a user