feat(jd): 京东数据库按公司隔离——读侧四口+写侧五口,公司之间不互看
客户口径「公司与公司之间不能互看」,推翻 2026-11-16 的「公共库无公司维度」。 读侧(统一走 DataReadScope#readCompanyIdOrOwn,非平台超管恒为本公司): - 列表 page:scopedCompanyId 下推到 XML productConds(铁律 20,SQL 侧过滤) - 导出 exportCsv:勾选 id 里有一行不属于本公司就整批拒绝(不做部分导出) - 详情 detail:别公司的行按「商品不存在」拒绝,不返回 403 泄露行是否存在 - 类目下拉 categories:与列表同口径;用户端采集建单侧按会话身份解析公司, 解析不出公司回空集而非全平台 - 店铺候选 availableShops:按公司隔离 写侧(统一走 DataReadScope#writeCompanyId): - 编辑/上传图片/删除/批量删除/批量归类五口都先过 assertRowsInCompany: 读侧藏起来的行仍能删=静默删除,不是隔离 - 分组归类额外比目标分组所在公司(平台超管也不得跨公司归类,否则分类计数串公司) 判据:AdminJdProductControllerTest 34/JdProductMapperSqlTest 5/ JdCategoryScopeServiceTest 23/JdGroupShopServiceTest 10/ JdProductQueryServiceUserPageTest 7 共 79 支绿; 后管 company-tab-wiring 12 支绿(跨端常量钉子同步)。
This commit is contained in:
+116
-104
@@ -97,6 +97,15 @@ class AdminJdProductControllerTest {
|
||||
private static final String COLUMN_KEY = "admin_jd_database";
|
||||
private static final String ROUTE_PATH = "jd-center/database";
|
||||
|
||||
/** 公司作用域桩:读/写都回 null(平台超管口径),让 controller 的 scopedCompanyId 走「不筛」分支。 */
|
||||
private static com.nanri.aiimage.common.service.DataReadScope dataScopeMock() {
|
||||
com.nanri.aiimage.common.service.DataReadScope scope =
|
||||
mock(com.nanri.aiimage.common.service.DataReadScope.class);
|
||||
when(scope.readCompanyIdOrOwn(any(), any())).thenReturn(null);
|
||||
when(scope.writeCompanyId(any())).thenReturn(null);
|
||||
return scope;
|
||||
}
|
||||
|
||||
/** 用例里的「当前分组」:数据权限分组 10,归属公司 5。 */
|
||||
private static final long GROUP_ID = 10L;
|
||||
private static final long COMPANY_ID = 5L;
|
||||
@@ -147,17 +156,19 @@ class AdminJdProductControllerTest {
|
||||
@Test
|
||||
void 读侧零公司维度_公司tab口径整批摘除() throws IOException {
|
||||
String source = stripComments(Files.readString(CONTROLLER));
|
||||
// 2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」=品牌库 2026-10-06 先例同形:
|
||||
// 摘的不只是 tab——company_id 参数与 superAdminScopedCompanyId 谓词一起撤,
|
||||
// 数据全平台公共(行 company_id 列仍是同步来源标记,不构成可见性边界)。
|
||||
assertFalse(source.contains("company_id"),
|
||||
"company_id 请求参数必须已删除,不得回潜(2026-11-16 随公司 tab 整批摘除)");
|
||||
// 2026-11-23 客户口径「公司与公司之间是不能互看的」,推翻 2026-11-16「公共库」定案:
|
||||
// 读侧按行 company_id 隔离(非平台超管钉本公司),写侧再按行级公司闸兜住。
|
||||
assertTrue(source.contains("@RequestParam(name = \"company_id\""),
|
||||
"company_id 请求参数必须在册(平台超管跨公司查看用;非超管传什么都不算)");
|
||||
assertTrue(source.contains("readCompanyIdOrOwn"),
|
||||
"读侧必须经 DataReadScope#readCompanyIdOrOwn 算公司作用域(唯一出口,不许自己写 if)");
|
||||
assertTrue(source.contains("writeCompanyId"),
|
||||
"写侧行级闸必须经 DataReadScope#writeCompanyId(编辑/传图/删除/批量删除)");
|
||||
assertTrue(source.contains("assertRowsInCompany"),
|
||||
"编辑/传图/删除/批量删除/批量归类动手前必须过行级公司闸"
|
||||
+ "(读侧藏起来的行仍然能删=静默删除,不是隔离)");
|
||||
assertFalse(source.contains("superAdminScopedCompanyId"),
|
||||
"superAdminScopedCompanyId 谓词必须已删除:第五道门(超管显式收窄)对京东只读面不再生效");
|
||||
assertFalse(source.contains("readCompanyIdOrOwn"),
|
||||
"不得走 readCompanyIdOrOwn:全平台公共数据对每一家管理员都是同一份全量,无公司可见性边界");
|
||||
assertFalse(source.contains("DataReadScope"),
|
||||
"DataReadScope 不得再注入京东只读控制器(公司收口已随 2026-11-16 摘除)");
|
||||
"不得沿用 superAdminScopedCompanyId 旧形状(它只在超管身上收窄、非超管不过滤=公司互看)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +176,7 @@ class AdminJdProductControllerTest {
|
||||
String source = stripComments(Files.readString(CONTROLLER));
|
||||
for (String param : List.of("page_size", "product_code", "title_keyword", "keyword",
|
||||
"shop_name", "min_price", "max_price",
|
||||
"group_id", "owner_group_id", "synced_from", "synced_to")) {
|
||||
"group_id", "owner_group_id", "synced_from", "synced_to", "company_id")) {
|
||||
assertTrue(source.contains(param), "查询参数必须 snake_case:" + param);
|
||||
}
|
||||
assertFalse(source.contains("@RequestParam(name = \"ungrouped\""));
|
||||
@@ -180,8 +191,9 @@ class AdminJdProductControllerTest {
|
||||
assertTrue(source.contains("@RequestParam(name = \"min_price\"")
|
||||
&& source.contains("@RequestParam(name = \"max_price\""),
|
||||
"价格区间参数 min_price/max_price 必须在册(v1.7 拍板)");
|
||||
// company_id 参数已随 2026-11-16「删除掉公司 tab」整批摘除(读侧零公司维度支另有反向钉)。
|
||||
assertFalse(source.contains("company_id"), "company_id 请求参数必须已删除,不得回潜");
|
||||
// 公司隔离(2026-11-23):company_id 在册(平台超管切公司);非超管由 readCompanyIdOrOwn 钉本公司。
|
||||
assertTrue(source.contains("@RequestParam(name = \"company_id\""),
|
||||
"company_id 请求参数必须在册(2026-11-23 公司与公司不能互看)");
|
||||
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
|
||||
assertFalse(source.contains("\"sale_status\""), "sale_status 筛选参数必须已删除,不得回潜");
|
||||
// 店铺筛选 v1.7 复活(2026-11-21 拍板「店铺名单维度完整对齐」):精确 eq 配合 group_id;
|
||||
@@ -294,7 +306,7 @@ class AdminJdProductControllerTest {
|
||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, deleteService, updateService, groupService, scopeService,
|
||||
authSupport, permissionMenuService);
|
||||
authSupport, permissionMenuService, dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(9L);
|
||||
@@ -315,10 +327,10 @@ class AdminJdProductControllerTest {
|
||||
// 读:菜单权限命中即放行(公共库一人一份全量)。
|
||||
JdProductPageVo pageVo = new JdProductPageVo();
|
||||
pageVo.setItems(List.of());
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID))
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID, null))
|
||||
.thenReturn(pageVo);
|
||||
assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, request)
|
||||
null, null, null, null, null, null, null, request)
|
||||
.isSuccess(), "普通账号有菜单权限时读必须放行(读写分档只收窄写)");
|
||||
|
||||
// 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。
|
||||
@@ -362,7 +374,7 @@ class AdminJdProductControllerTest {
|
||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, deleteService, updateService, mock(JdProductGroupService.class),
|
||||
mock(JdCategoryScopeService.class), authSupport, permissionMenuService);
|
||||
mock(JdCategoryScopeService.class), authSupport, permissionMenuService, dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(9L);
|
||||
@@ -422,7 +434,7 @@ class AdminJdProductControllerTest {
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||
AdminJdProductGroupController controller = new AdminJdProductGroupController(
|
||||
groupService, mock(JdGroupShopService.class), scopeService, authSupport, permissionMenuService);
|
||||
groupService, mock(JdGroupShopService.class), scopeService, authSupport, permissionMenuService, dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(9L);
|
||||
@@ -475,7 +487,7 @@ class AdminJdProductControllerTest {
|
||||
PermissionMenuService permissionMenuService = mock(PermissionMenuService.class);
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), updateService, groupService,
|
||||
scopeService, authSupport, permissionMenuService);
|
||||
scopeService, authSupport, permissionMenuService, dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(9L);
|
||||
@@ -519,7 +531,7 @@ class AdminJdProductControllerTest {
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
groupService, scopeService, authSupport, mock(PermissionMenuService.class));
|
||||
groupService, scopeService, authSupport, mock(PermissionMenuService.class), dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
@@ -534,12 +546,12 @@ class AdminJdProductControllerTest {
|
||||
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> controller.page(1L, 20L, null, null, null, null, 8L, null, null, null,
|
||||
null, null, null, null, request));
|
||||
null, null, null, null, null, request));
|
||||
assertTrue(ex.getMessage().contains("无权查看该分组的分类"),
|
||||
"跨组分类筛选必须 403 点名分组,不做空结果降级");
|
||||
|
||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any(), any(), any());
|
||||
any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
// ===================== 行为样本 =====================
|
||||
@@ -552,7 +564,7 @@ class AdminJdProductControllerTest {
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
groupService, scopeService, authSupport, mock(PermissionMenuService.class));
|
||||
groupService, scopeService, authSupport, mock(PermissionMenuService.class), dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
@@ -567,14 +579,14 @@ 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, null, null, null, null, null, GROUP_ID))
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID, null))
|
||||
.thenReturn(pageVo);
|
||||
|
||||
// 请求面没有 company_id:任何授权身份看到的都是同一份全量;分类列按 owner_group_id 取。
|
||||
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null,
|
||||
null, null, null, null, GROUP_ID, null, null, null, request);
|
||||
null, null, null, null, GROUP_ID, null, null, null, null, request);
|
||||
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID);
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null, null, null, null, GROUP_ID, null);
|
||||
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
|
||||
assertEquals(pageVo, response.getData());
|
||||
}
|
||||
@@ -587,7 +599,7 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), scopeService, authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
@@ -599,13 +611,13 @@ class AdminJdProductControllerTest {
|
||||
when(request.getParameter(name)).thenReturn(value);
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> controller.page(1L, 20L, null, null, null, null, 7L, null, null, null,
|
||||
null, null, null, null, request));
|
||||
null, null, null, null, null, request));
|
||||
assertTrue(ex.getMessage().contains("刷新页面"));
|
||||
when(request.getParameter(name)).thenReturn(null);
|
||||
}
|
||||
}
|
||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any(), any(), any());
|
||||
any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -615,7 +627,7 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
@@ -625,11 +637,11 @@ class AdminJdProductControllerTest {
|
||||
JdProductCategoryVo row = new JdProductCategoryVo();
|
||||
row.setName("艺考形体服");
|
||||
row.setProductCount(85L);
|
||||
when(queryService.categories()).thenReturn(List.of(row));
|
||||
when(queryService.categories(null)).thenReturn(List.of(row));
|
||||
|
||||
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(request);
|
||||
ApiResponse<List<JdProductCategoryVo>> response = controller.categories(null, request);
|
||||
|
||||
verify(queryService).categories();
|
||||
verify(queryService).categories(null);
|
||||
assertEquals(Boolean.TRUE, response.isSuccess(), "类目下拉与列表同一鉴权正门(200 信封)");
|
||||
assertEquals("艺考形体服", response.getData().get(0).getName(), "选项=已落库行的末级类目名(全平台去重)");
|
||||
assertEquals(85L, response.getData().get(0).getProductCount());
|
||||
@@ -643,7 +655,7 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), scopeService, authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
@@ -655,13 +667,13 @@ class AdminJdProductControllerTest {
|
||||
when(scopeService.readGroupOrNull(scope, null)).thenReturn(GROUP_ID);
|
||||
JdProductDetailVo detailVo = new JdProductDetailVo();
|
||||
detailVo.setId(11L);
|
||||
when(queryService.detail(11L, GROUP_ID)).thenReturn(detailVo);
|
||||
when(queryService.detail(11L, GROUP_ID, null)).thenReturn(detailVo);
|
||||
|
||||
ApiResponse<JdProductDetailVo> response = controller.detail(11L, null, request);
|
||||
ApiResponse<JdProductDetailVo> response = controller.detail(11L, null, null, request);
|
||||
|
||||
// 公共库详情没有公司维度(DataReadScope 反向钉在结构判据支,2026-11-16 已整批摘除);
|
||||
// 分类字段按「当前分组」取(V203)。
|
||||
verify(queryService).detail(11L, GROUP_ID);
|
||||
verify(queryService).detail(11L, GROUP_ID, null);
|
||||
assertEquals(Boolean.TRUE, response.isSuccess());
|
||||
assertEquals(detailVo, response.getData());
|
||||
}
|
||||
@@ -674,7 +686,7 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, deleteService, mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
@@ -703,7 +715,7 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, deleteService, mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
@@ -725,23 +737,23 @@ class AdminJdProductControllerTest {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any())).thenReturn(1L);
|
||||
any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||
|
||||
// page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。
|
||||
service.page(0L, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
service.page(0L, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class);
|
||||
ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), offset.capture(), limit.capture());
|
||||
isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), offset.capture(), limit.capture());
|
||||
assertEquals(0L, offset.getValue());
|
||||
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
|
||||
|
||||
// page=Long.MAX_VALUE / size=5000 ⇒ 钳到 10_000 页、1000 条(v1.7 上限);乘积 9_999_000 不得变负(铁律 15)。
|
||||
service.page(Long.MAX_VALUE, 5000L, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
service.page(Long.MAX_VALUE, 5000L, null, null, null, null, null, null, null, null, null, null, null, null, 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(),
|
||||
any(), any(), any(), any(), any(), any(), offsetMax.capture(), limitMax.capture());
|
||||
any(), any(), any(), any(), any(), any(), isNull(), offsetMax.capture(), limitMax.capture());
|
||||
assertEquals(9_999_000L, offsetMax.getValue(), "(page-1)*page_size 最大 9_999_000,钳制后不得溢出变负");
|
||||
assertEquals(1000, limitMax.getValue(), "page_size 上限已随 v1.7 放宽到 1000(对齐原型档位)");
|
||||
}
|
||||
@@ -753,10 +765,10 @@ 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, null, null, null, null, from, to, null, null));
|
||||
() -> service.page(1L, 20L, null, null, null, null, null, null, null, null, from, to, null, null, null));
|
||||
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
|
||||
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any());
|
||||
any(), any(), any(), any(), isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -764,18 +776,18 @@ class AdminJdProductControllerTest {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any())).thenReturn(1L);
|
||||
any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||
service.page(1L, 20L, null, " SKU-1 ", " 连衣裙 ", List.of(" 艺考形体服 "), 7L,
|
||||
null, null, null, null, null, null, null);
|
||||
null, null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, "SKU-1", "连衣裙", List.of("艺考形体服"), 7L,
|
||||
null, null, null, null, null, null, null);
|
||||
null, null, null, null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, "SKU-1", "连衣裙", List.of("艺考形体服"), 7L,
|
||||
null, null, null, null, null, null, null, 0L, 20);
|
||||
null, null, null, null, null, null, null, null, 0L, 20);
|
||||
|
||||
service.page(1L, 20L, null, " ", null, null, 0L, null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
service.page(1L, 20L, null, " ", null, null, 0L, null, null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, 0L, 20);
|
||||
null, null, null, null, null, 0L, 20);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -788,20 +800,20 @@ class AdminJdProductControllerTest {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any())).thenReturn(1L);
|
||||
any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||
|
||||
service.page(1L, 20L, null, null, null,
|
||||
java.util.Arrays.asList(" 女装 ", "女装", "", null, " 汉服/旗袍 "),
|
||||
null, null, null, null, null, null, null, null);
|
||||
null, null, null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, List.of("女装", "汉服/旗袍"),
|
||||
null, null, null, null, null, null, null, null);
|
||||
null, null, null, null, null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, null, null, List.of("女装", "汉服/旗袍"),
|
||||
null, null, null, null, null, null, null, null, 0L, 20);
|
||||
null, null, null, null, null, null, null, null, null, 0L, 20);
|
||||
|
||||
// 全空白/空集合=不过滤该面(与「全部类目」清选同口径,不得下发空 IN)
|
||||
service.page(1L, 20L, null, null, null, java.util.Arrays.asList(" ", ""),
|
||||
null, null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
null, null, null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
|
||||
Path xml = findJdProductMapperXml();
|
||||
String xmlText = stripComments(Files.readString(xml)).replaceAll("(?s)<!--.*?-->", "");
|
||||
@@ -839,18 +851,18 @@ class AdminJdProductControllerTest {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any())).thenReturn(1L);
|
||||
any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||
service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null,
|
||||
Boolean.TRUE, GROUP_ID);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, true, GROUP_ID);
|
||||
Boolean.TRUE, GROUP_ID, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, true, GROUP_ID, null);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null,
|
||||
null, null, true, GROUP_ID, 0L, 20);
|
||||
null, null, true, GROUP_ID, null, 0L, 20);
|
||||
|
||||
service.page(1L, 20L, null, null, null, null, null, null, null, null, null, null,
|
||||
Boolean.FALSE, GROUP_ID);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, false, GROUP_ID);
|
||||
Boolean.FALSE, GROUP_ID, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, false, GROUP_ID, null);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null,
|
||||
null, null, false, GROUP_ID, 0L, 20);
|
||||
null, null, false, GROUP_ID, null, 0L, 20);
|
||||
|
||||
// ③ 控制器直传:classified 原样进服务(owner_group_id 仍按作用域收敛后的值)。
|
||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||
@@ -859,7 +871,7 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), scopeService, authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
@@ -869,9 +881,9 @@ class AdminJdProductControllerTest {
|
||||
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, null, null, null,
|
||||
null, Boolean.TRUE, request);
|
||||
null, Boolean.TRUE, null, request);
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, null, null,
|
||||
null, Boolean.TRUE, GROUP_ID);
|
||||
null, Boolean.TRUE, GROUP_ID, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -884,27 +896,27 @@ class AdminJdProductControllerTest {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any())).thenReturn(1L);
|
||||
any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||
|
||||
// ① 三件新面原样直传:keyword/shopName trim 归一,价格 BigDecimal 原样。
|
||||
service.page(1L, 20L, " 连衣裙 ", null, null, null, 7L, " 测试店铺 ",
|
||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null);
|
||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null);
|
||||
verify(mapper).countProducts("连衣裙", null, null, null, 7L, "测试店铺",
|
||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null);
|
||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null);
|
||||
verify(mapper).selectProductPage("连衣裙", null, null, null, 7L, "测试店铺",
|
||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, 0L, 20);
|
||||
new BigDecimal("100"), new BigDecimal("200"), null, null, null, null, null, 0L, 20);
|
||||
|
||||
// ② 空白 keyword/shopName 归 null(不过滤该面)。
|
||||
service.page(1L, 20L, " ", null, null, null, 0L, " ", null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
service.page(1L, 20L, " ", null, null, null, 0L, " ", null, null, null, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null, null, null, null, null, null);
|
||||
|
||||
// ③ 价格倒挂按业务异常拒绝(同同步起止倒挂形状)。
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> service.page(1L, 20L, null, null, null, null, null, null,
|
||||
new BigDecimal("200"), new BigDecimal("100"), null, null, null, null));
|
||||
new BigDecimal("200"), new BigDecimal("100"), null, null, null, null, null));
|
||||
assertTrue(ex.getMessage().contains("价格区间最小值不能大于最大值"), "倒挂价格区间按业务异常拒绝");
|
||||
verify(mapper, times(2)).countProducts(any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any(), any(), any());
|
||||
any(), any(), any(), any(), any(), any(), isNull());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -919,20 +931,20 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
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");
|
||||
byte[] csvBytes = "\uFEFF商品编码\r\nA123".getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
when(queryService.exportCsv(List.of(11L, 12L))).thenReturn(csvBytes);
|
||||
when(queryService.exportCsv(List.of(11L, 12L), null)).thenReturn(csvBytes);
|
||||
|
||||
JdProductExportRequest body = new JdProductExportRequest();
|
||||
body.setIds(List.of(11L, 12L));
|
||||
ResponseEntity<byte[]> response = controller.export(body, request);
|
||||
ResponseEntity<byte[]> response = controller.export(body, null, request);
|
||||
|
||||
verify(queryService).exportCsv(List.of(11L, 12L));
|
||||
verify(queryService).exportCsv(List.of(11L, 12L), null);
|
||||
assertEquals(200, response.getStatusCode().value(), "放行必须是 200 附件响应(非 ApiResponse 信封)");
|
||||
assertTrue(response.getHeaders().getFirst("Content-Disposition").contains(".csv"),
|
||||
"Content-Disposition 必须带 .csv 文件名(DownloadHeaderUtil 兜 ASCII 回退与 UTF-8 双名)");
|
||||
@@ -949,14 +961,14 @@ class AdminJdProductControllerTest {
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), mock(JdCategoryScopeService.class), authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
mock(PermissionMenuService.class), dataScopeMock());
|
||||
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");
|
||||
// 服务侧限流是真源(服务级用例另钉 1001 拒绝);这里钉控制器原样透出业务异常、不吞成 500。
|
||||
when(queryService.exportCsv(any()))
|
||||
when(queryService.exportCsv(any(), isNull()))
|
||||
.thenThrow(new BusinessException("单次最多导出 1000 个商品,请缩小勾选范围"));
|
||||
|
||||
java.util.List<Long> oversized = new java.util.ArrayList<>();
|
||||
@@ -965,7 +977,7 @@ class AdminJdProductControllerTest {
|
||||
}
|
||||
JdProductExportRequest body = new JdProductExportRequest();
|
||||
body.setIds(oversized);
|
||||
BusinessException ex = assertThrows(BusinessException.class, () -> controller.export(body, request));
|
||||
BusinessException ex = assertThrows(BusinessException.class, () -> controller.export(body, null, request));
|
||||
assertTrue(ex.getMessage().contains("1000"), "超限文案必须点名上限 1000");
|
||||
}
|
||||
|
||||
@@ -981,7 +993,7 @@ class AdminJdProductControllerTest {
|
||||
second.setSyncedAt(LocalDateTime.of(2026, 11, 21, 9, 30));
|
||||
when(mapper.selectBatchIds(List.of(2L, 1L))).thenReturn(List.of(second, first));
|
||||
|
||||
byte[] bytes = service.exportCsv(List.of(2L, 1L));
|
||||
byte[] bytes = service.exportCsv(List.of(2L, 1L), null);
|
||||
String csv = new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
|
||||
|
||||
assertTrue(csv.startsWith("\uFEFF"), "必须带 UTF-8 BOM(Excel 双击直开中文不乱码)");
|
||||
@@ -998,17 +1010,17 @@ class AdminJdProductControllerTest {
|
||||
assertTrue(firstRow > 0 && secondRow > firstRow, "行分隔符存在");
|
||||
|
||||
// 空勾选拒绝(前端按钮置灰是第一道,这里是兜底);超上限同样拒绝(少导是交付事故)。
|
||||
BusinessException empty = assertThrows(BusinessException.class, () -> service.exportCsv(List.of()));
|
||||
BusinessException empty = assertThrows(BusinessException.class, () -> service.exportCsv(List.of(), null));
|
||||
assertTrue(empty.getMessage().contains("请先勾选"));
|
||||
BusinessException invalid = assertThrows(BusinessException.class,
|
||||
() -> service.exportCsv(java.util.Arrays.asList(0L, null)));
|
||||
() -> service.exportCsv(java.util.Arrays.asList(0L, null), null));
|
||||
assertTrue(invalid.getMessage().contains("请先勾选"));
|
||||
|
||||
java.util.List<Long> oversized = new java.util.ArrayList<>();
|
||||
for (long i = 1; i <= JdProductQueryService.MAX_EXPORT_IDS + 1; i++) {
|
||||
oversized.add(i);
|
||||
}
|
||||
BusinessException over = assertThrows(BusinessException.class, () -> service.exportCsv(oversized));
|
||||
BusinessException over = assertThrows(BusinessException.class, () -> service.exportCsv(oversized, null));
|
||||
assertTrue(over.getMessage().contains("1000"), "超限文案必须点名上限 1000");
|
||||
}
|
||||
|
||||
@@ -1037,7 +1049,7 @@ class AdminJdProductControllerTest {
|
||||
image.setHeight(800);
|
||||
when(imageMapper.selectList(any())).thenReturn(List.of(image));
|
||||
|
||||
JdProductDetailVo vo = service.detail(11L, null);
|
||||
JdProductDetailVo vo = service.detail(11L, null, null);
|
||||
|
||||
assertEquals(2, vo.getAttrGroups().size(), "tabs 数组逐个映射成 attrGroups(groupName=tab 字段)");
|
||||
assertEquals("商品基本信息", vo.getAttrGroups().get(0).getGroupName());
|
||||
@@ -1066,7 +1078,7 @@ class AdminJdProductControllerTest {
|
||||
JdProductEntity broken = productEntity(11L);
|
||||
broken.setAttrJson("{\"tabs\": [broken");
|
||||
when(mapper.selectById(11L)).thenReturn(broken);
|
||||
JdProductDetailVo brokenVo = service.detail(11L, null);
|
||||
JdProductDetailVo brokenVo = service.detail(11L, null, null);
|
||||
assertTrue(brokenVo.getAttrGroups().isEmpty(), "解析异常落空 attrGroups,不抛 500(AC-7)");
|
||||
assertEquals("{\"tabs\": [broken", brokenVo.getAttrJsonRaw(), "原文进 attrJsonRaw 兜底展示");
|
||||
|
||||
@@ -1074,7 +1086,7 @@ class AdminJdProductControllerTest {
|
||||
JdProductEntity foreign = productEntity(11L);
|
||||
foreign.setAttrJson("{\"attrs\":[{\"key\":\"x\",\"value\":\"y\"}]}");
|
||||
when(mapper.selectById(11L)).thenReturn(foreign);
|
||||
JdProductDetailVo foreignVo = service.detail(11L, null);
|
||||
JdProductDetailVo foreignVo = service.detail(11L, null, null);
|
||||
assertTrue(foreignVo.getAttrGroups().isEmpty(), "非契约形状落空 attrGroups");
|
||||
assertEquals("{\"attrs\":[{\"key\":\"x\",\"value\":\"y\"}]}", foreignVo.getAttrJsonRaw(),
|
||||
"未识别属性不丢弃:原文兜底透出(AC-7)");
|
||||
@@ -1083,7 +1095,7 @@ class AdminJdProductControllerTest {
|
||||
JdProductEntity blank = productEntity(11L);
|
||||
blank.setAttrJson(null);
|
||||
when(mapper.selectById(11L)).thenReturn(blank);
|
||||
JdProductDetailVo blankVo = service.detail(11L, null);
|
||||
JdProductDetailVo blankVo = service.detail(11L, null, null);
|
||||
assertTrue(blankVo.getAttrGroups().isEmpty());
|
||||
assertNull(blankVo.getAttrJsonRaw());
|
||||
}
|
||||
@@ -1112,7 +1124,7 @@ class AdminJdProductControllerTest {
|
||||
brokenJson.setSaleAttrsJson("[{\"name\":");
|
||||
when(skuMapper.selectList(any())).thenReturn(List.of(first, brokenJson));
|
||||
|
||||
JdProductDetailVo vo = service.detail(11L, null);
|
||||
JdProductDetailVo vo = service.detail(11L, null, null);
|
||||
|
||||
assertEquals(2, vo.getSkus().size(), "京麦那 12 行矩阵按入库行下发(抽屉渲染的唯一来源)");
|
||||
JdProductDetailVo.SkuVo sku = vo.getSkus().get(0);
|
||||
@@ -1137,14 +1149,14 @@ class AdminJdProductControllerTest {
|
||||
JdProductEntity row = productEntity(11L);
|
||||
row.setCompanyId(6L);
|
||||
when(mapper.selectById(11L)).thenReturn(row);
|
||||
assertNotNull(service.detail(11L, null));
|
||||
assertNotNull(service.detail(11L, null, null));
|
||||
|
||||
// 行不存在 ⇒ 按「商品不存在」拒绝。
|
||||
when(mapper.selectById(11L)).thenReturn(null);
|
||||
BusinessException ex = assertThrows(BusinessException.class, () -> service.detail(11L, null));
|
||||
BusinessException ex = assertThrows(BusinessException.class, () -> service.detail(11L, null, null));
|
||||
assertTrue(ex.getMessage().contains("商品不存在"));
|
||||
// id 非法同样拒绝。
|
||||
assertThrows(BusinessException.class, () -> service.detail(0L, null));
|
||||
assertThrows(BusinessException.class, () -> service.detail(0L, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1158,9 +1170,9 @@ class AdminJdProductControllerTest {
|
||||
JdProductEntity categorized = productEntity(1L);
|
||||
JdProductEntity missing = productEntity(2L);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any())).thenReturn(2L);
|
||||
any(), any(), any(), any(), isNull())).thenReturn(2L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any(), anyLong(), anyInt())).thenReturn(List.of(categorized, missing));
|
||||
any(), any(), any(), any(), isNull(), anyLong(), anyInt())).thenReturn(List.of(categorized, missing));
|
||||
when(assignMapper.selectList(any())).thenReturn(List.of(
|
||||
assign(1L, GROUP_ID, 3L), assign(2L, GROUP_ID, 99L)));
|
||||
JdProductGroupEntity category = new JdProductGroupEntity();
|
||||
@@ -1169,7 +1181,7 @@ class AdminJdProductControllerTest {
|
||||
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
|
||||
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null,
|
||||
null, null, null, GROUP_ID);
|
||||
null, null, null, GROUP_ID, null);
|
||||
|
||||
assertEquals(3L, vo.getItems().get(0).getGroupId(), "分类 id 取本组归属行");
|
||||
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集归属一次取齐分类名(无逐行查询)");
|
||||
@@ -1185,12 +1197,12 @@ class AdminJdProductControllerTest {
|
||||
JdProductQueryService service = queryService(mapper, mock(JdProductImageMapper.class),
|
||||
mock(JdProductSkuMapper.class), mock(JdProductGroupMapper.class), assignMapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any())).thenReturn(1L);
|
||||
any(), any(), any(), any(), isNull())).thenReturn(1L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any(), any(), anyLong(), anyInt())).thenReturn(List.of(productEntity(1L)));
|
||||
any(), any(), any(), any(), isNull(), anyLong(), anyInt())).thenReturn(List.of(productEntity(1L)));
|
||||
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null,
|
||||
null, null, null, null);
|
||||
null, null, null, null, null);
|
||||
|
||||
assertNull(vo.getItems().get(0).getGroupId(), "不属于任何分组的账号:分类列一律空(未分类)");
|
||||
assertNull(vo.getItems().get(0).getGroupName());
|
||||
@@ -1208,7 +1220,7 @@ class AdminJdProductControllerTest {
|
||||
|
||||
// 本组(10)没归类:detail 的 selectOne 回 null ⇒ 分类字段空。
|
||||
when(assignMapper.selectOne(any())).thenReturn(null);
|
||||
JdProductDetailVo untouched = service.detail(11L, GROUP_ID);
|
||||
JdProductDetailVo untouched = service.detail(11L, GROUP_ID, null);
|
||||
assertNull(untouched.getGroupId(), "本组没归类=未分类,不拿别组的归属顶上");
|
||||
assertNull(untouched.getGroupName());
|
||||
|
||||
@@ -1218,7 +1230,7 @@ class AdminJdProductControllerTest {
|
||||
category.setId(3L);
|
||||
category.setName("秋冬款");
|
||||
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
|
||||
JdProductDetailVo categorized = service.detail(11L, GROUP_ID);
|
||||
JdProductDetailVo categorized = service.detail(11L, GROUP_ID, null);
|
||||
assertEquals(3L, categorized.getGroupId());
|
||||
assertEquals("秋冬款", categorized.getGroupName());
|
||||
}
|
||||
|
||||
+18
@@ -113,6 +113,24 @@ class JdProductMapperSqlTest {
|
||||
assertTrue(sql.endsWith("ORDER BY p.shop_name LIMIT ?"), () -> "必须按店名升序+LIMIT 收尾: " + sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司隔离(2026-11-23 客户口径「公司与公司之间不能互看」):四条读路径(列表/总数/
|
||||
* 类目下拉/店铺候选)都必须能把 companyId 下推成 {@code p.company_id = ?};平台超管
|
||||
* (companyId 空)不得出现该谓词。漏一条=那条路径跨公司可见,且不会报错。
|
||||
*/
|
||||
@Test
|
||||
void 公司隔离谓词必须下推SQL() throws Exception {
|
||||
for (String id : java.util.List.of("countProducts", "selectProductPage",
|
||||
"selectProductCategories", "selectDistinctShopNames")) {
|
||||
String sql = render(id, Map.of("companyId", 5L, "offset", 0L, "limit", 20));
|
||||
assertTrue(sql.contains("p.company_id = ?"),
|
||||
() -> id + " 少了公司隔离谓词(该路径会跨公司返回): " + sql);
|
||||
}
|
||||
String bare = render("countProducts", Map.of("offset", 0L, "limit", 20));
|
||||
assertFalse(bare.contains("company_id"),
|
||||
() -> "平台超管(companyId 空)不得被钉死在某公司: " + bare);
|
||||
}
|
||||
|
||||
private static String render(String id) throws Exception {
|
||||
return render(id, Map.of("companyId", 1L, "taskId", 34956L));
|
||||
}
|
||||
|
||||
+45
-42
@@ -31,8 +31,9 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* <p>四档矩阵(2026-11-17 起各档可见集最后统一过「只留京东档 platform='jd' 分组」的平台闸):
|
||||
* 平台超管=全部公司全部组可读可写;公司超管=本公司全部组;
|
||||
* 管理员=全部可见组可写(2026-11-23 客户口径「管理人员只有分类权限」,不再要求组长身份);
|
||||
* 普通号=与管理员同可见、<b>零可写</b>(能开弹窗看,不能增删改分类、不能归类)。
|
||||
* 管理员=自己带的组可写、成员所属组只读(2026-11-23 客户口径「管理员之间分类不能互看」:
|
||||
* 不再继承上级带的组);普通号=自己带的组+成员所属组+上级组可见、<b>零可写</b>
|
||||
* (「管理员与员工可以互看分类」「普通员工没有权限分类」)。
|
||||
* 另钉三条收敛语义:不可见组读 403(不做空结果降级)、无分组上下文读回 null(页面照常可用)、
|
||||
* 写侧在「无可写组 / 多可写组未选 / 该组不可写 / 组行不存在」四种形状下的文案。
|
||||
* 下拉 label 前缀(2026-11-21 用户口径「这里不是选公司 是选超管/管理员」):平台超管跨多个
|
||||
@@ -168,75 +169,45 @@ class JdCategoryScopeServiceTest {
|
||||
* 管理人员普遍不是组长,拿不到分类入口)。可见性边界不变:不可见组仍双拒。
|
||||
*/
|
||||
@Test
|
||||
void 管理人员_全部可见组可写_含非组长身份所属组的组() {
|
||||
void 管理人员_自己带的组可写_成员所属组只读() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("admin");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of(group(10L, COMPANY_ID, "自己的组")));
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of(3L));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(11L, COMPANY_ID, "上司的组")));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(11L, COMPANY_ID, "组长A的组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(10L, 11L);
|
||||
assertThat(scope.writableGroupIds()).containsExactly(10L, 11L);
|
||||
// 2026-11-23 客户口径「管理员与管理员之间分类不能互看,同组的可以看、不同组的不能看」:
|
||||
// 分类可写只到自己带的组;作为别组成员时那组只读(归它的组长管)。
|
||||
assertThat(scope.writableGroupIds()).containsExactly(10L);
|
||||
assertThat(scope.canRead(11L)).isTrue();
|
||||
assertThat(scope.canWrite(11L)).isTrue();
|
||||
// 不可见组仍双拒:可写放开只到可见集为止,V203 分组隔离不松。
|
||||
assertThat(scope.canWrite(11L)).isFalse();
|
||||
// 不可见组仍双拒:V203 分组隔离不松。
|
||||
assertThat(scope.canRead(99L)).isFalse();
|
||||
assertThat(scope.canWrite(99L)).isFalse();
|
||||
}
|
||||
|
||||
/** 非组长的普通管理人员(只靠成员关系可见组)同样拿到分类可写——客户账号 阿华226655 的形状。 */
|
||||
/** 非组长的管理人员(只靠成员关系可见组):分类可读、不可写——写归该组组长。 */
|
||||
@Test
|
||||
void 管理人员非组长_成员关系可见的组也可写分类() {
|
||||
void 管理人员非组长_成员组可见但不可写() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("admin");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of(3L));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(11L, COMPANY_ID, "上司的组")));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(11L, COMPANY_ID, "组长A的组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(11L);
|
||||
assertThat(scope.writableGroupIds()).containsExactly(11L);
|
||||
assertThat(scope.groups()).singleElement()
|
||||
.satisfies(option -> assertThat(option.isEditable()).isTrue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 普通号_可见同组长但零可写() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of(3L));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(10L, COMPANY_ID, "A组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(10L);
|
||||
assertThat(scope.writableGroupIds()).isEmpty();
|
||||
assertThat(scope.groups()).singleElement()
|
||||
.satisfies(option -> assertThat(option.isEditable()).isFalse());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 不属于任何分组的账号_空作用域不报错() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of());
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).isEmpty();
|
||||
assertThat(scope.defaultGroupId()).isNull();
|
||||
assertThat(scope.groups()).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 2026-11-24 客户口径「普通管理员看不到同组管理员的分类」(线上账号 阿华112336 的形状:
|
||||
* 员工 1366 → 管理员 1365(不带组)→ 公司超管 1353(带组 49)):可见组沿 created_by_id
|
||||
@@ -332,6 +303,38 @@ class JdCategoryScopeServiceTest {
|
||||
assertThat(scope.canRead(22L)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 普通号_可见同组长但零可写() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of(3L));
|
||||
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(10L, COMPANY_ID, "A组")));
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).containsExactly(10L);
|
||||
assertThat(scope.writableGroupIds()).isEmpty();
|
||||
assertThat(scope.groups()).singleElement()
|
||||
.satisfies(option -> assertThat(option.isEditable()).isFalse());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 不属于任何分组的账号_空作用域不报错() {
|
||||
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("normal");
|
||||
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
|
||||
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
|
||||
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of());
|
||||
|
||||
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
|
||||
|
||||
assertThat(scope.visibleGroupIds()).isEmpty();
|
||||
assertThat(scope.defaultGroupId()).isNull();
|
||||
assertThat(scope.groups()).isEmpty();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 入参收敛
|
||||
|
||||
@Test
|
||||
|
||||
+6
-6
@@ -202,19 +202,19 @@ class JdGroupShopServiceTest {
|
||||
@Test
|
||||
void 可添加候选排除已有名单且limit钳制() {
|
||||
when(shopMapper.selectList(any())).thenReturn(List.of(shopRow(1L, CATEGORY_ID, "已有店A")));
|
||||
when(productMapper.selectDistinctShopNames("旗", List.of("已有店A"), 200))
|
||||
when(productMapper.selectDistinctShopNames("旗", List.of("已有店A"), 200, null))
|
||||
.thenReturn(List.of("旗舷店"));
|
||||
|
||||
assertEquals(List.of("旗舷店"),
|
||||
service.availableShops(" 旗 ", CATEGORY_ID, null), "keyword trim 后下推;limit 缺省钳到 200");
|
||||
service.availableShops(" 旗 ", CATEGORY_ID, null, null), "keyword trim 后下推;limit 缺省钳到 200");
|
||||
|
||||
// limit 钳制:500 请求 → 200(服务侧钳,mapper 不做第二次换算)。
|
||||
service.availableShops(null, CATEGORY_ID, 500);
|
||||
verify(productMapper).selectDistinctShopNames(null, List.of("已有店A"), 200);
|
||||
service.availableShops(null, CATEGORY_ID, 500, null);
|
||||
verify(productMapper).selectDistinctShopNames(null, List.of("已有店A"), 200, null);
|
||||
|
||||
// 不带排除分类:excludeNames 空清单(不生成 NOT IN);前两轮各查过一次名单表,共两次。
|
||||
when(productMapper.selectDistinctShopNames(null, List.of(), 50)).thenReturn(List.of("直接店"));
|
||||
assertEquals(List.of("直接店"), service.availableShops(null, null, 50));
|
||||
when(productMapper.selectDistinctShopNames(null, List.of(), 50, null)).thenReturn(List.of("直接店"));
|
||||
assertEquals(List.of("直接店"), service.availableShops(null, null, 50, null));
|
||||
verify(shopMapper, times(2)).selectList(any());
|
||||
}
|
||||
|
||||
|
||||
+39
-1
@@ -149,6 +149,44 @@ class JdProductQueryServiceUserPageTest {
|
||||
verify(jdProductMapper, never()).selectList(any());
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司隔离(2026-11-23 客户口径「公司与公司之间不能互看」):详情按行 company_id 校验,
|
||||
* 别公司的行按「商品不存在」拒绝(不 403,不泄露行是否存在);平台超管(null)不限。
|
||||
*/
|
||||
@Test
|
||||
void 详情跨公司按商品不存在拒绝_本公司放行() {
|
||||
JdProductEntity row = product(31L);
|
||||
row.setCompanyId(5L);
|
||||
when(jdProductMapper.selectById(31L)).thenReturn(row);
|
||||
when(jdProductImageMapper.selectList(any())).thenReturn(List.of());
|
||||
when(jdProductSkuMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
assertThat(service.detail(31L, null, 5L).getId()).as("本公司行正常返回").isEqualTo(31L);
|
||||
assertThat(service.detail(31L, null, null).getId()).as("平台超管不限公司").isEqualTo(31L);
|
||||
org.junit.jupiter.api.Assertions.assertThrows(
|
||||
com.nanri.aiimage.common.exception.BusinessException.class,
|
||||
() -> service.detail(31L, null, 6L),
|
||||
"别公司的行必须按「商品不存在」拒绝(不是 403,不泄露存在性)");
|
||||
}
|
||||
|
||||
/**
|
||||
* 写侧行级公司闸:请求 id 里只要有一行不属于作用域公司就整批拒绝;平台超管(null)不限。
|
||||
* 读侧藏起来的行仍然能删=静默删除,不是隔离——编辑/传图/删除/批量删除/归类都走这一道。
|
||||
*/
|
||||
@Test
|
||||
void 写侧行级公司闸_跨公司整批拒绝_本公司与平台超管放行() {
|
||||
JdProductEntity own = product(41L);
|
||||
own.setCompanyId(5L);
|
||||
when(jdProductMapper.selectBatchIds(List.of(41L))).thenReturn(List.of(own));
|
||||
|
||||
service.assertRowsInCompany(List.of(41L), 5L);
|
||||
service.assertRowsInCompany(List.of(41L), null);
|
||||
org.junit.jupiter.api.Assertions.assertThrows(
|
||||
com.nanri.aiimage.common.exception.BusinessException.class,
|
||||
() -> service.assertRowsInCompany(List.of(41L), 6L),
|
||||
"别公司的行必须整批拒绝(静默删掉别家数据比报错更糟)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 详情与列表都带回人工编辑锁_锁行可观测面() {
|
||||
// 2026-11-23 E2E 窗发现的缺口:V199 人工锁在编辑侧已置 1,但详情/列表 VO 不暴露,
|
||||
@@ -159,7 +197,7 @@ class JdProductQueryServiceUserPageTest {
|
||||
when(jdProductImageMapper.selectList(any())).thenReturn(List.of());
|
||||
when(jdProductSkuMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
com.nanri.aiimage.modules.jd.model.vo.JdProductDetailVo detail = service.detail(21L, null);
|
||||
com.nanri.aiimage.modules.jd.model.vo.JdProductDetailVo detail = service.detail(21L, null, null);
|
||||
assertThat(detail.getManualLocked()).as("详情 VO 带回人工锁").isEqualTo(1);
|
||||
|
||||
JdProductEntity listRow = product(22L);
|
||||
|
||||
Reference in New Issue
Block a user