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:
+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