refactor(phase-3): 3A 拆薄第十笔——AP 交付闸门与补检出件,服务 1942→1827
This commit is contained in:
+21
-136
@@ -10,6 +10,7 @@ import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentChunkSubmissionSupport;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentChunkSubmissionSupport.PreparedSubmittedChunk;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentChunkSubmissionSupport.SubmitContext;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentDeliverySupport;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.support.AppearancePatentExcelParser;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.common.util.GroupResultPropagator;
|
||||
@@ -661,6 +662,20 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
taskFileJobService, taskProgressSnapshotService, objectMapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* E 聚类(交付闸门与补检)住在 {@link AppearancePatentDeliverySupport}(3A 拆薄第十笔):
|
||||
* 覆盖率判定、交付行账、缺口写消息、两条补检预算逐字搬移;按名反射点名的四枚保留同名薄委托。
|
||||
*/
|
||||
private AppearancePatentDeliverySupport deliverySupport() {
|
||||
return new AppearancePatentDeliverySupport(
|
||||
MODULE_TYPE, properties, taskCacheService, taskFileJobService, fileTaskMapper,
|
||||
payloadSupport()::readParsedPayload,
|
||||
(parsed, rows, fallback) -> splitRowsBySourceFile(parsed, rows, fallback),
|
||||
rowReader()::loadPersistedResultRowsForRowsWithRetry,
|
||||
rowReader()::findResultRow,
|
||||
this::firstNonBlank, this::normalize);
|
||||
}
|
||||
|
||||
/**
|
||||
* D 聚类(分片回传与范围状态)住在 {@link AppearancePatentChunkSubmissionSupport}
|
||||
* (3A 拆薄第九笔)。任务准入、归属、分组展开、行计数、载荷写入、序列化与收尾由本类回调交出。
|
||||
@@ -1151,24 +1166,7 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
*/
|
||||
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={} keys={} noDataRows={}",
|
||||
task.getId(), job.getId(), facts.missingRows(), keys.size(), facts.noDataRows());
|
||||
return true;
|
||||
}
|
||||
log.warn("[appearance-patent] 交付缺口补检排不上队,转失败兜底出口按补检预算处置 taskId={} jobId={} missingRows={}",
|
||||
task.getId(), job.getId(), facts.missingRows());
|
||||
throw new BusinessException("有 " + facts.missingRows() + " 行未完成检测,等待补检轮");
|
||||
return deliverySupport().requestRecheckForMissingRows(task, job, facts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1177,18 +1175,7 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
* {@link AppearancePatentRowOutcome#summarize},两边不许各判一套。
|
||||
*/
|
||||
private AppearancePatentRowOutcome.Facts measureDeliveryFacts(FileTaskEntity task, FileResultEntity result) {
|
||||
AppearancePatentParsedPayloadDto parsed = payloadSupport().readParsedPayload(task);
|
||||
List<AppearancePatentParsedRowVo> parsedRows = parsed.getAllItems() == null
|
||||
? List.of() : parsed.getAllItems();
|
||||
AppearancePatentRowOutcome.Facts facts = AppearancePatentRowOutcome.Facts.EMPTY;
|
||||
for (AppearancePatentResultPackager.SourceRows item
|
||||
: splitRowsBySourceFile(parsed, parsedRows, result.getSourceFilename())) {
|
||||
Map<String, AppearancePatentResultRowDto> resultMap =
|
||||
rowReader().loadPersistedResultRowsForRowsWithRetry(task.getId(), item.rows());
|
||||
facts = facts.plus(AppearancePatentRowOutcome.summarize(
|
||||
item.rows(), row -> rowReader().findResultRow(row, resultMap)));
|
||||
}
|
||||
return facts;
|
||||
return deliverySupport().measureDeliveryFacts(task, result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1204,33 +1191,7 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
*/
|
||||
private boolean scheduleFallbackRecheck(FileTaskEntity task, FileResultEntity result,
|
||||
AppearancePatentRowOutcome.Facts facts) {
|
||||
int maxRounds = properties.getRecheckMaxRounds();
|
||||
if (task == null || task.getId() == null || result == null || result.getId() == null
|
||||
|| facts == null || maxRounds <= 0) {
|
||||
return false;
|
||||
}
|
||||
long done = taskCacheService.recheckRounds(task.getId());
|
||||
if (done >= maxRounds) {
|
||||
log.warn("[appearance-patent] 补检预算已耗尽,按已有结果交付 taskId={} rounds={}/{}",
|
||||
task.getId(), done, maxRounds);
|
||||
return false;
|
||||
}
|
||||
if (facts.missingRows() <= 0 || facts.missingKeys().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
taskCacheService.releaseRowInspection(task.getId(), facts.missingKeys(), true);
|
||||
TaskFileJobEntity reset = taskFileJobService.resetTerminalFailedForRecovery(
|
||||
task.getId(), MODULE_TYPE, result.getId());
|
||||
if (reset == null || !"PENDING".equals(reset.getStatus())) {
|
||||
log.warn("[appearance-patent] 失败兜底出口补检重排未接上,按已有结果交付 taskId={} resultId={} jobStatus={}",
|
||||
task.getId(), result.getId(), reset == null ? "ABSENT" : reset.getStatus());
|
||||
return false;
|
||||
}
|
||||
// 轮次只在重排真的接上之后才记:否则"没接上"也要扣一轮,预算会被失败的重排自己吃光
|
||||
taskCacheService.countRecheckRound(task.getId());
|
||||
log.warn("[appearance-patent] 失败兜底出口触发补检轮 taskId={} jobId={} round={}/{} missingRows={} keys={}",
|
||||
task.getId(), reset.getId(), done + 1, maxRounds, facts.missingRows(), facts.missingKeys().size());
|
||||
return true;
|
||||
return deliverySupport().scheduleFallbackRecheck(task, result, facts);
|
||||
}
|
||||
|
||||
private boolean completeLlmFileJob(FileTaskEntity task,
|
||||
@@ -1571,83 +1532,12 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
List<AppearancePatentParsedRowVo> parsedRows,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap,
|
||||
boolean allowPartial) {
|
||||
if (parsedRows == null || parsedRows.isEmpty()) {
|
||||
return AppearancePatentRowOutcome.Facts.EMPTY;
|
||||
}
|
||||
AppearancePatentRowOutcome.Facts facts =
|
||||
AppearancePatentRowOutcome.summarize(parsedRows, row -> rowReader().findResultRow(row, resultMap));
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
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();
|
||||
// 已判失败的任务走的是"按已有分片出部分结果"这条既有口径,这里再抛会把成品彻底拿掉;
|
||||
// 失败兜底路径(allowPartial=true,作业已判死)同理放行。
|
||||
// 两者都不再静默:上面的行账锚点必打,缺口由调用方写进任务错误信息,用户看得到「N 行没检测」。
|
||||
if (!taskAlreadyFailed && !allowPartial && 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;
|
||||
}
|
||||
for (AppearancePatentParsedRowVo parsedRow : parsedRows) {
|
||||
if (samples.size() >= 5) {
|
||||
break;
|
||||
}
|
||||
if (parsedRow == null) {
|
||||
continue;
|
||||
}
|
||||
if (AppearancePatentRowOutcome.classify(parsedRow, rowReader().findResultRow(parsedRow, resultMap))
|
||||
!= AppearancePatentRowOutcome.Kind.NOT_INSPECTED) {
|
||||
continue;
|
||||
}
|
||||
samples.add(firstNonBlank(parsedRow.getAsin(),
|
||||
firstNonBlank(parsedRow.getDisplayId(), "")));
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
private String noDataSuffix(AppearancePatentRowOutcome.Facts facts) {
|
||||
return facts.noDataRows() > 0
|
||||
? ";另有 " + facts.noDataRows() + " 行未采集到数据、无法检测"
|
||||
: "";
|
||||
return deliverySupport().validateCompleteLlmCoverage(taskId, parsedRows, resultMap, allowPartial);
|
||||
}
|
||||
|
||||
/** 交付缺口写进任务错误信息:让后台列表与用户端都能看到「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;
|
||||
return deliverySupport().appendDeliveryGapMessage(existingError, facts);
|
||||
}
|
||||
|
||||
|
||||
@@ -1667,12 +1557,7 @@ public class AppearancePatentTaskService extends AbstractFileTaskPipeline<Appear
|
||||
|
||||
|
||||
private boolean hasReasonFields(AppearancePatentResultRowDto row) {
|
||||
if (row == null) {
|
||||
return false;
|
||||
}
|
||||
return !normalize(row.getAppearanceReason()).isBlank()
|
||||
|| !normalize(row.getPatentReason()).isBlank()
|
||||
|| !normalize(row.getTitleReason()).isBlank();
|
||||
return deliverySupport().hasReasonFields(row);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+297
@@ -0,0 +1,297 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.service.support;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.task.TaskStatuses;
|
||||
import com.nanri.aiimage.config.AppearancePatentProperties;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentParsedPayloadDto;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentResultRowDto;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentParsedRowVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentTaskCacheService;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileResultEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskFileJobService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 外观专利的交付闸门与补检(E 聚类之一),从 {@code AppearancePatentTaskService} <b>原样搬移</b>
|
||||
* (3A 拆薄第十笔):覆盖率判定、交付行账、缺口写消息、两条补检预算(回传链路与失败兜底出口)。
|
||||
*
|
||||
* <p>无状态、按调用现取(与 {@code historyAssembler()} 同一先例),不新增 Spring bean。
|
||||
* 行读取、载荷读取、分片切分与首非空归一由宿主以回调交出,本件不直接持有那些件。
|
||||
*/
|
||||
@Slf4j
|
||||
public class AppearancePatentDeliverySupport {
|
||||
|
||||
private static final String STATUS_FAILED = TaskStatuses.FileTask.FAILED;
|
||||
|
||||
private final String moduleType;
|
||||
private final AppearancePatentProperties properties;
|
||||
private final AppearancePatentTaskCacheService taskCacheService;
|
||||
private final TaskFileJobService taskFileJobService;
|
||||
private final FileTaskMapper fileTaskMapper;
|
||||
private final PayloadReader payloadReader;
|
||||
private final RowSplitter rowSplitter;
|
||||
private final ResultRowLoader resultRowLoader;
|
||||
private final ResultRowFinder resultRowFinder;
|
||||
private final FirstNonBlank firstNonBlank;
|
||||
private final Normalizer normalizer;
|
||||
|
||||
public interface PayloadReader {
|
||||
AppearancePatentParsedPayloadDto read(FileTaskEntity task);
|
||||
}
|
||||
|
||||
public interface RowSplitter {
|
||||
List<AppearancePatentResultPackager.SourceRows> split(AppearancePatentParsedPayloadDto parsed,
|
||||
List<AppearancePatentParsedRowVo> rows,
|
||||
String fallbackFilename);
|
||||
}
|
||||
|
||||
public interface ResultRowLoader {
|
||||
Map<String, AppearancePatentResultRowDto> load(Long taskId, List<AppearancePatentParsedRowVo> rows);
|
||||
}
|
||||
|
||||
public interface ResultRowFinder {
|
||||
AppearancePatentResultRowDto find(AppearancePatentParsedRowVo row,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap);
|
||||
}
|
||||
|
||||
public interface FirstNonBlank {
|
||||
String pick(String preferred, String fallback);
|
||||
}
|
||||
|
||||
public interface Normalizer {
|
||||
String normalize(String value);
|
||||
}
|
||||
|
||||
public AppearancePatentDeliverySupport(String moduleType,
|
||||
AppearancePatentProperties properties,
|
||||
AppearancePatentTaskCacheService taskCacheService,
|
||||
TaskFileJobService taskFileJobService,
|
||||
FileTaskMapper fileTaskMapper,
|
||||
PayloadReader payloadReader,
|
||||
RowSplitter rowSplitter,
|
||||
ResultRowLoader resultRowLoader,
|
||||
ResultRowFinder resultRowFinder,
|
||||
FirstNonBlank firstNonBlank,
|
||||
Normalizer normalizer) {
|
||||
this.moduleType = moduleType;
|
||||
this.properties = properties;
|
||||
this.taskCacheService = taskCacheService;
|
||||
this.taskFileJobService = taskFileJobService;
|
||||
this.fileTaskMapper = fileTaskMapper;
|
||||
this.payloadReader = payloadReader;
|
||||
this.rowSplitter = rowSplitter;
|
||||
this.resultRowLoader = resultRowLoader;
|
||||
this.resultRowFinder = resultRowFinder;
|
||||
this.firstNonBlank = firstNonBlank;
|
||||
this.normalizer = normalizer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 有行没跑完就先别把半张表当成品发:撤销这些行的检测标记(完成态与处理中都要撤,
|
||||
* 否则 {@code beginRowInspection} 下一轮仍然申领不到它们),把作业排回队列补检一轮。
|
||||
*
|
||||
* <p>排不上队时**不许**退化成"按已有结果交付"。现网(2026-10-19)四例
|
||||
* {@code 交付缺口补检排不上队,按已有结果交付} 的 missingRows 是 112/455/1471/2110,
|
||||
* 作业全部 {@code retry_count=5}——把预算抛满的恰恰是"还没检完"(覆盖率抛、空结果抛),
|
||||
* 于是 {@code requeue} 那条 {@code retry_count < MAX} 的闸自我锁死:越慢越补不上。
|
||||
* 这里改吃抛:让作业走到终态失败,由 {@code fallbackAssembleResultFile} 按**补检自己的**
|
||||
* 预算({@code recheckMaxRounds})决定重排还是放行,两条预算不再互相占用。
|
||||
*
|
||||
* <p>行级重发次数仍受 {@code llmRowMaxRounds} 约束(到顶的行会被判死并写上
|
||||
* 「重发轮次已达上限」的结论,从此不再是空行),所以这条不会无限循环。
|
||||
*/
|
||||
public 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={} keys={} noDataRows={}",
|
||||
task.getId(), job.getId(), facts.missingRows(), keys.size(), facts.noDataRows());
|
||||
return true;
|
||||
}
|
||||
log.warn("[appearance-patent] 交付缺口补检排不上队,转失败兜底出口按补检预算处置 taskId={} jobId={} missingRows={}",
|
||||
task.getId(), job.getId(), facts.missingRows());
|
||||
throw new BusinessException("有 " + facts.missingRows() + " 行未完成检测,等待补检轮");
|
||||
}
|
||||
|
||||
/**
|
||||
* 只量行账、不出表。补检的决定必须做在 {@code assembleResultWorkbook} 之前,而那一跑完就把
|
||||
* 成品传上 OSS 并挂好了 {@code resultFileUrl}。判据与出表共用
|
||||
* {@link AppearancePatentRowOutcome#summarize},两边不许各判一套。
|
||||
*/
|
||||
public AppearancePatentRowOutcome.Facts measureDeliveryFacts(FileTaskEntity task, FileResultEntity result) {
|
||||
AppearancePatentParsedPayloadDto parsed = payloadReader.read(task);
|
||||
List<AppearancePatentParsedRowVo> parsedRows = parsed.getAllItems() == null
|
||||
? List.of() : parsed.getAllItems();
|
||||
AppearancePatentRowOutcome.Facts facts = AppearancePatentRowOutcome.Facts.EMPTY;
|
||||
for (AppearancePatentResultPackager.SourceRows item
|
||||
: rowSplitter.split(parsed, parsedRows, result.getSourceFilename())) {
|
||||
Map<String, AppearancePatentResultRowDto> resultMap =
|
||||
resultRowLoader.load(task.getId(), item.rows());
|
||||
facts = facts.plus(AppearancePatentRowOutcome.summarize(
|
||||
item.rows(), row -> resultRowFinder.find(row, resultMap)));
|
||||
}
|
||||
return facts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败兜底出口上的第二条补检预算。
|
||||
*
|
||||
* <p>{@code fallbackAssembleResultFile} 的注释原来断言「作业已判死,缺口不再有补齐窗口」,
|
||||
* 现网读数证明它是假的:底座早就有 {@code resetTerminalFailedForRecovery}(终态失败且 retry
|
||||
* 到顶 ⇒ retryCount 清零、重回 PENDING、重派发),补传恢复那条路一直在用它,只有交付缺口
|
||||
* 这条路没接上。轮次上限走 Redis 的 {@code recheckMaxRounds},与作业重试预算彻底分开——
|
||||
* 「因为慢而抛满重试」不再等于「永远补不了」。
|
||||
*
|
||||
* <p>预算耗尽、或重排没接上时仍按已有结果出表:「起码失败了也可以下载」那条保证不变。
|
||||
*/
|
||||
public boolean scheduleFallbackRecheck(FileTaskEntity task, FileResultEntity result,
|
||||
AppearancePatentRowOutcome.Facts facts) {
|
||||
int maxRounds = properties.getRecheckMaxRounds();
|
||||
if (task == null || task.getId() == null || result == null || result.getId() == null
|
||||
|| facts == null || maxRounds <= 0) {
|
||||
return false;
|
||||
}
|
||||
long done = taskCacheService.recheckRounds(task.getId());
|
||||
if (done >= maxRounds) {
|
||||
log.warn("[appearance-patent] 补检预算已耗尽,按已有结果交付 taskId={} rounds={}/{}",
|
||||
task.getId(), done, maxRounds);
|
||||
return false;
|
||||
}
|
||||
if (facts.missingRows() <= 0 || facts.missingKeys().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
taskCacheService.releaseRowInspection(task.getId(), facts.missingKeys(), true);
|
||||
TaskFileJobEntity reset = taskFileJobService.resetTerminalFailedForRecovery(
|
||||
task.getId(), moduleType, result.getId());
|
||||
if (reset == null || !"PENDING".equals(reset.getStatus())) {
|
||||
log.warn("[appearance-patent] 失败兜底出口补检重排未接上,按已有结果交付 taskId={} resultId={} jobStatus={}",
|
||||
task.getId(), result.getId(), reset == null ? "ABSENT" : reset.getStatus());
|
||||
return false;
|
||||
}
|
||||
// 轮次只在重排真的接上之后才记:否则"没接上"也要扣一轮,预算会被失败的重排自己吃光
|
||||
taskCacheService.countRecheckRound(task.getId());
|
||||
log.warn("[appearance-patent] 失败兜底出口触发补检轮 taskId={} jobId={} round={}/{} missingRows={} keys={}",
|
||||
task.getId(), reset.getId(), done + 1, maxRounds, facts.missingRows(), facts.missingKeys().size());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖率判定:分母必须是**真正会写进结果文件的那批行**,且"该行有没有数据"要同时看
|
||||
* 用户上传表的解析行与客户端回传的结果行——只看解析行,用户表不带标题列时分母恒为 0,
|
||||
* 闸门对整份文件失明(现网 6 份已交付文件里 20%–51% 空行、零告警就是这么来的)。
|
||||
* 判据本身在 {@link AppearancePatentRowOutcome#summarize},与表格文案共用一套,不许两边各判。
|
||||
*/
|
||||
public AppearancePatentRowOutcome.Facts validateCompleteLlmCoverage(Long taskId,
|
||||
List<AppearancePatentParsedRowVo> parsedRows,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap) {
|
||||
return validateCompleteLlmCoverage(taskId, parsedRows, resultMap, false);
|
||||
}
|
||||
|
||||
public AppearancePatentRowOutcome.Facts validateCompleteLlmCoverage(Long taskId,
|
||||
List<AppearancePatentParsedRowVo> parsedRows,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap,
|
||||
boolean allowPartial) {
|
||||
if (parsedRows == null || parsedRows.isEmpty()) {
|
||||
return AppearancePatentRowOutcome.Facts.EMPTY;
|
||||
}
|
||||
AppearancePatentRowOutcome.Facts facts =
|
||||
AppearancePatentRowOutcome.summarize(parsedRows, row -> resultRowFinder.find(row, resultMap));
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
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();
|
||||
// 已判失败的任务走的是"按已有分片出部分结果"这条既有口径,这里再抛会把成品彻底拿掉;
|
||||
// 失败兜底路径(allowPartial=true,作业已判死)同理放行。
|
||||
// 两者都不再静默:上面的行账锚点必打,缺口由调用方写进任务错误信息,用户看得到「N 行没检测」。
|
||||
if (!taskAlreadyFailed && !allowPartial && 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;
|
||||
}
|
||||
for (AppearancePatentParsedRowVo parsedRow : parsedRows) {
|
||||
if (samples.size() >= 5) {
|
||||
break;
|
||||
}
|
||||
if (parsedRow == null) {
|
||||
continue;
|
||||
}
|
||||
if (AppearancePatentRowOutcome.classify(parsedRow, resultRowFinder.find(parsedRow, resultMap))
|
||||
!= AppearancePatentRowOutcome.Kind.NOT_INSPECTED) {
|
||||
continue;
|
||||
}
|
||||
samples.add(firstNonBlank.pick(parsedRow.getAsin(),
|
||||
firstNonBlank.pick(parsedRow.getDisplayId(), "")));
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
private String noDataSuffix(AppearancePatentRowOutcome.Facts facts) {
|
||||
return facts.noDataRows() > 0
|
||||
? ";另有 " + facts.noDataRows() + " 行未采集到数据、无法检测"
|
||||
: "";
|
||||
}
|
||||
|
||||
/** 交付缺口写进任务错误信息:让后台列表与用户端都能看到「N 行没检测完」,而不是只有一张半空表。 */
|
||||
public 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.pick(existingError, "");
|
||||
if (existing.contains("未完成检测") || existing.contains("未采集到数据")) {
|
||||
return existing;
|
||||
}
|
||||
return existing.isBlank() ? gap.toString() : existing + ";" + gap;
|
||||
}
|
||||
|
||||
public boolean hasReasonFields(AppearancePatentResultRowDto row) {
|
||||
if (row == null) {
|
||||
return false;
|
||||
}
|
||||
return !normalizer.normalize(row.getAppearanceReason()).isBlank()
|
||||
|| !normalizer.normalize(row.getPatentReason()).isBlank()
|
||||
|| !normalizer.normalize(row.getTitleReason()).isBlank();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user