后端(外观专利逐行送检): 撤掉组代表折叠与兄弟行借用结论,覆盖率分母改成交付行集

现网取证(主机A MinIO 上 6 份已交付 xlsx 逐格数):结果文件里 20.7%~51.3% 的行显示
「未取得检测结果」,且空的是整行三列、这些 ASIN 一个都没被检过、行号连续成块
(10-08 任务 30426:1211 行只有 96 批 960 行有结论;10-09 任务 30455 的 281 行空行
100% 属于"同父号已有一行被判")。两条成因都在判据口径上:

1) 送检只挑组代表行,兄弟行指望发起那一轮复用代表结论 —— 同父号的 2_1/2_2/2_3
   各有各的 sku/标题/图片,借用等于成片行永不检测。按用户口径改为逐行申领、逐行送检,
   组代表折叠与 expandRows 摊派一并删除(合批省的是调用数,代价是漏检)。
2) 覆盖率闸门的分母按「用户上传表的解析行」有没有标题/图片判该行该不该检,而数据
   常在「客户端回传行」上 ⇒ 用户表不带标题列时分母恒 0、整段不判,成品半空而零告警。
   判据抽成 AppearancePatentRowOutcome(JUDGED/NOT_INSPECTED/NO_DATA),表格文案、
   原因 sheet 与闸门分母共用同一套;候选/工作单位计数也改用交付口径(旧的是
   "四字段任一可用",只带专利维度文本的行会被读成已检测,而专利维度根本不入表)。

配套:判失败的任务不再整段跳过闸门(仍按既有口径出部分结果,但必打
「交付行账不完整」锚点并把缺口写进 task.errorMessage);出表前缺口<阈值时撤行级
标记并 requeue 补检一轮(releaseRowInspection 三参版才允许撤完成标记,两参版语义
由老用例钉死不变);llm-coverage-min-ratio 0.5→0.95(Properties 与 application.yml
两处默认值,已查两台既无 env 覆盖也无外置 yml 该键);货源面接上同口径的
「交付行账」度量日志(只数不改行为,阈值等本面实测分布)。

