feat(jd): 京东数据库页分类状态快筛(已分类/未分类)——classified 参数按当前分组在 SQL 侧 EXISTS/NOT EXISTS 下推(铁律20同形,判据与读侧填分类列同形);后管工具栏「全部分类」旁三档下拉选中即查;与 11-16 撤掉的旧 grouped/ungrouped 无关(那两档读已停用列,控制器仍拒收)。判据:XML 两分支谓词/成对直传/classified 参数在册绊线+纯测试三档+挂载 2 例

This commit is contained in:
2026-11-17 16:58:28 +08:00
parent 20ee73349e
commit d25c91f6da
10 changed files with 220 additions and 43 deletions
@@ -189,6 +189,7 @@ async function load(): Promise<void> {
titleKeyword: filter.titleKeyword, titleKeyword: filter.titleKeyword,
category: filter.category, category: filter.category,
groupId: filter.groupId, groupId: filter.groupId,
classified: filter.classified,
ownerGroupId: ownerGroupId.value, ownerGroupId: ownerGroupId.value,
syncedFrom: filter.syncedFrom, syncedFrom: filter.syncedFrom,
syncedTo: filter.syncedTo, syncedTo: filter.syncedTo,
@@ -417,6 +418,20 @@ onMounted(async () => {
<el-option label="全部分类" value="" /> <el-option label="全部分类" value="" />
<el-option v-for="group in groupOptions" :key="group.id" :label="group.name" :value="String(group.id)" /> <el-option v-for="group in groupOptions" :key="group.id" :label="group.name" :value="String(group.id)" />
</el-select> </el-select>
<!-- 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选,快速筛出未分类和已分类的数据」):
已分类=当前分组下有分类(V203 归属表,与列表分类列同形——筛"未分类"的行分类列必显示未分类);
选中即查(回第一页),与「全部分类」下拉同壳同语义(value='' 行=回全量出口)。 -->
<el-select
v-model="filter.classified"
class="admin-filter"
placeholder="全部状态"
aria-label="筛选分类状态"
@change="apply"
>
<el-option label="全部状态" value="" />
<el-option label="已分类" value="classified" />
<el-option label="未分类" value="ungrouped" />
</el-select>
<!-- 分类管理(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」):V204 独立 <!-- 分类管理(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」):V204 独立
子菜单页整体并入本对话框(搜索+新建+改名+删除)。入口对所有人渲染(同组普通号 子菜单页整体并入本对话框(搜索+新建+改名+删除)。入口对所有人渲染(同组普通号
只读可看,V203),写控件由对话框按当前分组 editable 分档。 --> 只读可看,V203),写控件由对话框按当前分组 editable 分档。 -->
@@ -29,6 +29,7 @@ export async function fetchJdProductList(
titleKeyword: params.titleKeyword ?? '', titleKeyword: params.titleKeyword ?? '',
category: params.category ?? '', category: params.category ?? '',
groupId: params.groupId ?? '', groupId: params.groupId ?? '',
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
syncedFrom: params.syncedFrom ?? '', syncedFrom: params.syncedFrom ?? '',
syncedTo: params.syncedTo ?? '', syncedTo: params.syncedTo ?? '',
}, },
@@ -29,6 +29,12 @@ export interface JdProductFilterState {
category: string category: string
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */ /** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
groupId: string groupId: string
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):
* ''/缺省=全部,'classified'=已分类(当前分组下有分类),'ungrouped'=未分类。
* 语义按 V203 归属表(当前数据权限分组)判定,与列表分类列同形;不是 11-16 撤掉的
* 旧 grouped/ungrouped 参数(那两档读已停用的 biz_jd_product.group_id 列,后端仍拒收)。
* 可选:既有纯测试夹具字面量不带该键仍合法,缺省按「全部」处理。 */
classified?: '' | 'classified' | 'ungrouped'
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */ /** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
syncedFrom: string syncedFrom: string
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */ /** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
@@ -36,7 +42,7 @@ export interface JdProductFilterState {
} }
export function createJdProductFilterState(): JdProductFilterState { export function createJdProductFilterState(): JdProductFilterState {
return { productCode: '', titleKeyword: '', category: '', groupId: '', syncedFrom: '', syncedTo: '' } return { productCode: '', titleKeyword: '', category: '', groupId: '', classified: '', syncedFrom: '', syncedTo: '' }
} }
/** 是否有任一激活筛选条件。 */ /** 是否有任一激活筛选条件。 */
@@ -45,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.classified) return true
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
return false return false
} }
@@ -59,6 +66,9 @@ export interface JdProductQuery {
category?: string category?: string
/** 自定义分类 id(当前分组下的一个分类;V203 起按归属表 EXISTS 过滤)。 */ /** 自定义分类 id(当前分组下的一个分类;V203 起按归属表 EXISTS 过滤)。 */
group_id?: number group_id?: number
/** 分类状态快筛(2026-11-17):true=已分类、false=未分类,缺省不下发=全部。
* 后端按「当前分组」(owner_group_id)的归属表 EXISTS/NOT EXISTS 在 SQL 侧下推。 */
classified?: boolean
/** 当前数据权限分组 id(分类列/分类筛选都按它取;V203「不同组不能看到跨组的分类」)。 */ /** 当前数据权限分组 id(分类列/分类筛选都按它取;V203「不同组不能看到跨组的分类」)。 */
owner_group_id?: number owner_group_id?: number
synced_from?: string synced_from?: string
@@ -73,6 +83,8 @@ export interface JdProductListParams {
titleKeyword?: string titleKeyword?: string
category?: string category?: string
groupId?: string groupId?: string
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
classified?: string
/** 当前分组(数据权限分组 id):分类列/分类筛选的作用域,非筛选条件(重置不清它)。 */ /** 当前分组(数据权限分组 id):分类列/分类筛选的作用域,非筛选条件(重置不清它)。 */
ownerGroupId?: number | null ownerGroupId?: number | null
syncedFrom?: string syncedFrom?: string
@@ -90,6 +102,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
// 分类状态快筛:只认两个显式档位,其余值(含脏值)按「全部」不下发——后端 classified
// 只收 true/false/缺省,不拿脏值冒充档位。
if (state.classified === 'classified') query.classified = true
else if (state.classified === 'ungrouped') query.classified = false
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)
@@ -108,6 +108,25 @@ test('京东列表参数——page 钳制防 (page-1)*page_size 溢出(铁律
assert.equal(offset, 999_900) assert.equal(offset, 999_900)
}) })
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):
* 只认 'classified'/'ungrouped' 两档显式值,映射成布尔 `classified`;''/缺省/脏值不下发。
* 参数名是新档 classified——不是后端仍拒收的旧 grouped/ungrouped 查询参数。 */
test('京东列表参数——classified 三档:已分类→true、未分类→false、全部/脏值不下发', () => {
const yes = toJdProductListParams({ ...createJdProductFilterState(), classified: 'classified' }, 1, 20, 11)
assert.equal(yes.classified, true)
assert.equal(yes.owner_group_id, 11, 'classified 与当前分组成对下发(后端按组判已/未分类)')
const no = toJdProductListParams({ ...createJdProductFilterState(), classified: 'ungrouped' }, 1, 20)
assert.equal(no.classified, false, '未分类档必须下发 false——缺省不下发=全部,两者语义不同')
for (const blank of ['', undefined, 'grouped', 'nonsense'] as const) {
const q = toJdProductListParams({ ...createJdProductFilterState(), classified: blank }, 1, 20)
assert.equal('classified' in q, false, `classified=${String(blank)} 按「全部」处理,不拿脏值冒充档位`)
}
assert.deepEqual(toJdProductListParams(createJdProductFilterState(), 1, 20), { page: 1, page_size: 20 },
'出厂空态不带 classified(重置回全部)')
})
test('详情解析——attrGroups/images 结构化解析(snake 容错、缺 url 弃行)', () => { test('详情解析——attrGroups/images 结构化解析(snake 容错、缺 url 弃行)', () => {
const detail = parseJdProductDetail({ const detail = parseJdProductDetail({
code: 0, code: 0,
@@ -262,6 +262,35 @@ describe('批量编辑分类(店铺分类弹窗 2026-11-17 下线后的替代
}) })
}) })
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选,快速筛出未分类和已分类的数据」):
* 工具栏「全部分类」旁新增「筛选分类状态」下拉(全部状态/已分类/未分类),选中即查重回第一页;
* 页面发的是筛选态字符串(classified/ungrouped),布尔换算收在 jd-product-filter 单一出口
* (纯测试钉形状);重置回出厂空态不带档位。 */
describe('分类状态快筛(已分类/未分类)', () => {
it('下拉三档在册;选「未分类」按 classified="ungrouped" 重查且回第一页', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
expect(optionLabels(wrapper, '筛选分类状态')).toEqual(['全部状态', '已分类', '未分类'])
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
await pickSelectOption(wrapper, '筛选分类状态', '未分类')
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '选中即查重取列表')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject(
{ classified: 'ungrouped', page: 1 }, '未分类档下发 ungrouped 态并回第一页')
wrapper.unmount()
})
it('选「已分类」下发 classified 态;「重置」回出厂空态重查不带档位', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
await pickSelectOption(wrapper, '筛选分类状态', '已分类')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified')
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('',
'重置把筛选面回出厂空态(全部),不残留档位')
wrapper.unmount()
})
})
/** 分类管理入口(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」): /** 分类管理入口(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」):
* V204 独立子菜单页下线,工具栏「分类管理」打开 JdCategoryManageDialog(搜索+新建+ * V204 独立子菜单页下线,工具栏「分类管理」打开 JdCategoryManageDialog(搜索+新建+
* 改名+删除);入口对所有人渲染(同组普通号只读可看),写控件由对话框按 editable 分档; * 改名+删除);入口对所有人渲染(同组普通号只读可看),写控件由对话框按 editable 分档;
@@ -120,6 +120,9 @@ public class AdminJdProductController {
@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)")
@RequestParam(name = "synced_to", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedTo, @RequestParam(name = "synced_to", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedTo,
@Parameter(description = "分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):"
+ "true=当前分组下有分类,false=未分类,缺省=全部;按 V203 归属表 SQL 侧下推")
@RequestParam(name = "classified", required = false) Boolean classified,
HttpServletRequest request) { HttpServletRequest request) {
RequestOperator operator = requireJdAccess(request); RequestOperator operator = requireJdAccess(request);
if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) { if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) {
@@ -131,7 +134,8 @@ public class AdminJdProductController {
requireVisibleCategory(scope, groupId); requireVisibleCategory(scope, groupId);
} }
return ApiResponse.success(jdProductQueryService.page(page, pageSize, return ApiResponse.success(jdProductQueryService.page(page, pageSize,
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo, scopedOwnerGroupId)); productCode, titleKeyword, category, groupId, syncedFrom, syncedTo, classified,
scopedOwnerGroupId));
} }
@GetMapping("/categories") @GetMapping("/categories")
@@ -49,13 +49,18 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
* 「分类不要了,全部整合到类目里」撤掉(独立「分类」筛选框前端下线, * 「分类不要了,全部整合到类目里」撤掉(独立「分类」筛选框前端下线,
* {@code groupId} 改由类目面板「自定义分类」选中驱动)。 * {@code groupId} 改由类目面板「自定义分类」选中驱动)。
* 店铺名过滤参数已随 2026-11-15 客户口径「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。 * 店铺名过滤参数已随 2026-11-15 客户口径「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。
* {@code classified}+{@code ownerGroupId}(2026-11-17 用户口径「加个已分类和未分类的筛选」):
* 按 V203 归属表 EXISTS/NOT EXISTS 快筛分类状态,NULL=不过滤;与 11-16 撤掉的旧
* grouped/ungrouped(读已停用的 biz_jd_product.group_id 列)不是一回事。
*/ */
long countProducts(@Param("productCode") String productCode, long countProducts(@Param("productCode") String productCode,
@Param("titleKeyword") String titleKeyword, @Param("titleKeyword") String titleKeyword,
@Param("category") String category, @Param("category") String category,
@Param("groupId") Long groupId, @Param("groupId") Long groupId,
@Param("syncedFrom") LocalDateTime syncedFrom, @Param("syncedFrom") LocalDateTime syncedFrom,
@Param("syncedTo") LocalDateTime syncedTo); @Param("syncedTo") LocalDateTime syncedTo,
@Param("classified") Boolean classified,
@Param("ownerGroupId") Long ownerGroupId);
/** /**
* 商品上架配额计数({@code JdPublishQuotaService}):按 owner uid 集(管理员本人+ * 商品上架配额计数({@code JdPublishQuotaService}):按 owner uid 集(管理员本人+
@@ -95,6 +100,8 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
@Param("groupId") Long groupId, @Param("groupId") Long groupId,
@Param("syncedFrom") LocalDateTime syncedFrom, @Param("syncedFrom") LocalDateTime syncedFrom,
@Param("syncedTo") LocalDateTime syncedTo, @Param("syncedTo") LocalDateTime syncedTo,
@Param("classified") Boolean classified,
@Param("ownerGroupId") Long ownerGroupId,
@Param("offset") long offset, @Param("offset") long offset,
@Param("limit") int limit); @Param("limit") int limit);
@@ -79,14 +79,18 @@ public class JdProductQueryService {
* 分页查询商品行({@code synced_at} 倒序)。 * 分页查询商品行({@code synced_at} 倒序)。
* *
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq(2026-11-16 起 * <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq(2026-11-16 起
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)。 * 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)、分类状态档
* 未分类/已分类两档(ungrouped/grouped)与独立「分类」筛选框随同日口径 * {@code classified}(2026-11-17 用户口径「加个已分类和未分类的筛选」:true=当前分组下
* 「分类不要了,全部整合到类目里」整批撤掉。 * 有分类、false=没有、null=全部;按 V203 归属表 EXISTS/NOT EXISTS 在 SQL 侧下推,
* 判据与 {@link #fillGroupNames} 填分类列的条件同形——「筛选说未分类的行,列表分类列
* 也必须是未分类」)。
* 2026-11-16 撤掉的旧 ungrouped/grouped 两档读的是已停用的 biz_jd_product.group_id 列,
* 与本档不是一回事;独立「分类」筛选框的撤掉口径不变。
* 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p> * 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p>
*/ */
public JdProductPageVo page(Long page, Long pageSize, public JdProductPageVo page(Long page, Long pageSize,
String productCode, String titleKeyword, String category, Long groupId, String productCode, String titleKeyword, String category, Long groupId,
LocalDateTime syncedFrom, LocalDateTime syncedTo, Long ownerGroupId) { LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified, Long ownerGroupId) {
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) { if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
throw new BusinessException("开始时间不能晚于结束时间"); throw new BusinessException("开始时间不能晚于结束时间");
} }
@@ -94,14 +98,14 @@ 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(productCode, titleKeyword, category, Filter filter = filter(productCode, titleKeyword, category,
groupId, syncedFrom, syncedTo); groupId, syncedFrom, syncedTo, classified);
long total = jdProductMapper.countProducts(filter.productCode(), long total = jdProductMapper.countProducts(filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(), filter.titleKeyword(), filter.category(), filter.groupId(),
filter.syncedFrom(), filter.syncedTo()); filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId);
List<JdProductEntity> rows = total <= 0 ? List.of() List<JdProductEntity> rows = total <= 0 ? List.of()
: jdProductMapper.selectProductPage(filter.productCode(), : jdProductMapper.selectProductPage(filter.productCode(),
filter.titleKeyword(), filter.category(), filter.groupId(), filter.titleKeyword(), filter.category(), filter.groupId(),
filter.syncedFrom(), filter.syncedTo(), filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
(safePage - 1) * safeSize, (int) safeSize); (safePage - 1) * safeSize, (int) safeSize);
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList(); List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
fillGroupNames(items, ownerGroupId); fillGroupNames(items, ownerGroupId);
@@ -176,18 +180,19 @@ public class JdProductQueryService {
// ---------------------------------------------------------------- 过滤面 // ---------------------------------------------------------------- 过滤面
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘)。 */ /** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘);
* classified 原样直传(null=不过滤该面,2026-11-17 分类状态快筛)。 */
private record Filter(String productCode, String titleKeyword, private record Filter(String productCode, String titleKeyword,
String category, Long groupId, String category, Long groupId,
LocalDateTime syncedFrom, LocalDateTime syncedTo) { LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
} }
private static Filter filter(String productCode, String titleKeyword, private static Filter filter(String productCode, String titleKeyword,
String category, Long groupId, String category, Long groupId,
LocalDateTime syncedFrom, LocalDateTime syncedTo) { LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
Long safeGroupId = groupId != null && groupId > 0 ? groupId : null; Long safeGroupId = groupId != null && groupId > 0 ? groupId : null;
return new Filter(trimToNull(productCode), trimToNull(titleKeyword), return new Filter(trimToNull(productCode), trimToNull(titleKeyword),
trimToNull(category), safeGroupId, syncedFrom, syncedTo); trimToNull(category), safeGroupId, syncedFrom, syncedTo, classified);
} }
// ---------------------------------------------------------------- 列表/详情搬运 // ---------------------------------------------------------------- 列表/详情搬运
@@ -122,6 +122,29 @@
WHERE a.product_id = p.id AND a.category_id = #{groupId} WHERE a.product_id = p.id AND a.category_id = #{groupId}
) )
</if> </if>
<!-- 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):已分类=在
「当前数据权限分组」(owner_group_id)下有 category_id 非空的归属行——与读侧
fillGroupNames 把分类列填出来的条件同形;未分类=NOT EXISTS。谓词 SQL 侧下推
(铁律 20 同形,不得 Java 侧对已取页 filter)。owner_group_id 为 NULL(作用域
无可分组)时 EXISTS 恒假、NOT EXISTS 恒真——与列表「分类列全空」口径天然一致,
不需要服务侧特判。与 2026-11-16 撤掉的旧 grouped/ungrouped 不是一回事:那两档
读的是已停用的 biz_jd_product.group_id 列,本档读 V203 归属表。 -->
<if test="classified != null">
<choose>
<when test="classified == true">
AND EXISTS (
SELECT 1 FROM biz_jd_product_group_assign cs
WHERE cs.product_id = p.id AND cs.owner_group_id = #{ownerGroupId} AND cs.category_id IS NOT NULL
)
</when>
<otherwise>
AND NOT EXISTS (
SELECT 1 FROM biz_jd_product_group_assign cs
WHERE cs.product_id = p.id AND cs.owner_group_id = #{ownerGroupId} AND cs.category_id IS NOT NULL
)
</otherwise>
</choose>
</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>
@@ -164,6 +164,10 @@ class AdminJdProductControllerTest {
} }
assertFalse(source.contains("@RequestParam(name = \"ungrouped\"")); assertFalse(source.contains("@RequestParam(name = \"ungrouped\""));
assertFalse(source.contains("@RequestParam(name = \"grouped\"")); assertFalse(source.contains("@RequestParam(name = \"grouped\""));
// 2026-11-17 分类状态快筛:新参数名 classified(不复用旧 grouped/ungrouped 两档——
// 那两档读已停用的 biz_jd_product.group_id 列,语义不同,旧参数仍必须被拒收)。
assertTrue(source.contains("@RequestParam(name = \"classified\""),
"分类状态快筛参数 classified 必须在册(2026-11-17 用户口径)");
// company_id 参数已随 2026-11-16「删除掉公司 tab」整批摘除(读侧零公司维度支另有反向钉)。 // company_id 参数已随 2026-11-16「删除掉公司 tab」整批摘除(读侧零公司维度支另有反向钉)。
assertFalse(source.contains("company_id"), "company_id 请求参数必须已删除,不得回潜"); assertFalse(source.contains("company_id"), "company_id 请求参数必须已删除,不得回潜");
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。 // 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
@@ -279,8 +283,8 @@ class AdminJdProductControllerTest {
// 读:菜单权限命中即放行(公共库一人一份全量)。 // 读:菜单权限命中即放行(公共库一人一份全量)。
JdProductPageVo pageVo = new JdProductPageVo(); JdProductPageVo pageVo = new JdProductPageVo();
pageVo.setItems(List.of()); pageVo.setItems(List.of());
when(queryService.page(1L, 20L, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo); when(queryService.page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo);
assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null, null, request) assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null, null, null, request)
.isSuccess(), "非超管有菜单权限时读必须放行(读写分档只收窄写)"); .isSuccess(), "非超管有菜单权限时读必须放行(读写分档只收窄写)");
// 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。 // 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。
@@ -429,11 +433,11 @@ class AdminJdProductControllerTest {
when(groupService.requireCategory(8L)).thenReturn(category(8L, 20L)); when(groupService.requireCategory(8L)).thenReturn(category(8L, 20L));
BusinessException ex = assertThrows(BusinessException.class, BusinessException ex = assertThrows(BusinessException.class,
() -> controller.page(1L, 20L, null, null, null, 8L, null, null, null, request)); () -> controller.page(1L, 20L, null, null, null, 8L, null, null, null, null, request));
assertTrue(ex.getMessage().contains("无权查看该分组的分类"), assertTrue(ex.getMessage().contains("无权查看该分组的分类"),
"跨组分类筛选必须 403 点名分组,不做空结果降级"); "跨组分类筛选必须 403 点名分组,不做空结果降级");
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any()); verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
} }
// ===================== 行为样本 ===================== // ===================== 行为样本 =====================
@@ -461,13 +465,13 @@ class AdminJdProductControllerTest {
pageVo.setTotal(0L); pageVo.setTotal(0L);
pageVo.setPage(1L); pageVo.setPage(1L);
pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT); pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT);
when(queryService.page(1L, 20L, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo); when(queryService.page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo);
// 请求面没有 company_id:任何授权身份看到的都是同一份全量;分类列按 owner_group_id 取。 // 请求面没有 company_id:任何授权身份看到的都是同一份全量;分类列按 owner_group_id 取。
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null, ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null,
GROUP_ID, null, null, request); GROUP_ID, null, null, null, request);
verify(queryService).page(1L, 20L, null, null, null, null, null, null, GROUP_ID); verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID);
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)"); assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
assertEquals(pageVo, response.getData()); assertEquals(pageVo, response.getData());
} }
@@ -491,12 +495,12 @@ class AdminJdProductControllerTest {
for (String value : List.of("true", "false", "")) { for (String value : List.of("true", "false", "")) {
when(request.getParameter(name)).thenReturn(value); when(request.getParameter(name)).thenReturn(value);
BusinessException ex = assertThrows(BusinessException.class, BusinessException ex = assertThrows(BusinessException.class,
() -> controller.page(1L, 20L, null, null, null, 7L, null, null, null, request)); () -> controller.page(1L, 20L, null, null, null, 7L, null, null, null, null, request));
assertTrue(ex.getMessage().contains("刷新页面")); assertTrue(ex.getMessage().contains("刷新页面"));
when(request.getParameter(name)).thenReturn(null); when(request.getParameter(name)).thenReturn(null);
} }
} }
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any()); verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
} }
@Test @Test
@@ -615,23 +619,23 @@ class AdminJdProductControllerTest {
void 查询服务分页钳制防溢出() { void 查询服务分页钳制防溢出() {
JdProductMapper mapper = mock(JdProductMapper.class); JdProductMapper mapper = mock(JdProductMapper.class);
JdProductQueryService service = queryService(mapper); JdProductQueryService service = queryService(mapper);
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L); when(mapper.countProducts(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); service.page(0L, 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(),
offset.capture(), limit.capture()); 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); service.page(Long.MAX_VALUE, 500L, 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(),
offsetMax.capture(), limitMax.capture()); 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());
} }
@@ -643,23 +647,77 @@ 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, from, to, null)); () -> service.page(1L, 20L, null, null, null, null, from, to, null, null));
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝"); assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any()); verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any());
} }
@Test @Test
void 查询服务过滤面原样直传且空串归null() { void 查询服务过滤面原样直传且空串归null() {
JdProductMapper mapper = mock(JdProductMapper.class); JdProductMapper mapper = mock(JdProductMapper.class);
JdProductQueryService service = queryService(mapper); JdProductQueryService service = queryService(mapper);
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L); when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null, null); service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null, null, null);
verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null); verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null);
verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, 0L, 20); verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null, 0L, 20);
service.page(1L, 20L, " ", null, null, 0L, null, null, null); service.page(1L, 20L, " ", null, null, 0L, null, null, null, null);
verify(mapper).countProducts(null, null, null, null, null, null); verify(mapper).countProducts(null, null, null, null, null, null, null, null);
verify(mapper).selectProductPage(null, null, null, null, null, null, 0L, 20); verify(mapper).selectProductPage(null, null, null, null, null, null, null, null, 0L, 20);
}
/**
* 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):
* ① classified+ownerGroupId 必须原样下传给 mapper(谓词在 XML 的 EXISTS/NOT EXISTS 段,
* 铁律 20 同形——不得 Java 侧对已取页 filter);
* ② XML 绊线:两分支谓词逐字在册(改回 Java filter 或摘掉 owner_group_id 关联即红);
* ③ 控制器把请求的 classified 直传服务(不吞、不改写)。
*/
@Test
void 分类状态快筛必须SQL下推且classified与ownerGroupId成对直传() throws IOException {
// ② XML 绊线:classified 档的 EXISTS/NOT EXISTS 两分支都在 productConds 里,
// 且按「当前分组」owner_group_id+category_id 非空判——与读侧填分类列同形。
Path xml = findJdProductMapperXml();
String xmlText = stripComments(Files.readString(xml)).replaceAll("(?s)<!--.*?-->", "");
assertTrue(xmlText.contains("classified == true"),
"XML 必须有 classified==true 的已分类分支(SQL 侧下推,铁律 20 同形)");
assertTrue(xmlText.contains("cs.owner_group_id = #{ownerGroupId}")
&& xmlText.contains("cs.category_id IS NOT NULL"),
"已分类判据必须按当前分组归属行且 category_id 非空(与 fillGroupNames 同形)");
assertTrue(xmlText.contains("NOT EXISTS"), "未分类档必须是 NOT EXISTS(不是空结果降级)");
assertEquals(2, count(xmlText, "cs.product_id = p.id"),
"EXISTS/NOT EXISTS 两分支各一处商品关联,缺一个即红");
// ① 服务直传:classified 与 ownerGroupId 成对进 mapper(计数与分页同一过滤面)。
JdProductMapper mapper = mock(JdProductMapper.class);
JdProductQueryService service = queryService(mapper);
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
service.page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, GROUP_ID);
verify(mapper).countProducts(null, null, null, null, null, null, true, GROUP_ID);
verify(mapper).selectProductPage(null, null, null, null, null, null, true, GROUP_ID, 0L, 20);
service.page(1L, 20L, null, null, null, null, null, null, Boolean.FALSE, GROUP_ID);
verify(mapper).countProducts(null, null, null, null, null, null, false, GROUP_ID);
verify(mapper).selectProductPage(null, null, null, null, null, null, false, GROUP_ID, 0L, 20);
// ③ 控制器直传:classified 原样进服务(owner_group_id 仍按作用域收敛后的值)。
JdProductQueryService queryService = mock(JdProductQueryService.class);
JdCategoryScopeService scopeService = mock(JdCategoryScopeService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
AdminJdProductController controller = new AdminJdProductController(
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
mock(JdProductGroupService.class), scopeService, authSupport,
mock(PermissionMenuService.class));
AdminUserEntity operator = new AdminUserEntity();
operator.setId(7L);
HttpServletRequest request = mock(HttpServletRequest.class);
when(authSupport.requireUser(request)).thenReturn(operator);
when(authSupport.currentRole(operator)).thenReturn("super_admin");
JdCategoryScopeService.JdCategoryScope scope = writableScope(GROUP_ID, COMPANY_ID);
when(scopeService.resolve(operator)).thenReturn(scope);
when(scopeService.readGroupOrNull(scope, null)).thenReturn(GROUP_ID);
controller.page(1L, 20L, null, null, null, null, null, null, null, Boolean.TRUE, request);
verify(queryService).page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, GROUP_ID);
} }
@Test @Test
@@ -807,8 +865,8 @@ class AdminJdProductControllerTest {
JdProductEntity categorized = productEntity(1L); JdProductEntity categorized = productEntity(1L);
JdProductEntity missing = productEntity(2L); JdProductEntity missing = productEntity(2L);
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(2L); when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
anyLong(), anyInt())).thenReturn(List.of(categorized, missing)); anyLong(), anyInt())).thenReturn(List.of(categorized, missing));
when(assignMapper.selectList(any())).thenReturn(List.of( when(assignMapper.selectList(any())).thenReturn(List.of(
assign(1L, GROUP_ID, 3L), assign(2L, GROUP_ID, 99L))); assign(1L, GROUP_ID, 3L), assign(2L, GROUP_ID, 99L)));
@@ -817,7 +875,7 @@ class AdminJdProductControllerTest {
category.setName("秋冬款"); category.setName("秋冬款");
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category)); when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, GROUP_ID); JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID);
assertEquals(3L, vo.getItems().get(0).getGroupId(), "分类 id 取本组归属行"); assertEquals(3L, vo.getItems().get(0).getGroupId(), "分类 id 取本组归属行");
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集归属一次取齐分类名(无逐行查询)"); assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集归属一次取齐分类名(无逐行查询)");
@@ -832,11 +890,11 @@ class AdminJdProductControllerTest {
JdProductGroupAssignMapper assignMapper = mock(JdProductGroupAssignMapper.class); JdProductGroupAssignMapper assignMapper = mock(JdProductGroupAssignMapper.class);
JdProductQueryService service = queryService(mapper, mock(JdProductImageMapper.class), JdProductQueryService service = queryService(mapper, mock(JdProductImageMapper.class),
mock(JdProductSkuMapper.class), mock(JdProductGroupMapper.class), assignMapper); mock(JdProductSkuMapper.class), mock(JdProductGroupMapper.class), assignMapper);
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L); when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
anyLong(), anyInt())).thenReturn(List.of(productEntity(1L))); anyLong(), anyInt())).thenReturn(List.of(productEntity(1L)));
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null); JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null);
assertNull(vo.getItems().get(0).getGroupId(), "不属于任何分组的账号:分类列一律空(未分类)"); assertNull(vo.getItems().get(0).getGroupId(), "不属于任何分组的账号:分类列一律空(未分类)");
assertNull(vo.getItems().get(0).getGroupName()); assertNull(vo.getItems().get(0).getGroupName());