task-116: 后台管理新增/导入表单弹窗化 + 分组管理独立菜单与UI优化 + 轻量进度端点
- 后台管理页(admin)所有面板的新增/导入表单改为弹窗操作,原有字段 ID 全部保留、提交逻辑不变;导入删除入口不再触发二次确认拦截 - 分组管理升级为独立菜单(V102 + schema initializer),移除 5 个面板内的管理分组按钮;分组列表改为蓝白主题、增加权限分组横幅 - Python 侧 group-manage 权限守卫(_ensure_backend_menu_access 补充 group-manage) - 引入 V101(biz_task_file_job 复合索引)+ 新增 TaskProgressLight/TaskFileJob 轻量端点与进度聚合作 - 前端 progress-light / page-separated-loads / dispatch-guard 共享模块及单元测试
This commit is contained in:
+552
@@ -0,0 +1,552 @@
|
||||
package com.nanri.aiimage.modules.publish.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.config.InstanceMetadata;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
import com.nanri.aiimage.modules.publish.mapper.PublishFileMapper;
|
||||
import com.nanri.aiimage.modules.publish.mapper.PublishItemMapper;
|
||||
import com.nanri.aiimage.modules.publish.model.entity.PublishFileEntity;
|
||||
import com.nanri.aiimage.modules.publish.model.entity.PublishItemEntity;
|
||||
import com.nanri.aiimage.modules.publish.model.vo.PublishDashboardVo;
|
||||
import com.nanri.aiimage.modules.publish.model.vo.PublishFileVo;
|
||||
import com.nanri.aiimage.modules.publish.model.vo.PublishHistoryVo;
|
||||
import com.nanri.aiimage.modules.publish.model.vo.PublishResultVo;
|
||||
import com.nanri.aiimage.modules.publish.model.vo.PublishTaskDetailVo;
|
||||
import com.nanri.aiimage.modules.publish.model.vo.PublishTaskVo;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileResultMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskChunkMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskScopeStateMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileResultEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskChunkEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskScopeStateEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskDistributedLockService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskFileJobService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskProgressLightAssembler;
|
||||
import com.nanri.aiimage.modules.task.service.TransientPayloadStorageService;
|
||||
import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopSwitchService;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 任务 114:批量加载等价快照测试。
|
||||
* 同一夹具下,批量路径(history 批量 IN / dashboard 聚合 / progress 批量)与逐条基准
|
||||
* (getTaskDetail 的 selectById + 按 taskId 过滤装配)输出完全一致。
|
||||
* 快照可重复;篡改基准即失败;覆盖历史/结果/dashboard 三页;全量回归门禁。
|
||||
*/
|
||||
class PublishBatchLoadingSnapshotEquivTest {
|
||||
|
||||
private static final String MODULE = "PUBLISH";
|
||||
private static final java.io.File GOLDEN =
|
||||
new java.io.File("src/test/resources/publish/golden/batch-loading-snapshot.txt");
|
||||
|
||||
private final List<FileTaskEntity> taskDb = new ArrayList<>();
|
||||
private final List<PublishFileEntity> fileDb = new ArrayList<>();
|
||||
private final List<FileResultEntity> resultDb = new ArrayList<>();
|
||||
private final List<TaskFileJobEntity> jobDb = new ArrayList<>();
|
||||
|
||||
private FileTaskMapper fileTaskMapper;
|
||||
private PublishFileMapper publishFileMapper;
|
||||
private FileResultMapper fileResultMapper;
|
||||
private TaskFileJobService taskFileJobService;
|
||||
|
||||
private PublishTaskService service;
|
||||
|
||||
@BeforeAll
|
||||
static void initializeMybatisMetadata() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, FileTaskEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, FileResultEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, PublishFileEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, PublishItemEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, TaskChunkEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, TaskScopeStateEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, TaskFileJobEntity.class);
|
||||
}
|
||||
|
||||
private static String renderDashboard(PublishDashboardVo vo) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("pending=").append(vo.getPendingCount())
|
||||
.append(" running=").append(vo.getRunningCount())
|
||||
.append(" success=").append(vo.getSuccessCount())
|
||||
.append(" failed=").append(vo.getFailedCount()).append('\n');
|
||||
for (PublishTaskDetailVo item : vo.getRecent()) {
|
||||
sb.append(renderTaskDetail(item));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String renderTaskDetail(PublishTaskDetailVo detail) {
|
||||
PublishTaskVo task = detail.getTask();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("task id=").append(task.getId())
|
||||
.append(" no=").append(task.getTaskNo())
|
||||
.append(" status=").append(task.getStatus())
|
||||
.append(" src=").append(task.getSourceFileCount())
|
||||
.append(" ok=").append(task.getSuccessFileCount())
|
||||
.append(" fail=").append(task.getFailedFileCount())
|
||||
.append(" comp=").append(task.getCompletedFileCount())
|
||||
.append(" rows=").append(task.getTotalRows())
|
||||
.append("/").append(task.getProcessedRows())
|
||||
.append(" pct=").append(task.getPercent())
|
||||
.append(" err=").append(task.getErrorMessage())
|
||||
.append('\n');
|
||||
for (PublishFileVo file : detail.getFiles()) {
|
||||
sb.append(" file id=").append(file.getFileId())
|
||||
.append(" key=").append(file.getFileKey())
|
||||
.append(" shop=").append(file.getShopName())
|
||||
.append("/").append(file.getShopId())
|
||||
.append(" matched=").append(file.isMatched())
|
||||
.append(" status=").append(file.getStatus())
|
||||
.append(" rows=").append(file.getTotalRows())
|
||||
.append("/").append(file.getProcessedRows())
|
||||
.append(" pct=").append(file.getPercent())
|
||||
.append('\n');
|
||||
}
|
||||
PublishResultVo result = detail.getResult();
|
||||
if (result != null) {
|
||||
sb.append(" result id=").append(result.getResultId())
|
||||
.append(" ready=").append(result.getFileReady())
|
||||
.append(" url=").append(result.getDownloadUrl())
|
||||
.append(" job=").append(result.getFileJobId())
|
||||
.append("/").append(result.getFileJobStatus())
|
||||
.append(" retry=").append(result.getFileJobRetryCount())
|
||||
.append(" joberr=").append(result.getFileJobError())
|
||||
.append(" err=").append(result.getErrorMessage())
|
||||
.append('\n');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String renderHistory(PublishHistoryVo vo) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("total=").append(vo.getTotal()).append('\n');
|
||||
for (PublishTaskDetailVo item : vo.getItems()) {
|
||||
sb.append(renderTaskDetail(item));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String renderBatch(List<PublishTaskDetailVo> items) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (PublishTaskDetailVo item : items) {
|
||||
sb.append(renderTaskDetail(item));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** 从渲染后的 wrapper 提取 IN 查询引用的全部 id(.in() 每个元素一个 #{ew.paramNameValuePairs.x} 参数)。 */
|
||||
private static List<Long> inParamIds(LambdaQueryWrapper<?> q) {
|
||||
String segment = q.getSqlSegment() == null ? "" : q.getSqlSegment();
|
||||
List<Long> ids = new ArrayList<>();
|
||||
java.util.regex.Matcher m = java.util.regex.Pattern
|
||||
.compile("#\\{ew\\.paramNameValuePairs\\.(\\w+)}").matcher(segment);
|
||||
Map<String, Object> params = q.getParamNameValuePairs();
|
||||
while (m.find()) {
|
||||
Object value = params.get(m.group(1));
|
||||
if (value instanceof Number n) {
|
||||
ids.add(n.longValue());
|
||||
} else if (value instanceof List<?> list) {
|
||||
for (Object item : list) {
|
||||
if (item instanceof Number n) {
|
||||
ids.add(n.longValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
fileTaskMapper = mock(FileTaskMapper.class);
|
||||
publishFileMapper = mock(PublishFileMapper.class);
|
||||
fileResultMapper = mock(FileResultMapper.class);
|
||||
taskFileJobService = mock(TaskFileJobService.class);
|
||||
OssStorageService ossStorageService = mock(OssStorageService.class);
|
||||
|
||||
doAnswer(invocation -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
LambdaQueryWrapper<FileTaskEntity> q = invocation.getArgument(0);
|
||||
String segment = q.getSqlSegment() == null ? "" : q.getSqlSegment();
|
||||
List<Object> params = new ArrayList<>(q.getParamNameValuePairs().values());
|
||||
List<Long> wanted = new ArrayList<>();
|
||||
for (Object value : params) {
|
||||
if (value instanceof List<?> list) {
|
||||
for (Object item : list) {
|
||||
if (item instanceof Number n) {
|
||||
wanted.add(n.longValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<FileTaskEntity> filtered = new ArrayList<>();
|
||||
for (FileTaskEntity task : taskDb) {
|
||||
if (!MODULE.equals(task.getModuleType())) {
|
||||
continue;
|
||||
}
|
||||
if (wanted.isEmpty()) {
|
||||
filtered.add(task);
|
||||
} else if (wanted.contains(task.getId())) {
|
||||
filtered.add(task);
|
||||
}
|
||||
}
|
||||
filtered.sort((a, b) -> b.getCreatedAt().compareTo(a.getCreatedAt()));
|
||||
if (segment.toLowerCase().contains("limit")) {
|
||||
int cap = 50;
|
||||
java.util.regex.Matcher m = java.util.regex.Pattern
|
||||
.compile("limit\\s+(\\d+)", java.util.regex.Pattern.CASE_INSENSITIVE).matcher(segment);
|
||||
if (m.find()) {
|
||||
cap = Integer.parseInt(m.group(1));
|
||||
}
|
||||
return filtered.subList(0, Math.min(cap, filtered.size()));
|
||||
}
|
||||
return filtered;
|
||||
}).when(fileTaskMapper).selectList(any());
|
||||
|
||||
doAnswer(invocation -> {
|
||||
Long id = invocation.getArgument(0);
|
||||
return taskDb.stream().filter(t -> t.getId().equals(id)).findFirst().orElse(null);
|
||||
}).when(fileTaskMapper).selectById(any(Long.class));
|
||||
|
||||
doAnswer(invocation -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
LambdaQueryWrapper<PublishFileEntity> q = invocation.getArgument(0);
|
||||
List<Long> wanted = inParamIds(q);
|
||||
return fileDb.stream()
|
||||
.filter(f -> wanted.contains(f.getTaskId()))
|
||||
.sorted((a, b) -> a.getId().compareTo(b.getId()))
|
||||
.toList();
|
||||
}).when(publishFileMapper).selectList(any());
|
||||
|
||||
doAnswer(invocation -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
LambdaQueryWrapper<FileResultEntity> q = invocation.getArgument(0);
|
||||
List<Long> wanted = inParamIds(q);
|
||||
return resultDb.stream()
|
||||
.filter(r -> wanted.contains(r.getTaskId()))
|
||||
.sorted((a, b) -> a.getId().compareTo(b.getId()))
|
||||
.toList();
|
||||
}).when(fileResultMapper).selectList(any());
|
||||
|
||||
lenient().when(taskFileJobService.findAssembleJobsByResultIds(any(), any())).thenAnswer(invocation -> {
|
||||
List<?> ids = invocation.getArgument(1);
|
||||
Map<Long, TaskFileJobEntity> map = new HashMap<>();
|
||||
if (ids != null) {
|
||||
for (TaskFileJobEntity job : jobDb) {
|
||||
if (job.getResultId() != null && ids.contains(job.getResultId())) {
|
||||
map.put(job.getResultId(), job);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
when(fileTaskMapper.selectCount(any())).thenAnswer(invocation -> (long) taskDb.stream()
|
||||
.filter(t -> MODULE.equals(t.getModuleType()) && Long.valueOf(1L).equals(t.getUserId())).count());
|
||||
|
||||
when(fileTaskMapper.selectMaps(any())).thenAnswer(invocation -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
com.baomidou.mybatisplus.core.conditions.Wrapper<FileTaskEntity> wrapper = invocation.getArgument(0);
|
||||
String segment = wrapper.getSqlSegment() == null ? "" : wrapper.getSqlSegment();
|
||||
assertTrue(segment.toLowerCase().contains("group by"), "聚合查询必须带 GROUP BY: " + segment);
|
||||
Map<String, Long> counts = new HashMap<>();
|
||||
for (FileTaskEntity task : taskDb) {
|
||||
if (!MODULE.equals(task.getModuleType()) || task.getUserId() == null || task.getStatus() == null) {
|
||||
continue;
|
||||
}
|
||||
counts.merge(task.getStatus(), 1L, Long::sum);
|
||||
}
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
for (Map.Entry<String, Long> entry : counts.entrySet()) {
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
row.put("status", entry.getKey());
|
||||
row.put("cnt", entry.getValue());
|
||||
rows.add(row);
|
||||
}
|
||||
return rows;
|
||||
});
|
||||
|
||||
when(ossStorageService.generateFreshDownloadUrl(any())).thenAnswer(
|
||||
invocation -> "https://oss" + invocation.getArgument(0));
|
||||
|
||||
service = new PublishTaskService(
|
||||
mock(LocalFileStorageService.class), mock(ZiniaoShopSwitchService.class),
|
||||
mock(PublishWorkbookService.class), publishFileMapper, mock(PublishItemMapper.class),
|
||||
fileTaskMapper, fileResultMapper, mock(TaskChunkMapper.class),
|
||||
mock(TaskScopeStateMapper.class), taskFileJobService,
|
||||
mock(TaskDistributedLockService.class), mock(TransientPayloadStorageService.class),
|
||||
ossStorageService, new ObjectMapper(), mock(TransactionTemplate.class),
|
||||
mock(InstanceMetadata.class),
|
||||
mock(TaskProgressLightAssembler.class));
|
||||
}
|
||||
|
||||
private static FileTaskEntity task(long id, String status, LocalDateTime createdAt, Integer src, Integer ok, Integer fail) {
|
||||
FileTaskEntity task = new FileTaskEntity();
|
||||
task.setId(id);
|
||||
task.setModuleType(MODULE);
|
||||
task.setUserId(1L);
|
||||
task.setStatus(status);
|
||||
task.setCreatedAt(createdAt);
|
||||
task.setUpdatedAt(createdAt);
|
||||
task.setFinishedAt(status.equals("SUCCESS") || status.equals("FAILED") ? createdAt.plusMinutes(5) : null);
|
||||
task.setTaskNo("T" + id);
|
||||
task.setSourceFileCount(src);
|
||||
task.setSuccessFileCount(ok);
|
||||
task.setFailedFileCount(fail);
|
||||
return task;
|
||||
}
|
||||
|
||||
private static PublishFileEntity file(Long id, Long taskId, String status, Integer total, Integer processed) {
|
||||
PublishFileEntity file = new PublishFileEntity();
|
||||
file.setId(id);
|
||||
file.setTaskId(taskId);
|
||||
file.setFileKey("key" + id);
|
||||
file.setSourceFilename("s" + id + ".xlsx");
|
||||
file.setShopName("Shop " + (id % 3));
|
||||
file.setShopId("SHOP" + (id % 3));
|
||||
file.setMatched(1);
|
||||
file.setStatus(status);
|
||||
file.setTotalRows(total);
|
||||
file.setProcessedRows(processed);
|
||||
file.setCreatedAt(LocalDateTime.of(2026, 8, 1, 10, 0));
|
||||
return file;
|
||||
}
|
||||
|
||||
private static FileResultEntity result(Long id, Long taskId, String error) {
|
||||
FileResultEntity result = new FileResultEntity();
|
||||
result.setId(id);
|
||||
result.setTaskId(taskId);
|
||||
result.setModuleType(MODULE);
|
||||
result.setResultFilename("r" + id + ".xlsx");
|
||||
result.setResultFileUrl("result/publish/" + id + "/out.xlsx");
|
||||
result.setSuccess(1);
|
||||
result.setErrorMessage(error);
|
||||
result.setCreatedAt(LocalDateTime.of(2026, 8, 1, 11, 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
private static TaskFileJobEntity job(Long id, Long resultId, String status, Integer retry, String error) {
|
||||
TaskFileJobEntity job = new TaskFileJobEntity();
|
||||
job.setId(id);
|
||||
job.setResultId(resultId);
|
||||
job.setModuleType(MODULE);
|
||||
job.setStatus(status);
|
||||
job.setRetryCount(retry);
|
||||
job.setErrorMessage(error);
|
||||
return job;
|
||||
}
|
||||
|
||||
/** 固定夹具:5 任务 ×(成功多文件/运行中+失败文件/待命无结果/失败+Job 错误/成功单文件)+ 结果与 Job 关联。 */
|
||||
private void seed() {
|
||||
taskDb.add(task(1L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 9, 1), 2, 2, 0));
|
||||
taskDb.add(task(2L, "RUNNING", LocalDateTime.of(2026, 8, 1, 9, 2), 2, 0, 1));
|
||||
taskDb.add(task(3L, "PENDING", LocalDateTime.of(2026, 8, 1, 9, 3), 1, 0, 0));
|
||||
taskDb.add(task(4L, "FAILED", LocalDateTime.of(2026, 8, 1, 9, 4), 1, 0, 1));
|
||||
taskDb.add(task(5L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 9, 5), 1, 1, 0));
|
||||
fileDb.add(file(101L, 1L, "SUCCESS", 10, 10));
|
||||
fileDb.add(file(102L, 1L, "SUCCESS", 20, 20));
|
||||
fileDb.add(file(201L, 2L, "RUNNING", 30, 12));
|
||||
fileDb.add(file(202L, 2L, "FAILED", 5, 3));
|
||||
fileDb.add(file(301L, 3L, "PENDING", 8, 0));
|
||||
fileDb.add(file(401L, 4L, "FAILED", 9, 4));
|
||||
fileDb.add(file(501L, 5L, "SUCCESS", 15, 15));
|
||||
resultDb.add(result(901L, 1L, null));
|
||||
resultDb.add(result(902L, 2L, "still running"));
|
||||
resultDb.add(result(904L, 4L, "boom"));
|
||||
jobDb.add(job(801L, 901L, "SUCCESS", 0, null));
|
||||
jobDb.add(job(802L, 902L, "RUNNING", 1, null));
|
||||
jobDb.add(job(804L, 904L, "FAILED", 2, "assemble failed"));
|
||||
}
|
||||
|
||||
private List<FileTaskEntity> orderedTasks() {
|
||||
return taskDb.stream()
|
||||
.filter(t -> MODULE.equals(t.getModuleType()) && Long.valueOf(1L).equals(t.getUserId()))
|
||||
.sorted((a, b) -> b.getCreatedAt().compareTo(a.getCreatedAt()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/** 逐条基准:与批量路径相同的装配语义,但每任务一次 getTaskDetail(selectById 单条路径)。 */
|
||||
private String baselineDetails() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (FileTaskEntity task : orderedTasks()) {
|
||||
sb.append(renderTaskDetail(service.getTaskDetail(task.getId(), 1L)));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String baselineHistoryText() {
|
||||
return "total=" + taskDb.stream()
|
||||
.filter(t -> MODULE.equals(t.getModuleType()) && Long.valueOf(1L).equals(t.getUserId())).count()
|
||||
+ "\n" + baselineDetails();
|
||||
}
|
||||
|
||||
private String historySnapshot() {
|
||||
return renderHistory(service.history(1L, 50));
|
||||
}
|
||||
|
||||
private String dashboardSnapshot() {
|
||||
return renderDashboard(service.dashboard(1L));
|
||||
}
|
||||
|
||||
private String resultSnapshot() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (FileTaskEntity task : orderedTasks()) {
|
||||
sb.append(renderTaskDetail(service.getTaskDetail(task.getId(), 1L)));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** progress 批量:请求顺序按 createdAt 倒序(与 history 语义一致),输出明细。 */
|
||||
private String batchSnapshot() {
|
||||
List<Long> ids = orderedTasks().stream().map(FileTaskEntity::getId).toList();
|
||||
return renderBatch(service.getTaskProgress(1L, ids).getItems());
|
||||
}
|
||||
|
||||
private static String readGolden() throws Exception {
|
||||
return java.nio.file.Files.readString(GOLDEN.toPath(), java.nio.charset.StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_history_snapshot_equiv() throws Exception {
|
||||
seed();
|
||||
assertEquals(baselineHistoryText(), historySnapshot(),
|
||||
"history 批量装配输出与逐条基准完全一致");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_dashboard_snapshot_equiv() throws Exception {
|
||||
seed();
|
||||
PublishDashboardVo vo = service.dashboard(1L);
|
||||
assertEquals(1L, vo.getPendingCount());
|
||||
assertEquals(1L, vo.getRunningCount());
|
||||
assertEquals(2L, vo.getSuccessCount());
|
||||
assertEquals(1L, vo.getFailedCount());
|
||||
String recent = "";
|
||||
for (PublishTaskDetailVo item : vo.getRecent()) {
|
||||
recent += renderTaskDetail(item);
|
||||
}
|
||||
assertEquals(baselineDetails(), recent.toString(),
|
||||
"dashboard recent 明细与逐条基准完全一致");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_result_snapshot_equiv() throws Exception {
|
||||
seed();
|
||||
assertEquals(baselineDetails(), resultSnapshot(),
|
||||
"结果页逐条装配与逐条基准完全一致");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_pagination_equiv() throws Exception {
|
||||
seed();
|
||||
PublishHistoryVo limited = service.history(1L, 3);
|
||||
assertEquals(3, limited.getItems().size(), "limit 3 只取最近 3 条");
|
||||
StringBuilder expected = new StringBuilder("total=5\n");
|
||||
for (FileTaskEntity task : orderedTasks().subList(0, 3)) {
|
||||
expected.append(renderTaskDetail(service.getTaskDetail(task.getId(), 1L)));
|
||||
}
|
||||
assertEquals(expected.toString(), renderHistory(limited), "分页输出与基准最近 3 条一致");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_batch_progress_equiv() throws Exception {
|
||||
seed();
|
||||
assertEquals(baselineDetails(), batchSnapshot(),
|
||||
"progress 批量明细与逐条基准完全一致");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_snapshot_reproducible() throws Exception {
|
||||
seed();
|
||||
assertEquals(baselineDetails(), baselineDetails(), "基准可重复");
|
||||
assertEquals(historySnapshot(), historySnapshot(), "批量快照可重复");
|
||||
assertEquals(dashboardSnapshot(), dashboardSnapshot(), "dashboard 快照可重复");
|
||||
assertEquals(resultSnapshot(), resultSnapshot(), "结果快照可重复");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_snapshot_golden_committed() {
|
||||
assertTrue(GOLDEN.isFile(), "golden 文件必须存在并入库: " + GOLDEN.getAbsolutePath());
|
||||
assertTrue(GOLDEN.length() > 0, "golden 非空");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_snapshot_covers_all() throws Exception {
|
||||
seed();
|
||||
String golden = readGolden();
|
||||
assertTrue(golden.contains("task id=1"), "golden 覆盖任务 1(成功多文件)");
|
||||
assertTrue(golden.contains("task id=2"), "golden 覆盖任务 2(运行中+失败文件)");
|
||||
assertTrue(golden.contains("task id=3"), "golden 覆盖任务 3(无结果)");
|
||||
assertTrue(golden.contains("task id=4"), "golden 覆盖任务 4(失败+Job 错误)");
|
||||
assertTrue(golden.contains("task id=5"), "golden 覆盖任务 5(成功单文件)");
|
||||
assertTrue(golden.contains("result id=901"), "golden 覆盖成功结果");
|
||||
assertTrue(golden.contains("result id=902"), "golden 覆盖运行中结果");
|
||||
assertTrue(golden.contains("result id=904"), "golden 覆盖失败结果");
|
||||
assertTrue(golden.contains("joberr=assemble failed"), "golden 覆盖 Job 错误信息");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_snapshot_diff_fails() throws Exception {
|
||||
seed();
|
||||
String original = readGolden();
|
||||
assertTrue(original.contains("task id=1"), "golden 内容合法");
|
||||
try {
|
||||
java.nio.file.Files.writeString(GOLDEN.toPath(), original + "\n# tampered",
|
||||
java.nio.charset.StandardCharsets.UTF_8);
|
||||
AssertionError failure = null;
|
||||
try {
|
||||
assertEquals(original, readGolden(), "篡改后 golden 与原始不一致");
|
||||
} catch (AssertionError ex) {
|
||||
failure = ex;
|
||||
}
|
||||
assertTrue(failure != null, "篡改 golden 后断言应失败");
|
||||
} finally {
|
||||
java.nio.file.Files.writeString(GOLDEN.toPath(), original,
|
||||
java.nio.charset.StandardCharsets.UTF_8);
|
||||
}
|
||||
assertEquals(original, readGolden(), "恢复原始 golden");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_snapshot_regression_guard() throws Exception {
|
||||
seed();
|
||||
assertEquals(baselineHistoryText(), historySnapshot(), "历史快照与基准一致");
|
||||
assertEquals(baselineDetails(), resultSnapshot(), "结果快照与基准一致");
|
||||
assertEquals(baselineDetails(), batchSnapshot(), "progress 快照与基准一致");
|
||||
assertEquals(readGolden(), historySnapshot(), "整体输出与 golden 快照一致");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_snapshot_equiv_fails_on_mutation() throws Exception {
|
||||
seed();
|
||||
String before = historySnapshot();
|
||||
assertEquals(before, historySnapshot());
|
||||
taskDb.getFirst().setStatus("RUNNING");
|
||||
assertNotEquals(before, historySnapshot(), "数据变化后快照必须不同(等价门禁可感知改动)");
|
||||
}
|
||||
}
|
||||
+321
@@ -0,0 +1,321 @@
|
||||
package com.nanri.aiimage.modules.publish.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.config.InstanceMetadata;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
import com.nanri.aiimage.modules.publish.mapper.PublishFileMapper;
|
||||
import com.nanri.aiimage.modules.publish.mapper.PublishItemMapper;
|
||||
import com.nanri.aiimage.modules.publish.model.entity.PublishFileEntity;
|
||||
import com.nanri.aiimage.modules.publish.model.entity.PublishItemEntity;
|
||||
import com.nanri.aiimage.modules.publish.model.vo.PublishDashboardVo;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileResultMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskChunkMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskScopeStateMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileResultEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskChunkEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskScopeStateEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskDistributedLockService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskFileJobService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskProgressLightAssembler;
|
||||
import com.nanri.aiimage.modules.task.service.TransientPayloadStorageService;
|
||||
import com.nanri.aiimage.modules.ziniao.service.ZiniaoShopSwitchService;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
/**
|
||||
* 任务 108:dashboard 聚合查询。
|
||||
* dashboard 状态统计由 4 次逐条 selectCount 改为 1 次 GROUP BY 聚合(selectMaps status→count);
|
||||
* 输出结构(pendingCount/runningCount/successCount/failedCount/recent)与逐条统计完全一致;
|
||||
* 聚合结果为空时各计数为 0;recent 列表语义不变。
|
||||
*/
|
||||
class PublishDashboardAggregateTest {
|
||||
|
||||
private static final String MODULE = "PUBLISH";
|
||||
|
||||
private final List<FileTaskEntity> taskDb = new ArrayList<>();
|
||||
private final AtomicInteger aggregateCallCount = new AtomicInteger();
|
||||
private final AtomicInteger recentListCallCount = new AtomicInteger();
|
||||
|
||||
private FileTaskMapper fileTaskMapper;
|
||||
private PublishItemMapper publishItemMapper;
|
||||
private PublishFileMapper publishFileMapper;
|
||||
private FileResultMapper fileResultMapper;
|
||||
private TaskFileJobService taskFileJobService;
|
||||
private OssStorageService ossStorageService;
|
||||
|
||||
private PublishTaskService service;
|
||||
|
||||
@BeforeAll
|
||||
static void initializeMybatisMetadata() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, FileTaskEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, FileResultEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, PublishFileEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, PublishItemEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, TaskChunkEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, TaskScopeStateEntity.class);
|
||||
}
|
||||
|
||||
/** 从渲染后的 wrapper 参数中提取 userId(先 getSqlSegment 强制渲染,再读 paramNameValuePairs)。 */
|
||||
private static Long userIdOf(Wrapper<FileTaskEntity> wrapper, String segment) {
|
||||
AbstractWrapper<FileTaskEntity, ?, ?> q = (AbstractWrapper<FileTaskEntity, ?, ?>) wrapper;
|
||||
List<Long> numbers = new ArrayList<>();
|
||||
for (Object value : q.getParamNameValuePairs().values()) {
|
||||
if (value instanceof Number n) {
|
||||
numbers.add(n.longValue());
|
||||
} else if (value instanceof Iterable<?> iterable) {
|
||||
for (Object item : iterable) {
|
||||
if (item instanceof Number n) {
|
||||
numbers.add(n.longValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return numbers.stream().filter(Long.class::isInstance).map(Long.class::cast).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
fileTaskMapper = mock(FileTaskMapper.class);
|
||||
publishItemMapper = mock(PublishItemMapper.class);
|
||||
publishFileMapper = mock(PublishFileMapper.class);
|
||||
fileResultMapper = mock(FileResultMapper.class);
|
||||
taskFileJobService = mock(TaskFileJobService.class);
|
||||
ossStorageService = mock(OssStorageService.class);
|
||||
|
||||
// 聚合查询:一次 selectMaps,按模块+用户过滤后 status→count
|
||||
doAnswer(invocation -> {
|
||||
aggregateCallCount.incrementAndGet();
|
||||
Wrapper<FileTaskEntity> wrapper = invocation.getArgument(0);
|
||||
String segment = wrapper.getSqlSegment() == null ? "" : wrapper.getSqlSegment();
|
||||
assertTrue(segment.toLowerCase().contains("group by"), "聚合查询必须带 GROUP BY: " + segment);
|
||||
Long userId = userIdOf(wrapper, segment);
|
||||
Map<String, Long> counts = new HashMap<>();
|
||||
for (FileTaskEntity task : taskDb) {
|
||||
if (!MODULE.equals(task.getModuleType()) || task.getUserId() == null || task.getStatus() == null) {
|
||||
continue;
|
||||
}
|
||||
if (userId != null && !userId.equals(task.getUserId())) {
|
||||
continue;
|
||||
}
|
||||
counts.merge(task.getStatus(), 1L, Long::sum);
|
||||
}
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
for (Map.Entry<String, Long> entry : counts.entrySet()) {
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
row.put("status", entry.getKey());
|
||||
row.put("cnt", entry.getValue());
|
||||
rows.add(row);
|
||||
}
|
||||
return rows;
|
||||
}).when(fileTaskMapper).selectMaps(any());
|
||||
|
||||
// recent 列表:history() 依赖的明细查询
|
||||
doAnswer(invocation -> {
|
||||
recentListCallCount.incrementAndGet();
|
||||
LambdaQueryWrapper<FileTaskEntity> q = invocation.getArgument(0);
|
||||
String segment = q.getSqlSegment() == null ? "" : q.getSqlSegment();
|
||||
Long userId = userIdOf(q, segment);
|
||||
List<FileTaskEntity> filtered = new ArrayList<>();
|
||||
for (FileTaskEntity task : taskDb) {
|
||||
if (!MODULE.equals(task.getModuleType()) || task.getUserId() == null) {
|
||||
continue;
|
||||
}
|
||||
if (userId != null && !userId.equals(task.getUserId())) {
|
||||
continue;
|
||||
}
|
||||
filtered.add(task);
|
||||
}
|
||||
filtered.sort((a, b) -> b.getCreatedAt().compareTo(a.getCreatedAt()));
|
||||
if (segment.toLowerCase().contains("limit")) {
|
||||
int cap = 10;
|
||||
java.util.regex.Matcher m = java.util.regex.Pattern
|
||||
.compile("limit\\s+(\\d+)", java.util.regex.Pattern.CASE_INSENSITIVE).matcher(segment);
|
||||
if (m.find()) {
|
||||
cap = Integer.parseInt(m.group(1));
|
||||
}
|
||||
return filtered.subList(0, Math.min(cap, filtered.size()));
|
||||
}
|
||||
return filtered;
|
||||
}).when(fileTaskMapper).selectList(any());
|
||||
|
||||
lenient().when(publishFileMapper.selectList(any())).thenReturn(List.of());
|
||||
lenient().when(fileResultMapper.selectList(any())).thenReturn(List.of());
|
||||
lenient().when(taskFileJobService.findAssembleJobsByResultIds(any(), any())).thenReturn(Map.of());
|
||||
lenient().when(ossStorageService.generateFreshDownloadUrl(any())).thenReturn("https://oss/x");
|
||||
|
||||
service = new PublishTaskService(
|
||||
mock(LocalFileStorageService.class), mock(ZiniaoShopSwitchService.class),
|
||||
mock(PublishWorkbookService.class), publishFileMapper, publishItemMapper,
|
||||
fileTaskMapper, fileResultMapper, mock(TaskChunkMapper.class),
|
||||
mock(TaskScopeStateMapper.class), taskFileJobService,
|
||||
mock(TaskDistributedLockService.class), mock(TransientPayloadStorageService.class),
|
||||
ossStorageService, new ObjectMapper(), mock(TransactionTemplate.class),
|
||||
mock(InstanceMetadata.class),
|
||||
mock(TaskProgressLightAssembler.class));
|
||||
}
|
||||
|
||||
private static FileTaskEntity task(long id, long userId, String status, LocalDateTime createdAt) {
|
||||
FileTaskEntity task = new FileTaskEntity();
|
||||
task.setId(id);
|
||||
task.setUserId(userId);
|
||||
task.setModuleType(MODULE);
|
||||
task.setStatus(status);
|
||||
task.setCreatedAt(createdAt);
|
||||
return task;
|
||||
}
|
||||
|
||||
private void seed() {
|
||||
taskDb.add(task(1L, 7L, "PENDING", LocalDateTime.of(2026, 8, 1, 10, 1)));
|
||||
taskDb.add(task(2L, 7L, "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 2)));
|
||||
taskDb.add(task(3L, 7L, "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 3)));
|
||||
taskDb.add(task(4L, 7L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 10, 4)));
|
||||
taskDb.add(task(5L, 7L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 10, 5)));
|
||||
taskDb.add(task(6L, 7L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 10, 6)));
|
||||
taskDb.add(task(7L, 7L, "FAILED", LocalDateTime.of(2026, 8, 1, 10, 7)));
|
||||
taskDb.add(task(8L, 7L, "FAILED", LocalDateTime.of(2026, 8, 1, 10, 8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardCounts() {
|
||||
seed();
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertEquals(1L, vo.getPendingCount());
|
||||
assertEquals(2L, vo.getRunningCount());
|
||||
assertEquals(3L, vo.getSuccessCount());
|
||||
assertEquals(2L, vo.getFailedCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardEmptyUser() {
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertEquals(0L, vo.getPendingCount());
|
||||
assertEquals(0L, vo.getRunningCount());
|
||||
assertEquals(0L, vo.getSuccessCount());
|
||||
assertEquals(0L, vo.getFailedCount());
|
||||
assertTrue(vo.getRecent().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardAggregateSql() {
|
||||
seed();
|
||||
service.dashboard(7L);
|
||||
assertEquals(1, aggregateCallCount.get(), "状态统计一次 GROUP BY 聚合,不逐条 COUNT");
|
||||
verify(fileTaskMapper, times(1)).selectMaps(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardRecentTasks() {
|
||||
seed();
|
||||
taskDb.add(task(9L, 7L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 10, 9)));
|
||||
taskDb.add(task(10L, 7L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 10, 10)));
|
||||
taskDb.add(task(11L, 7L, "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 11)));
|
||||
taskDb.add(task(12L, 7L, "RUNNING", LocalDateTime.of(2026, 8, 1, 10, 12)));
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertEquals(10, vo.getRecent().size(), "recent 固定最多 10 条");
|
||||
assertEquals(12L, vo.getRecent().getFirst().getTask().getId(), "最近任务按 createdAt 倒序");
|
||||
assertEquals(3L, vo.getRecent().getLast().getTask().getId(), "超出 10 条的最旧任务被截断");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardConsistency() {
|
||||
seed();
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
Map<String, Long> perStatus = new HashMap<>();
|
||||
for (FileTaskEntity task : taskDb) {
|
||||
perStatus.merge(task.getStatus(), 1L, Long::sum);
|
||||
}
|
||||
assertEquals(perStatus.getOrDefault("PENDING", 0L).longValue(), vo.getPendingCount(), "与逐条统计一致");
|
||||
assertEquals(perStatus.getOrDefault("RUNNING", 0L).longValue(), vo.getRunningCount());
|
||||
assertEquals(perStatus.getOrDefault("SUCCESS", 0L).longValue(), vo.getSuccessCount());
|
||||
assertEquals(perStatus.getOrDefault("FAILED", 0L).longValue(), vo.getFailedCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardMixedStatus() {
|
||||
taskDb.add(task(1L, 7L, "PENDING", LocalDateTime.of(2026, 8, 1, 9, 0)));
|
||||
taskDb.add(task(2L, 7L, "RUNNING", LocalDateTime.of(2026, 8, 1, 9, 1)));
|
||||
taskDb.add(task(3L, 7L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 9, 2)));
|
||||
taskDb.add(task(4L, 7L, "FAILED", LocalDateTime.of(2026, 8, 1, 9, 3)));
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertEquals(1L, vo.getPendingCount());
|
||||
assertEquals(1L, vo.getRunningCount());
|
||||
assertEquals(1L, vo.getSuccessCount());
|
||||
assertEquals(1L, vo.getFailedCount());
|
||||
assertEquals(4, vo.getRecent().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardUserFiltered() {
|
||||
seed();
|
||||
taskDb.add(task(9L, 8L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 11, 0)));
|
||||
taskDb.add(task(10L, 8L, "FAILED", LocalDateTime.of(2026, 8, 1, 11, 1)));
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertEquals(3L, vo.getSuccessCount(), "只统计当前用户任务");
|
||||
assertEquals(2L, vo.getFailedCount());
|
||||
assertEquals(8, vo.getRecent().size(), "recent 只含当前用户任务");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardBigData() {
|
||||
for (int i = 1; i <= 500; i++) {
|
||||
String status = i % 4 == 0 ? "SUCCESS" : (i % 4 == 1 ? "FAILED" : (i % 4 == 2 ? "RUNNING" : "PENDING"));
|
||||
taskDb.add(task(1000L + i, 7L, status, LocalDateTime.of(2026, 8, 1, 0, 0).plusMinutes(i)));
|
||||
}
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertEquals(125L, vo.getPendingCount());
|
||||
assertEquals(125L, vo.getRunningCount());
|
||||
assertEquals(125L, vo.getSuccessCount());
|
||||
assertEquals(125L, vo.getFailedCount());
|
||||
assertEquals(1, aggregateCallCount.get(), "大数据量仍一次聚合");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardOtherModuleExcluded() {
|
||||
seed();
|
||||
taskDb.add(task(99L, 7L, "SUCCESS", LocalDateTime.of(2026, 8, 1, 12, 0)));
|
||||
taskDb.getLast().setModuleType("SIMILAR_ASIN");
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertEquals(3L, vo.getSuccessCount(), "其他模块任务不计入");
|
||||
assertEquals(8, vo.getRecent().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dashboardRecentDetailAssembled() {
|
||||
seed();
|
||||
PublishDashboardVo vo = service.dashboard(7L);
|
||||
assertNotNull(vo.getRecent().getFirst().getTask(), "recent 明细含 task 信息");
|
||||
assertEquals("FAILED", vo.getRecent().getFirst().getTask().getStatus());
|
||||
assertEquals(8L, vo.getRecent().getFirst().getTask().getId());
|
||||
assertEquals(1, aggregateCallCount.get());
|
||||
assertEquals(1, recentListCallCount.get(), "recent 列表一次明细查询");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user