测试:外观专利整包 203 例、加货源共 645 例全绿。新增 AppearancePatentRowOutcomeTest(15)、
AppearancePatentDeliveryGateTest(9)、SimilarAsinDeliveryLedgerTest(3),
并在 RowMarkTimingTest 钉住"同父号子行逐行申领""兄弟行不得继承结论"。
This commit is contained in:
2026-10-10 11:32:37 +08:00
parent 0d59a733d4
commit 122faf7c74
12 changed files with 405 additions and 259 deletions
@@ -200,8 +200,7 @@ class AppearancePatentChunkRowIndexTest {
ReflectionTestUtils.invokeMethod(service, "submitLlmBatches",
task(), new FileResultEntity(), job(),
List.of(chunk(SCOPE_A, POINTER_A, HASH_A), chunk(SCOPE_B, POINTER_B, HASH_B),
chunk(SCOPE_C, POINTER_C, "hash-c-stale")),
Map.of());
chunk(SCOPE_C, POINTER_C, "hash-c-stale")));
verify(transientPayloadStorageService, times(2)).resolvePayload(eq(POINTER_C), anyString());
}
@@ -212,8 +211,7 @@ class AppearancePatentChunkRowIndexTest {
ReflectionTestUtils.invokeMethod(service, "submitLlmBatches",
task(), new FileResultEntity(), job(),
List.of(chunk(SCOPE_A, POINTER_A, HASH_A), chunk(SCOPE_B, POINTER_B, HASH_B),
chunk(SCOPE_C, POINTER_C, HASH_C)),
Map.of());
chunk(SCOPE_C, POINTER_C, HASH_C)));
}
private FileTaskEntity task() {
@@ -47,6 +47,9 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.contains;
@@ -317,7 +320,7 @@ class AppearancePatentRowMarkTimingTest {
private void submit() {
ReflectionTestUtils.invokeMethod(service, "submitLlmBatches",
task(), new FileResultEntity(), job(), List.of(chunk()), Map.of());
task(), new FileResultEntity(), job(), List.of(chunk()));
}
private void stubMergeWrite(int updatedRows) {
@@ -347,6 +350,118 @@ class AppearancePatentRowMarkTimingTest {
return job;
}
/**
* 只带专利维度文本的行必须仍然是候选。旧口径把"四个字段任一可用"当成已检测,
* 而这种行会在交付表格里显示成三列全空(标题维/外观维/结论)——退出候选就等于永久空白。
*/
@Test
@SuppressWarnings("unchecked")
void rowCarryingOnlyPatentRiskIsStillACandidate() {
String onlyPatent = "[{\"rowToken\":\"r3\",\"asin\":\"B0A0000003\",\"title\":\"BAG\","
+ "\"url\":\"http://img/3.jpg\",\"groupKey\":\"g3\",\"patentRisk\":\"无侵权\"}]";
when(transientPayloadStorageService.resolvePayload(eq(POINTER), anyString())).thenReturn(onlyPatent);
when(taskCacheService.beginRowInspection(eq(TASK_ID), anyString())).thenReturn(true);
List<AppearancePatentResultRowDto> candidates = (List<AppearancePatentResultRowDto>) ReflectionTestUtils
.invokeMethod(service, "collectPendingLlmCandidates", List.of(chunk()), new AppearancePatentTaskService.ChunkRowKeyIndex());
assertEquals(1, candidates.size());
assertEquals("r3", candidates.get(0).getRowToken());
}
/**
* 同一父号下的子序行必须各自行级申领(2026-10-10 口径):{@code 2_1/2_2/2_3} 是不同 sku、
* 各有各的标题与图片链接,历史上只挑「组代表行」送检、兄弟行借用其结论,
* 现网形状是成片空行(10-09 任务 30455 的 281 行空行 100% 属于"同父号已有一行被判")。
*/
@Test
@SuppressWarnings("unchecked")
void everySubRowOfTheSameGroupIsClaimedIndividually() {
String threeSubRows = "[{\"rowToken\":\"r21\",\"id\":\"2_1\",\"asin\":\"B0A0000001\",\"country\":\"US\","
+ "\"title\":\"SHOE A\",\"url\":\"http://img/a.jpg\",\"groupKey\":\"g1\"},"
+ "{\"rowToken\":\"r22\",\"id\":\"2_2\",\"asin\":\"B0A0000002\",\"country\":\"US\","
+ "\"title\":\"SHOE B\",\"url\":\"http://img/b.jpg\",\"groupKey\":\"g1\"},"
+ "{\"rowToken\":\"r23\",\"id\":\"2_3\",\"asin\":\"B0A0000003\",\"country\":\"US\","
+ "\"title\":\"SHOE C\",\"url\":\"http://img/c.jpg\",\"groupKey\":\"g1\"}]";
when(transientPayloadStorageService.resolvePayload(eq(POINTER), anyString())).thenReturn(threeSubRows);
when(taskCacheService.beginRowInspection(eq(TASK_ID), anyString())).thenReturn(true);
List<AppearancePatentResultRowDto> candidates = (List<AppearancePatentResultRowDto>) ReflectionTestUtils
.invokeMethod(service, "collectPendingLlmCandidates", List.of(chunk()),
new AppearancePatentTaskService.ChunkRowKeyIndex());
assertEquals(3, candidates.size(), "同父号三行必须都进候选,不能只检一行");
verify(taskCacheService).beginRowInspection(TASK_ID, "r21");
verify(taskCacheService).beginRowInspection(TASK_ID, "r22");
verify(taskCacheService).beginRowInspection(TASK_ID, "r23");
}
/** 兄弟行已经判完,不能反过来把没判的行"代表掉"——那正是成片空行的来源。 */
@Test
@SuppressWarnings("unchecked")
void judgedRowDoesNotSuppressItsUnjudgedSiblings() {
String mixed = "[{\"rowToken\":\"r21\",\"id\":\"2_1\",\"asin\":\"B0A0000001\",\"country\":\"US\","
+ "\"title\":\"SHOE A\",\"url\":\"http://img/a.jpg\",\"groupKey\":\"g1\","
+ "\"titleRisk\":\"无侵权\",\"appearanceRisk\":\"无侵权\",\"conclusion\":\"无侵权\"},"
+ "{\"rowToken\":\"r22\",\"id\":\"2_2\",\"asin\":\"B0A0000002\",\"country\":\"US\","
+ "\"title\":\"SHOE B\",\"url\":\"http://img/b.jpg\",\"groupKey\":\"g1\"}]";
when(transientPayloadStorageService.resolvePayload(eq(POINTER), anyString())).thenReturn(mixed);
when(taskCacheService.beginRowInspection(eq(TASK_ID), anyString())).thenReturn(true);
List<AppearancePatentResultRowDto> candidates = (List<AppearancePatentResultRowDto>) ReflectionTestUtils
.invokeMethod(service, "collectPendingLlmCandidates", List.of(chunk()),
new AppearancePatentTaskService.ChunkRowKeyIndex());
assertEquals(1, candidates.size());
assertEquals("r22", candidates.get(0).getRowToken(), "该检的是没结论的那一行,不是已经检过的");
}
/**
* 落库不许把代表行的结论写进兄弟行:捕获真正写回对象存储的载荷文本,
* 断言兄弟行仍然没有结论字段。借用一旦回来,这条会红。
*/
@Test
void mergeWritesBackOnlyTheLandedRowAndNeverStampsSiblings() {
String twoRows = "[{\"rowToken\":\"r21\",\"id\":\"2_1\",\"asin\":\"B0A0000001\",\"country\":\"US\","
+ "\"title\":\"SHOE A\",\"url\":\"http://img/a.jpg\",\"groupKey\":\"g1\"},"
+ "{\"rowToken\":\"r22\",\"id\":\"2_2\",\"asin\":\"B0A0000002\",\"country\":\"US\","
+ "\"title\":\"SHOE B\",\"url\":\"http://img/b.jpg\",\"groupKey\":\"g1\"}]";
when(transientPayloadStorageService.resolvePayload(eq(POINTER), anyString())).thenReturn(twoRows);
when(transientPayloadStorageService.storeChunkPayloadVersioned(anyString(), anyLong(), anyString(), anyInt(), anyString()))
.thenReturn("ptr-new");
when(taskChunkMapper.update(any(), any())).thenReturn(1);
AppearancePatentResultRowDto landed = row("r21", "2_1", "B0A0000001");
landed.setTitleRisk("无侵权");
landed.setAppearanceRisk("无侵权");
landed.setConclusion("无侵权");
ReflectionTestUtils.invokeMethod(service, "mergeLlmRowsIntoChunks",
task(), List.of(landed), List.of(landed), new AppearancePatentTaskService.ChunkRowKeyIndex());
ArgumentCaptor<String> written = ArgumentCaptor.forClass(String.class);
verify(transientPayloadStorageService, org.mockito.Mockito.atLeastOnce()).storeChunkPayloadVersioned(
anyString(), eq(TASK_ID), anyString(), anyInt(), written.capture());
boolean landedCarriesVerdict = false;
for (String payload : written.getAllValues()) {
assertTrue(payload.contains("\"rowToken\":\"r22\""), "兄弟行必须仍在载荷里(不许被删掉): " + payload);
int sibling = payload.indexOf("\"rowToken\":\"r22\"");
assertFalse(payload.substring(sibling).contains("无侵权"), "兄弟行不得继承代表行的结论: " + payload);
if (payload.contains("\"rowToken\":\"r21\"") && payload.contains("无侵权")) {
landedCarriesVerdict = true;
}
}
assertTrue(landedCarriesVerdict, "落库的那一行要带着自己的结论写回: " + written.getAllValues());
}
private AppearancePatentResultRowDto row(String rowToken, String id, String asin) {
AppearancePatentResultRowDto row = new AppearancePatentResultRowDto();
row.setRowToken(rowToken);
row.setId(id);
row.setAsin(asin);
row.setCountry("US");
return row;
}
private TaskChunkEntity chunk() {
TaskChunkEntity chunk = new TaskChunkEntity();
chunk.setId(11L);
@@ -153,6 +153,33 @@ class AppearancePatentTaskCacheServiceRowMarkTest {
verify(valueOperations, never()).set(anyString(), anyString(), any(Duration.class));
}
/**
* 交付缺口补检那条出口允许连完成标记一起撤(2026-10-10):结果落过库却又读不回来的行,
* 不撤就永远申领不到,表格里永久写着"未完成检测"。代价是那行可能被重发一次 LLM——
* 由调用方显式传 true 承担,默认那条路(releaseRowInspection 两参版)一个字不许变。
*/
@Test
void releaseWithCompletionClearDropsBothMarks() {
cache.releaseRowInspection(TASK_ID, List.of(ROW_KEY), true);
ArgumentCaptor<String> deleted = ArgumentCaptor.forClass(String.class);
verify(redisTemplate, org.mockito.Mockito.times(2)).delete(deleted.capture());
assertTrue(deleted.getAllValues().stream().anyMatch(k -> k.contains("inflight-rows")),
"处理中键必须撤掉,否则补检轮仍然申领不到");
assertTrue(deleted.getAllValues().stream().anyMatch(k -> k.contains("processed-rows")),
"补检出口必须把完成标记也撤掉");
}
/** 三参版传 false 时必须与两参版同形:已经落库结论的行不许被这条路重发。 */
@Test
void releaseWithoutCompletionClearKeepsProcessedMark() {
cache.releaseRowInspection(TASK_ID, List.of(ROW_KEY), false);
ArgumentCaptor<String> deleted = ArgumentCaptor.forClass(String.class);
verify(redisTemplate).delete(deleted.capture());
assertFalse(deleted.getValue().contains("processed-rows"), "false 分支不得删完成标记");
}
/** 每发起一轮就自增一次:这是重发上限唯一的数据来源。 */
@Test
void roundCountIncrementsPerRound() {
@@ -11,6 +11,7 @@ import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentResu
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentSubmitResultRequest;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentParsedRowVo;
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentTaskCacheService;
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentRowOutcome;
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentSheetBuilder;
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentRowNormalizer;
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
@@ -209,7 +210,8 @@ class AppearancePatentTaskServiceDelegationTest {
try (XSSFWorkbook wb = new XSSFWorkbook(out)) {
Row data = wb.getSheet("外观专利检测结果").getRow(1);
assertEquals("未取得检测结果", data.getCell(9).getStringCellValue(), "无结果行判定列显式标注(空白与没风险无法区分)");
assertEquals(AppearancePatentRowOutcome.NO_DATA_TEXT, data.getCell(9).getStringCellValue(),
"无结果行且解析行连标题/图片都没有 ⇒ 标成「未采集到数据」,不能读成「没跑到检测」");
assertEquals("失败", data.getCell(12).getStringCellValue(), "无结果行状态判失败");
assertEquals("brand-A", data.getCell(4).getStringCellValue(), "品牌仍从解析行 values 回退");
assertEquals("", data.getCell(5).getStringCellValue(), "无结果行价格留空(resolvePrice 仅读结果行,与现状一致)");
@@ -151,14 +151,14 @@ class AppearancePatentSheetBuilderTest {
assertEquals("title-a", data.getCell(6).getStringCellValue(), "无结果行回退解析行标题");
assertEquals("http://img/a.jpg", data.getCell(7).getStringCellValue(), "回退解析行 URL");
assertEquals("SKU-1", data.getCell(8).getStringCellValue(), "回退解析行 sku");
assertEquals("未取得检测结果", data.getCell(9).getStringCellValue(), "无结果行标题维度显式标注");
assertEquals("未取得检测结果", data.getCell(10).getStringCellValue(), "无结果行外观维度显式标注");
assertEquals("未取得检测结果", data.getCell(11).getStringCellValue(), "无结果行结论显式标注");
assertEquals(AppearancePatentRowOutcome.NOT_INSPECTED_TEXT, data.getCell(9).getStringCellValue(), "无结果行标题维度显式标注");
assertEquals(AppearancePatentRowOutcome.NOT_INSPECTED_TEXT, data.getCell(10).getStringCellValue(), "无结果行外观维度显式标注");
assertEquals(AppearancePatentRowOutcome.NOT_INSPECTED_TEXT, data.getCell(11).getStringCellValue(), "无结果行结论显式标注");
assertEquals("失败", data.getCell(12).getStringCellValue(), "无结果行状态判失败,不能留空");
Row reason = wb.getSheet("原因").getRow(1);
assertEquals("B01A", reason.getCell(0).getStringCellValue());
assertTrue(reason.getCell(1).getStringCellValue().contains("未取得检测结果"),
assertTrue(reason.getCell(1).getStringCellValue().contains("未完成检测"),
"原因 sheet 也要说明这行为什么没有原因: " + reason.getCell(1).getStringCellValue());
}
}
@@ -196,7 +196,7 @@ class AppearancePatentSheetBuilderTest {
AppearancePatentSheetBuilder.rowKey(r), r));
Row data = wb.getSheet("外观专利检测结果").getRow(1);
assertEquals("未取得检测结果", data.getCell(11).getStringCellValue(), "空白结论改写成显式标注");
assertEquals(AppearancePatentRowOutcome.NOT_INSPECTED_TEXT, data.getCell(11).getStringCellValue(), "空白结论改写成显式标注");
assertEquals("失败", data.getCell(12).getStringCellValue());
}
}