feat(看板): 变体采集只看在跑,进度列改客户端同源口径
两件事,都是用户当场指出的读数误导: 1. 变体采集页签徽章 106 是麦象历史全量。console 代理一次只接受一个 status, 故 status 缺省时服务端合并 0(等待)∪1(处理中),按 createTime 倒序后内存切片; 单状态各拉 200 条,触顶打 warn。前端状态下拉去掉「已完成/处理失败」两个入口。 2. 进度列的「已完成 0 / 总 1」来自 source_file_count(采集/跟价都是单文件任务), 与客户端进度条不同源。改为按模块分档:COLLECT_DATA 取 result_json 的 $.totalRows/$.processedRows(与客户端「关键词进度:第 X/N 个」同一对数), PRICE_TRACK/SHOP_MATCH 这类客户端本来没有进度条的返回 0,前端 progressTotal<=0 显示「—」且不再画 0% 进度轨;PUBLISH/DELETE_BRAND/品牌行保持文件数/品牌行数。 护栏:Mapper SQL 渲染 26 例、QueryService 34 例、VariantService 8 例、 ScopeService 7 例;前端 node:test 1653 例。docs/specs/16-client-task-console.md 的「进度口径」一节按新规则重写。
This commit is contained in:
+21
@@ -290,6 +290,27 @@ class TaskCenterQueryMapperSqlTest {
|
||||
assertEquals(2, boundSql.getParameterMappings().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键词进度只从 result_json 抽两个数:整列拉回服务层会把 30s 轮询的载荷撑爆
|
||||
* (result_json 装的是采集统计 + 明细),所以选列必须钉死成这三列。
|
||||
*/
|
||||
@Test
|
||||
void collectDataKeywordStatsReadsOnlyTwoJsonPaths() {
|
||||
BoundSql boundSql = render("selectCollectDataKeywordStats", params("taskIds", List.of(1L, 2L)));
|
||||
String sql = sqlOf(boundSql);
|
||||
|
||||
assertTrue(sql.startsWith("SELECT t.id AS taskId,"
|
||||
+ "JSON_UNQUOTE(JSON_EXTRACT(t.result_json,'$.totalRows')) AS totalRows,"
|
||||
+ "JSON_UNQUOTE(JSON_EXTRACT(t.result_json,'$.processedRows')) AS processedRows"
|
||||
+ " FROM biz_file_task t"), "只回三列,大 JSON 不出库:" + sql);
|
||||
assertTrue(sql.contains("UPPER(t.module_type) = 'COLLECT_DATA'"), "只有采集数据有关键词进度");
|
||||
assertTrue(sql.contains("AND t.result_json IS NOT NULL"), "没有回写过统计的任务不参与");
|
||||
assertFalse(sql.contains("JSON_VALID"), "列是原生 JSON,不需要文本合法性守卫");
|
||||
assertEquals(2, boundSql.getParameterMappings().size(), "一次批量按任务号取");
|
||||
assertEquals(1L, boundSql.getAdditionalParameter("__frch_tid_0"));
|
||||
assertEquals(2L, boundSql.getAdditionalParameter("__frch_tid_1"));
|
||||
}
|
||||
|
||||
/** 店铺只有两个真来源:上架结果文件的 shop_name、逐店落行的模块的 source_filename。 */
|
||||
@Test
|
||||
void shopSourcesAreBatchedByTaskId() {
|
||||
|
||||
+71
-1
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.taskcenter.service;
|
||||
|
||||
import com.nanri.aiimage.modules.taskcenter.mapper.TaskCenterQueryMapper;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterCollectStatsRow;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterDeviceRow;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterShopRow;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterShopStatRow;
|
||||
@@ -47,7 +48,9 @@ import static org.mockito.Mockito.when;
|
||||
* ① 卡住只有一个窗口(进行中且 10 分钟无上报);
|
||||
* ② 汇总卡的「在跑店铺」与店铺面板行数同源,且都不把「不挂店铺」桶算成店铺;
|
||||
* ③ 每个进行中任务必须在面板里出现(无店铺归属的落合成桶,不许静默消失);
|
||||
* ④ 店铺只认真来源(上架文件 / 逐店落行文件),快照的 {@code current_scope_key} 是实例锁,不是店铺。
|
||||
* ④ 店铺只认真来源(上架文件 / 逐店落行文件),快照的 {@code current_scope_key} 是实例锁,不是店铺;
|
||||
* ⑤ 无快照的进度回退跟客户端「有没有进度条」对齐(用户 2026-10-04 定案):采集数据用关键词进度,
|
||||
* 上架/删除ASIN/品牌沿用文件·行计数,客户端压根不画条的业务不许回退成误导的 0/1。
|
||||
* SQL 本身由 TaskCenterQueryMapperSqlTest 守。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -132,6 +135,14 @@ class TaskCenterQueryServiceTest {
|
||||
return row;
|
||||
}
|
||||
|
||||
private static TaskCenterCollectStatsRow collectStatsRow(long taskId, String totalRows, String processedRows) {
|
||||
TaskCenterCollectStatsRow row = new TaskCenterCollectStatsRow();
|
||||
row.setTaskId(taskId);
|
||||
row.setTotalRows(totalRows);
|
||||
row.setProcessedRows(processedRows);
|
||||
return row;
|
||||
}
|
||||
|
||||
private static TaskCenterDeviceRow deviceNameRow(String deviceId, String deviceName) {
|
||||
TaskCenterDeviceRow row = new TaskCenterDeviceRow();
|
||||
row.setDeviceId(deviceId);
|
||||
@@ -480,6 +491,65 @@ class TaskCenterQueryServiceTest {
|
||||
assertEquals(0L, second.getShopCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectDataRowWithoutSnapshotUsesKeywordProgress() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
TaskCenterTaskRow row = taskRow(1L, "COLLECT_DATA", "RUNNING", now, now);
|
||||
row.setTotalCount(1L);
|
||||
row.setSuccessCount(0L);
|
||||
|
||||
stubPage(List.of(row));
|
||||
when(queryMapper.selectSnapshots(any())).thenReturn(List.of());
|
||||
when(queryMapper.selectCollectDataKeywordStats(List.of(1L)))
|
||||
.thenReturn(List.of(collectStatsRow(1L, "60", "12")));
|
||||
stubPublishShops(List.of());
|
||||
stubFileResultShops(List.of());
|
||||
|
||||
TaskCenterTaskRowVo vo = item(service.tasks(superScope(), new TaskCenterTaskQuery()), 1L);
|
||||
|
||||
assertEquals(60L, vo.getProgressTotal(), "总 = 关键词数(与客户端「关键词进度:第 X/N 个」同源)");
|
||||
assertEquals(12L, vo.getProgressSuccess(), "已完成 = 已处理关键词数,不是输入文件数");
|
||||
assertEquals(0L, vo.getProgressFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modulesWithoutClientProgressBarHaveNoFallbackCount() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
TaskCenterTaskRow priceTrack = taskRow(1L, "PRICE_TRACK", "RUNNING", now, now);
|
||||
priceTrack.setTotalCount(1L);
|
||||
priceTrack.setSuccessCount(0L);
|
||||
TaskCenterTaskRow shopMatch = taskRow(2L, "SHOP_MATCH", "RUNNING", now, now);
|
||||
shopMatch.setTotalCount(1L);
|
||||
|
||||
stubPage(List.of(priceTrack, shopMatch));
|
||||
when(queryMapper.selectSnapshots(any())).thenReturn(List.of());
|
||||
stubPublishShops(List.of());
|
||||
stubFileResultShops(List.of());
|
||||
|
||||
TaskCenterTaskPageVo page = service.tasks(superScope(), new TaskCenterTaskQuery());
|
||||
|
||||
assertEquals(0L, item(page, 1L).getProgressTotal(), "跟价客户端没进度条 → 不回退文件数,前端画「—」");
|
||||
assertEquals(0L, item(page, 2L).getProgressTotal(), "定时匹配同理");
|
||||
verify(queryMapper, never()).selectCollectDataKeywordStats(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectDataWithoutStatsPayloadDegradesToNoProgress() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
TaskCenterTaskRow row = taskRow(1L, "COLLECT_DATA", "PENDING", now, now);
|
||||
row.setTotalCount(1L);
|
||||
|
||||
stubPage(List.of(row));
|
||||
when(queryMapper.selectSnapshots(any())).thenReturn(List.of());
|
||||
when(queryMapper.selectCollectDataKeywordStats(List.of(1L))).thenReturn(List.of(
|
||||
collectStatsRow(1L, "abc", null)));
|
||||
stubPublishShops(List.of());
|
||||
stubFileResultShops(List.of());
|
||||
|
||||
assertEquals(0L, item(service.tasks(superScope(), new TaskCenterTaskQuery()), 1L).getProgressTotal(),
|
||||
"脏值/缺字段按无进度处理,不拿文件数兜底");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shopSourcesDedupeAcrossBothTables() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
+57
-7
@@ -6,6 +6,7 @@ import com.nanri.aiimage.modules.notification.client.MaixiangConsoleClient.Batch
|
||||
import com.nanri.aiimage.modules.taskcenter.mapper.TaskCenterQueryMapper;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterUserRow;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.vo.TaskCenterVariantPageVo;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.vo.TaskCenterVariantTaskVo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -29,7 +30,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 变体采集页签的 Java 侧口径:可见用户 → uid 集合(逗号拼接、排序稳定)、
|
||||
* 分页归一化、uid → 账号名映射、麦象不可达/未配置时返回空页。
|
||||
* 分页归一化、uid → 账号名映射、麦象不可达/未配置时返回空页;
|
||||
* 不传 status = 只看在跑(等待 0 ∪ 处理中 1 合并,历史终态不进默认口径)。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TaskCenterVariantServiceTest {
|
||||
@@ -52,6 +54,11 @@ class TaskCenterVariantServiceTest {
|
||||
resMes, "{\"file_url\": \"https://oss.aishufu.top/a.xlsx\"}");
|
||||
}
|
||||
|
||||
private static BatchTaskItem item(String taskId, String uid, int status, String resMes, LocalDateTime createTime) {
|
||||
return new BatchTaskItem(taskId, "variant-collection", uid, status,
|
||||
createTime, createTime, resMes, "{\"file_url\": \"https://oss.aishufu.top/a.xlsx\"}");
|
||||
}
|
||||
|
||||
private static TaskCenterUserRow userRow(Long id, String username) {
|
||||
TaskCenterUserRow row = new TaskCenterUserRow();
|
||||
row.setUserId(id);
|
||||
@@ -106,17 +113,58 @@ class TaskCenterVariantServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void superAdminPassesNoUidFilterAndDefaultPaging() {
|
||||
void superAdminWithoutStatusSeesOnlyActiveMergedFromBothStatuses() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage(isNull(), isNull(), eq("variant-collection"), eq(1), eq(20)))
|
||||
.thenReturn(BatchTaskPage.EMPTY);
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(0), eq("variant-collection"), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(1, List.of(item("t-wait", "5", 0, "已添加至任务队列,等待执行"))));
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(1), eq("variant-collection"), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(2, List.of(item("t-run", "5", 1, "已采集 12 条"))));
|
||||
when(queryMapper.selectUsernames(List.of(5L))).thenReturn(List.of(userRow(5L, "ali")));
|
||||
|
||||
TaskCenterVariantPageVo page = service.variantTasks(superScope(), null, null, null, null);
|
||||
|
||||
assertEquals(0, page.getItems().size());
|
||||
assertEquals(3, page.getTotal(), "不传 status = 在跑(等待+处理中)之和,不再是历史全量 106");
|
||||
assertEquals(2, page.getItems().size());
|
||||
assertEquals(1, page.getPage());
|
||||
assertEquals(20, page.getPageSize());
|
||||
verify(queryMapper, never()).selectUsernames(any());
|
||||
assertEquals("等待执行", page.getItems().get(0).getStatusLabel());
|
||||
verify(consoleClient, never()).batchTasksPage(any(), isNull(), any(), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void activeMergeSortsByCreateTimeDescAndSlicesPages() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(0), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(2, List.of(
|
||||
item("t-old", "5", 0, "等待", LocalDateTime.of(2026, 10, 4, 1, 0)),
|
||||
item("t-mid", "5", 0, "等待", LocalDateTime.of(2026, 10, 4, 2, 0)))));
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(1), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(1, List.of(
|
||||
item("t-new", "5", 1, "处理中", LocalDateTime.of(2026, 10, 4, 3, 0)))));
|
||||
|
||||
TaskCenterVariantPageVo first = service.variantTasks(superScope(), null, null, 1, 2);
|
||||
assertEquals(List.of("t-new", "t-mid"),
|
||||
first.getItems().stream().map(TaskCenterVariantTaskVo::getTaskId).toList(),
|
||||
"两个状态合并后按创建时间倒序,不是先等待后处理中的拼接序");
|
||||
TaskCenterVariantPageVo second = service.variantTasks(superScope(), null, null, 2, 2);
|
||||
assertEquals(List.of("t-old"),
|
||||
second.getItems().stream().map(TaskCenterVariantTaskVo::getTaskId).toList());
|
||||
TaskCenterVariantPageVo beyond = service.variantTasks(superScope(), null, null, 3, 2);
|
||||
assertEquals(0, beyond.getItems().size(), "越界页给空列表");
|
||||
assertEquals(3, beyond.getTotal(), "total 不随空页归零");
|
||||
}
|
||||
|
||||
@Test
|
||||
void activeTotalFallsBackToItemCountWhenMaixiangTotalIsSentinel() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(0), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(-1, List.of(item("t-1", "5", 0, "等待"))));
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(1), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(-1, List.of()));
|
||||
|
||||
TaskCenterVariantPageVo page = service.variantTasks(superScope(), null, null, 1, 20);
|
||||
|
||||
assertEquals(1, page.getTotal(), "-1 哨兵不能把在跑数算成负数");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,10 +181,12 @@ class TaskCenterVariantServiceTest {
|
||||
@Test
|
||||
void nonNumericUidAndUnknownStatusDegradeGracefully() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage("5", null, "variant-collection", 1, 20))
|
||||
when(consoleClient.batchTasksPage("5", 0, "variant-collection", 1, 200))
|
||||
.thenReturn(new BatchTaskPage(3, List.of(
|
||||
item("t-1", "collect-27475", 0, "已添加至任务队列,等待执行"),
|
||||
item("t-2", "5", 9, ""))));
|
||||
when(consoleClient.batchTasksPage("5", 1, "variant-collection", 1, 200))
|
||||
.thenReturn(BatchTaskPage.EMPTY);
|
||||
when(queryMapper.selectUsernames(List.of(5L))).thenReturn(List.of(userRow(5L, "ali")));
|
||||
|
||||
TaskCenterVariantPageVo page = service.variantTasks(scoped(5L), null, null, 1, 20);
|
||||
|
||||
Reference in New Issue
Block a user