feat(appearance-patent): 外观专利数据库改为按主管划分的一主管一卡(2026-11-11 客户「应该是只显示一个卡片的才对」「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」)——后端新增 GET /supervisors 主管聚合(组键=与「所属主管」列同源的归属表达式:主管本人取自己、普通账户取创建人、读不到归同一 NULL 组;返回条数/任务数/最近任务号/最近同步/国家集,total 是主管数),卡片[下载]走 /export 新增 supervisor_user_id 按同一表达式收窄(不近似成 user_id OR created_by_id);共享 cleanItemConds 前移到 i. 前缀并复用(铁律 20 SQL 下推);后管页面由「每明细一卡」改为「一主管一卡」(卡头主管名/条数/任务/国家/最新 + 下载,对齐店铺数据记录一店一卡),明细分页卡片下架(3488 条铺成几千张卡是客户不要的形态),明细仍走 /export 表格看;护栏台账同轮更新(XML_SELECT_TOTAL 105→109、XML_STATEMENT_TOTAL 151→155、PageDefaults 56→58、SourceScan 52→55/vo 11→14、wiring 新增 /supervisors 发送口);后端 test-compile rc=0、controller 22 例绿+6 支护栏绿,前端 vue-tsc rc=0、mount 13/13、三支 node --test 21/21

