diff --git a/backend-java/src/main/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeService.java b/backend-java/src/main/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeService.java index a016f8262..0d0852f07 100644 --- a/backend-java/src/main/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeService.java +++ b/backend-java/src/main/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeService.java @@ -213,7 +213,13 @@ public class JdCategoryScopeService { String groupName = group.getGroupName() == null ? "" : group.getGroupName().trim(); String label = groupName; if (platformSuperAdmin) { - String companyName = companyNames.get(group.getCompanyId()); + // 归属公司可为 NULL(V153 口径:组长账号已不存在、归属无从追溯),而 companyNames() + // 在「一个公司 id 都取不到」时返回的是 Map.of()——对不可变空 Map 调 get(null) 会抛 + // NullPointerException(2026-11-16 22:00 线上实录:全空归属时整个京东数据库 500, + // 列表/分类/scope 三端点同时挂)。故先判空再取,取不到就只显示组名。 + Long groupCompanyId = group.getCompanyId(); + String companyName = groupCompanyId == null || groupCompanyId <= 0 + ? null : companyNames.get(groupCompanyId); label = companyName == null || companyName.isBlank() ? groupName : companyName + " / " + groupName; } diff --git a/backend-java/src/test/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeServiceTest.java b/backend-java/src/test/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeServiceTest.java index b2903f5cd..39632e44e 100644 --- a/backend-java/src/test/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeServiceTest.java +++ b/backend-java/src/test/java/com/nanri/aiimage/modules/jd/service/JdCategoryScopeServiceTest.java @@ -225,6 +225,49 @@ class JdCategoryScopeServiceTest { verify(adminUserMapper, org.mockito.Mockito.times(1)).selectById(anyLong()); } + /** + * 平台超管 + 全部组的归属公司都是 NULL(V153 留下的存量形状:组长账号已不存在)。 + * + *

2026-11-16 22:00 线上实录:这种数据的整页 500——{@code companyNames()} 在「一个公司 id + * 都取不到」时返回 {@code Map.of()},`Map.of().get(null)` 抛 NullPointerException, + * 列表/分类/scope 三个端点同时挂。判据:不炸、组名不加前缀、也不去查公司表。

+ */ + @Test + void 平台超管_组归属公司全为NULL时不炸且组名不带前缀() { + AdminUserEntity operator = user(USER_ID, COMPANY_ID); + when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin"); + when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(true); + when(shopManageGroupMapper.selectAllGroups()).thenReturn(List.of( + groupWithoutCompany(10L, "A组"), groupWithoutCompany(11L, "B组"))); + + JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator); + + assertThat(scope.visibleGroupIds()).containsExactly(10L, 11L); + assertThat(scope.writableGroupIds()).containsExactly(10L, 11L); + assertThat(scope.groups()).extracting(JdCategoryGroupOptionVo::getLabel) + .containsExactly("A组", "B组"); + verify(companyMapper, never()).selectBatchIds(any()); + } + + /** 部分组没归属公司(NULL)、部分有:有归属的带公司前缀,没归属的只显示组名。 */ + @Test + void 平台超管_组归属公司部分为NULL时只给有归属的加前缀() { + AdminUserEntity operator = user(USER_ID, COMPANY_ID); + when(adminAuthSupport.currentRole(operator)).thenReturn("super_admin"); + when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(true); + when(shopManageGroupMapper.selectAllGroups()).thenReturn(List.of( + group(10L, 1L, "A组"), groupWithoutCompany(11L, "B组"))); + CompanyEntity company = new CompanyEntity(); + company.setId(1L); + company.setCompanyName("甲公司"); + when(companyMapper.selectBatchIds(any())).thenReturn(List.of(company)); + + JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator); + + assertThat(scope.groups()).extracting(JdCategoryGroupOptionVo::getLabel) + .containsExactly("甲公司 / A组", "B组"); + } + @Test void scope回执_带平台超管标记与每组可写标记() { AdminUserEntity operator = user(USER_ID, COMPANY_ID); @@ -261,6 +304,14 @@ class JdCategoryScopeServiceTest { return group; } + /** 归属公司为 NULL 的组(V153 口径:组长账号已不存在,归属无从追溯)。 */ + private static ShopManageGroupEntity groupWithoutCompany(long id, String name) { + ShopManageGroupEntity group = new ShopManageGroupEntity(); + group.setId(id); + group.setGroupName(name); + return group; + } + /** 直接构作用域(跳过解析):可见组 / 可写组 / 下拉项三者按入参给。 */ private static JdCategoryScopeService.JdCategoryScope scope(List visible, List writable, List optionGroupIds) {