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
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
@@ -41,12 +42,14 @@ import java.util.concurrent.atomic.AtomicLong;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -185,6 +188,32 @@ class SimilarAsinTaskServiceParseDelegationTest {
assertEquals("uploads/f1.xlsx::1@2", vo.getGroups().get(0).getGroupKey(), "分组键按归一化 fileKey 拼接");
}
@Test
void test_parse_records_collect_channel() throws Exception {
// V183:执行方由这一单自己定,界面选的通道必须在建单时落进 collect_channel。
File workbook = buildWorkbook(List.<String[]>of(new String[]{"1", "B01A", "US"}));
assertEquals("ONLINE", insertedChannel(workbook, "uploads/collect-online.xlsx", "ONLINE"));
assertEquals("LOCAL", insertedChannel(workbook, "uploads/collect-local.xlsx", " local "));
assertNull(insertedChannel(workbook, "uploads/collect-absent.xlsx", null),
"不传就留空=按模块默认,未升级前端的行为一字不变");
assertNull(insertedChannel(workbook, "uploads/collect-dirty.xlsx", "本机"),
"不可识别的值按不登记处理,不把脏值钉进库里让单子永久卡在一侧");
}
/** 跑一次建单,取回落库任务头的通道字段。 */
private String insertedChannel(File workbook, String fileKey, String collectChannel) {
when(localFileStorageService.findLocalSourceFile(fileKey)).thenReturn(workbook);
SimilarAsinParseRequest request = request(fileKey);
request.setCollectChannel(collectChannel);
// 只清调用记录、保留赋值 id 的桩:一个用例连跑四次建单,否则 captor 拿到的是上一单的实体
clearInvocations(fileTaskMapper);
service.parseAndCreateTask(request, "test-device");
ArgumentCaptor<FileTaskEntity> captor = ArgumentCaptor.forClass(FileTaskEntity.class);
verify(fileTaskMapper).insert(captor.capture());
return captor.getValue().getCollectChannel();
}
@Test
void test_parse_delegates_validator() throws Exception {
// 重复 ASIN+国家 / 非字母数字 ASIN:校验器标记但不改接收结果(与改造前一致)
@@ -195,6 +195,7 @@ class SimilarAsinCreateTaskSnapshotTest {
+ " taskNoPrefix=" + taskNoPrefix(task.getTaskNo())
+ " moduleType=" + dash(task.getModuleType())
+ " taskMode=" + dash(task.getTaskMode())
+ " collectChannel=" + dash(task.getCollectChannel())
+ " status=" + dash(task.getStatus())
+ " sourceFileCount=" + task.getSourceFileCount()
+ " ok=" + task.getSuccessFileCount()