feat(jd): 京东数据库筛选行加「分类状态」下拉(全部/已分类/未分类)

This commit is contained in:
2026-11-15 23:00:13 +08:00
parent e175e85973
commit d0aa93759d
10 changed files with 135 additions and 45 deletions
@@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
/** 京东数据库页(v1.4 Phase 5):公共的京东商品库(2026-11-15 用户定案「不区分公司、属于 /** 京东数据库页(v1.4 Phase 5):公共的京东商品库(2026-11-15 用户定案「不区分公司、属于
* 公共的」,分类同亚马逊口径全平台一份),筛选行(店铺/商品编码/标题关键字/分类/类目/ * 公共的」,分类同亚马逊口径全平台一份),筛选行(店铺/商品编码/标题关键字/分类/分类状态/
* 同步起止 date 对)+查询/重置/店铺分类 + 自绘明细表(勾选列+点行开详情抽屉) * 类目/同步起止 date 对)+查询/重置/店铺分类 + 自绘明细表(勾选列+点行开详情抽屉)
* + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。 * + 删除(单行/批量,先删桶对象、全成功才删库行,确认弹窗点名数量)+ OldPagination。
* 公司维度只剩超管的公司 tab(=筛选管理员,非超管没有这个筛选、看到同一份公共全量); * 公司维度只剩超管的公司 tab(=筛选管理员,非超管没有这个筛选、看到同一份公共全量);
* 列表按京麦商品列表样式(2026-11-15 用户口径):店铺/分类前置为第 1/2 列;商品信息列=京麦同款 * 列表按京麦商品列表样式(2026-11-15 用户口径):店铺/分类前置为第 1/2 列;商品信息列=京麦同款
@@ -122,6 +122,7 @@ async function load(): Promise<void> {
titleKeyword: filter.titleKeyword, titleKeyword: filter.titleKeyword,
category: filter.category, category: filter.category,
groupId: filter.groupId, groupId: filter.groupId,
groupScope: filter.groupScope,
syncedFrom: filter.syncedFrom, syncedFrom: filter.syncedFrom,
syncedTo: filter.syncedTo, syncedTo: filter.syncedTo,
companyId: companyTab.requestCompanyId, companyId: companyTab.requestCompanyId,
@@ -238,8 +239,8 @@ async function removeMany(picked: JdProductItem[], message: string): Promise<voi
} }
// 超管切公司 tab = 重新取数:店铺/编码/关键字/类目/日期是按行集筛的自由值,在另一家的 // 超管切公司 tab = 重新取数:店铺/编码/关键字/类目/日期是按行集筛的自由值,在另一家的
// 行集里筛不出东西,必须一起清(分组全平台一份,groupId 与公司维度正交、不清); // 行集里筛不出东西,必须一起清(分组与分类状态全平台一份,groupId/groupScope 与公司维度
// 类目选项与行集同源,按新 tab 重取;分组选项是全局的、进页取一次即可。 // 正交、不清);类目选项与行集同源,按新 tab 重取;分组选项是全局的、进页取一次即可。
watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadCategoryOptions(); void load() }) watch(() => companyTab.activeId, () => { filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadCategoryOptions(); void load() })
onMounted(() => { onMounted(() => {
@@ -279,6 +280,17 @@ onMounted(() => {
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option> <option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
</select> </select>
</div> </div>
<div class="form-group">
<label>分类状态</label>
<!-- 分类状态(2026-11-15 客户口径「查询已分类的跟未分类,分类好的可以不显示」):
选中即查,同分组/类目口径;与上方「分类」(具体分组等值过滤)正交——
这里只按 group_id 是否为空分档。 -->
<select v-model="filter.groupScope" @change="apply">
<option value="">全部</option>
<option value="grouped">已分类</option>
<option value="ungrouped">未分类</option>
</select>
</div>
<div class="form-group"> <div class="form-group">
<label>类目</label> <label>类目</label>
<!-- 类目(京麦末级类目)选中即查:同分组口径,选完立刻按该类目过滤刷新(回第一页)。 --> <!-- 类目(京麦末级类目)选中即查:同分组口径,选完立刻按该类目过滤刷新(回第一页)。 -->
@@ -30,6 +30,7 @@ export async function fetchJdProductList(
titleKeyword: params.titleKeyword ?? '', titleKeyword: params.titleKeyword ?? '',
category: params.category ?? '', category: params.category ?? '',
groupId: params.groupId ?? '', groupId: params.groupId ?? '',
groupScope: params.groupScope ?? '',
syncedFrom: params.syncedFrom ?? '', syncedFrom: params.syncedFrom ?? '',
syncedTo: params.syncedTo ?? '', syncedTo: params.syncedTo ?? '',
}, },
@@ -1,7 +1,9 @@
/** 京东数据库页筛选纯函数(v1.4 Phase 5):店铺/商品编码/标题关键字/类目/分组/同步起止 + snake 分页参数。 /** 京东数据库页筛选纯函数(v1.4 Phase 5):店铺/商品编码/标题关键字/类目/分组/分类状态/同步起止 + snake 分页参数。
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 20、上限 100)、`shop_name`、 * 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 20、上限 100)、`shop_name`、
* `product_code`、`title_keyword`、`category`(京麦末级类目等值过滤,2026-11-15 增)、 * `product_code`、`title_keyword`、`category`(京麦末级类目等值过滤,2026-11-15 增)、
* `group_id`、`synced_from`/`synced_to`(ISO yyyy-MM-dd;空白不下发)。 * `group_id`、`grouped`(只看已分类,2026-11-15 客户口径「查询已分类的跟未分类,分类好的
* 可以不显示」增)、`ungrouped`(只看未分类,页面「分类状态」档与店铺分类弹窗共用)、
* `synced_from`/`synced_to`(ISO yyyy-MM-dd;空白不下发)。
* 商品状态筛选与导出(2026-11-15 客户口径「这两个不要/导出也不用」)已从前端下线; * 商品状态筛选与导出(2026-11-15 客户口径「这两个不要/导出也不用」)已从前端下线;
* 后端 `sale_status` 参数与 `/export` 端点保留(无 UI 入口),重上时从 git 历史找回取值口。 * 后端 `sale_status` 参数与 `/export` 端点保留(无 UI 入口),重上时从 git 历史找回取值口。
* 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size * 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size
@@ -29,6 +31,9 @@ export interface JdProductFilterState {
category: string category: string
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */ /** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
groupId: string groupId: string
/** 分类状态(2026-11-15 客户口径「查询已分类的跟未分类」):''=全部、
* 'grouped'=只看已分类(group_id 非空)、'ungrouped'=只看未分类(group_id 为空)。 */
groupScope: '' | 'grouped' | 'ungrouped'
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */ /** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
syncedFrom: string syncedFrom: string
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */ /** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
@@ -36,7 +41,7 @@ export interface JdProductFilterState {
} }
export function createJdProductFilterState(): JdProductFilterState { export function createJdProductFilterState(): JdProductFilterState {
return { shopName: '', productCode: '', titleKeyword: '', category: '', groupId: '', syncedFrom: '', syncedTo: '' } return { shopName: '', productCode: '', titleKeyword: '', category: '', groupId: '', groupScope: '', syncedFrom: '', syncedTo: '' }
} }
/** 是否有任一激活筛选条件。 */ /** 是否有任一激活筛选条件。 */
@@ -46,6 +51,7 @@ export function jdProductFilterActive(state: JdProductFilterState): boolean {
if ((state.titleKeyword || '').trim()) return true if ((state.titleKeyword || '').trim()) return true
if ((state.category || '').trim()) return true if ((state.category || '').trim()) return true
if ((state.groupId || '').trim()) return true if ((state.groupId || '').trim()) return true
if ((state.groupScope || '').trim()) return true
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
return false return false
} }
@@ -63,6 +69,8 @@ export interface JdProductQuery {
/** 未分类过滤(店铺分类弹窗「未分类」范围):true=只看 group_id 为空的行。 /** 未分类过滤(店铺分类弹窗「未分类」范围):true=只看 group_id 为空的行。
* 同 group_id 一样由 api 发送口下传——构造器不认识它(弹窗的取数不走筛选态)。 */ * 同 group_id 一样由 api 发送口下传——构造器不认识它(弹窗的取数不走筛选态)。 */
ungrouped?: boolean ungrouped?: boolean
/** 已分类过滤(页面筛选行「分类状态」=已分类):true=只看 group_id 非空的行。 */
grouped?: boolean
synced_from?: string synced_from?: string
synced_to?: string synced_to?: string
/** 公司 tab:白名单构造不点名它,字段只为 api 发送口的 `query.company_id = params.companyId` 存在。 */ /** 公司 tab:白名单构造不点名它,字段只为 api 发送口的 `query.company_id = params.companyId` 存在。 */
@@ -78,6 +86,8 @@ export interface JdProductListParams {
titleKeyword?: string titleKeyword?: string
category?: string category?: string
groupId?: string groupId?: string
/** 分类状态档(''=全部 | 'grouped' | 'ungrouped');页面筛选行传,弹窗不传。 */
groupScope?: '' | 'grouped' | 'ungrouped'
/** 未分类范围(true=只看未分类行);仅店铺分类弹窗右栏传,页面筛选行不用。 */ /** 未分类范围(true=只看未分类行);仅店铺分类弹窗右栏传,页面筛选行不用。 */
ungrouped?: boolean ungrouped?: boolean
syncedFrom?: string syncedFrom?: string
@@ -98,6 +108,10 @@ function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuer
if (category) query.category = category if (category) query.category = category
const groupId = Number.parseInt((state.groupId || '').trim(), 10) const groupId = Number.parseInt((state.groupId || '').trim(), 10)
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
// 分类状态档:未分类走既有 ungrouped 参数(与店铺分类弹窗同一后端谓词),
// 已分类走 grouped;''(全部)不下发。
if (state.groupScope === 'ungrouped') query.ungrouped = true
if (state.groupScope === 'grouped') query.grouped = true
const syncedFrom = validIsoDateOrUndefined(state.syncedFrom) const syncedFrom = validIsoDateOrUndefined(state.syncedFrom)
if (syncedFrom) query.synced_from = syncedFrom if (syncedFrom) query.synced_from = syncedFrom
const syncedTo = validIsoDateOrUndefined(state.syncedTo) const syncedTo = validIsoDateOrUndefined(state.syncedTo)
@@ -73,3 +73,23 @@ test('类目筛选参数序列化:空串不下发、非空下发 category(
assert.equal(toJdProductListParams(filtered, 1, 20).category, '服饰内衣', '去空白透传(等值过滤)') assert.equal(toJdProductListParams(filtered, 1, 20).category, '服饰内衣', '去空白透传(等值过滤)')
assert.equal(jdProductFilterActive(filtered), true, '选中类目算激活筛选') assert.equal(jdProductFilterActive(filtered), true, '选中类目算激活筛选')
}) })
/** 分类状态筛选(2026-11-15 客户口径「查询已分类的跟未分类,分类好的可以不显示」):
* 全部不下发、已分类下发 grouped、未分类下发 ungrouped(与店铺分类弹窗同一后端谓词)。 */
test('分类状态筛选参数序列化:全部不下发、已分类 grouped、未分类 ungrouped', async () => {
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
await import('../src/pages/jd/jd-product-filter.ts')
const empty = createJdProductFilterState()
assert.equal('grouped' in toJdProductListParams(empty, 1, 20), false, '全部不下发 grouped')
assert.equal('ungrouped' in toJdProductListParams(empty, 1, 20), false, '全部不下发 ungrouped')
const grouped = { ...empty, groupScope: 'grouped' as const }
assert.equal(toJdProductListParams(grouped, 1, 20).grouped, true, '已分类档下发 grouped=true')
assert.equal('ungrouped' in toJdProductListParams(grouped, 1, 20), false, '已分类档不下发 ungrouped')
assert.equal(jdProductFilterActive(grouped), true, '选中已分类算激活筛选')
const ungrouped = { ...empty, groupScope: 'ungrouped' as const }
assert.equal(toJdProductListParams(ungrouped, 1, 20).ungrouped, true, '未分类档下发 ungrouped=true')
assert.equal('grouped' in toJdProductListParams(ungrouped, 1, 20), false, '未分类档不下发 grouped')
assert.equal(jdProductFilterActive(ungrouped), true, '选中未分类算激活筛选')
})
@@ -278,10 +278,10 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1) expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
// 第 1 个 select = 分组(既有契约不动),类目下拉紧随其后 // 第 1 个 select = 分组(既有契约不动),第 2 个 = 分类状态(2026-11-15 增),类目下拉第 3
const selects = wrapper.findAll('.jd-filter-row select') const selects = wrapper.findAll('.jd-filter-row select')
expect(selects).toHaveLength(2) expect(selects).toHaveLength(3)
const categorySelect = selects[1] const categorySelect = selects[2]
const optionTexts = categorySelect.findAll('option').map((o) => o.text()) const optionTexts = categorySelect.findAll('option').map((o) => o.text())
expect(optionTexts[0]).toBe('全部类目') expect(optionTexts[0]).toBe('全部类目')
expect(optionTexts).toContain('服饰内衣(120)') expect(optionTexts).toContain('服饰内衣(120)')
@@ -293,6 +293,24 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '运动户外', page: 1 }) expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '运动户外', page: 1 })
}) })
it('分类状态下拉:全部/已分类/未分类三档,选中即查回第一页并下发对应参数', async () => {
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
const selects = wrapper.findAll('.jd-filter-row select')
const scopeSelect = selects[1]
const optionTexts = scopeSelect.findAll('option').map((o) => o.text())
expect(optionTexts).toEqual(['全部', '已分类', '未分类'])
// 选「已分类」= 只看 group_id 非空的行(分类好的行想单独看时用这一档)
await scopeSelect.setValue('grouped')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupScope: 'grouped', page: 1 })
// 选「未分类」= 只看 group_id 为空的行(分类好的不显示)
await scopeSelect.setValue('ungrouped')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupScope: 'ungrouped', page: 1 })
})
it('重置把筛选面回空并回第一页重取', async () => { it('重置把筛选面回空并回第一页重取', async () => {
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 }) const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
const textInputs = wrapper.findAll('.form-group input[type="text"]') const textInputs = wrapper.findAll('.form-group input[type="text"]')
@@ -103,6 +103,8 @@ public class AdminJdProductController {
@Parameter(description = "分组 id") @RequestParam(name = "group_id", required = false) Long groupId, @Parameter(description = "分组 id") @RequestParam(name = "group_id", required = false) Long groupId,
@Parameter(description = "只看未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)") @Parameter(description = "只看未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)")
@RequestParam(name = "ungrouped", required = false) Boolean ungrouped, @RequestParam(name = "ungrouped", required = false) Boolean ungrouped,
@Parameter(description = "只看已分类(group_id IS NOT NULL,页面筛选行「分类状态」档)")
@RequestParam(name = "grouped", required = false) Boolean grouped,
@Parameter(description = "同步开始时间(包含,ISO datetime)") @Parameter(description = "同步开始时间(包含,ISO datetime)")
@RequestParam(name = "synced_from", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedFrom, @RequestParam(name = "synced_from", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedFrom,
@Parameter(description = "同步结束时间(包含,ISO datetime)") @Parameter(description = "同步结束时间(包含,ISO datetime)")
@@ -115,7 +117,7 @@ public class AdminJdProductController {
// 非超管传什么都不收——公共库对每一家管理员都是同一份全量。 // 非超管传什么都不收——公共库对每一家管理员都是同一份全量。
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(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, ungrouped, syncedFrom, syncedTo)); productCode, titleKeyword, category, groupId, ungrouped, grouped, syncedFrom, syncedTo));
} }
@GetMapping("/categories") @GetMapping("/categories")
@@ -42,9 +42,10 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
/** /**
* 后管只读页总数(Phase 5,v1.4):与 {@link #selectProductPage} 同一过滤面 * 后管只读页总数(Phase 5,v1.4):与 {@link #selectProductPage} 同一过滤面
* (公司/店铺名/商品编码/标题关键词/类目/分组/未分类/同步起止,全部 SQL 侧下推, * (公司/店铺名/商品编码/标题关键词/类目/分组/未分类/已分类/同步起止,全部 SQL 侧下推,
* 铁律 20)。{@code companyId}/{@code groupId} 为空或 ≤0=不过滤该面; * 铁律 20)。{@code companyId}/{@code groupId} 为空或 ≤0=不过滤该面;
* {@code ungrouped=true}=只看未分类行(group_id IS NULL,店铺分类弹窗「未分类」范围)。 * {@code ungrouped=true}=只看未分类行(group_id IS NULL,店铺分类弹窗「未分类」范围);
* {@code grouped=true}=只看已分类行(group_id IS NOT NULL,页面筛选行「分类状态」档)。
*/ */
long countProducts(@Param("companyId") Long companyId, long countProducts(@Param("companyId") Long companyId,
@Param("shopName") String shopName, @Param("shopName") String shopName,
@@ -53,6 +54,7 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
@Param("category") String category, @Param("category") String category,
@Param("groupId") Long groupId, @Param("groupId") Long groupId,
@Param("ungrouped") Boolean ungrouped, @Param("ungrouped") Boolean ungrouped,
@Param("grouped") Boolean grouped,
@Param("syncedFrom") LocalDateTime syncedFrom, @Param("syncedFrom") LocalDateTime syncedFrom,
@Param("syncedTo") LocalDateTime syncedTo); @Param("syncedTo") LocalDateTime syncedTo);
@@ -95,6 +97,7 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
@Param("category") String category, @Param("category") String category,
@Param("groupId") Long groupId, @Param("groupId") Long groupId,
@Param("ungrouped") Boolean ungrouped, @Param("ungrouped") Boolean ungrouped,
@Param("grouped") Boolean grouped,
@Param("syncedFrom") LocalDateTime syncedFrom, @Param("syncedFrom") LocalDateTime syncedFrom,
@Param("syncedTo") LocalDateTime syncedTo, @Param("syncedTo") LocalDateTime syncedTo,
@Param("offset") long offset, @Param("offset") long offset,
@@ -76,11 +76,12 @@ public class JdProductQueryService {
* *
* <p>过滤面:公司(物化列 eq)、店铺名 contains、商品编码 contains、标题关键词 contains、 * <p>过滤面:公司(物化列 eq)、店铺名 contains、商品编码 contains、标题关键词 contains、
* 类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、 * 类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗「未分类」范围)、
* 同步起止(datetime 闭区间)。</p> * 已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,2026-11-15 客户口径
* 「查询已分类的跟未分类,分类好的可以不显示」)、同步起止(datetime 闭区间)。</p>
*/ */
public JdProductPageVo page(Long page, Long pageSize, Long scopedCompanyId, String shopName, public JdProductPageVo page(Long page, Long pageSize, Long scopedCompanyId, String shopName,
String productCode, String titleKeyword, String category, Long groupId, Boolean ungrouped, String productCode, String titleKeyword, String category, Long groupId, Boolean ungrouped,
LocalDateTime syncedFrom, LocalDateTime syncedTo) { Boolean grouped, LocalDateTime syncedFrom, LocalDateTime syncedTo) {
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) { if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
throw new BusinessException("开始时间不能晚于结束时间"); throw new BusinessException("开始时间不能晚于结束时间");
} }
@@ -88,14 +89,15 @@ public class JdProductQueryService {
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE); : Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
Filter filter = filter(scopedCompanyId, shopName, productCode, titleKeyword, category, Filter filter = filter(scopedCompanyId, shopName, productCode, titleKeyword, category,
groupId, ungrouped, syncedFrom, syncedTo); groupId, ungrouped, grouped, syncedFrom, syncedTo);
long total = jdProductMapper.countProducts(filter.companyId(), filter.shopName(), filter.productCode(), long total = jdProductMapper.countProducts(filter.companyId(), filter.shopName(), filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(), filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
filter.syncedFrom(), filter.syncedTo()); filter.grouped(), filter.syncedFrom(), filter.syncedTo());
List<JdProductEntity> rows = total <= 0 ? List.of() List<JdProductEntity> rows = total <= 0 ? List.of()
: jdProductMapper.selectProductPage(filter.companyId(), filter.shopName(), filter.productCode(), : jdProductMapper.selectProductPage(filter.companyId(), filter.shopName(), filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(), filter.titleKeyword(), filter.category(), filter.groupId(), filter.ungrouped(),
filter.syncedFrom(), filter.syncedTo(), (safePage - 1) * safeSize, (int) safeSize); filter.grouped(), filter.syncedFrom(), filter.syncedTo(),
(safePage - 1) * safeSize, (int) safeSize);
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList(); List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
fillGroupNames(items); fillGroupNames(items);
JdProductPageVo vo = new JdProductPageVo(); JdProductPageVo vo = new JdProductPageVo();
@@ -172,17 +174,22 @@ public class JdProductQueryService {
/** 服务侧过滤面归一:companyId/groupId ≤0 按没选处理,文本 trim 后空串归 null。 */ /** 服务侧过滤面归一:companyId/groupId ≤0 按没选处理,文本 trim 后空串归 null。 */
private record Filter(Long companyId, String shopName, String productCode, String titleKeyword, private record Filter(Long companyId, String shopName, String productCode, String titleKeyword,
String category, Long groupId, Boolean ungrouped, LocalDateTime syncedFrom, LocalDateTime syncedTo) { String category, Long groupId, Boolean ungrouped, Boolean grouped,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
} }
private static Filter filter(Long scopedCompanyId, String shopName, String productCode, String titleKeyword, private static Filter filter(Long scopedCompanyId, String shopName, String productCode, String titleKeyword,
String category, Long groupId, Boolean ungrouped, LocalDateTime syncedFrom, LocalDateTime syncedTo) { String category, Long groupId, Boolean ungrouped, Boolean grouped,
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null; Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
Long safeGroupId = groupId != null && groupId > 0 ? groupId : null; Long safeGroupId = groupId != null && groupId > 0 ? groupId : null;
// 未分类与其它过滤面同口径:没显式要(true)=null=不进 IS NULL 分支。 // 未分类与其它过滤面同口径:没显式要(true)=null=不进 IS NULL 分支。
Boolean safeUngrouped = Boolean.TRUE.equals(ungrouped) ? Boolean.TRUE : null; Boolean safeUngrouped = Boolean.TRUE.equals(ungrouped) ? Boolean.TRUE : null;
// 已分类同口径:true=只看 group_id IS NOT NULL 的行;与未分类同选时 SQL 侧两谓词相与=空集
// (前端下拉是单选,正常到不了这个组合)。
Boolean safeGrouped = Boolean.TRUE.equals(grouped) ? Boolean.TRUE : null;
return new Filter(companyId, trimToNull(shopName), trimToNull(productCode), trimToNull(titleKeyword), return new Filter(companyId, trimToNull(shopName), trimToNull(productCode), trimToNull(titleKeyword),
trimToNull(category), safeGroupId, safeUngrouped, syncedFrom, syncedTo); trimToNull(category), safeGroupId, safeUngrouped, safeGrouped, syncedFrom, syncedTo);
} }
// ---------------------------------------------------------------- 列表/详情搬运 // ---------------------------------------------------------------- 列表/详情搬运
@@ -102,7 +102,9 @@
<!-- 后管只读页(Phase 5,v1.4)过滤面:公司(物化列 eq)、店铺名/商品编码/标题关键词 <!-- 后管只读页(Phase 5,v1.4)过滤面:公司(物化列 eq)、店铺名/商品编码/标题关键词
(contains LIKE)、类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗 (contains LIKE)、类目 eq、分组 eq、未分类(group_id IS NULL,店铺分类弹窗
「未分类」范围)、同步起止(datetime 闭区间)。 「未分类」范围)、已分类(group_id IS NOT NULL,页面筛选行「分类状态」档,
2026-11-15 客户口径「查询已分类的跟未分类,分类好的可以不显示」)、
同步起止(datetime 闭区间)。
sale_status 筛选随 2026-11-15 客户口径撤掉(前端筛选框下线;列本身与详情/回传链不动)。 sale_status 筛选随 2026-11-15 客户口径撤掉(前端筛选框下线;列本身与详情/回传链不动)。
全部走 #{} 占位符;offset/limit 必须是服务侧钳制后的值(铁律 15),mapper 不做第二次换算。 --> 全部走 #{} 占位符;offset/limit 必须是服务侧钳制后的值(铁律 15),mapper 不做第二次换算。 -->
<sql id="productConds"> <sql id="productConds">
@@ -113,6 +115,7 @@
<if test="category != null and category != ''">AND p.category_path = #{category}</if> <if test="category != null and category != ''">AND p.category_path = #{category}</if>
<if test="groupId != null and groupId &gt; 0">AND p.group_id = #{groupId}</if> <if test="groupId != null and groupId &gt; 0">AND p.group_id = #{groupId}</if>
<if test="ungrouped != null and ungrouped">AND p.group_id IS NULL</if> <if test="ungrouped != null and ungrouped">AND p.group_id IS NULL</if>
<if test="grouped != null and grouped">AND p.group_id IS NOT NULL</if>
<if test="syncedFrom != null">AND p.synced_at &gt;= #{syncedFrom}</if> <if test="syncedFrom != null">AND p.synced_at &gt;= #{syncedFrom}</if>
<if test="syncedTo != null">AND p.synced_at &lt;= #{syncedTo}</if> <if test="syncedTo != null">AND p.synced_at &lt;= #{syncedTo}</if>
</sql> </sql>
@@ -128,7 +128,7 @@ class AdminJdProductControllerTest {
void 分页参数snake且带默认值() throws IOException { void 分页参数snake且带默认值() throws IOException {
String source = stripComments(Files.readString(CONTROLLER)); String source = stripComments(Files.readString(CONTROLLER));
for (String param : List.of("page_size", "shop_name", "product_code", "title_keyword", for (String param : List.of("page_size", "shop_name", "product_code", "title_keyword",
"group_id", "ungrouped", "synced_from", "synced_to", "company_id")) { "group_id", "ungrouped", "grouped", "synced_from", "synced_to", "company_id")) {
assertTrue(source.contains(param), "查询参数必须 snake_case:" + param); assertTrue(source.contains(param), "查询参数必须 snake_case:" + param);
} }
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。 // 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
@@ -196,13 +196,13 @@ class AdminJdProductControllerTest {
pageVo.setTotal(0L); pageVo.setTotal(0L);
pageVo.setPage(1L); pageVo.setPage(1L);
pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT); pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT);
when(queryService.page(1L, 20L, 5L, null, null, null, null, null, null, null, null)).thenReturn(pageVo); when(queryService.page(1L, 20L, 5L, null, null, null, null, null, null, null, null, null)).thenReturn(pageVo);
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, null, 5L, request); null, null, null, null, 5L, request);
verify(dataReadScope).superAdminScopedCompanyId(operator, 5L); verify(dataReadScope).superAdminScopedCompanyId(operator, 5L);
verify(queryService).page(1L, 20L, 5L, null, null, null, null, null, null, null, null); verify(queryService).page(1L, 20L, 5L, null, null, 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());
} }
@@ -324,23 +324,23 @@ class AdminJdProductControllerTest {
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));
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L); when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
// page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。 // page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。
service.page(0L, null, null, null, null, null, null, null, null, null, null); service.page(0L, null, null, null, null, null, null, null, null, null, null, null);
ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class);
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), offset.capture(), limit.capture()); isNull(), isNull(), isNull(), isNull(), offset.capture(), limit.capture());
assertEquals(0L, offset.getValue()); assertEquals(0L, offset.getValue());
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue()); assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
// page=Long.MAX_VALUE / size=500 ⇒ 钳到 10_000 页、100 条;乘积 999_900 不得变负(铁律 15)。 // page=Long.MAX_VALUE / size=500 ⇒ 钳到 10_000 页、100 条;乘积 999_900 不得变负(铁律 15)。
service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null, null, null, null); service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null, null, null, null, null);
ArgumentCaptor<Long> offsetMax = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Long> offsetMax = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Integer> limitMax = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> limitMax = ArgumentCaptor.forClass(Integer.class);
verify(mapper, times(2)).selectProductPage(any(), any(), any(), any(), any(), any(), verify(mapper, times(2)).selectProductPage(any(), any(), any(), any(), any(), any(),
any(), any(), any(), offsetMax.capture(), limitMax.capture()); any(), any(), any(), any(), offsetMax.capture(), limitMax.capture());
assertEquals(999_900L, offsetMax.getValue(), "(page-1)*page_size 最大 999_900,钳制后不得溢出变负"); assertEquals(999_900L, offsetMax.getValue(), "(page-1)*page_size 最大 999_900,钳制后不得溢出变负");
assertEquals(100, limitMax.getValue()); assertEquals(100, limitMax.getValue());
} }
@@ -354,9 +354,9 @@ class AdminJdProductControllerTest {
LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0); LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0);
LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0); LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0);
BusinessException ex = assertThrows(BusinessException.class, BusinessException ex = assertThrows(BusinessException.class,
() -> service.page(1L, 20L, null, null, null, null, null, null, null, from, to)); () -> service.page(1L, 20L, null, null, null, null, null, null, null, null, from, to));
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝"); assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any()); verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
} }
@Test @Test
@@ -365,27 +365,37 @@ class AdminJdProductControllerTest {
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));
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(0L); when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(0L);
// 超管显式传 5 ⇒ 按公司 5 筛(收窄);groupId ≤0 按没选分组处理;文本两侧空白剥掉。 // 超管显式传 5 ⇒ 按公司 5 筛(收窄);groupId ≤0 按没选分组处理;文本两侧空白剥掉。
// 类目(京麦末级类目名)走同一过滤面:传值原样直传、空白归 null。 // 类目(京麦末级类目名)走同一过滤面:传值原样直传、空白归 null。
service.page(1L, 20L, 5L, " 店铺甲 ", " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 0L, null, null, null); service.page(1L, 20L, 5L, " 店铺甲 ", " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 0L, null, null, null, null);
verify(mapper).countProducts(eq(5L), eq("店铺甲"), eq("SKU-1"), eq("连衣裙"), verify(mapper).countProducts(eq(5L), eq("店铺甲"), eq("SKU-1"), eq("连衣裙"),
eq("艺考形体服"), isNull(), isNull(), isNull(), isNull()); eq("艺考形体服"), isNull(), isNull(), isNull(), isNull(), isNull());
// 全量(scopedCompanyId=null)⇒ companyId 不过滤。 // 全量(scopedCompanyId=null)⇒ companyId 不过滤。
service.page(1L, 20L, null, null, null, null, null, null, null, null, null); service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(), verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), isNull()); isNull(), isNull(), isNull(), isNull(), isNull());
// 未分类范围(店铺分类弹窗「未分类」页签):ungrouped=true 原样下推到 SQL 侧。 // 未分类范围(店铺分类弹窗「未分类」页签):ungrouped=true 原样下推到 SQL 侧。
service.page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, null, null); service.page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, null, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(), verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), eq(Boolean.TRUE), isNull(), isNull()); isNull(), eq(Boolean.TRUE), isNull(), isNull(), isNull());
// ungrouped=false / 缺省按不过滤处理(Filter 归一成 null,不进 IS NULL 分支); // ungrouped=false / 缺省按不过滤处理(Filter 归一成 null,不进 IS NULL 分支);
// 与②「全量」那发同形状,累计 2 次。 // 与②「全量」那发同形状,累计 2 次。
service.page(1L, 20L, null, null, null, null, null, null, Boolean.FALSE, null, null); service.page(1L, 20L, null, null, null, null, null, null, Boolean.FALSE, null, null, null);
verify(mapper, times(2)).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(), verify(mapper, times(2)).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), isNull()); isNull(), isNull(), isNull(), isNull(), isNull());
// 已分类档(页面筛选行「分类状态」=已分类,2026-11-15 客户口径「分类好的可以不显示」反选):
// grouped=true 原样下推到 SQL 侧(group_id IS NOT NULL),ungrouped 不动。
service.page(1L, 20L, null, null, null, null, null, null, null, Boolean.TRUE, null, null);
verify(mapper).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), eq(Boolean.TRUE), isNull(), isNull());
// grouped=false / 缺省同口径归一成 null(不进 IS NOT NULL 分支);与②「全量」累计 3 次。
service.page(1L, 20L, null, null, null, null, null, null, null, Boolean.FALSE, null, null);
verify(mapper, times(3)).countProducts(isNull(), isNull(), isNull(), isNull(), isNull(),
isNull(), isNull(), isNull(), isNull(), isNull());
} }
@Test @Test
@@ -586,8 +596,8 @@ class AdminJdProductControllerTest {
grouped.setGroupId(3L); grouped.setGroupId(3L);
JdProductEntity missing = productEntity(2L); JdProductEntity missing = productEntity(2L);
missing.setGroupId(99L); missing.setGroupId(99L);
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L); when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(),
anyLong(), anyInt())).thenReturn(List.of(grouped, missing)); anyLong(), anyInt())).thenReturn(List.of(grouped, missing));
com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity group = com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity group =
new com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity(); new com.nanri.aiimage.modules.jd.model.entity.JdProductGroupEntity();
@@ -595,7 +605,7 @@ class AdminJdProductControllerTest {
group.setName("秋冬款"); group.setName("秋冬款");
when(groupMapper.selectBatchIds(any())).thenReturn(List.of(group)); when(groupMapper.selectBatchIds(any())).thenReturn(List.of(group));
JdProductPageVo vo = service.page(1L, 20L, 5L, null, null, null, null, null, null, null, null); JdProductPageVo vo = service.page(1L, 20L, 5L, null, null, null, null, null, null, null, null, null);
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集 group_id 一次取齐分组名(无逐行查询)"); assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集 group_id 一次取齐分组名(无逐行查询)");
assertNull(vo.getItems().get(1).getGroupName(), "分组已删=不猜名字(铁律 30),前端展示 -"); assertNull(vo.getItems().get(1).getGroupName(), "分组已删=不猜名字(铁律 30),前端展示 -");