feat(collect-channel): 采集执行方按单判定并随 /parse 落库

「这一单交本机还是线上」原先是全局 yml aiimage.collect-routing.local-enabled,
一台服务器一个值,把同机所有账号捆成同一个执行方:本机开着的用户被迫走线上,
跑 Linux 兜底的用户也没法把某一单留在本机。现改为建单时逐单登记
biz_file_task.collect_channel(V183,可空=按模块默认),全局开关只留兜底窗口。

- 列可空且不回填:空值按模块默认解释,APPEARANCE_PATENT/SIMILAR_ASIN 读作 LOCAL、
  其余读作 ONLINE,与撤掉的 AIIMAGE_COLLECT_LOCAL_* 出厂值逐字节等价,
  历史单与未升级前端行为不变。
- TaskRetryCloneSupport.buildChild 必须继承通道:原单选了线上,重试掉回模块默认
  等于悄悄换执行方。
- CollectChannel 用逐值比对而非 valueOf+catch 判「不可识别」:后者会把静默 catch
  总数顶过 CatchSilenceRatchetTest 上限 1057。
- 两支建单快照 golden 随 collect_channel 键重建(只多出 collectChannel=null)。
This commit is contained in:
2026-10-31 12:33:09 +08:00
parent 7459177bb4
commit 7469c710d7
25 changed files with 400 additions and 131 deletions
@@ -64,11 +64,11 @@ class AppearancePatentActivateRoutingTest {
}
@Test
void 本地采集开启时_activate_走条件更新并刷心跳() {
FileTaskEntity task = pendingTask();
void 本机通道的单_activate_走条件更新并刷心跳() {
FileTaskEntity task = pendingTask(com.nanri.aiimage.modules.task.model.CollectChannel.LOCAL);
when(fileTaskMapper.selectById(TASK_ID)).thenReturn(task);
when(fileTaskMapper.update(isNull(), any())).thenReturn(1);
AppearancePatentTaskService service = service(routing(true));
AppearancePatentTaskService service = service(new CollectRoutingProperties());
service.activateTask(TASK_ID, USER_ID);
@@ -82,9 +82,10 @@ class AppearancePatentActivateRoutingTest {
}
@Test
void 本地采集关闭时_activate_保持后台语义并明确拒绝() {
when(fileTaskMapper.selectById(TASK_ID)).thenReturn(pendingTask());
AppearancePatentTaskService service = service(routing(false));
void 线上通道的单_activate_保持后台语义并明确拒绝() {
when(fileTaskMapper.selectById(TASK_ID))
.thenReturn(pendingTask(com.nanri.aiimage.modules.task.model.CollectChannel.ONLINE));
AppearancePatentTaskService service = service(new CollectRoutingProperties());
BusinessException error = assertThrows(BusinessException.class,
() -> service.activateTask(TASK_ID, USER_ID));
@@ -93,18 +94,24 @@ class AppearancePatentActivateRoutingTest {
verify(fileTaskMapper, never()).update(isNull(), any());
}
private static CollectRoutingProperties routing(boolean local) {
CollectRoutingProperties properties = new CollectRoutingProperties();
properties.setLocalEnabled(Map.of(CollectRoutingProperties.MODULE_APPEARANCE_PATENT, local));
return properties;
@Test
void 未登记通道的历史单按模块默认走本机() {
FileTaskEntity task = pendingTask(null);
when(fileTaskMapper.selectById(TASK_ID)).thenReturn(task);
when(fileTaskMapper.update(isNull(), any())).thenReturn(1);
service(new CollectRoutingProperties()).activateTask(TASK_ID, USER_ID);
verify(taskCacheService).touchTaskHeartbeat(TASK_ID);
}
private FileTaskEntity pendingTask() {
private FileTaskEntity pendingTask(com.nanri.aiimage.modules.task.model.CollectChannel channel) {
FileTaskEntity task = new FileTaskEntity();
task.setId(TASK_ID);
task.setModuleType(AppearancePatentTaskService.MODULE_TYPE);
task.setUserId(USER_ID);
task.setStatus("PENDING");
task.setCollectChannel(channel == null ? null : channel.name());
return task;
}
@@ -161,6 +161,7 @@ class AppearancePatentCreateTaskSnapshotTest {
+ " moduleType=" + task.getModuleType()
+ " status=" + task.getStatus()
+ " taskMode=" + task.getTaskMode()
+ " collectChannel=" + task.getCollectChannel()
+ " sourceFileCount=" + task.getSourceFileCount()
+ " successFileCount=" + task.getSuccessFileCount()
+ " failedFileCount=" + task.getFailedFileCount()
@@ -448,6 +449,26 @@ class AppearancePatentCreateTaskSnapshotTest {
assertTrue(resultEvent.contains(" rowCount=2"), "rowCount 记的是接受行数(4 行夹具去掉 dropped 与全空行):" + resultEvent);
}
@Test
void 建单按界面选的通道落库() throws Exception {
// V183:执行方由这一单自己定(界面 LOCAL/ONLINE 单选框),建单就得把选择写进头行。
Harness online = harnessWithFiles("uploads/main.xlsx", mixedWorkbook(), null, null);
AppearancePatentParseRequest picked = request(7L, List.of(source("uploads/main.xlsx", "17.xlsx")));
picked.setCollectChannel(" online ");
online.service().parseAndCreateTask(picked, "device-1");
assertTrue(firstTaskInsert(online).contains(" collectChannel=ONLINE"),
"选线上的单子必须钉成 ONLINE,否则 activate 会把任务推回本机客户端:" + firstTaskInsert(online));
Harness legacy = harnessWithFiles("uploads/main.xlsx", mixedWorkbook(), null, null);
legacy.service().parseAndCreateTask(request(7L, List.of(source("uploads/main.xlsx", "17.xlsx"))), "device-1");
assertTrue(firstTaskInsert(legacy).contains(" collectChannel=null"),
"未升级前端不传通道=不登记,由模块默认兜(外观专利默认本机),历史行为不变:" + firstTaskInsert(legacy));
}
private static String firstTaskInsert(Harness harness) {
return harness.events.stream().filter(e -> e.startsWith("task.insert")).findFirst().orElse("<无 task.insert>");
}
@Test
void 头行先落库再有载荷指针() throws Exception {
Harness harness = harnessWithFiles("uploads/main.xlsx", mixedWorkbook(), null, null);