feat(jd): 分类状态快筛 backend-only pick(d25c91f6 的 backend-java 差集打在 ee613db0 上;jar 不含 V209——20ee7334 留原窗随其配套前端发;后管面从主树 HEAD 单独出包)

This commit is contained in:
2026-11-17 17:14:29 +08:00
parent ee613db05b
commit ed644384cc
5 changed files with 139 additions and 42 deletions
@@ -164,6 +164,10 @@ class AdminJdProductControllerTest {
}
assertFalse(source.contains("@RequestParam(name = \"ungrouped\""));
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」整批摘除(读侧零公司维度支另有反向钉)。
assertFalse(source.contains("company_id"), "company_id 请求参数必须已删除,不得回潜");
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
@@ -279,8 +283,8 @@ class AdminJdProductControllerTest {
// 读:菜单权限命中即放行(公共库一人一份全量)。
JdProductPageVo pageVo = new JdProductPageVo();
pageVo.setItems(List.of());
when(queryService.page(1L, 20L, 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)
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, null, request)
.isSuccess(), "非超管有菜单权限时读必须放行(读写分档只收窄写)");
// 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。
@@ -429,11 +433,11 @@ class AdminJdProductControllerTest {
when(groupService.requireCategory(8L)).thenReturn(category(8L, 20L));
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("无权查看该分组的分类"),
"跨组分类筛选必须 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.setPage(1L);
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 取。
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(pageVo, response.getData());
}
@@ -491,12 +495,12 @@ class AdminJdProductControllerTest {
for (String value : List.of("true", "false", "")) {
when(request.getParameter(name)).thenReturn(value);
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("刷新页面"));
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
@@ -615,23 +619,23 @@ class AdminJdProductControllerTest {
void 查询服务分页钳制防溢出() {
JdProductMapper mapper = mock(JdProductMapper.class);
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。
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<Integer> limit = ArgumentCaptor.forClass(Integer.class);
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
offset.capture(), limit.capture());
isNull(), isNull(), offset.capture(), limit.capture());
assertEquals(0L, offset.getValue());
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
// 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<Integer> limitMax = ArgumentCaptor.forClass(Integer.class);
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(100, limitMax.getValue());
}
@@ -643,23 +647,77 @@ class AdminJdProductControllerTest {
LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0);
LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0);
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("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any());
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any());
}
@Test
void 查询服务过滤面原样直传且空串归null() {
JdProductMapper mapper = mock(JdProductMapper.class);
JdProductQueryService service = queryService(mapper);
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L);
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null, null);
verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null);
verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, 0L, 20);
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null, null, null);
verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null);
verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null, 0L, 20);
service.page(1L, 20L, " ", null, null, 0L, null, null, null);
verify(mapper).countProducts(null, null, null, null, null, null);
verify(mapper).selectProductPage(null, null, null, null, null, null, 0L, 20);
service.page(1L, 20L, " ", null, null, 0L, null, null, null, null);
verify(mapper).countProducts(null, null, null, null, null, null, null, null);
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null, 0L, 20);
}
/**
* 分类状态快筛(2026-11-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
@@ -807,8 +865,8 @@ class AdminJdProductControllerTest {
JdProductEntity categorized = productEntity(1L);
JdProductEntity missing = productEntity(2L);
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(2L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(),
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
anyLong(), anyInt())).thenReturn(List.of(categorized, missing));
when(assignMapper.selectList(any())).thenReturn(List.of(
assign(1L, GROUP_ID, 3L), assign(2L, GROUP_ID, 99L)));
@@ -817,7 +875,7 @@ class AdminJdProductControllerTest {
category.setName("秋冬款");
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("秋冬款", vo.getItems().get(0).getGroupName(), "行集归属一次取齐分类名(无逐行查询)");
@@ -832,11 +890,11 @@ class AdminJdProductControllerTest {
JdProductGroupAssignMapper assignMapper = mock(JdProductGroupAssignMapper.class);
JdProductQueryService service = queryService(mapper, mock(JdProductImageMapper.class),
mock(JdProductSkuMapper.class), mock(JdProductGroupMapper.class), assignMapper);
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(),
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
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).getGroupName());