fix(外观专利): 整批品牌查询失败的文案按真因分档(BK B95-02)
现网 16890 侧成片刷「解密失败: Malformed UTF-8 data」,交付表却一律写 「品牌库上游整体不可用」——上游其实有应答,坏的是应答体解密, 运维照「上游挂了」去查永远查不到东西。 - 新增 AppearancePatentBrandFailureText:批内 reason 全同形才分档 (全解密→解密链路故障、全不可达→服务不可达、混形/空→通用文案), 三条文案都保留「商标查询失败」前缀(状态列与 isBrandQueryFailed 靠它判失败)。 - AppearancePatentLlmClient 的 brandAggregateFailure 收成一行委派; 删掉只被测试调用的 boolean buildTitleRisk 重载(String 版保留兼容)。 - 用例 +5:整批解密/整批不可达/混形与空 reason/三条文案互不相同且同前缀。
This commit is contained in:
+86
@@ -0,0 +1,86 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.client;
|
||||
|
||||
import com.nanri.aiimage.modules.brand.client.BrandCheckClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 整批品牌查询全失败时,标题列该写哪句人话。
|
||||
*
|
||||
* <p>2026-11-11 现网(BACKLOG B95-02):16890 侧 {@code 解密失败: Malformed UTF-8 data} 成片刷,
|
||||
* 交付表却一律写「品牌库上游整体不可用」——上游其实**有应答**,坏的是应答体解密,运维照着
|
||||
* 「上游挂了」去查永远查不到东西。真因不同,指向的动作不同,所以按批内 reason 分档。
|
||||
*
|
||||
* <p>三条文案都必须以「商标查询失败」开头:{@code AppearancePatentLlmClient#isBrandQueryFailed}
|
||||
* 与状态列都靠这个前缀判定失败,措辞可以变,前缀不能变。
|
||||
*
|
||||
* <p>单独成类而不是塞回客户端:{@code AppearancePatentLlmClient} 已在可读性棘轮的
|
||||
* 「超长文件点名」账上,只许减。
|
||||
*/
|
||||
final class AppearancePatentBrandFailureText {
|
||||
|
||||
/** 分不出真因时的通用文案(保底,不是默认)。 */
|
||||
static final String UPSTREAM_UNAVAILABLE =
|
||||
"商标查询失败:品牌库上游整体不可用(本批待查词无一返回结果,非本行数据问题)";
|
||||
|
||||
/** 批内真因统一是「拿回了包但解不开」。 */
|
||||
static final String DECRYPT_BROKEN =
|
||||
"商标查询失败:品牌库返回内容无法解密(服务侧解密链路故障,非本行数据问题)";
|
||||
|
||||
/** 批内真因统一是「连接根本没建立」。 */
|
||||
static final String SERVICE_UNREACHABLE =
|
||||
"商标查询失败:品牌检测服务不可达(连接未建立,非本行数据问题)";
|
||||
|
||||
private AppearancePatentBrandFailureText() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 整批待查词是否无一返回可用结果;是则给出该批的行级文案,否则 null(逐行写「商标查询失败」)。
|
||||
*
|
||||
* <p>判据刻意保守:只要有任何一行拿到过侵权命中、或有任何一行查成功过,就返回 null。
|
||||
* 没发过查询的行(LLM 已判「无」、或标题为空)不参与判定,否则一批全是"无需查"的行
|
||||
* 会被误判成上游故障。
|
||||
*/
|
||||
static String aggregate(List<BrandCheckClient.BrandCheckBatchResult> brandChecks) {
|
||||
boolean anyChecked = false;
|
||||
List<String> reasons = new ArrayList<>();
|
||||
for (BrandCheckClient.BrandCheckBatchResult check : brandChecks) {
|
||||
if (check == null || check.brands() == null || check.brands().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
anyChecked = true;
|
||||
// 命中过侵权就说明上游至少在返回结果,那种行优先给真实结论,不升级成整批口径
|
||||
if (check.hasFailedData() || !check.hasQueryFailedData()) {
|
||||
return null;
|
||||
}
|
||||
reasons.add(normalize(check.reason()));
|
||||
}
|
||||
return anyChecked ? classify(reasons) : null;
|
||||
}
|
||||
|
||||
/** 批内 reason 全同形才分档;空 reason 或混形一律落回通用文案(不猜)。 */
|
||||
static String classify(List<String> reasons) {
|
||||
if (reasons == null || reasons.isEmpty()) {
|
||||
return UPSTREAM_UNAVAILABLE;
|
||||
}
|
||||
boolean allDecrypt = true;
|
||||
boolean allUnreachable = true;
|
||||
for (String reason : reasons) {
|
||||
String text = normalize(reason);
|
||||
if (text.isEmpty()) {
|
||||
return UPSTREAM_UNAVAILABLE;
|
||||
}
|
||||
allDecrypt &= text.contains("解密");
|
||||
allUnreachable &= text.contains("不可达") || text.contains("连接未建立");
|
||||
}
|
||||
if (allDecrypt) {
|
||||
return DECRYPT_BROKEN;
|
||||
}
|
||||
return allUnreachable ? SERVICE_UNREACHABLE : UPSTREAM_UNAVAILABLE;
|
||||
}
|
||||
|
||||
private static String normalize(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
}
|
||||
+17
-26
@@ -256,9 +256,9 @@ public class AppearancePatentLlmClient {
|
||||
*/
|
||||
private void applyLlmRowsInOneBatch(List<AppearancePatentResultRowDto> llmRows, List<LlmResult> llmResults) {
|
||||
List<BrandCheckClient.BrandCheckBatchResult> brandChecks = brandChecksFor(llmResults);
|
||||
boolean brandUpstreamUnavailable = brandUpstreamUnavailable(brandChecks);
|
||||
String aggregateFailure = brandAggregateFailure(brandChecks);
|
||||
for (int k = 0; k < llmRows.size(); k++) {
|
||||
applyResult(llmRows.get(k), llmResults.get(k), brandChecks.get(k), brandUpstreamUnavailable);
|
||||
applyResult(llmRows.get(k), llmResults.get(k), brandChecks.get(k), aggregateFailure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1076,10 +1076,10 @@ public class AppearancePatentLlmClient {
|
||||
resolved.add(result);
|
||||
}
|
||||
List<BrandCheckClient.BrandCheckBatchResult> brandChecks = brandChecksFor(resolved);
|
||||
boolean brandUpstreamUnavailable = brandUpstreamUnavailable(brandChecks);
|
||||
String aggregateFailure = brandAggregateFailure(brandChecks);
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
AppearancePatentResultRowDto row = copy(rows.get(i));
|
||||
applyResult(row, resolved.get(i), brandChecks.get(i), brandUpstreamUnavailable);
|
||||
applyResult(row, resolved.get(i), brandChecks.get(i), aggregateFailure);
|
||||
merged.add(row);
|
||||
}
|
||||
return merged;
|
||||
@@ -1134,37 +1134,24 @@ public class AppearancePatentLlmClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* 整批待查词是否无一返回可用结果——用来把「上游整体挂了」和「这个词查不了」分开写。
|
||||
*
|
||||
* <p>判据刻意保守:只要有任何一行拿到过侵权命中、或有任何一行查成功过,就不算整体不可用,
|
||||
* 仍按逐行的「商标查询失败」写。没发过查询的行(LLM 已判「无」、或标题为空)不参与判定,
|
||||
* 否则一批全是"无需查"的行会被误判成上游故障。
|
||||
* 整批待查词是否无一返回可用结果——是则给出该批的行级文案,否则 null(逐行写「商标查询失败」)。
|
||||
* 分档与判据都在 {@link AppearancePatentBrandFailureText}(本文件只许减,见可读性棘轮)。
|
||||
*/
|
||||
private static boolean brandUpstreamUnavailable(
|
||||
private String brandAggregateFailure(
|
||||
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;
|
||||
return AppearancePatentBrandFailureText.aggregate(brandChecks);
|
||||
}
|
||||
|
||||
void applyResult(AppearancePatentResultRowDto row, LlmResult result,
|
||||
BrandCheckClient.BrandCheckBatchResult brandCheck,
|
||||
boolean brandUpstreamUnavailable) {
|
||||
String brandAggregateFailure) {
|
||||
if (row == null || result == null) {
|
||||
return;
|
||||
}
|
||||
if (isNoTitleRisk(result)) {
|
||||
row.setTitleRisk(NO_INFRINGEMENT);
|
||||
} else if (shouldCheckBrand(result)) {
|
||||
row.setTitleRisk(buildTitleRisk(result.title(), brandCheck, brandUpstreamUnavailable));
|
||||
row.setTitleRisk(buildTitleRisk(result.title(), brandCheck, brandAggregateFailure));
|
||||
} else {
|
||||
row.setTitleRisk("");
|
||||
}
|
||||
@@ -1196,11 +1183,15 @@ public class AppearancePatentLlmClient {
|
||||
}
|
||||
|
||||
String buildTitleRisk(String llmTitle, BrandCheckClient.BrandCheckBatchResult brandCheck) {
|
||||
return buildTitleRisk(llmTitle, brandCheck, false);
|
||||
return buildTitleRisk(llmTitle, brandCheck, (String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param brandAggregateFailure 整批全失败时的行级文案(见 {@link AppearancePatentBrandFailureText});
|
||||
* null=不是整批口径,逐行写「商标查询失败」
|
||||
*/
|
||||
String buildTitleRisk(String llmTitle, BrandCheckClient.BrandCheckBatchResult brandCheck,
|
||||
boolean brandUpstreamUnavailable) {
|
||||
String brandAggregateFailure) {
|
||||
List<String> brands = brandCheck == null ? List.of() : brandCheck.brands();
|
||||
if (brands == null || brands.isEmpty()) {
|
||||
return firstNonBlank(llmTitle, "");
|
||||
@@ -1210,7 +1201,7 @@ public class AppearancePatentLlmClient {
|
||||
}
|
||||
if (brandCheck.hasQueryFailedData()) {
|
||||
// 命中过侵权就说明上游至少在返回结果,那种行优先给真实结论,不升级成整批口径。
|
||||
return brandUpstreamUnavailable ? BRAND_UPSTREAM_UNAVAILABLE : BRAND_QUERY_FAILED;
|
||||
return brandAggregateFailure == null ? BRAND_QUERY_FAILED : brandAggregateFailure;
|
||||
}
|
||||
return NO_INFRINGEMENT;
|
||||
}
|
||||
|
||||
+73
-3
@@ -106,10 +106,11 @@ class AppearancePatentLlmClientTest {
|
||||
BrandCheckClient.BrandCheckBatchResult failed =
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike"), "");
|
||||
|
||||
assertThat(client.buildTitleRisk("nike air", failed, true))
|
||||
assertThat(client.buildTitleRisk("nike air", failed,
|
||||
AppearancePatentBrandFailureText.UPSTREAM_UNAVAILABLE))
|
||||
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
|
||||
// 只有它自己查失败时维持原文案:不许把个例升级成整批口径
|
||||
assertThat(client.buildTitleRisk("nike air", failed, false)).isEqualTo("商标查询失败");
|
||||
assertThat(client.buildTitleRisk("nike air", failed, (String) null)).isEqualTo("商标查询失败");
|
||||
}
|
||||
|
||||
/** 整批不可用不许盖掉真实命中——这一行只要拿到过侵权结论就先给结论。 */
|
||||
@@ -118,7 +119,8 @@ class AppearancePatentLlmClientTest {
|
||||
BrandCheckClient.BrandCheckBatchResult hit =
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("阿凡达"), List.of("阿凡达"), List.of(), "");
|
||||
|
||||
assertThat(client.buildTitleRisk("阿凡达 联名", hit, true)).isEqualTo("侵权");
|
||||
assertThat(client.buildTitleRisk("阿凡达 联名", hit,
|
||||
AppearancePatentBrandFailureText.UPSTREAM_UNAVAILABLE)).isEqualTo("侵权");
|
||||
}
|
||||
|
||||
/** 长文案要一路传到结论列;旧输入逐字不变由上一个用例守住。 */
|
||||
@@ -129,6 +131,74 @@ class AppearancePatentLlmClientTest {
|
||||
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2026-11-11 现网(BACKLOG B95-02):16890 侧 `解密失败: Malformed UTF-8 data` 成片刷,
|
||||
* 交付表却一律写「品牌库上游整体不可用」——上游其实有应答,坏的是应答体解密,
|
||||
* 运维照着「上游挂了」去查永远查不到东西。真因必须写进标题列。
|
||||
*/
|
||||
@Test
|
||||
void 整批解密失败要写成解密而不是上游整体不可用() throws Exception {
|
||||
String decryptReason = "查询或解密失败: 解密失败: Malformed UTF-8 data";
|
||||
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);
|
||||
when(brandCheckClient.checkTitleTexts(anyList(), eq("Terms"), any())).thenReturn(List.of(
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike"),
|
||||
decryptReason),
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("puma"), List.of(), List.of("puma"),
|
||||
decryptReason)));
|
||||
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(AppearancePatentBrandFailureText.DECRYPT_BROKEN);
|
||||
// 前缀不能变:状态列与 isBrandQueryFailed 都靠它判失败
|
||||
assertThat(r.getTitleRisk()).startsWith("商标查询失败");
|
||||
assertThat(r.getTitleRisk()).doesNotContain("上游整体不可用");
|
||||
});
|
||||
}
|
||||
|
||||
/** 整批全失败且原因是「连接没建立」时,文案要指向服务不可达,而不是解密或通用文案。 */
|
||||
@Test
|
||||
void 整批连接不上要写成服务不可达() {
|
||||
String unreachable = "品牌检测服务不可达(连接未建立,非本行数据问题)";
|
||||
BrandCheckClient.BrandCheckBatchResult failed =
|
||||
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike"),
|
||||
unreachable);
|
||||
|
||||
assertThat(client.buildTitleRisk("nike air", failed,
|
||||
AppearancePatentBrandFailureText.classify(List.of(unreachable))))
|
||||
.isEqualTo(AppearancePatentBrandFailureText.SERVICE_UNREACHABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判据保守:reason 混形、或有行没给 reason 时一律落回通用文案,不猜真因——
|
||||
* 猜错的运维文案比笼统的更贵。
|
||||
*/
|
||||
@Test
|
||||
void reason混形或不给原因时维持通用文案() {
|
||||
assertThat(AppearancePatentBrandFailureText.classify(
|
||||
List.of("查询或解密失败: 解密失败: x", "品牌检测服务不可达(连接未建立)")))
|
||||
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
|
||||
assertThat(AppearancePatentBrandFailureText.classify(List.of("", "")))
|
||||
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
|
||||
}
|
||||
|
||||
/** 三条文案都必须以「商标查询失败」开头且彼此不同,否则分档就会把状态列或归因搅乱。 */
|
||||
@Test
|
||||
void 三种整批文案都保留商标查询失败前缀且互不相同() {
|
||||
List<String> texts = List.of(
|
||||
AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE,
|
||||
AppearancePatentBrandFailureText.DECRYPT_BROKEN,
|
||||
AppearancePatentBrandFailureText.SERVICE_UNREACHABLE);
|
||||
assertThat(texts).allSatisfy(t -> assertThat(t).startsWith("商标查询失败"));
|
||||
assertThat(texts).doesNotHaveDuplicates();
|
||||
}
|
||||
|
||||
@Test
|
||||
void spacedNoInfringementAppearanceDoesNotLeakIntoConclusion() throws Exception {
|
||||
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);
|
||||
|
||||
Reference in New Issue
Block a user