后端(补提交): 上一笔 pathspec 漏了 4 个未跟踪新文件——提交树本身编译不过

122faf7c 用 -- 指定路径提交,未跟踪文件不会被带上(共树下这是同一个坑第二次):
AppearancePatentRowOutcome 是主代码新引用的判据类,缺它就是一棵编译不过的树;
三支新用例(行结局分类 15 例 / 交付闸门 9 例 / 货源交付口径 3 例)同理。
This commit is contained in:
2026-10-10 11:33:20 +08:00
parent 122faf7c74
commit 09867f612d
4 changed files with 891 additions and 0 deletions
@@ -0,0 +1,184 @@
package com.nanri.aiimage.modules.appearancepatent.service.support;
import com.nanri.aiimage.modules.appearancepatent.model.dto.AppearancePatentResultRowDto;
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentParsedRowVo;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
/**
* 一行「没出结论」到底是哪一种原因的唯一点径:交付表格的文案与覆盖率闸门的分母共用这里。
*
* <p>历史上两边各判各的:闸门按**用户上传表的解析行**有没有标题/图片决定这行算不算
* 「该被检测」,而表格按**客户端回传的结果行**有没有标题/图片决定这行有没有结论。
* 现网(2026-10-06~10-09 实测 6 份已交付文件)用户表常只给 id/ASIN/国家,标题与图片链接
* 全靠采集回传 ⇒ 解析行两列恒空 ⇒ 闸门分母为 0、整段不判,表里 20%–51% 的行写着
* 「未取得检测结果」而日志里一条覆盖率告警都没有。
*/
public final class AppearancePatentRowOutcome {
public enum Kind {
/** 三维结论齐了,正常交付。 */
JUDGED,
/** 该行有数据、本该检出,但没有可用结论:检测没跑到或结果丢了。 */
NOT_INSPECTED,
/** 连标题和图片都没采集到,无从检测。 */
NO_DATA
}
/**
* 「有数据却没检」的专用文案。它和 {@link AppearancePatentSheetBuilder#NO_RESULT_TEXT}
* 必须分开:后者意味着"检了但没答上",前者意味着"根本没跑到这一行",
* 用户拿到的处置动作完全不同(等补检 / 重新发起)。
*/
public static final String NOT_INSPECTED_TEXT = "该行未完成检测(任务提前结束),重新运行可补检";
public static final String NO_DATA_TEXT = "该行未采集到数据(标题与图片都没有),无法检测";
private AppearancePatentRowOutcome() {
}
public static Kind classify(AppearancePatentParsedRowVo parsedRow,
AppearancePatentResultRowDto resultRow) {
if (isJudged(resultRow)) {
return Kind.JUDGED;
}
return hasCheckableData(parsedRow, resultRow) ? Kind.NOT_INSPECTED : Kind.NO_DATA;
}
/** 交付口径的"这行有结论":标题维、外观维、结论三列都得有可用文本(结论依赖前两者)。 */
public static boolean isJudged(AppearancePatentResultRowDto resultRow) {
return resultRow != null
&& isUsableField(resultRow.getTitleRisk())
&& isUsableField(resultRow.getAppearanceRisk())
&& isUsableField(resultRow.getConclusion());
}
public static boolean isUsableField(String value) {
String normalized = AppearancePatentSheetBuilder.normalize(value);
return !normalized.isBlank() && !AppearancePatentSheetBuilder.isTechnicalLlmFailure(normalized);
}
/**
* 行上有没有任何能展示给用户的东西(三个维度、结论、错误原文)。
* 全空才由行级文案({@link #NOT_INSPECTED_TEXT} / {@link #NO_DATA_TEXT})接管;
* 只要带着错误原文,就让它照原样进格子——把「LLM http 503 模型过载」盖成泛化文案,
* 用户和运维都失去归因线索。
*/
public static boolean carriesNothingToShow(AppearancePatentResultRowDto resultRow) {
return resultRow == null
|| (isBlank(resultRow.getTitleRisk()) && isBlank(resultRow.getAppearanceRisk())
&& isBlank(resultRow.getConclusion()) && isBlank(resultRow.getError()));
}
private static boolean isBlank(String value) {
return AppearancePatentSheetBuilder.normalize(value).isBlank();
}
/**
* 这行到底有没有东西可检——解析行与回传行**任一处**有标题或图片链接就算有。
* 只看解析行是历史缺陷:数据在回传行上,闸门因此对整份文件失明。
*/
public static boolean hasCheckableData(AppearancePatentParsedRowVo parsedRow,
AppearancePatentResultRowDto resultRow) {
return !titleOf(parsedRow, resultRow).isBlank() || !urlOf(parsedRow, resultRow).isBlank();
}
public static String titleOf(AppearancePatentParsedRowVo parsedRow,
AppearancePatentResultRowDto resultRow) {
String fromResult = resultRow == null ? "" : AppearancePatentSheetBuilder.normalize(resultRow.getTitle());
String fromParsed = parsedRow == null ? "" : AppearancePatentSheetBuilder.normalize(parsedRow.getTitle());
return fromResult.isBlank() ? fromParsed : fromResult;
}
public static String urlOf(AppearancePatentParsedRowVo parsedRow,
AppearancePatentResultRowDto resultRow) {
String fromResult = resultRow == null ? "" : AppearancePatentSheetBuilder.normalize(resultRow.getUrl());
String fromParsed = parsedRow == null ? "" : AppearancePatentSheetBuilder.normalize(parsedRow.getUrl());
return fromResult.isBlank() ? fromParsed : fromResult;
}
/** 未完成检测的行在格子里写什么;已判定的行不走这里。 */
public static String missingText(Kind kind) {
return switch (kind) {
case NO_DATA -> NO_DATA_TEXT;
case NOT_INSPECTED -> NOT_INSPECTED_TEXT;
case JUDGED -> "";
};
}
/**
* 按交付口径数一遍行账。
*
* @param rows 真正会写进结果文件的行集(与出表同一集合,不许自挑)
* @param finder 与出表同一个取结果函数,保证"闸门看到的行"="表格里的行"
*/
public static Facts summarize(List<AppearancePatentParsedRowVo> rows,
Function<AppearancePatentParsedRowVo, AppearancePatentResultRowDto> finder) {
int expected = 0;
int judged = 0;
int noData = 0;
Set<String> missingKeys = new LinkedHashSet<>();
List<AppearancePatentParsedRowVo> rowsToRead = rows == null ? List.of() : rows;
for (AppearancePatentParsedRowVo parsedRow : rowsToRead) {
if (parsedRow == null) {
continue;
}
AppearancePatentResultRowDto resultRow = finder == null ? null : finder.apply(parsedRow);
Kind kind = classify(parsedRow, resultRow);
if (kind == Kind.NO_DATA) {
noData++;
continue;
}
expected++;
if (kind == Kind.JUDGED) {
judged++;
continue;
}
addIfPresent(missingKeys, AppearancePatentSheetBuilder.rowKey(parsedRow));
if (resultRow != null) {
addIfPresent(missingKeys, AppearancePatentSheetBuilder.rowKey(resultRow));
}
}
return new Facts(expected, judged, noData, List.copyOf(missingKeys));
}
private static void addIfPresent(Set<String> target, String value) {
if (value != null && !value.isBlank()) {
target.add(value);
}
}
/**
* @param expectedRows 该被检测的行数(分母,交付口径)
* @param judgedRows 其中拿到完整结论的行数(分子)
* @param noDataRows 连数据都没采集到、无从检测的行数(进文案,不进分母)
* @param missingKeys 未完成检测行的行键,供补检轮撤销标记重新申领
*/
public record Facts(int expectedRows, int judgedRows, int noDataRows, List<String> missingKeys) {
public static final Facts EMPTY = new Facts(0, 0, 0, List.of());
public int missingRows() {
return Math.max(0, expectedRows - judgedRows);
}
/** 分母为 0 时按 1 计:一个该检的行都没有,不存在"覆盖率不足"。 */
public double coverage() {
return expectedRows <= 0 ? 1D : (double) judgedRows / expectedRows;
}
public Facts plus(Facts other) {
if (other == null) {
return this;
}
List<String> keys = new ArrayList<>(missingKeys);
keys.addAll(other.missingKeys());
return new Facts(expectedRows + other.expectedRows(), judgedRows + other.judgedRows(),
noDataRows + other.noDataRows(), List.copyOf(new LinkedHashSet<>(keys)));
}
}
}