This commit is contained in:
2026-11-11 12:31:28 +08:00
parent 2a2e276c32
commit e1767faff5
17 changed files with 903 additions and 298 deletions
@@ -12,6 +12,9 @@ import com.nanri.aiimage.modules.appearancepatent.mapper.AppearancePatentCleanIt
import com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemPageVo;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemVo;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorPageVo;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorVo;
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentCleanItemQueryService;
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
import jakarta.servlet.http.HttpServletRequest;
@@ -378,15 +381,21 @@ class AdminAppearancePatentCleanItemsControllerTest {
long scopeCalls = source.split("readCompanyIdOrOwn\\(", -1).length - 1;
assertTrue(scopeCalls >= 2, "分页与导出两支 handler 都必须走 readCompanyIdOrOwn 公司隔离,实得 " + scopeCalls);
// 导出是全量导出(服务侧另有 EXPORT_MAX_ROWS 上限),不收 page/page_size:
// 全文件 page_size 只允许出现一次(分页 handler 的参数声明)。
// 带分页参数的两个 handler 各声明一次 page_size(明细分页 + 2026-11-11 主管聚合卡片页,
// total 是主管数);导出两支(全量/按主管)都不收分页参数,所以分母恒为 2。
long pageSizeParams = source.split("page_size", -1).length - 1;
assertEquals(1, pageSizeParams, "导出不收分页参数,page_size 只许出现在分页 handler 的参数声明里");
assertEquals(2, pageSizeParams, "page_size 只许出现在两个分页 handler 的参数声明里(明细分页+主管卡片),"
+ "导出不许收分页参数");
// 分组(主管=组长)筛选:group_id 在分页与导出两支都要收;选项不下新端点(复用
// 既有 GET /shop-manages/groups,与去重页/店铺管理同源)。
long groupParams = source.split("group_id", -1).length - 1;
assertTrue(groupParams >= 2, "分页与导出都必须收 group_id(主管=组长,就是分组,2026-11-11 客户口径)");
assertFalse(source.contains("\"/supervisors\""),
"选项复用既有分组端点,本控制器不得再挂 /supervisors 第二份选项源");
// 2026-11-11 二次改版:/supervisors 是<b>主管聚合卡片</b>(一主管一卡),不是分组选项源;
// 「选项不得另开端点」的判据改成看 /groups——本控制器不许自带一份分组选项。
assertTrue(source.contains("\"/supervisors\""),
"主管聚合卡片端点必须是 GET /supervisors(客户「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」)");
assertFalse(source.contains("\"/groups\""),
"分组选项复用既有 GET /shop-manages/groups,本控制器不得再挂分组选项端点");
}
@Test
@@ -408,7 +417,7 @@ class AdminAppearancePatentCleanItemsControllerTest {
byte[] payload = "xlsx-bytes".getBytes(StandardCharsets.UTF_8);
when(queryService.export(null, null, null, null, null, null, 5L)).thenReturn(payload);
ResponseEntity<byte[]> response = controller.export(null, null, null, null, null, null, 5L, request);
ResponseEntity<byte[]> response = controller.export(null, null, null, null, null, null, null, 5L, request);
verify(dataReadScope).readCompanyIdOrOwn(operator, 5L);
verify(queryService).export(null, null, null, null, null, null, 5L);
@@ -538,9 +547,124 @@ class AdminAppearancePatentCleanItemsControllerTest {
}
}
// ===================== 2026-11-11 二次改版:按主管聚合(一主管一卡) =====================
@Test
void 主管聚合一主管一卡_条数任务国家最新与主管名齐备() {
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
AdminUserMapper adminUserMapper = mock(AdminUserMapper.class);
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
mapper, adminUserMapper, mock(ShopManageGroupMapper.class));
when(mapper.countSupervisors(any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
AppearancePatentSupervisorSummaryVo leaderCard = new AppearancePatentSupervisorSummaryVo();
leaderCard.setSupervisorId(9L);
leaderCard.setItemCount(120L);
leaderCard.setTaskCount(3L);
leaderCard.setLastTaskId(33874L);
leaderCard.setLastSyncedAt(LocalDateTime.of(2026, 11, 11, 11, 34));
leaderCard.setCountryCsv("DE,UK");
AppearancePatentSupervisorSummaryVo unknownCard = new AppearancePatentSupervisorSummaryVo();
unknownCard.setSupervisorId(null);
unknownCard.setItemCount(5L);
unknownCard.setTaskCount(1L);
when(mapper.selectSupervisorSummaries(any(), any(), any(), any(), any(), any(), any(), eq(0L), anyInt()))
.thenReturn(List.of(leaderCard, unknownCard));
AdminUserEntity leader = new AdminUserEntity();
leader.setId(9L);
leader.setUsername(" 主管甲 ");
when(adminUserMapper.selectBatchIds(anyCollection())).thenAnswer(invocation -> {
Collection<?> ids = invocation.getArgument(0);
List<AdminUserEntity> out = new ArrayList<>();
if (ids.contains(9L)) out.add(leader);
return out;
});
AppearancePatentSupervisorPageVo vo = service.supervisorPage(1L, 10L, null, null, null, null, 5L);
assertEquals(2L, vo.getTotal(), "total 是主管数(不是明细条数——铺明细分页会把几千条画成几千张卡)");
assertEquals(2, vo.getItems().size(), "一主管一卡");
AppearancePatentSupervisorVo first = vo.getItems().get(0);
assertEquals("主管甲", first.getSupervisorName(), "主管名批量富化,两侧空白剥掉");
assertEquals(120L, first.getItemCount());
assertEquals(3L, first.getTaskCount(), "任务数是 COUNT(DISTINCT task_id)");
assertEquals(33874L, first.getLastTaskId(), "卡片「任务」行显示最近任务号");
assertEquals(LocalDateTime.of(2026, 11, 11, 11, 34), first.getLastSyncedAt());
assertEquals(List.of("DE", "UK"), first.getCountryCodes(), "国家 csv 拆成码集(前端用自己的字典翻中文)");
AppearancePatentSupervisorVo second = vo.getItems().get(1);
assertNull(second.getSupervisorName(), "读不到主管=不猜名字(铁律 30),前端展示 -");
assertNull(second.getSupervisorId(), "未知主管组的 supervisorId 为 null(该卡不提供按主管下载)");
assertEquals(List.of(), second.getCountryCodes(), "空国家 csv 拆成空列表,不下发 null");
}
@Test
void 主管聚合_分组读不出用户时短路不碰mapper() {
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
ShopManageGroupMapper groupMapper = mock(ShopManageGroupMapper.class);
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
mapper, mock(AdminUserMapper.class), groupMapper);
when(groupMapper.selectUserIdsByGroupId(9L)).thenReturn(List.of());
AppearancePatentSupervisorPageVo vo = service.supervisorPage(1L, 10L, null, null, null, 9L, 5L);
assertEquals(0L, vo.getTotal());
assertTrue(vo.getItems().isEmpty());
verify(mapper, never()).countSupervisors(any(), any(), any(), any(), any(), any(), any());
verify(mapper, never()).selectSupervisorSummaries(any(), any(), any(), any(), any(), any(), any(),
anyLong(), anyInt());
}
@Test
void 按主管导出走主管专口并保留xlsx主管列() throws Exception {
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
AdminUserMapper adminUserMapper = mock(AdminUserMapper.class);
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
mapper, adminUserMapper, mock(ShopManageGroupMapper.class));
when(mapper.countSupervisorItems(any(), any(), any(), any(), any(), any(), any(), eq(9L))).thenReturn(1L);
when(mapper.selectSupervisorItems(any(), any(), any(), any(), any(), any(), any(), eq(9L), eq(0L), anyInt()))
.thenReturn(List.of(rowEntity(1L, 33L)));
AdminUserEntity plainOwner = new AdminUserEntity();
plainOwner.setId(33L);
plainOwner.setUsername("sub-user-1");
plainOwner.setCreatedById(9L);
AdminUserEntity creator = new AdminUserEntity();
creator.setId(9L);
creator.setUsername("主管甲");
when(adminUserMapper.selectBatchIds(anyCollection())).thenAnswer(invocation -> {
Collection<?> ids = invocation.getArgument(0);
List<AdminUserEntity> out = new ArrayList<>();
if (ids.contains(33L)) out.add(plainOwner);
if (ids.contains(9L)) out.add(creator);
return out;
});
byte[] bytes = service.exportBySupervisor(9L, null, null, null, null, 5L);
// 走的是主管专口:不能落到不按主管收窄的 countCleanItems/selectCleanItemPage 上
verify(mapper, never()).countCleanItems(any(), any(), any(), any(), any(), any(), any());
verify(mapper, never()).selectCleanItemPage(any(), any(), any(), any(), any(), any(), any(),
anyLong(), anyInt());
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
Sheet sheet = workbook.getSheetAt(0);
assertEquals(1, sheet.getLastRowNum(), "表头 + 1 行明细");
assertEquals("主管甲", sheet.getRow(1).getCell(8).getStringCellValue(),
"按主管导出同样带所属主管列(与全量导出同一表头)");
}
}
@Test
void 主管聚合端点与按主管导出参数就位() throws IOException {
String source = stripComments(Files.readString(CONTROLLER));
assertTrue(source.contains("supervisorPage("), "主管聚合必须落到服务的 supervisorPage");
assertTrue(source.contains("supervisor_user_id"), "按主管导出参数名 supervisor_user_id(卡片「下载」)");
assertTrue(source.contains("exportBySupervisor("), "按主管导出必须走主管专口(按归属表达式收窄,不近似成 user_id OR created_by_id)");
assertTrue(source.contains("AppearancePatentSupervisorPageVo"), "主管卡片页信封类型必须点名");
}
/** 导出/分页用例共用的明细行夹具:task 归 owner,值非空便于按列对撞。 */
private static CleanItemEntity rowEntity(long id, long userId) {
CleanItemEntity entity = new CleanItemEntity();
private static CleanItemEntity rowEntity(long id, long userId) { CleanItemEntity entity = new CleanItemEntity();
entity.setId(id);
entity.setResultId(900 + id);
entity.setTaskId(33179L);