后端(外观专利逐行送检): 撤掉组代表折叠与兄弟行借用结论,覆盖率分母改成交付行集
现网取证(主机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:
@@ -79,8 +79,11 @@ public class AppearancePatentProperties {
|
||||
* 组装结果文件时要求的 LLM 覆盖率下限(0~1,<=0 关闭)。
|
||||
* 低于该比例说明大批行根本没拿到结论(如 2026-09-20 任务 28805:904 行只检了 1 行却报成功),
|
||||
* 此时判任务失败并由失败通知告警,而不是交付一份看着完整、实际是复制结论的表。
|
||||
* 默认 0.5 只拦塌陷级异常;生产正常任务实测约 0.91(28798:723 行 658 行有结论),
|
||||
* 需要更严时调高,调到 1.0 即要求全行有结论。
|
||||
*
|
||||
* <p>2026-10-10 从 0.5 抬到 0.95:0.5 意味着半张表可以空着照样出文件。现网实测(10-06~10-09
|
||||
* 六份已交付 xlsx)空行比例 20.7%–51.3%,全部在 0.5 之上放行、且一条覆盖率告警都没打——
|
||||
* 因为旧分母按用户上传表的解析行数,用户表不带标题列时分母恒为 0。
|
||||
* 分母口径已改为「会写进结果文件的行集」,判据见 AppearancePatentRowOutcome。
|
||||
*/
|
||||
private double llmCoverageMinRatio = 0.5D;
|
||||
private double llmCoverageMinRatio = 0.95D;
|
||||
}
|
||||
|
||||
+14
-2
@@ -58,7 +58,7 @@ public class AppearancePatentTaskCacheService extends AbstractPendingRowTaskCach
|
||||
return first == null || first;
|
||||
} catch (Exception ex) {
|
||||
log.warn("[appearance-patent-cache] begin row inspection degraded taskId={} rowKey={} msg={}", taskId, rowKey, ex.getMessage());
|
||||
// Redis 降级时放行,由持久化层的 hasResolvedLlmFields 判据兜底去重。
|
||||
// Redis 降级时放行,由持久化层的 AppearancePatentRowOutcome.isJudged 判据兜底去重。
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -102,9 +102,18 @@ public class AppearancePatentTaskCacheService extends AbstractPendingRowTaskCach
|
||||
|
||||
/**
|
||||
* 撤销处理中标记(本批没拿到可用结果时调用):让下一轮立刻能重新申领,不等 15 分钟 TTL。
|
||||
* TTL 只用来兜住「进程在批中被杀」。
|
||||
* TTL 只用来兜住「进程在批中被杀」。完成标记**不动**——动它会让已经落库的行重跑并重复计费。
|
||||
*/
|
||||
public void releaseRowInspection(Long taskId, List<String> rowKeys) {
|
||||
releaseRowInspection(taskId, rowKeys, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param alsoClearCompletionMark 交付缺口补检专用:结果落过库却又读不回来(分片被清、载荷过期)时,
|
||||
* 这行既没结论也再申领不到,等于扣了次数永久空着;只有这条出口
|
||||
* 允许连完成标记一起撤,代价(可能重发一次 LLM)由调用方点名承担。
|
||||
*/
|
||||
public void releaseRowInspection(Long taskId, List<String> rowKeys, boolean alsoClearCompletionMark) {
|
||||
if (taskId == null || taskId <= 0 || rowKeys == null || rowKeys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -114,6 +123,9 @@ public class AppearancePatentTaskCacheService extends AbstractPendingRowTaskCach
|
||||
}
|
||||
try {
|
||||
stringRedisTemplate.delete(inFlightRowKey(taskId, rowKey));
|
||||
if (alsoClearCompletionMark) {
|
||||
stringRedisTemplate.delete(processedRowKey(taskId, rowKey));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.warn("[appearance-patent-cache] release row inspection degraded taskId={} rowKey={} msg={}",
|
||||
taskId, rowKey, ex.getMessage());
|
||||
|
||||
+164
-219
@@ -35,6 +35,7 @@ import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentParse
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentTaskBatchVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentTaskDetailVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentTaskItemVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentRowOutcome;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentSheetBuilder;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
@@ -944,8 +945,7 @@ public class AppearancePatentTaskService {
|
||||
private void submitLlmBatches(FileTaskEntity task,
|
||||
FileResultEntity result,
|
||||
TaskFileJobEntity job,
|
||||
List<TaskChunkEntity> chunks,
|
||||
Map<String, List<AppearancePatentParsedRowVo>> allRowsByBaseId) {
|
||||
List<TaskChunkEntity> chunks) {
|
||||
if (chunks == null || chunks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -954,7 +954,7 @@ public class AppearancePatentTaskService {
|
||||
int batchSize = Math.max(1, properties.getLlmBatchSize());
|
||||
ChunkRowKeyIndex rowKeyIndex = new ChunkRowKeyIndex();
|
||||
List<AppearancePatentResultRowDto> candidates = terminalizeRoundExhaustedRows(
|
||||
task, allRowsByBaseId, collectPendingLlmCandidates(chunks, rowKeyIndex), rowKeyIndex);
|
||||
task, collectPendingLlmCandidates(chunks, rowKeyIndex), rowKeyIndex);
|
||||
boolean flushRemainder = isResultSubmissionComplete(task.getId());
|
||||
if (!flushRemainder && !candidates.isEmpty()) {
|
||||
LocalDateTime jobUpdatedAt = job.getUpdatedAt();
|
||||
@@ -1007,7 +1007,7 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
List<String> keysToRetry = new ArrayList<>(batchRowKeys);
|
||||
try {
|
||||
Set<String> landedKeys = mergeLlmRowsIntoChunks(task, allRowsByBaseId, llmRows, batchRows, rowKeyIndex);
|
||||
Set<String> landedKeys = mergeLlmRowsIntoChunks(task, llmRows, batchRows, rowKeyIndex);
|
||||
// 完成标记只能打在真正落库的行上——这是「发版重启会不会丢行」的分界线
|
||||
if (batchAnswered) {
|
||||
List<String> landed = batchRowKeys.stream().filter(landedKeys::contains).toList();
|
||||
@@ -1046,7 +1046,6 @@ public class AppearancePatentTaskService {
|
||||
*/
|
||||
private List<AppearancePatentResultRowDto> terminalizeRoundExhaustedRows(
|
||||
FileTaskEntity task,
|
||||
Map<String, List<AppearancePatentParsedRowVo>> allRowsByBaseId,
|
||||
List<AppearancePatentResultRowDto> candidates,
|
||||
ChunkRowKeyIndex rowKeyIndex) {
|
||||
int maxRounds = properties.getLlmRowMaxRounds();
|
||||
@@ -1072,7 +1071,7 @@ public class AppearancePatentTaskService {
|
||||
List<String> exhaustedKeys = exhausted.stream().map(this::rowKey).filter(key -> !key.isBlank()).toList();
|
||||
boolean rowsTerminated = false;
|
||||
try {
|
||||
mergeLlmRowsIntoChunks(task, allRowsByBaseId, llmClient.markRowsFailed(exhausted, reason),
|
||||
mergeLlmRowsIntoChunks(task, llmClient.markRowsFailed(exhausted, reason),
|
||||
exhausted, rowKeyIndex);
|
||||
rowsTerminated = true;
|
||||
} finally {
|
||||
@@ -1087,7 +1086,6 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
|
||||
private Set<String> mergeLlmRowsIntoChunks(FileTaskEntity task,
|
||||
Map<String, List<AppearancePatentParsedRowVo>> allRowsByBaseId,
|
||||
List<AppearancePatentResultRowDto> llmRows,
|
||||
List<AppearancePatentResultRowDto> batchRows,
|
||||
ChunkRowKeyIndex rowKeyIndex) {
|
||||
@@ -1108,8 +1106,7 @@ public class AppearancePatentTaskService {
|
||||
deduped.put(key, row);
|
||||
}
|
||||
}
|
||||
return mergeLlmRowsIntoSubmittedChunks(task, new ArrayList<>(deduped.values()), allRowsByBaseId,
|
||||
null, null, rowKeyIndex);
|
||||
return mergeLlmRowsIntoSubmittedChunks(task, new ArrayList<>(deduped.values()), null, null, rowKeyIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1128,31 +1125,63 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 收集未检测的候选行:**逐行**申领——同一父号下的 {@code 2_1/2_2/2_3} 每行都各自进候选、各自送检。
|
||||
*
|
||||
* <p>历史上这里只挑「组代表行」,其余兄弟行指望 {@code expandRows} 在发起那一轮借用代表行的结论——
|
||||
* 那是把「同一个父号」当成「同一件东西」,而子序行各有各的 sku、标题和图片链接。
|
||||
* 口径(2026-10-10 用户定):这些行**都要检测**。折叠与借用一起撤掉,因为借用的后果不是省钱,
|
||||
* 而是成片空行随结果文件交付(10-08 任务 30426:1211 行里只有 960 行有结论、251 行整段空白,
|
||||
* 而任务报成功;10-09 任务 30455 的 281 行空行 100% 属于"同父号已有一行被判"这一形状)。
|
||||
*
|
||||
* <p>"这行算不算已经检过"用交付口径(标题维+外观维+结论三列齐,见
|
||||
* {@link AppearancePatentRowOutcome#isJudged})。旧代码用的是"四个字段里任一可用",于是
|
||||
* 只带着专利维度文本、或只带一个 error 的行会被判"已检测",从此退出候选,而表格里它那三列全是空的。
|
||||
*/
|
||||
private List<AppearancePatentResultRowDto> collectPendingLlmCandidates(List<TaskChunkEntity> chunks,
|
||||
ChunkRowKeyIndex rowKeyIndex) {
|
||||
if (chunks == null || chunks.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<AppearancePatentResultRowDto> candidates = new ArrayList<>();
|
||||
int claimBlocked = 0;
|
||||
int judgedSkipped = 0;
|
||||
int noDataSkipped = 0;
|
||||
int chunkRows = 0;
|
||||
for (TaskChunkEntity chunk : chunks) {
|
||||
Map<String, AppearancePatentResultRowDto> persistedRows = readChunkRows(chunk);
|
||||
if (persistedRows.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
// 这一遍已经把所有分片的载荷读进来了,顺手把「这片里有哪些行」记进索引:
|
||||
// 这一遍已经把这批分片的载荷读进来了,顺手把「这片里有哪些行」记进索引:
|
||||
// 下面每批落库前都要这份索引,不记的话就得每批把全部分片重读重解析一遍
|
||||
rememberChunkRowKeys(rowKeyIndex, chunk, persistedRows.keySet());
|
||||
for (AppearancePatentResultRowDto row : pickGroupRepresentativesForLlm(persistedRows.values())) {
|
||||
chunkRows += persistedRows.size();
|
||||
for (AppearancePatentResultRowDto row : persistedRows.values()) {
|
||||
String key = rowKey(row);
|
||||
if (key.isBlank() || hasResolvedLlmFields(row)) {
|
||||
if (key.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
if (AppearancePatentRowOutcome.isJudged(row)) {
|
||||
judgedSkipped++;
|
||||
continue;
|
||||
}
|
||||
if (!shouldInspectRow(row)) {
|
||||
// 连标题带图都没采到的行:送过去也只能回"外观识别异常",白扣一次
|
||||
noDataSkipped++;
|
||||
continue;
|
||||
}
|
||||
if (!taskCacheService.beginRowInspection(chunk.getTaskId(), key)) {
|
||||
// 被"处理中/已完成"标记挡住的行必须数得出来:历史上这里静默 continue,
|
||||
// 于是"扣了次数却永久没结论"和"这行本来就不该检"在日志里长得一模一样
|
||||
claimBlocked++;
|
||||
continue;
|
||||
}
|
||||
candidates.add(row);
|
||||
}
|
||||
}
|
||||
log.info("[appearance-patent] 候选收集逐行申领 taskId={} chunkRows={} judgedSkipped={} noDataSkipped={} claimBlocked={} candidates={}",
|
||||
chunks.get(0).getTaskId(), chunkRows, judgedSkipped, noDataSkipped, claimBlocked, candidates.size());
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@@ -1167,8 +1196,8 @@ public class AppearancePatentTaskService {
|
||||
int total = 0;
|
||||
for (TaskChunkEntity chunk : chunks) {
|
||||
Map<String, AppearancePatentResultRowDto> persistedRows = readChunkRows(chunk);
|
||||
for (AppearancePatentResultRowDto row : pickGroupRepresentativesForLlm(persistedRows.values())) {
|
||||
if (!rowKey(row).isBlank() && !hasResolvedLlmFields(row)) {
|
||||
for (AppearancePatentResultRowDto row : persistedRows.values()) {
|
||||
if (!rowKey(row).isBlank() && !AppearancePatentRowOutcome.isJudged(row)) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
@@ -1186,7 +1215,8 @@ public class AppearancePatentTaskService {
|
||||
if (persistedRows.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
int unresolved = pickGroupRepresentativesForLlm(persistedRows.values()).size();
|
||||
int unresolved = (int) persistedRows.values().stream()
|
||||
.filter(row -> !rowKey(row).isBlank() && !AppearancePatentRowOutcome.isJudged(row)).count();
|
||||
if (unresolved > 0) {
|
||||
total += Math.max(1, (unresolved + batchSize - 1) / batchSize);
|
||||
}
|
||||
@@ -1226,8 +1256,7 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
log.info("[appearance-patent] stale recovery created assemble job taskId={} resultId={} jobId={} jobStatus={} chunkCount={}",
|
||||
task.getId(), result.getId(), job.getId(), job.getStatus(), chunks.size());
|
||||
Map<String, List<AppearancePatentParsedRowVo>> allRowsByBaseId = loadAllRowsByBaseId(task);
|
||||
submitLlmBatches(task, result, job, chunks, allRowsByBaseId);
|
||||
submitLlmBatches(task, result, job, chunks);
|
||||
if (isResultSubmissionComplete(task.getId())) {
|
||||
taskFileJobService.requeue(job.getId(), "检测结果已回流,正在组装 xlsx");
|
||||
} else {
|
||||
@@ -1535,104 +1564,6 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
private List<AppearancePatentResultRowDto> expandRows(List<AppearancePatentResultRowDto> representatives,
|
||||
Map<String, List<AppearancePatentParsedRowVo>> allRowsByBaseId) {
|
||||
if (representatives == null || representatives.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<AppearancePatentResultRowDto> result = new ArrayList<>();
|
||||
Set<String> emittedKeys = new LinkedHashSet<>();
|
||||
for (AppearancePatentResultRowDto representative : representatives) {
|
||||
List<AppearancePatentParsedRowVo> siblings = resolveSiblingRows(representative, allRowsByBaseId);
|
||||
if (siblings == null || siblings.isEmpty()) {
|
||||
result.add(representative);
|
||||
continue;
|
||||
}
|
||||
for (AppearancePatentParsedRowVo sibling : siblings) {
|
||||
String key = rowKey(sibling);
|
||||
if (!emittedKeys.add(key)) {
|
||||
continue;
|
||||
}
|
||||
result.add(copyResultToSibling(representative, sibling));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<AppearancePatentParsedRowVo> resolveSiblingRows(AppearancePatentResultRowDto representative,
|
||||
Map<String, List<AppearancePatentParsedRowVo>> groupedRows) {
|
||||
if (representative == null || groupedRows == null || groupedRows.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
String representativeGroupKey = normalize(representative.getGroupKey());
|
||||
if (!representativeGroupKey.isBlank()) {
|
||||
return groupedRows.getOrDefault(representativeGroupKey, List.of());
|
||||
}
|
||||
String representativeKey = rowKey(representative);
|
||||
String representativeLegacyKey = legacyRowKey(representative);
|
||||
for (List<AppearancePatentParsedRowVo> rows : groupedRows.values()) {
|
||||
for (AppearancePatentParsedRowVo row : rows) {
|
||||
if (Objects.equals(representativeKey, rowKey(row))
|
||||
|| Objects.equals(representativeLegacyKey, legacyRowKey(row))) {
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private Map<String, List<AppearancePatentParsedRowVo>> loadAllRowsByBaseId(FileTaskEntity task) {
|
||||
try {
|
||||
AppearancePatentParsedPayloadDto payload = readParsedPayload(task);
|
||||
List<AppearancePatentParsedRowVo> rows = payload.getAllItems();
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
rows = payload.getItems();
|
||||
}
|
||||
if ((rows == null || rows.isEmpty()) && payload.getGroups() != null) {
|
||||
rows = payload.getGroups().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(group -> group.getItems() == null ? java.util.stream.Stream.empty() : group.getItems().stream())
|
||||
.toList();
|
||||
}
|
||||
return groupRowsByBaseId(rows);
|
||||
} catch (Exception ex) {
|
||||
log.warn("[appearance-patent] read all rows failed taskId={} err={}", task.getId(), ex.getMessage());
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
private List<AppearancePatentResultRowDto> pickGroupRepresentativesForLlm(java.util.Collection<AppearancePatentResultRowDto> rows) {
|
||||
Map<String, List<AppearancePatentResultRowDto>> groupedRows = new LinkedHashMap<>();
|
||||
if (rows == null) {
|
||||
return List.of();
|
||||
}
|
||||
for (AppearancePatentResultRowDto row : rows) {
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String key = firstNonBlank(normalize(row.getGroupKey()), rowKey(row));
|
||||
groupedRows.computeIfAbsent(key, ignored -> new ArrayList<>()).add(row);
|
||||
}
|
||||
List<AppearancePatentResultRowDto> representatives = new ArrayList<>();
|
||||
for (List<AppearancePatentResultRowDto> siblings : groupedRows.values()) {
|
||||
boolean alreadyResolved = siblings.stream().anyMatch(this::hasCompleteLlmResult);
|
||||
if (alreadyResolved) {
|
||||
continue;
|
||||
}
|
||||
AppearancePatentResultRowDto candidate = null;
|
||||
for (AppearancePatentResultRowDto sibling : siblings) {
|
||||
if (shouldInspectRow(sibling)) {
|
||||
candidate = sibling;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (candidate != null) {
|
||||
representatives.add(candidate);
|
||||
}
|
||||
}
|
||||
return representatives;
|
||||
}
|
||||
|
||||
private List<AppearancePatentParsedGroupVo> buildParsedGroups(List<AppearancePatentParsedRowVo> rows) {
|
||||
List<AppearancePatentParsedGroupVo> groups = new ArrayList<>();
|
||||
for (List<AppearancePatentParsedRowVo> siblings : groupRowsByBaseId(rows).values()) {
|
||||
@@ -1724,33 +1655,6 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
private AppearancePatentResultRowDto copyResultToSibling(AppearancePatentResultRowDto representative, AppearancePatentParsedRowVo sibling) {
|
||||
AppearancePatentResultRowDto row = new AppearancePatentResultRowDto();
|
||||
row.setSourceFileKey(sibling.getSourceFileKey());
|
||||
row.setSourceFilename(sibling.getSourceFilename());
|
||||
row.setRowToken(sibling.getRowToken());
|
||||
row.setGroupKey(sibling.getGroupKey());
|
||||
row.setId(sibling.getDisplayId());
|
||||
row.setAsin(sibling.getAsin());
|
||||
row.setCountry(sibling.getCountry());
|
||||
row.setSku(firstNonBlank(representative.getSku(), sibling.getSku()));
|
||||
row.setBrand(representative.getBrand());
|
||||
row.setUrl(firstNonBlank(representative.getUrl(), sibling.getUrl()));
|
||||
row.setTitle(firstNonBlank(representative.getTitle(), sibling.getTitle()));
|
||||
row.setError(representative.getError());
|
||||
row.setStatus(representative.getStatus());
|
||||
row.setTitleRisk(representative.getTitleRisk());
|
||||
row.setAppearanceRisk(representative.getAppearanceRisk());
|
||||
row.setPatentRisk(representative.getPatentRisk());
|
||||
row.setConclusion(representative.getConclusion());
|
||||
row.setTitleReason(representative.getTitleReason());
|
||||
row.setAppearanceReason(representative.getAppearanceReason());
|
||||
row.setPatentReason(representative.getPatentReason());
|
||||
row.setScore(representative.getScore());
|
||||
row.setDone(representative.getDone());
|
||||
return row;
|
||||
}
|
||||
|
||||
private String readAiPrompt(FileTaskEntity task) {
|
||||
try {
|
||||
return readParsedPayload(task).getAiPrompt();
|
||||
@@ -1781,6 +1685,7 @@ public class AppearancePatentTaskService {
|
||||
|
||||
private void finalizeTask(FileTaskEntity task, String error, int rowCount, boolean assembleWorkbook) {
|
||||
String finalError = error;
|
||||
AppearancePatentRowOutcome.Facts deliveryFacts = AppearancePatentRowOutcome.Facts.EMPTY;
|
||||
FileResultEntity result = null;
|
||||
boolean hasPersistedResultRows = hasPersistedResultRows(task.getId());
|
||||
List<FileResultEntity> rows = fileResultMapper.selectList(new LambdaQueryWrapper<FileResultEntity>()
|
||||
@@ -1796,7 +1701,7 @@ public class AppearancePatentTaskService {
|
||||
boolean shouldAssembleResult = assembleWorkbook && (finalError == null || finalError.isBlank() || hasPersistedResultRows);
|
||||
if (shouldAssembleResult && shouldAssembleSynchronously()) {
|
||||
try {
|
||||
assembleResultWorkbook(task, result);
|
||||
deliveryFacts = assembleResultWorkbook(task, result);
|
||||
} catch (Exception ex) {
|
||||
log.warn("[appearance-patent] assemble result workbook failed taskId={} err={}", task.getId(), ex.getMessage());
|
||||
finalError = firstNonBlank(finalError, "Generate appearance patent result failed");
|
||||
@@ -1808,7 +1713,8 @@ public class AppearancePatentTaskService {
|
||||
task.setStatus(resolveTaskExecutionStatus(waitingForAssemble, failed));
|
||||
task.setSuccessFileCount(failed ? 0 : 1);
|
||||
task.setFailedFileCount(failed ? 1 : 0);
|
||||
task.setErrorMessage(finalError);
|
||||
// 缺口只写在消息里,不参与 failed 计算:95% 以上有结论的单仍是成功,但用户要看得见"N 行没检测完"
|
||||
task.setErrorMessage(appendDeliveryGapMessage(finalError, deliveryFacts));
|
||||
task.setUpdatedAt(LocalDateTime.now());
|
||||
task.setFinishedAt(waitingForAssemble ? null : LocalDateTime.now());
|
||||
fileTaskMapper.updateById(task);
|
||||
@@ -1921,25 +1827,58 @@ public class AppearancePatentTaskService {
|
||||
int plannedLlmUnits = Math.max(1, llmWorkUnits);
|
||||
int totalProgressUnits = Math.max(3, plannedLlmUnits + 3);
|
||||
saveFileBuildProgress(task, job, totalProgressUnits, 0, "正在提交检测");
|
||||
Map<String, List<AppearancePatentParsedRowVo>> allRowsByBaseId = loadAllRowsByBaseId(task);
|
||||
submitLlmBatches(task, result, job, chunks, allRowsByBaseId);
|
||||
submitLlmBatches(task, result, job, chunks);
|
||||
if (STATUS_RUNNING.equals(task.getStatus()) && !isResultSubmissionComplete(task.getId())) {
|
||||
taskFileJobService.touchRunning(job.getId());
|
||||
touchJavaSideTaskActivity(task.getId());
|
||||
saveFileBuildProgress(task, job, totalProgressUnits, Math.max(1, plannedLlmUnits), "等待 Python 继续回传数据");
|
||||
return false;
|
||||
}
|
||||
completeLlmFileJob(task, result, job, totalProgressUnits);
|
||||
return completeLlmFileJob(task, result, job, totalProgressUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
* 有行没跑完就先别把半张表当成品发:撤销这些行的检测标记(完成态与处理中都要撤,
|
||||
* 否则 {@code beginRowInspection} 下一轮仍然申领不到它们),把作业排回队列补检一轮。
|
||||
*
|
||||
* <p>不会无限补检:作业重排受 {@code TaskFileJobService} 的 MAX_RETRY_COUNT 约束(requeue 返回
|
||||
* false 时这里就放行出文件),行级重发次数受 {@code llmRowMaxRounds} 约束(到顶的行会被判死并
|
||||
* 写上「重发轮次已达上限」的结论,从此不再是空行)。
|
||||
*/
|
||||
private boolean requestRecheckForMissingRows(FileTaskEntity task, TaskFileJobEntity job,
|
||||
AppearancePatentRowOutcome.Facts facts) {
|
||||
if (task == null || job == null || job.getId() == null || facts == null
|
||||
|| facts.missingRows() <= 0 || facts.missingKeys().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
List<String> keys = facts.missingKeys();
|
||||
// 只有这条出口允许连完成标记一起撤:结果落过库却又读不回来的行,不撤就永远补不回来。
|
||||
// 代价(该行可能被重发一次 LLM、多扣一次次数)是这一档修法里用户点名要付的。
|
||||
taskCacheService.releaseRowInspection(task.getId(), keys, true);
|
||||
boolean requeued = taskFileJobService.requeue(job.getId(),
|
||||
"有 " + facts.missingRows() + " 行未完成检测,补检一轮后重新组装结果文件");
|
||||
if (!requeued) {
|
||||
log.warn("[appearance-patent] 交付缺口补检排不上队,按已有结果交付 taskId={} jobId={} missingRows={}",
|
||||
task.getId(), job.getId(), facts.missingRows());
|
||||
return false;
|
||||
}
|
||||
log.warn("[appearance-patent] 交付缺口触发补检轮 taskId={} jobId={} missingRows={} keys={} noDataRows={}",
|
||||
task.getId(), job.getId(), facts.missingRows(), keys.size(), facts.noDataRows());
|
||||
return true;
|
||||
}
|
||||
|
||||
private void completeLlmFileJob(FileTaskEntity task,
|
||||
private boolean completeLlmFileJob(FileTaskEntity task,
|
||||
FileResultEntity result,
|
||||
TaskFileJobEntity job,
|
||||
int totalProgressUnits) {
|
||||
int assembleProgress = Math.max(1, totalProgressUnits - 2);
|
||||
saveFileBuildProgress(task, job, totalProgressUnits, assembleProgress, "正在组装 xlsx");
|
||||
assembleResultWorkbook(task, result);
|
||||
AppearancePatentRowOutcome.Facts deliveryFacts = assembleResultWorkbook(task, result);
|
||||
if (requestRecheckForMissingRows(task, job, deliveryFacts)) {
|
||||
// 半张表先不发出去:撤销未完成行的检测标记、把作业排回队列补检一轮,
|
||||
// 上限由行级轮次闸(llmRowMaxRounds)与作业重试上限共同兜住。
|
||||
return false;
|
||||
}
|
||||
saveFileBuildProgress(task, job, totalProgressUnits, totalProgressUnits - 1, "正在上传结果文件");
|
||||
fileResultMapper.updateById(result);
|
||||
boolean taskAlreadyFailed = STATUS_FAILED.equals(task.getStatus())
|
||||
@@ -1948,18 +1887,18 @@ public class AppearancePatentTaskService {
|
||||
task.setStatus(resolveTaskExecutionStatus(false, taskAlreadyFailed));
|
||||
task.setSuccessFileCount(taskAlreadyFailed ? 0 : 1);
|
||||
task.setFailedFileCount(taskAlreadyFailed ? 1 : 0);
|
||||
task.setErrorMessage(taskAlreadyFailed ? existingError : null);
|
||||
task.setErrorMessage(appendDeliveryGapMessage(taskAlreadyFailed ? existingError : null, deliveryFacts));
|
||||
task.setUpdatedAt(LocalDateTime.now());
|
||||
task.setFinishedAt(LocalDateTime.now());
|
||||
fileTaskMapper.updateById(task);
|
||||
taskCacheService.deleteTaskCache(task.getId());
|
||||
saveFileBuildProgress(task, job, totalProgressUnits, totalProgressUnits, "结果文件已生成");
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 返回真正落库的行键;没匹配到分片行的键不会出现在里面,调用方据此决定要不要撤销已检测标记。 */
|
||||
private Set<String> mergeLlmRowsIntoSubmittedChunks(FileTaskEntity task,
|
||||
List<AppearancePatentResultRowDto> llmRows,
|
||||
Map<String, List<AppearancePatentParsedRowVo>> allRowsByBaseId,
|
||||
String fallbackScopeHash,
|
||||
Integer fallbackChunkIndex,
|
||||
ChunkRowKeyIndex rowKeyIndex) {
|
||||
@@ -1979,7 +1918,7 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
Map<String, Map<String, AppearancePatentResultRowDto>> mergeRowsByChunk = new LinkedHashMap<>();
|
||||
for (AppearancePatentResultRowDto resultRow : llmRows) {
|
||||
for (AppearancePatentResultRowDto expandedRow : expandRows(List.of(resultRow), allRowsByBaseId)) {
|
||||
for (AppearancePatentResultRowDto expandedRow : List.of(resultRow)) {
|
||||
String rowKey = rowKey(expandedRow);
|
||||
if (rowKey.isBlank()) {
|
||||
continue;
|
||||
@@ -2256,7 +2195,7 @@ public class AppearancePatentTaskService {
|
||||
.eq(TaskScopeStateEntity::getModuleType, MODULE_TYPE));
|
||||
}
|
||||
|
||||
private void assembleResultWorkbook(FileTaskEntity task, FileResultEntity result) {
|
||||
private AppearancePatentRowOutcome.Facts assembleResultWorkbook(FileTaskEntity task, FileResultEntity result) {
|
||||
AppearancePatentParsedPayloadDto parsed = readParsedPayload(task);
|
||||
List<AppearancePatentParsedRowVo> parsedRows = parsed.getAllItems() == null
|
||||
? List.of() : parsed.getAllItems();
|
||||
@@ -2268,6 +2207,7 @@ public class AppearancePatentTaskService {
|
||||
long resolvedRows = 0L;
|
||||
long reasonRows = 0L;
|
||||
int conclusionPropagated = 0;
|
||||
AppearancePatentRowOutcome.Facts deliveryFacts = AppearancePatentRowOutcome.Facts.EMPTY;
|
||||
File outputDir = new File(storageProperties.getLocalTempDir(), "appearance-patent-result");
|
||||
if (!outputDir.exists() && !outputDir.mkdirs()) {
|
||||
throw new BusinessException("创建结果目录失败");
|
||||
@@ -2280,7 +2220,8 @@ public class AppearancePatentTaskService {
|
||||
loadPersistedResultRowsForRowsWithRetry(task.getId(), item.rows());
|
||||
// 覆盖率先于「本文件无结果就跳过」判定:整源文件的 LLM 结果全丢(分片被跳过、
|
||||
// 结果清空)时覆盖率是 0%,必须在这里判掉,不能让 zip 少一个文件还报任务成功。
|
||||
validateCompleteLlmCoverage(task.getId(), item.rows(), resultMap);
|
||||
deliveryFacts = deliveryFacts.plus(
|
||||
validateCompleteLlmCoverage(task.getId(), item.rows(), resultMap));
|
||||
List<AppearancePatentParsedRowVo> receivedRows = filterReceivedParsedRows(item.rows(), resultMap);
|
||||
if (receivedRows.isEmpty()) {
|
||||
resultMap.clear();
|
||||
@@ -2351,6 +2292,7 @@ public class AppearancePatentTaskService {
|
||||
result.setResultFileSize(uploadFile.length());
|
||||
result.setResultContentType(contentType);
|
||||
result.setRowCount(receivedRowCount);
|
||||
return deliveryFacts;
|
||||
} finally {
|
||||
for (SourceResultWorkbook workbook : workbooks) {
|
||||
if (workbook.file().exists() && !workbook.file().delete()) {
|
||||
@@ -2474,68 +2416,90 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖率判定:分母必须是**解析出的全部行**(只滤掉不需要送检的行),不能是已经拿到结果的行。
|
||||
* 传已过滤的集合会让分母恒等于分子 —— 整片结果丢失(chunk payload 缺失被跳过、
|
||||
* 客户端漏回传)时覆盖率仍是 100%,阈值形同虚设。
|
||||
* 覆盖率判定:分母必须是**真正会写进结果文件的那批行**,且"该行有没有数据"要同时看
|
||||
* 用户上传表的解析行与客户端回传的结果行——只看解析行,用户表不带标题列时分母恒为 0,
|
||||
* 闸门对整份文件失明(现网 6 份已交付文件里 20%–51% 空行、零告警就是这么来的)。
|
||||
* 判据本身在 {@link AppearancePatentRowOutcome#summarize},与表格文案共用一套,不许两边各判。
|
||||
*/
|
||||
private void validateCompleteLlmCoverage(Long taskId,
|
||||
private AppearancePatentRowOutcome.Facts validateCompleteLlmCoverage(Long taskId,
|
||||
List<AppearancePatentParsedRowVo> parsedRows,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap) {
|
||||
if (parsedRows == null || parsedRows.isEmpty()) {
|
||||
return;
|
||||
return AppearancePatentRowOutcome.Facts.EMPTY;
|
||||
}
|
||||
AppearancePatentRowOutcome.Facts facts =
|
||||
AppearancePatentRowOutcome.summarize(parsedRows, row -> findResultRow(row, resultMap));
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
if (task != null && STATUS_FAILED.equals(task.getStatus())) {
|
||||
return;
|
||||
boolean taskAlreadyFailed = task != null && STATUS_FAILED.equals(task.getStatus());
|
||||
if (facts.missingRows() > 0 || facts.noDataRows() > 0) {
|
||||
log.warn("[appearance-patent] 交付行账不完整 taskId={} expectedRows={} judgedRows={} missingRows={} noDataRows={} coverage={} taskFailed={} samples={}",
|
||||
taskId, facts.expectedRows(), facts.judgedRows(), facts.missingRows(), facts.noDataRows(),
|
||||
String.format("%.2f%%", facts.coverage() * 100), taskAlreadyFailed,
|
||||
sampleAsins(parsedRows, resultMap, facts));
|
||||
}
|
||||
double minCoverage = properties.getLlmCoverageMinRatio();
|
||||
// 已判失败的任务走的是"按已有分片出部分结果"这条既有口径,这里再抛会把成品彻底拿掉;
|
||||
// 但它不再静默:上面的行账锚点必打,缺口由调用方写进任务错误信息,用户看得到「N 行没检测」。
|
||||
if (!taskAlreadyFailed && minCoverage > 0 && facts.expectedRows() > 0
|
||||
&& facts.coverage() + 1e-9 < minCoverage) {
|
||||
throw new BusinessException("LLM 结果不完整:仅 " + facts.judgedRows() + "/" + facts.expectedRows()
|
||||
+ " 行拿到检测结论(低于 " + Math.round(minCoverage * 100) + "% 覆盖率下限)"
|
||||
+ noDataSuffix(facts) + ",请重新运行任务");
|
||||
}
|
||||
return facts;
|
||||
}
|
||||
|
||||
private List<String> sampleAsins(List<AppearancePatentParsedRowVo> parsedRows,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap,
|
||||
AppearancePatentRowOutcome.Facts facts) {
|
||||
List<String> samples = new ArrayList<>(5);
|
||||
if (facts.missingRows() <= 0) {
|
||||
return samples;
|
||||
}
|
||||
int expectedRows = 0;
|
||||
int missingRows = 0;
|
||||
List<String> sampleAsins = new ArrayList<>();
|
||||
for (AppearancePatentParsedRowVo parsedRow : parsedRows) {
|
||||
if (!hasPromptFields(parsedRow)) {
|
||||
if (samples.size() >= 5) {
|
||||
break;
|
||||
}
|
||||
if (parsedRow == null) {
|
||||
continue;
|
||||
}
|
||||
expectedRows++;
|
||||
AppearancePatentResultRowDto resultRow = findResultRow(parsedRow, resultMap);
|
||||
if (resultRow == null || !hasDeliverableLlmResult(resultRow)) {
|
||||
missingRows++;
|
||||
if (sampleAsins.size() < 5) {
|
||||
sampleAsins.add(firstNonBlank(parsedRow.getAsin(), firstNonBlank(parsedRow.getDisplayId(), "")));
|
||||
}
|
||||
if (AppearancePatentRowOutcome.classify(parsedRow, findResultRow(parsedRow, resultMap))
|
||||
!= AppearancePatentRowOutcome.Kind.NOT_INSPECTED) {
|
||||
continue;
|
||||
}
|
||||
samples.add(firstNonBlank(parsedRow.getAsin(),
|
||||
firstNonBlank(parsedRow.getDisplayId(), "")));
|
||||
}
|
||||
if (expectedRows <= 0) {
|
||||
return;
|
||||
}
|
||||
int resolvedRows = expectedRows - missingRows;
|
||||
double coverage = (double) resolvedRows / expectedRows;
|
||||
double minCoverage = properties.getLlmCoverageMinRatio();
|
||||
if (missingRows > 0) {
|
||||
log.warn("[appearance-patent] incomplete llm coverage taskId={} expectedRows={} missingRows={} coverage={} samples={}",
|
||||
taskId, expectedRows, missingRows, String.format("%.2f%%", coverage * 100), sampleAsins);
|
||||
}
|
||||
if (minCoverage > 0 && coverage + 1e-9 < minCoverage) {
|
||||
throw new BusinessException("LLM 结果不完整:仅 " + resolvedRows + "/" + expectedRows
|
||||
+ " 行拿到检测结论(低于 " + Math.round(minCoverage * 100) + "% 覆盖率下限),请重新运行任务");
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* 交付口径的完整性判定:结论依赖标题维度、外观维度和最终结论三列。
|
||||
* 与 {@link #hasCompleteLlmResult} 的区别是不看 patentRisk —— 现网正常返回里 patent
|
||||
* 恒为空串(见 AppearancePatentLlmClient 的 LlmResult 构造),拿它当必要条件会把每个任务都判成不完整。
|
||||
*/
|
||||
private boolean hasDeliverableLlmResult(AppearancePatentResultRowDto row) {
|
||||
return hasUsableLlmField(row.getTitleRisk())
|
||||
&& hasUsableLlmField(row.getAppearanceRisk())
|
||||
&& hasUsableLlmField(row.getConclusion());
|
||||
private String noDataSuffix(AppearancePatentRowOutcome.Facts facts) {
|
||||
return facts.noDataRows() > 0
|
||||
? ";另有 " + facts.noDataRows() + " 行未采集到数据、无法检测"
|
||||
: "";
|
||||
}
|
||||
|
||||
private boolean hasCompleteLlmResult(AppearancePatentResultRowDto row) {
|
||||
return hasUsableLlmField(row.getTitleRisk())
|
||||
&& hasUsableLlmField(row.getAppearanceRisk())
|
||||
&& hasUsableLlmField(row.getPatentRisk())
|
||||
&& hasUsableLlmField(row.getConclusion());
|
||||
/** 交付缺口写进任务错误信息:让后台列表与用户端都能看到「N 行没检测完」,而不是只有一张半空表。 */
|
||||
private String appendDeliveryGapMessage(String existingError, AppearancePatentRowOutcome.Facts facts) {
|
||||
if (facts == null || (facts.missingRows() <= 0 && facts.noDataRows() <= 0)) {
|
||||
return existingError;
|
||||
}
|
||||
StringBuilder gap = new StringBuilder();
|
||||
if (facts.missingRows() > 0) {
|
||||
gap.append("有 ").append(facts.missingRows()).append(" 行未完成检测");
|
||||
}
|
||||
if (facts.noDataRows() > 0) {
|
||||
if (gap.length() > 0) {
|
||||
gap.append("、");
|
||||
}
|
||||
gap.append("有 ").append(facts.noDataRows()).append(" 行未采集到数据");
|
||||
}
|
||||
gap.append("(结果文件中这些行已单独标注)");
|
||||
String existing = firstNonBlank(existingError, "");
|
||||
if (existing.contains("未完成检测") || existing.contains("未采集到数据")) {
|
||||
return existing;
|
||||
}
|
||||
return existing.isBlank() ? gap.toString() : existing + ";" + gap;
|
||||
}
|
||||
|
||||
private boolean hasPersistedResultRows(Long taskId) {
|
||||
@@ -2853,29 +2817,10 @@ public class AppearancePatentTaskService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasPromptFields(AppearancePatentParsedRowVo row) {
|
||||
return row != null && (!normalize(row.getTitle()).isBlank() || !normalize(row.getUrl()).isBlank());
|
||||
}
|
||||
|
||||
private boolean shouldInspectRow(AppearancePatentResultRowDto row) {
|
||||
return row != null && (!normalize(row.getTitle()).isBlank() || !normalize(row.getUrl()).isBlank());
|
||||
}
|
||||
|
||||
private boolean hasResolvedLlmFields(AppearancePatentResultRowDto row) {
|
||||
if (row == null) {
|
||||
return false;
|
||||
}
|
||||
return hasUsableLlmField(row.getTitleRisk())
|
||||
|| hasUsableLlmField(row.getAppearanceRisk())
|
||||
|| hasUsableLlmField(row.getPatentRisk())
|
||||
|| hasUsableLlmField(row.getConclusion());
|
||||
}
|
||||
|
||||
private boolean hasUsableLlmField(String value) {
|
||||
String normalized = normalize(value);
|
||||
return !normalized.isBlank() && !AppearancePatentSheetBuilder.isTechnicalLlmFailure(normalized);
|
||||
}
|
||||
|
||||
private Map<String, Integer> buildHeaderMap(Row header, DataFormatter formatter) {
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
for (int i = 0; i < header.getLastCellNum(); i++) {
|
||||
|
||||
+34
-17
@@ -43,9 +43,10 @@ public final class AppearancePatentSheetBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* 没拿到判定的行写进格子里的显式文案。
|
||||
* 「检到了这一行、但这一列没给出文本」时写进格子的文案。
|
||||
*
|
||||
* <p>交付只要求 LLM 覆盖率过半({@code llm-coverage-min-ratio}),所以少数缺失行照样出文件。
|
||||
* <p>整行压根没检出结论的,走 {@link AppearancePatentRowOutcome#NOT_INSPECTED_TEXT} 与
|
||||
* {@link AppearancePatentRowOutcome#NO_DATA_TEXT}——三种原因对应的处置动作不同,不能挤进同一句。
|
||||
* 历史上这些格子留空,而"空白"和"没风险"在表格里长得一模一样——用户把漏检当成了安全,
|
||||
* 这正是最贵的那种静默失败。
|
||||
*/
|
||||
@@ -58,7 +59,11 @@ public final class AppearancePatentSheetBuilder {
|
||||
*/
|
||||
public static final String PENDING_REVIEW_SUFFIX = "·商标待复核";
|
||||
|
||||
private static final String NO_RESULT_REASON = NO_RESULT_TEXT + ":该行没有返回判定,重新运行任务可补检";
|
||||
private static final String NOT_INSPECTED_REASON = AppearancePatentRowOutcome.NOT_INSPECTED_TEXT
|
||||
+ ":该行没拿到判定,重新运行任务可补检";
|
||||
|
||||
private static final String NO_DATA_REASON = AppearancePatentRowOutcome.NO_DATA_TEXT
|
||||
+ ":请先在采集侧补齐该行数据";
|
||||
|
||||
public static void buildResultSheet(Workbook workbook, List<AppearancePatentParsedRowVo> rows,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap) {
|
||||
@@ -94,6 +99,8 @@ public final class AppearancePatentSheetBuilder {
|
||||
continue;
|
||||
}
|
||||
AppearancePatentResultRowDto resultRow = finder.apply(parsedRow);
|
||||
AppearancePatentRowOutcome.Kind kind = AppearancePatentRowOutcome.classify(parsedRow, resultRow);
|
||||
String outcomeMissingText = AppearancePatentRowOutcome.missingText(kind);
|
||||
Row row = sheet.createRow(rowIndex++);
|
||||
int col = 0;
|
||||
row.createCell(col++).setCellValue(firstNonBlank(parsedRow.getDisplayId(), parsedRow.getSourceId()));
|
||||
@@ -102,17 +109,18 @@ public final class AppearancePatentSheetBuilder {
|
||||
row.createCell(col++).setCellValue(readValueByHeader(parsedRow, "卖家名称", "卖家名", "卖家", "店铺名称", "店铺名", "seller name", "seller_name", "seller-name", "sellername", "store name", "shop name"));
|
||||
row.createCell(col++).setCellValue(resolveBrand(resultRow, parsedRow));
|
||||
row.createCell(col++).setCellValue(resolvePrice(resultRow));
|
||||
row.createCell(col++).setCellValue(resultRow == null ? firstNonBlank(parsedRow.getTitle(), "") : firstNonBlank(resultRow.getTitle(), parsedRow.getTitle()));
|
||||
row.createCell(col++).setCellValue(resultRow == null ? firstNonBlank(parsedRow.getUrl(), "") : firstNonBlank(resultRow.getUrl(), parsedRow.getUrl()));
|
||||
row.createCell(col++).setCellValue(firstNonBlank(AppearancePatentRowOutcome.titleOf(parsedRow, resultRow), ""));
|
||||
row.createCell(col++).setCellValue(firstNonBlank(AppearancePatentRowOutcome.urlOf(parsedRow, resultRow), ""));
|
||||
row.createCell(col++).setCellValue(resultRow == null ? firstNonBlank(parsedRow.getSku(), "") : firstNonBlank(resultRow.getSku(), parsedRow.getSku()));
|
||||
String titleRiskCell = resultRow == null
|
||||
? NO_RESULT_TEXT
|
||||
// 行级文案只在"整行什么都没带回来"时接管:带着 LLM 错误原文的行必须照原样显示错误,
|
||||
// 否则用户和运维都失去归因线索(这条是老用例 test_sheet_builder_llm_failure_user_facing_cells 撞出来的)
|
||||
boolean rowLevelText = kind != AppearancePatentRowOutcome.Kind.JUDGED
|
||||
&& AppearancePatentRowOutcome.carriesNothingToShow(resultRow);
|
||||
String titleRiskCell = rowLevelText ? outcomeMissingText
|
||||
: firstNonBlank(userFacingLlmCellValue(resultRow, resultRow.getTitleRisk()), NO_RESULT_TEXT);
|
||||
String appearanceRiskCell = resultRow == null
|
||||
? NO_RESULT_TEXT
|
||||
String appearanceRiskCell = rowLevelText ? outcomeMissingText
|
||||
: firstNonBlank(userFacingLlmCellValue(resultRow, resultRow.getAppearanceRisk()), NO_RESULT_TEXT);
|
||||
String conclusionCell = resultRow == null
|
||||
? NO_RESULT_TEXT
|
||||
String conclusionCell = rowLevelText ? outcomeMissingText
|
||||
: firstNonBlank(userFacingConclusion(resultRow), NO_RESULT_TEXT);
|
||||
row.createCell(col++).setCellValue(titleRiskCell);
|
||||
row.createCell(col++).setCellValue(appearanceRiskCell);
|
||||
@@ -148,15 +156,24 @@ public final class AppearancePatentSheetBuilder {
|
||||
AppearancePatentResultRowDto resultRow = finder.apply(parsedRow);
|
||||
Row row = sheet.createRow(rowIndex++);
|
||||
row.createCell(0).setCellValue(asin);
|
||||
// 只有"整行没结果"才代写原因;有结果的行原本就没原因可写(无风险),不能污染成缺失说明
|
||||
String missingReason = resultRow == null ? NO_RESULT_REASON : "";
|
||||
row.createCell(1).setCellValue(resultRow == null ? missingReason : firstNonBlank(resultRow.getAppearanceReason(), ""));
|
||||
row.createCell(2).setCellValue(resultRow == null ? missingReason : firstNonBlank(resultRow.getPatentReason(), ""));
|
||||
row.createCell(3).setCellValue(resultRow == null ? missingReason : firstNonBlank(resultRow.getTitleReason(), ""));
|
||||
// 只有"这行没给出结论"才代写原因;已判定的行原本就没原因可写(无风险),不能污染成缺失说明
|
||||
String missingReason = missingReason(AppearancePatentRowOutcome.classify(parsedRow, resultRow));
|
||||
row.createCell(1).setCellValue(resultRow == null ? missingReason : firstNonBlank(resultRow.getAppearanceReason(), missingReason));
|
||||
row.createCell(2).setCellValue(resultRow == null ? missingReason : firstNonBlank(resultRow.getPatentReason(), missingReason));
|
||||
row.createCell(3).setCellValue(resultRow == null ? missingReason : firstNonBlank(resultRow.getTitleReason(), missingReason));
|
||||
rowIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
/** 结论没出来时,「原因」sheet 要说清是哪一种没出来:没数据 / 没跑到 / 跑了没答上。 */
|
||||
private static String missingReason(AppearancePatentRowOutcome.Kind kind) {
|
||||
return switch (kind) {
|
||||
case NO_DATA -> NO_DATA_REASON;
|
||||
case NOT_INSPECTED -> NOT_INSPECTED_REASON;
|
||||
case JUDGED -> "";
|
||||
};
|
||||
}
|
||||
|
||||
public static AppearancePatentResultRowDto findResultRow(AppearancePatentParsedRowVo parsedRow,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap) {
|
||||
if (parsedRow == null || resultMap == null || resultMap.isEmpty()) {
|
||||
@@ -298,7 +315,7 @@ public final class AppearancePatentSheetBuilder {
|
||||
return preferred == null || preferred.isBlank() ? fallback : preferred.trim();
|
||||
}
|
||||
|
||||
private static String normalize(String val) {
|
||||
public static String normalize(String val) {
|
||||
return val == null ? "" : val.replace(String.valueOf((char) 0xFEFF), "").replace((char) 0x3000, ' ').trim().replaceAll("\\s+", " ");
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -94,6 +94,17 @@ public final class SimilarAsinResultTextSupport {
|
||||
return !normalized.isBlank() && !isTechnicalLlmFailure(normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* 交付口径:结果表真正给用户的两个判定列(相似度、是否同款)都得有可用文本,才算这行给出了结论。
|
||||
* 与 {@link #hasResolvedLlmFields} 的区别是后者是「十一个字段任一可用」——只填上 category 或 status
|
||||
* 的行会被读成「已经检测」,而它在表格里两列都是空的。这条先只做度量入口,不改既有行为。
|
||||
*/
|
||||
public static boolean hasDeliverableResult(SimilarAsinResultRowDto row) {
|
||||
return row != null
|
||||
&& hasUsableLlmField(row.getSimilarity())
|
||||
&& hasUsableLlmField(row.getIsConform());
|
||||
}
|
||||
|
||||
public static boolean hasResolvedLlmFields(SimilarAsinResultRowDto row) {
|
||||
if (row == null) {
|
||||
return false;
|
||||
|
||||
+20
-5
@@ -189,11 +189,16 @@ public class SimilarAsinResultWorkbookAssembler {
|
||||
List.of("不符合"),
|
||||
"[similar-asin] taskId=" + task.getId()
|
||||
);
|
||||
long undeliveredRows = captured.rows().stream()
|
||||
.map(row -> SimilarAsinChunkMergeSupport.findResultRow(row, sourceResultMap))
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.filter(resultRow -> !SimilarAsinResultTextSupport.hasDeliverableResult(resultRow))
|
||||
.count();
|
||||
writeResultWorkbook(xlsx, captured.rows(), sourceResultMap, taskImageCache, imageSpool);
|
||||
ensureResultAssemblyNotInterrupted();
|
||||
return new SourceResultWorkbook(
|
||||
xlsx, filename, captured.rows().size(), persistedRows,
|
||||
sourceResultMap.size(), resolvedRows, conformPropagated);
|
||||
sourceResultMap.size(), resolvedRows, conformPropagated, undeliveredRows);
|
||||
}));
|
||||
}
|
||||
try {
|
||||
@@ -235,9 +240,18 @@ public class SimilarAsinResultWorkbookAssembler {
|
||||
int conformPropagated = workbooks.stream()
|
||||
.mapToInt(SourceResultWorkbook::conformPropagated)
|
||||
.sum();
|
||||
log.info("[similar-asin] bounded assemble workbook taskId={} parsedRows={} persistedRows={} resultRows={} resolvedRows={} propagated={} sources={} costMs={}",
|
||||
long undeliveredRows = workbooks.stream()
|
||||
.mapToLong(SourceResultWorkbook::undeliveredRows)
|
||||
.sum();
|
||||
if (undeliveredRows > 0) {
|
||||
// 交付行账:货源这一面还没有覆盖率闸,先把「表格里两列空着的行」数出来并报警,
|
||||
// 有了真实分布才谈得上定阈值(不拿别的模块的数字当这里的基线)
|
||||
log.warn("[similar-asin] 交付行账不完整 taskId={} resultRows={} undeliveredRows={} sources={}",
|
||||
task.getId(), resultRows, undeliveredRows, sourceRows.size());
|
||||
}
|
||||
log.info("[similar-asin] bounded assemble workbook taskId={} parsedRows={} persistedRows={} resultRows={} resolvedRows={} propagated={} undeliveredRows={} sources={} costMs={}",
|
||||
task.getId(), parsedRows.size(), persistedResultRows, resultRows,
|
||||
resolvedRows, conformPropagated, sourceRows.size(),
|
||||
resolvedRows, conformPropagated, undeliveredRows, sourceRows.size(),
|
||||
System.currentTimeMillis() - assembleStart);
|
||||
if (resultRows == 0) {
|
||||
String failureSummary = chunkPayloadSupport.collectChunkReadFailureSummary(task.getId());
|
||||
@@ -1084,9 +1098,10 @@ public class SimilarAsinResultWorkbookAssembler {
|
||||
int persistedRows,
|
||||
int resultRows,
|
||||
long resolvedRows,
|
||||
int conformPropagated) {
|
||||
int conformPropagated,
|
||||
long undeliveredRows) {
|
||||
private SourceResultWorkbook(File file, String filename, int rowCount) {
|
||||
this(file, filename, rowCount, 0, 0, 0L, 0);
|
||||
this(file, filename, rowCount, 0, 0, 0L, 0, 0L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user