fix(外观专利): 整批商标查询无一返回时表上改说「上游整体不可用」
2026-10-19 现网取证:品牌库代理套餐过期(供应商回 {"code":-1,"message":"套餐不存在"})
→ 16890 代理池恒为 0、一次代理都没挂上 → 全部直连打 WIPO branddb 被整片 Forbidden
→ 交付表 11 行全写「商标查询失败」。逐行失败可能是那个词本身查不了,整批全失败只可能
是上游挂了,两者在表上必须长得不一样;否则运维故障被伪装成数据问题,用户看不出该做什么。
新文案保留「商标查询失败」前缀,让三处既有语义逐字不变:
- isBrandQueryFailed() 继续成立
- buildConclusion 该支从返回常量改为返回 titleRisk(旧输入输出相同,新输入自动带原因)
- resolveResultStatus:新文案不含「侵权」二字,照旧判「失败」(已单独钉桩)
判据刻意保守:任一行拿到过侵权命中、或任一行查成功过即不升级;没发过查询的行
(LLM 已判「无」、标题为空)不参与判定,否则一批"无需查"的行会被误判成上游故障。
表上仍不会出现「欠费」二字——那个信息只存在于 16890 内部,Java 侧看不见。要把
message 一路带到表格,需先给 /root/BrandTesting 建版本控制再改它的响应契约。
AppearancePatentLlmClientTest 14 例 / SheetBuilder 15 例 / BrandBatch 3 例 /
BrandCheckClient* 12 例全绿;整个 test 源集 546 类编译通过,证明 applyResult
签名改动无漏改调用方。
This commit is contained in:
+52
-6
@@ -52,6 +52,19 @@ public class AppearancePatentLlmClient {
|
||||
private static final String INFRINGEMENT = "侵权";
|
||||
private static final String NO_INFRINGEMENT = "无侵权";
|
||||
private static final String BRAND_QUERY_FAILED = "商标查询失败";
|
||||
/**
|
||||
* 整批待查词无一返回结果时的文案,与逐行的「商标查询失败」区分开。
|
||||
*
|
||||
* <p>逐行失败还可能是那个词本身查不了;整批全失败只可能是上游整体不可用。2026-10-19 现网
|
||||
* 就是这样:品牌库的代理套餐过期(供应商回 {@code {"code":-1,"message":"套餐不存在"}}),
|
||||
* 16890 的代理池恒为 0、一次代理都没挂上,全部直连打 WIPO branddb 被整片 Forbidden,
|
||||
* 而交付表上每行只写「商标查询失败」——既看不出这是运维故障,更看不出该去续什么。
|
||||
*
|
||||
* <p>保留「商标查询失败」前缀:{@link #isBrandQueryFailed} 的既有判定、以及状态列
|
||||
* {@code resolveResultStatus}(不含「侵权」即判失败)都因此逐字不变。
|
||||
*/
|
||||
static final String BRAND_UPSTREAM_UNAVAILABLE =
|
||||
"商标查询失败:品牌库上游整体不可用(本批待查词无一返回结果,非本行数据问题)";
|
||||
private static final String APPEARANCE_ANOMALY = "外观识别异常";
|
||||
private static final String MISSING_ROW_DATA = "爬虫数据缺失";
|
||||
|
||||
@@ -220,8 +233,9 @@ public class AppearancePatentLlmClient {
|
||||
*/
|
||||
private void applyLlmRowsInOneBatch(List<AppearancePatentResultRowDto> llmRows, List<LlmResult> llmResults) {
|
||||
List<BrandCheckClient.BrandCheckBatchResult> brandChecks = brandChecksFor(llmResults);
|
||||
boolean brandUpstreamUnavailable = brandUpstreamUnavailable(brandChecks);
|
||||
for (int k = 0; k < llmRows.size(); k++) {
|
||||
applyResult(llmRows.get(k), llmResults.get(k), brandChecks.get(k));
|
||||
applyResult(llmRows.get(k), llmResults.get(k), brandChecks.get(k), brandUpstreamUnavailable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -979,9 +993,10 @@ public class AppearancePatentLlmClient {
|
||||
resolved.add(result);
|
||||
}
|
||||
List<BrandCheckClient.BrandCheckBatchResult> brandChecks = brandChecksFor(resolved);
|
||||
boolean brandUpstreamUnavailable = brandUpstreamUnavailable(brandChecks);
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
AppearancePatentResultRowDto row = copy(rows.get(i));
|
||||
applyResult(row, resolved.get(i), brandChecks.get(i));
|
||||
applyResult(row, resolved.get(i), brandChecks.get(i), brandUpstreamUnavailable);
|
||||
merged.add(row);
|
||||
}
|
||||
return merged;
|
||||
@@ -1035,15 +1050,38 @@ public class AppearancePatentLlmClient {
|
||||
return Arrays.asList(byRowIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 整批待查词是否无一返回可用结果——用来把「上游整体挂了」和「这个词查不了」分开写。
|
||||
*
|
||||
* <p>判据刻意保守:只要有任何一行拿到过侵权命中、或有任何一行查成功过,就不算整体不可用,
|
||||
* 仍按逐行的「商标查询失败」写。没发过查询的行(LLM 已判「无」、或标题为空)不参与判定,
|
||||
* 否则一批全是"无需查"的行会被误判成上游故障。
|
||||
*/
|
||||
private static boolean brandUpstreamUnavailable(
|
||||
List<BrandCheckClient.BrandCheckBatchResult> brandChecks) {
|
||||
boolean anyChecked = false;
|
||||
for (BrandCheckClient.BrandCheckBatchResult check : brandChecks) {
|
||||
if (check == null || check.brands() == null || check.brands().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
anyChecked = true;
|
||||
if (check.hasFailedData() || !check.hasQueryFailedData()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return anyChecked;
|
||||
}
|
||||
|
||||
void applyResult(AppearancePatentResultRowDto row, LlmResult result,
|
||||
BrandCheckClient.BrandCheckBatchResult brandCheck) {
|
||||
BrandCheckClient.BrandCheckBatchResult brandCheck,
|
||||
boolean brandUpstreamUnavailable) {
|
||||
if (row == null || result == null) {
|
||||
return;
|
||||
}
|
||||
if (isNoTitleRisk(result)) {
|
||||
row.setTitleRisk(NO_INFRINGEMENT);
|
||||
} else if (shouldCheckBrand(result)) {
|
||||
row.setTitleRisk(buildTitleRisk(result.title(), brandCheck));
|
||||
row.setTitleRisk(buildTitleRisk(result.title(), brandCheck, brandUpstreamUnavailable));
|
||||
} else {
|
||||
row.setTitleRisk("");
|
||||
}
|
||||
@@ -1069,6 +1107,11 @@ public class AppearancePatentLlmClient {
|
||||
}
|
||||
|
||||
String buildTitleRisk(String llmTitle, BrandCheckClient.BrandCheckBatchResult brandCheck) {
|
||||
return buildTitleRisk(llmTitle, brandCheck, false);
|
||||
}
|
||||
|
||||
String buildTitleRisk(String llmTitle, BrandCheckClient.BrandCheckBatchResult brandCheck,
|
||||
boolean brandUpstreamUnavailable) {
|
||||
List<String> brands = brandCheck == null ? List.of() : brandCheck.brands();
|
||||
if (brands == null || brands.isEmpty()) {
|
||||
return firstNonBlank(llmTitle, "");
|
||||
@@ -1077,7 +1120,8 @@ public class AppearancePatentLlmClient {
|
||||
return INFRINGEMENT;
|
||||
}
|
||||
if (brandCheck.hasQueryFailedData()) {
|
||||
return BRAND_QUERY_FAILED;
|
||||
// 命中过侵权就说明上游至少在返回结果,那种行优先给真实结论,不升级成整批口径。
|
||||
return brandUpstreamUnavailable ? BRAND_UPSTREAM_UNAVAILABLE : BRAND_QUERY_FAILED;
|
||||
}
|
||||
return NO_INFRINGEMENT;
|
||||
}
|
||||
@@ -1092,9 +1136,11 @@ public class AppearancePatentLlmClient {
|
||||
if (isBrandQueryFailed(titleRisk)) {
|
||||
// 外观已经判出「无侵权」时别把它整格盖掉:这一行缺的只是商标那一维,
|
||||
// 结论要说「外观无侵权·商标待复核」,用户才不会把已判出的外观结论读成"整单没检测"。
|
||||
// 另一支回 titleRisk 而不是常量:整批不可用那套长文案要原样传到结论列。
|
||||
// 逐行失败时 titleRisk 本就等于该常量,所以旧输入的输出逐字不变。
|
||||
return isNoInfringement(appearanceRisk)
|
||||
? "外观" + normalize(appearanceRisk) + AppearancePatentSheetBuilder.PENDING_REVIEW_SUFFIX
|
||||
: BRAND_QUERY_FAILED;
|
||||
: firstNonBlank(titleRisk, BRAND_QUERY_FAILED);
|
||||
}
|
||||
return firstNonBlank(fallbackConclusion, "");
|
||||
}
|
||||
|
||||
+87
@@ -79,6 +79,40 @@ class AppearancePatentLlmClientTest {
|
||||
assertThat(client.buildConclusion("商标查询失败", "侵权", "")).isEqualTo("侵权");
|
||||
}
|
||||
|
||||
/**
|
||||
* 整批待查词无一返回结果时,表上必须说清「上游整体不可用」而不是逐行的「商标查询失败」。
|
||||
* 2026-10-19 现网:品牌库的代理套餐过期(供应商回 套餐不存在)→ 16890 代理池恒为 0、
|
||||
* 一次代理都没挂上 → 全部直连打 WIPO branddb 被整片 Forbidden → 交付表 11 行全写
|
||||
* 「商标查询失败」,既看不出是运维故障,更看不出该去续什么。
|
||||
*/
|
||||
@Test
|
||||
void titleRiskNamesUpstreamOutageOnlyWhenWholeBatchFailed() {
|
||||
BrandCheckClient.BrandCheckBatchResult failed =
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike"));
|
||||
|
||||
assertThat(client.buildTitleRisk("nike air", failed, true))
|
||||
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
|
||||
// 只有它自己查失败时维持原文案:不许把个例升级成整批口径
|
||||
assertThat(client.buildTitleRisk("nike air", failed, false)).isEqualTo("商标查询失败");
|
||||
}
|
||||
|
||||
/** 整批不可用不许盖掉真实命中——这一行只要拿到过侵权结论就先给结论。 */
|
||||
@Test
|
||||
void infringementStillWinsOverWholeBatchOutageMessage() {
|
||||
BrandCheckClient.BrandCheckBatchResult hit =
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("阿凡达"), List.of("阿凡达"), List.of());
|
||||
|
||||
assertThat(client.buildTitleRisk("阿凡达 联名", hit, true)).isEqualTo("侵权");
|
||||
}
|
||||
|
||||
/** 长文案要一路传到结论列;旧输入逐字不变由上一个用例守住。 */
|
||||
@Test
|
||||
void conclusionCarriesUpstreamOutageReason() {
|
||||
assertThat(client.buildConclusion(
|
||||
AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE, "外观识别异常", ""))
|
||||
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipBrandCheckWhenLlmTitleIsNone() throws Exception {
|
||||
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);
|
||||
@@ -103,6 +137,59 @@ class AppearancePatentLlmClientTest {
|
||||
verify(brandCheckClient, never()).checkTitleText(anyString(), anyString());
|
||||
}
|
||||
|
||||
private static AppearancePatentLlmClient clientWith(BrandCheckClient brandCheckClient) {
|
||||
return new AppearancePatentLlmClient(new AppearancePatentProperties(), new ObjectMapper(),
|
||||
null, brandCheckClient, mock(UserSecretUsageService.class));
|
||||
}
|
||||
|
||||
private static AppearancePatentResultRowDto newRow(String id) {
|
||||
AppearancePatentResultRowDto row = new AppearancePatentResultRowDto();
|
||||
row.setId(id);
|
||||
return row;
|
||||
}
|
||||
|
||||
/** 整批无一返回结果 ⇒ 每一行都升级成「上游整体不可用」。 */
|
||||
@Test
|
||||
void wholeBatchQueryFailureEscalatesEveryRow() throws Exception {
|
||||
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);
|
||||
when(brandCheckClient.checkTitleTexts(anyList(), eq("Terms"))).thenReturn(List.of(
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike")),
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("puma"), List.of(), List.of("puma"))));
|
||||
String dataText = """
|
||||
{"data":[{"row_id":"1","title":"nike","title_reason":"nike","appearance":"外观识别异常","result":""},
|
||||
{"row_id":"2","title":"puma","title_reason":"puma","appearance":"外观识别异常","result":""}]}
|
||||
""";
|
||||
|
||||
List<AppearancePatentResultRowDto> merged = clientWith(brandCheckClient)
|
||||
.mergeRowsFromDataText(List.of(newRow("1"), newRow("2")), dataText);
|
||||
|
||||
assertThat(merged).hasSize(2);
|
||||
assertThat(merged).allSatisfy(r -> assertThat(r.getTitleRisk())
|
||||
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判据必须保守:只要有一行查成功过,就不是"整体不可用",失败那行仍按逐行文案写。
|
||||
* 否则一次零星抖动就会把整表刷成运维告警口径,反而把真正的个例盖掉。
|
||||
*/
|
||||
@Test
|
||||
void oneSuccessfulRowKeepsOthersOnPerRowFailureText() throws Exception {
|
||||
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);
|
||||
when(brandCheckClient.checkTitleTexts(anyList(), eq("Terms"))).thenReturn(List.of(
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike")),
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("puma"), List.of(), List.of())));
|
||||
String dataText = """
|
||||
{"data":[{"row_id":"1","title":"nike","title_reason":"nike","appearance":"外观识别异常","result":""},
|
||||
{"row_id":"2","title":"puma","title_reason":"puma","appearance":"外观识别异常","result":""}]}
|
||||
""";
|
||||
|
||||
List<AppearancePatentResultRowDto> merged = clientWith(brandCheckClient)
|
||||
.mergeRowsFromDataText(List.of(newRow("1"), newRow("2")), dataText);
|
||||
|
||||
assertThat(merged.get(0).getTitleRisk()).isEqualTo("商标查询失败");
|
||||
assertThat(merged.get(1).getTitleRisk()).isEqualTo("无侵权");
|
||||
}
|
||||
|
||||
@Test
|
||||
void callBrandCheckOnlyWhenTitleAndAppearanceArePresent() throws Exception {
|
||||
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);
|
||||
|
||||
+3
@@ -327,6 +327,9 @@ class AppearancePatentSheetBuilderTest {
|
||||
assertEquals("成功", AppearancePatentSheetBuilder.resolveResultStatus("已侵权"));
|
||||
// 商标没成功 / 外观识别异常 / 技术失败 / 空白 → 失败
|
||||
assertEquals("失败", AppearancePatentSheetBuilder.resolveResultStatus("商标查询失败"));
|
||||
// 整批上游不可用那套长文案同样不能被判成成功:它不含「侵权」二字,也不带待复核标记
|
||||
assertEquals("失败", AppearancePatentSheetBuilder.resolveResultStatus(
|
||||
"商标查询失败:品牌库上游整体不可用(本批待查词无一返回结果,非本行数据问题)"));
|
||||
assertEquals("失败", AppearancePatentSheetBuilder.resolveResultStatus("外观识别异常"));
|
||||
assertEquals("失败", AppearancePatentSheetBuilder.resolveResultStatus("LLM http 503: overloaded"));
|
||||
assertEquals("失败", AppearancePatentSheetBuilder.resolveResultStatus(" "));
|
||||
|
||||
Reference in New Issue
Block a user