feat: 外观专利改直连 LLM(DeepSeek/Gemini)、无效ASIN菜单更名 BRAND_DB、紫鸟店铺索引场景化
- AppearancePatent:Coze 工作流切换为 llm-host 直连模型(title/appearance 双模型、行并发、重试),配置键迁移并保留旧环境变量兜底 - InvalidAsinDataMapper 补充按值+品牌唯一键查询 - ZiniaoShopIndexService 新增店铺分类/索引场景 - V98:无效ASIN菜单 rename 补充 BRAND_DB;docs 架构优化规划 - 配套单测更新
This commit is contained in:
+470
-804
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -35,7 +35,7 @@ import java.nio.charset.StandardCharsets;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/appearance-patent")
|
||||
@Tag(name = "外观专利检测", description = "外观专利检测任务接口。前端上传 Excel 后由 Java 解析并创建任务;Python 回传商品数据;Java 负责攒批调用 Coze、补齐子行、生成最终 xlsx 并上传 OSS。")
|
||||
@Tag(name = "外观专利检测", description = "外观专利检测任务接口。前端上传 Excel 后由 Java 解析并创建任务;Python 回传商品数据;Java 负责攒批调用 LLM 检测、补齐子行、生成最终 xlsx 并上传 OSS。")
|
||||
public class AppearancePatentController {
|
||||
|
||||
private final AppearancePatentTaskService service;
|
||||
@@ -110,7 +110,7 @@ public class AppearancePatentController {
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{taskId}/result")
|
||||
@Operation(summary = "提交 Python 回传结果", description = "Python 回传商品数据接口。items 可以是一条或多条;Java 先原样保存回传数据,再内部攒够 10 条调用 Coze。done=true 表示 Python 已完成全部回传,Java 会强制处理剩余不足 10 条的数据并生成最终 xlsx。")
|
||||
@Operation(summary = "提交 Python 回传结果", description = "Python 回传商品数据接口。items 可以是一条或多条;Java 先原样保存回传数据,再内部攒够 10 条调用 LLM 检测。done=true 表示 Python 已完成全部回传,Java 会强制处理剩余不足 10 条的数据并生成最终 xlsx。")
|
||||
public ApiResponse<Void> result(
|
||||
@Parameter(description = "外观专利检测任务 ID。任务必须处于 RUNNING 状态。", required = true, example = "3938")
|
||||
@PathVariable Long taskId,
|
||||
|
||||
+3
-3
@@ -24,17 +24,17 @@ public class AppearancePatentParseRequest {
|
||||
|
||||
@JsonProperty("ai_prompt")
|
||||
@JsonAlias({"aiPrompt", "prompt"})
|
||||
@Schema(description = "AI 提示词。非必填;为空时前端会使用默认提示词。后端会保存该提示词,并在调用 Coze workflow 时作为 prompt 参数传入。", example = "请排查这些亚马逊商品在英国及欧洲地区是否存在知识产权侵权风险。")
|
||||
@Schema(description = "AI 提示词。非必填;为空时前端会使用默认提示词。后端会保存该提示词,并在调用 LLM 时作为附加要求传入。", example = "请排查这些亚马逊商品在英国及欧洲地区是否存在知识产权侵权风险。")
|
||||
private String aiPrompt;
|
||||
|
||||
@JsonProperty("api_key")
|
||||
@JsonAlias({"apiKey"})
|
||||
@Schema(description = "传递给 Coze workflow parameters.api_key 的任务级密钥。")
|
||||
@Schema(description = "调用 LLM API 的任务级密钥。")
|
||||
@NotBlank(message = "密钥不能为空")
|
||||
private String apiKey;
|
||||
|
||||
@JsonProperty("patent_token")
|
||||
@JsonAlias({"patentToken"})
|
||||
@Schema(description = "传递给 Coze workflow parameters.patent_token 的专利汇令牌。非必填。")
|
||||
@Schema(description = "专利汇令牌。非必填。")
|
||||
private String patentToken;
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,10 +14,10 @@ public class AppearancePatentParsedPayloadDto {
|
||||
@Schema(description = "AI 提示词")
|
||||
private String aiPrompt;
|
||||
|
||||
@Schema(description = "传递给 Coze workflow parameters.api_key 的任务级密钥")
|
||||
@Schema(description = "调用 LLM API 的任务级密钥")
|
||||
private String apiKey;
|
||||
|
||||
@Schema(description = "传递给 Coze workflow parameters.patent_token 的专利汇令牌")
|
||||
@Schema(description = "专利汇令牌")
|
||||
private String patentToken;
|
||||
|
||||
@Schema(description = "本次解析的源文件列表")
|
||||
|
||||
+7
-7
@@ -29,7 +29,7 @@ public class AppearancePatentResultRowDto {
|
||||
@Schema(description = "站点或国家。来自 Excel 的国家列,例如英国、德国、法国。", example = "英国")
|
||||
private String country;
|
||||
|
||||
@Schema(description = "商品 SKU。Java 调用 Coze 时会放入 items[].sku。", example = "SKU-001")
|
||||
@Schema(description = "商品 SKU。Java 调用 LLM 时会作为标题识别输入。", example = "SKU-001")
|
||||
@JsonAlias({"SKU", "sellerSku", "seller_sku", "merchantSku", "merchant_sku", "商品SKU", "商品 sku", "库存SKU"})
|
||||
private String sku;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AppearancePatentResultRowDto {
|
||||
@JsonAlias({"Price", "价格"})
|
||||
private String price;
|
||||
|
||||
@Schema(description = "商品主图或待检测图片 URL。Java 调用 Coze 时会放入 url_list。", example = "https://webstatic.aiproxy.vip/output/20260425/103322/demo.jpg")
|
||||
@Schema(description = "商品主图或待检测图片 URL。Java 调用 LLM 时会作为外观检测图片输入。", example = "https://webstatic.aiproxy.vip/output/20260425/103322/demo.jpg")
|
||||
@JsonAlias({
|
||||
"imageUrl", "image_url", "imgUrl", "img_url", "pictureUrl", "picture_url",
|
||||
"mainImage", "main_image", "mainImageUrl", "main_image_url",
|
||||
@@ -51,24 +51,24 @@ public class AppearancePatentResultRowDto {
|
||||
})
|
||||
private String url;
|
||||
|
||||
@Schema(description = "商品标题。Java 调用 Coze 时会放入 title_list;为空时会回退使用 ASIN。", example = "Women Floral Dress Summer Casual")
|
||||
@Schema(description = "商品标题。Java 调用 LLM 时会作为标题识别输入;为空时会回退使用 ASIN。", example = "Women Floral Dress Summer Casual")
|
||||
@JsonAlias({"productTitle", "product_title", "itemTitle", "item_title", "商品标题", "商品名称", "标题"})
|
||||
private String title;
|
||||
|
||||
@Schema(description = "单行错误信息。通常用于记录 Python 单行处理异常;Coze 失败时后端会尽量保留原始行,不强行写入风险结果。", example = "图片地址为空")
|
||||
@Schema(description = "单行错误信息。通常用于记录 Python 单行处理异常;LLM 检测失败时后端会尽量保留原始行,不强行写入风险结果。", example = "图片地址为空")
|
||||
private String error;
|
||||
|
||||
@Schema(description = "单行完成标记。当前主要使用请求体顶层 done 控制任务收尾,该字段仅作兼容。", example = "true")
|
||||
private Boolean done;
|
||||
|
||||
@JsonAlias({"row_status", "rowStatus", "Status"})
|
||||
@Schema(description = "Coze 行处理状态", example = "success", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
@Schema(description = "行处理状态", example = "success", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String status;
|
||||
|
||||
@Schema(description = "Java 调用 Coze 后生成的标题维度检测结果,对应最终 xlsx 的“标题维度(商标)”列。Python 回传请求中不要传该字段;即使传入,后端也会以 Java/Coze 处理结果为准。", example = "标题未发现明显商标侵权风险。", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
@Schema(description = "Java 调用 LLM 后生成的标题维度检测结果,对应最终 xlsx 的“标题维度(商标)”列。Python 回传请求中不要传该字段;即使传入,后端也会以 Java/LLM 处理结果为准。", example = "标题未发现明显商标侵权风险。", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String titleRisk;
|
||||
|
||||
@Schema(description = "Java 调用 Coze 后生成的外观维度检测结果,对应最终 xlsx 的“外观维度(外观设计专利)”列。Python 回传请求中不要传该字段。", example = "未发现明显外观设计专利侵权风险。", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
@Schema(description = "Java 调用 LLM 后生成的外观维度检测结果,对应最终 xlsx 的“外观维度(外观设计专利)”列。Python 回传请求中不要传该字段。", example = "未发现明显外观设计专利侵权风险。", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String appearanceRisk;
|
||||
|
||||
@JsonAlias({"patent ", "patent"})
|
||||
|
||||
+40
@@ -126,11 +126,51 @@ public class AppearancePatentTaskCacheService {
|
||||
try {
|
||||
stringRedisTemplate.delete(pendingRowsKey(taskId));
|
||||
stringRedisTemplate.delete(heartbeatKey(taskId));
|
||||
stringRedisTemplate.delete(processedRowsKey(taskId));
|
||||
} catch (Exception ex) {
|
||||
log.warn("[appearance-patent-cache] delete degraded taskId={} msg={}", taskId, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 行级检测去重:Redis SETNX,防止 submitResult 与 stale 恢复双入口并发处理同一批。
|
||||
* 返回 true 表示首次标记(应执行检测),false 表示已处理过(跳过)。
|
||||
*/
|
||||
public boolean markRowProcessed(Long taskId, String rowKey) {
|
||||
if (taskId == null || taskId <= 0 || rowKey == null || rowKey.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Boolean first = stringRedisTemplate.opsForValue().setIfAbsent(
|
||||
processedRowKey(taskId, rowKey), "1", Duration.ofHours(TTL_HOURS));
|
||||
return Boolean.TRUE.equals(first);
|
||||
} catch (Exception ex) {
|
||||
log.warn("[appearance-patent-cache] mark row processed degraded taskId={} rowKey={} msg={}", taskId, rowKey, ex.getMessage());
|
||||
// Redis 降级时放行,由持久化层的 hasResolvedCozeFields 判据兜底去重。
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRowProcessed(Long taskId, String rowKey) {
|
||||
if (taskId == null || taskId <= 0 || rowKey == null || rowKey.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return Boolean.TRUE.equals(stringRedisTemplate.hasKey(processedRowKey(taskId, rowKey)));
|
||||
} catch (Exception ex) {
|
||||
log.warn("[appearance-patent-cache] check row processed degraded taskId={} rowKey={} msg={}", taskId, rowKey, ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String processedRowsKey(Long taskId) {
|
||||
return "appearance-patent:task:processed-rows:" + taskId;
|
||||
}
|
||||
|
||||
private String processedRowKey(Long taskId, String rowKey) {
|
||||
return processedRowsKey(taskId) + ":" + rowKey;
|
||||
}
|
||||
|
||||
private String pendingRowsKey(Long taskId) {
|
||||
return "appearance-patent:task:pending-rows:" + taskId;
|
||||
}
|
||||
|
||||
+167
-1459
File diff suppressed because it is too large
Load Diff
+8
-3
@@ -11,14 +11,19 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface InvalidAsinDataMapper extends BaseMapper<InvalidAsinDataEntity> {
|
||||
|
||||
/** 批量 INSERT IGNORE:命中唯一键 (data_value, brand) 的重复行静默跳过,幂等。 */
|
||||
/**
|
||||
* 批量 INSERT IGNORE:命中唯一键 (data_value, brand) 的重复行静默跳过,幂等。
|
||||
* created_at/updated_at 不显式写入:依赖列的 DEFAULT CURRENT_TIMESTAMP。
|
||||
* 显式传 null 会绕过默认值,在宽松 SQL 模式下落为 '0000-00-00 00:00:00',
|
||||
* 随后在 NO_ZERO_DATE 模式(生产已启用)下读取即报 Zero date value prohibited。
|
||||
*/
|
||||
@Insert("""
|
||||
<script>
|
||||
INSERT IGNORE INTO biz_invalid_asin_data
|
||||
(data_value, brand, record_source, created_at, updated_at)
|
||||
(data_value, brand, record_source)
|
||||
VALUES
|
||||
<foreach collection="rows" item="row" separator=",">
|
||||
(#{row.dataValue}, #{row.brand}, #{row.recordSource}, #{row.createdAt}, #{row.updatedAt})
|
||||
(#{row.dataValue}, #{row.brand}, #{row.recordSource})
|
||||
</foreach>
|
||||
</script>
|
||||
""")
|
||||
|
||||
+74
@@ -195,6 +195,7 @@ public class ZiniaoShopIndexService {
|
||||
int skippedApiKeyCount = 0;
|
||||
int whitelistSkippedApiKeyCount = 0;
|
||||
boolean completeCoverage = true;
|
||||
List<String> whitelistBlockedApiKeys = new ArrayList<>();
|
||||
try {
|
||||
List<ZiniaoApiKeyProvider.ApiKeyAccount> allApiKeyAccounts = ziniaoApiKeyProvider.listApiKeyAccounts();
|
||||
List<ZiniaoApiKeyProvider.ApiKeyAccount> apiKeyAccounts = selectApiKeyBatchByOffset(
|
||||
@@ -217,6 +218,7 @@ public class ZiniaoShopIndexService {
|
||||
completeCoverage = false;
|
||||
if (ziniaoAuthService.isIpWhitelistError(ex)) {
|
||||
whitelistSkippedApiKeyCount++;
|
||||
whitelistBlockedApiKeys.add(apiKey);
|
||||
markIpWhitelistBlockedSafely(apiKeyAccount, ex.getMessage());
|
||||
log.warn("[ziniao-index] skip apiKey reason=IP_WHITELIST accountName={} msg={}", companyName, ex.getMessage());
|
||||
continue;
|
||||
@@ -233,6 +235,7 @@ public class ZiniaoShopIndexService {
|
||||
if (ziniaoAuthService.isIpWhitelistError(ex)) {
|
||||
skippedApiKeyCount++;
|
||||
whitelistSkippedApiKeyCount++;
|
||||
whitelistBlockedApiKeys.add(apiKey);
|
||||
completeCoverage = false;
|
||||
markIpWhitelistBlockedSafely(apiKeyAccount, ex.getMessage());
|
||||
log.warn("[ziniao-index] skip apiKey reason=IP_WHITELIST accountName={} companyId={} msg={}",
|
||||
@@ -252,6 +255,7 @@ public class ZiniaoShopIndexService {
|
||||
if (ziniaoAuthService.isIpWhitelistError(ex)) {
|
||||
skippedApiKeyCount++;
|
||||
whitelistSkippedApiKeyCount++;
|
||||
whitelistBlockedApiKeys.add(apiKey);
|
||||
completeCoverage = false;
|
||||
markIpWhitelistBlockedSafely(apiKeyAccount, ex.getMessage());
|
||||
log.warn("[ziniao-index] skip apiKey reason=IP_WHITELIST accountName={} companyId={} userId={} msg={}",
|
||||
@@ -380,6 +384,7 @@ public class ZiniaoShopIndexService {
|
||||
log.info("[ziniao-index] skip stale marking for partial refresh completedApiKeys={}/{} skippedApiKeys={} nextOffset={}",
|
||||
completedApiKeyCount, allApiKeyAccounts.size(), skippedApiKeyCount, nextOffset);
|
||||
}
|
||||
syncWhitelistBlockedMarks(whitelistBlockedApiKeys, now);
|
||||
|
||||
cursor.setStatus("SUCCESS");
|
||||
List<String> refreshMessages = new ArrayList<>();
|
||||
@@ -583,6 +588,75 @@ public class ZiniaoShopIndexService {
|
||||
return tb >= ta ? b : a;
|
||||
}
|
||||
|
||||
/**
|
||||
* 本轮因 IP 白名单被跳过的 apiKey,其名下的索引行保持 ACTIVE 且 lastRefreshedAt 不再更新,
|
||||
* 20 分钟后会落入"已过保鲜期"。这里给这些行写入 refreshBlockedReason / lastRefreshBlockedAt,
|
||||
* 让查询侧 {@link #shouldBypassFreshnessBecauseWhitelistFailure} 得以豁免保鲜期判断。
|
||||
* 仅写入本轮被阻断的键对应行;成功键的行一旦重新 put() 即为无阻断字段的新对象。
|
||||
*/
|
||||
private void syncWhitelistBlockedMarks(List<String> whitelistBlockedApiKeys, long now) {
|
||||
if (whitelistBlockedApiKeys == null || whitelistBlockedApiKeys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<String> blockedApiKeyHashes = new HashSet<>();
|
||||
for (String apiKey : whitelistBlockedApiKeys) {
|
||||
blockedApiKeyHashes.add(buildApiKeyHash(apiKey));
|
||||
}
|
||||
List<ZiniaoMemoryStoreEntity> entities = ziniaoMemoryStoreService.listAliveEntitiesByType(
|
||||
ZiniaoMemoryStoreService.CACHE_TYPE_SHOP_INDEX_ENTRY,
|
||||
SHOP_INDEX_LIST_LIMIT
|
||||
);
|
||||
if (entities.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<ZiniaoMemoryStoreEntity> updates = new ArrayList<>();
|
||||
int changedCount = 0;
|
||||
for (ZiniaoMemoryStoreEntity entity : entities) {
|
||||
if (entity == null || entity.getId() == null || entity.getPayloadJson() == null) {
|
||||
continue;
|
||||
}
|
||||
ZiniaoShopIndexEntryDto existingEntry;
|
||||
try {
|
||||
existingEntry = objectMapper.readValue(entity.getPayloadJson(), ZiniaoShopIndexEntryDto.class);
|
||||
} catch (Exception ex) {
|
||||
log.warn("[ziniao-index] skip corrupt shop_index row while marking whitelist-blocked cacheKey={}", entity.getCacheKey());
|
||||
continue;
|
||||
}
|
||||
if (existingEntry == null || !STATUS_ACTIVE.equals(existingEntry.getStatus())
|
||||
|| existingEntry.getApiKeyHash() == null
|
||||
|| !blockedApiKeyHashes.contains(existingEntry.getApiKeyHash())) {
|
||||
continue;
|
||||
}
|
||||
long lastRefreshed = existingEntry.getLastRefreshedAt() == null ? 0L : existingEntry.getLastRefreshedAt();
|
||||
boolean changed = !REFRESH_BLOCKED_REASON_IP_WHITELIST.equals(existingEntry.getRefreshBlockedReason())
|
||||
|| existingEntry.getLastRefreshBlockedAt() == null
|
||||
|| existingEntry.getLastRefreshBlockedAt() < lastRefreshed;
|
||||
if (!changed) {
|
||||
continue;
|
||||
}
|
||||
existingEntry.setRefreshBlockedReason(REFRESH_BLOCKED_REASON_IP_WHITELIST);
|
||||
existingEntry.setLastRefreshBlockedAt(Math.max(now, lastRefreshed));
|
||||
String newPayload;
|
||||
try {
|
||||
newPayload = objectMapper.writeValueAsString(existingEntry);
|
||||
} catch (Exception ex) {
|
||||
throw new BusinessException("写入紫鸟记忆存储失败", ex);
|
||||
}
|
||||
entity.setPayloadJson(newPayload);
|
||||
entity.setExpiresAt(LocalDateTime.now().plus(resolveEntryTtl()));
|
||||
entity.setUpdatedAt(LocalDateTime.now());
|
||||
updates.add(entity);
|
||||
changedCount++;
|
||||
}
|
||||
if (!updates.isEmpty()) {
|
||||
ziniaoMemoryStoreService.updateStaleMarks(updates);
|
||||
}
|
||||
if (changedCount > 0) {
|
||||
log.info("[ziniao-index] marked whitelist-blocked shop_index rows count={} blockedApiKeys={}",
|
||||
changedCount, whitelistBlockedApiKeys.size());
|
||||
}
|
||||
}
|
||||
|
||||
private void markMissingEntriesAsStale(Set<String> activeCacheKeys, long now) {
|
||||
List<ZiniaoMemoryStoreEntity> entities = ziniaoMemoryStoreService.listAliveEntitiesByType(
|
||||
ZiniaoMemoryStoreService.CACHE_TYPE_SHOP_INDEX_ENTRY,
|
||||
|
||||
Reference in New Issue
Block a user