提交一些更改
This commit is contained in:
+132
-17
@@ -231,9 +231,6 @@ public class SimilarAsinCozeClient {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("workflow_id", credential.workflowId());
|
||||
body.put("parameters", parameters);
|
||||
if (apiKey != null && !apiKey.isBlank()) {
|
||||
body.put("api_key", apiKey.trim());
|
||||
}
|
||||
body.put("is_async", Boolean.TRUE);
|
||||
log.info("[similar-asin] coze request credential={} url={} body={}",
|
||||
credential.name(),
|
||||
@@ -351,16 +348,19 @@ public class SimilarAsinCozeClient {
|
||||
}
|
||||
|
||||
private Map<String, Object> buildParameters(List<SimilarAsinResultRowDto> rows, String prompt, String apiKey) {
|
||||
List<String> asins = rows.stream().map(row -> nonBlank(row.getAsin(), "")).toList();
|
||||
List<String> skus = rows.stream().map(row -> nonBlank(row.getSku(), "")).toList();
|
||||
List<String> titles = rows.stream().map(row -> nonBlank(row.getTitle(), row.getAsin())).toList();
|
||||
List<String> urls = rows.stream().map(row -> nonBlank(row.getUrl(), "")).toList();
|
||||
List<List<String>> urlLists = rows.stream().map(SimilarAsinResultRowDto::getUrls).toList();
|
||||
List<String> asins = rows.stream().map(row -> safeText(row.getAsin())).toList();
|
||||
List<String> titles = rows.stream().map(row -> safeText(firstNonBlank(row.getTitle(), row.getAsin()))).toList();
|
||||
List<String> skus = rows.stream().map(row -> safeText(row.getSku())).toList();
|
||||
List<String> urls = rows.stream().map(this::primaryImageUrl).toList();
|
||||
List<List<String>> urlLists = rows.stream().map(this::imageUrls).toList();
|
||||
|
||||
Map<String, Object> parameters = new LinkedHashMap<>();
|
||||
parameters.put("items", buildItemObjects(asins, skus, titles, urls, urlLists));
|
||||
parameters.put("items", buildItemObjects(asins, titles, skus, urls, urlLists));
|
||||
parameters.put("prompt", prompt == null ? "" : prompt);
|
||||
if (apiKey != null && !apiKey.isBlank()) {
|
||||
// legacy flag:当线上 coze 工作流回退到老契约时,把环境变量
|
||||
// AIIMAGE_SIMILAR_ASIN_COZE_INCLUDE_LEGACY_API_KEY=true 即可重新塞 api_key。
|
||||
boolean includeLegacyApiKey = properties.isCozeIncludeLegacyApiKey();
|
||||
if (includeLegacyApiKey && apiKey != null && !apiKey.isBlank()) {
|
||||
parameters.put("api_key", apiKey.trim());
|
||||
}
|
||||
return parameters;
|
||||
@@ -397,18 +397,31 @@ public class SimilarAsinCozeClient {
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> buildItemObjects(List<String> asins,
|
||||
List<String> skus,
|
||||
List<String> titles,
|
||||
List<String> skus,
|
||||
List<String> urls,
|
||||
List<List<String>> urlLists) {
|
||||
// legacy flag:保留切回旧字段顺序 {asin, sku, url, target_urls, title} 的开关,
|
||||
// 默认 false 使用当前顺序 {asin, url, target_urls, title, sku}。
|
||||
boolean useLegacyOrder = properties.isCozeUseLegacyItemFieldOrder();
|
||||
List<Map<String, Object>> items = new ArrayList<>(asins.size());
|
||||
for (int i = 0; i < asins.size(); i++) {
|
||||
String url = urls.get(i);
|
||||
List<String> imageUrls = urlLists.get(i);
|
||||
Map<String, Object> item = new LinkedHashMap<>();
|
||||
item.put("asin", asins.get(i));
|
||||
item.put("sku", skus.get(i));
|
||||
item.put("title", titles.get(i));
|
||||
item.put("url", urls.get(i));
|
||||
item.put("target_urls", urlLists.get(i));
|
||||
if (useLegacyOrder) {
|
||||
item.put("asin", asins.get(i));
|
||||
item.put("sku", skus.get(i));
|
||||
item.put("url", url);
|
||||
item.put("target_urls", imageUrls);
|
||||
item.put("title", titles.get(i));
|
||||
} else {
|
||||
item.put("asin", asins.get(i));
|
||||
item.put("url", url);
|
||||
item.put("target_urls", imageUrls);
|
||||
item.put("title", titles.get(i));
|
||||
item.put("sku", skus.get(i));
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
return items;
|
||||
@@ -568,6 +581,7 @@ public class SimilarAsinCozeClient {
|
||||
return false;
|
||||
}
|
||||
return !normalize(result.rowToken()).isBlank()
|
||||
|| !normalize(result.groupKey()).isBlank()
|
||||
|| !normalize(result.rowId()).isBlank()
|
||||
|| !normalize(result.asin()).isBlank();
|
||||
}
|
||||
@@ -602,6 +616,48 @@ public class SimilarAsinCozeClient {
|
||||
row.setTitleReason(result.titleReason());
|
||||
row.setAppearanceReason(result.appearanceReason());
|
||||
row.setPatentReason(result.patentReason());
|
||||
normalizeRequiredBusinessFields(row);
|
||||
}
|
||||
|
||||
private void normalizeRequiredBusinessFields(SimilarAsinResultRowDto row) {
|
||||
if (row == null || !hasBusinessCozeResult(row)) {
|
||||
return;
|
||||
}
|
||||
boolean filledStock = false;
|
||||
boolean filledSimilarity = false;
|
||||
if (normalize(row.getIsStock()).isBlank()) {
|
||||
row.setIsStock("\u672a\u77e5");
|
||||
filledStock = true;
|
||||
}
|
||||
if (normalize(row.getSimilarity()).isBlank()) {
|
||||
row.setSimilarity("0%");
|
||||
filledSimilarity = true;
|
||||
}
|
||||
// \u5728 error \u5b57\u6bb5\u8ffd\u52a0 marker\uff0c\u5bfc\u51fa/BI \u4fa7\u53ef\u636e\u6b64\u533a\u5206"\u4e1a\u52a1\u771f\u5b9e\u7a7a"\u4e0e"\u4ee3\u7801\u515c\u5e95\u586b\u7684"\u3002
|
||||
// \u4ec5\u5728\u539f\u503c\u4e3a\u7a7a\u65f6\u586b\u5165\u515c\u5e95\uff0c\u6240\u4ee5\u4e24\u4e2a marker \u5404\u81ea\u72ec\u7acb\u5224\u5b9a\uff0c\u4e0d\u4f1a\u91cd\u590d\u8ffd\u52a0\u3002
|
||||
if (filledStock || filledSimilarity) {
|
||||
StringBuilder marker = new StringBuilder();
|
||||
if (filledStock) {
|
||||
marker.append("|coze-default-stock");
|
||||
}
|
||||
if (filledSimilarity) {
|
||||
marker.append("|coze-default-similarity");
|
||||
}
|
||||
String existingError = row.getError();
|
||||
String markerText = marker.toString();
|
||||
if (existingError == null || existingError.isBlank()) {
|
||||
row.setError(markerText.startsWith("|") ? markerText.substring(1) : markerText);
|
||||
} else if (!existingError.contains(markerText.trim())) {
|
||||
row.setError(existingError + markerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasBusinessCozeResult(SimilarAsinResultRowDto row) {
|
||||
return !normalize(row.getIsConform()).isBlank()
|
||||
|| !normalize(row.getReason()).isBlank()
|
||||
|| !normalize(row.getCategory()).isBlank()
|
||||
|| !normalize(row.getStatus()).isBlank();
|
||||
}
|
||||
|
||||
private RestClient restClient() {
|
||||
@@ -1056,6 +1112,65 @@ public class SimilarAsinCozeClient {
|
||||
return preferred == null || preferred.isBlank() ? fallback : preferred.trim();
|
||||
}
|
||||
|
||||
private String safeText(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
private List<String> safeUrls(List<String> urls) {
|
||||
if (urls == null || urls.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return urls.stream()
|
||||
.map(this::safeText)
|
||||
.filter(value -> !value.isBlank())
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void putIfPresent(Map<String, Object> item, String key, String value) {
|
||||
String normalized = safeText(value);
|
||||
if (!normalized.isBlank()) {
|
||||
item.put(key, normalized);
|
||||
}
|
||||
}
|
||||
|
||||
private void putIfPresent(Map<String, Object> item, String key, List<String> values) {
|
||||
if (values != null && !values.isEmpty()) {
|
||||
item.put(key, values);
|
||||
}
|
||||
}
|
||||
|
||||
private String primaryImageUrl(SimilarAsinResultRowDto row) {
|
||||
if (row == null) {
|
||||
return "";
|
||||
}
|
||||
String url = safeText(row.getUrl());
|
||||
if (!url.isBlank()) {
|
||||
return url;
|
||||
}
|
||||
List<String> urls = safeUrls(row.getUrls());
|
||||
return urls.isEmpty() ? "" : urls.get(0);
|
||||
}
|
||||
|
||||
private List<String> imageUrls(SimilarAsinResultRowDto row) {
|
||||
if (row == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> urls = safeUrls(row.getUrls());
|
||||
if (!urls.isEmpty()) {
|
||||
return urls;
|
||||
}
|
||||
String primaryUrl = primaryImageUrl(row);
|
||||
return primaryUrl.isBlank() ? List.of() : List.of(primaryUrl);
|
||||
}
|
||||
|
||||
private String cozeGroupKey(SimilarAsinResultRowDto row) {
|
||||
if (row == null) {
|
||||
return "";
|
||||
}
|
||||
String groupKey = safeText(row.getGroupKey());
|
||||
return groupKey.isBlank() ? rowKey(row) : groupKey;
|
||||
}
|
||||
|
||||
private String normalize(String value) {
|
||||
return value == null ? "" : value.replace(String.valueOf((char) 0xFEFF), "").replace((char) 0x3000, ' ').trim();
|
||||
}
|
||||
@@ -1164,7 +1279,7 @@ public class SimilarAsinCozeClient {
|
||||
|
||||
public boolean isFailed() {
|
||||
String normalized = status == null ? "" : status.trim().toUpperCase(Locale.ROOT);
|
||||
return normalized.contains("FAILED") || normalized.contains("ERROR") || normalized.contains("CANCEL");
|
||||
return normalized.contains("FAIL") || normalized.contains("ERROR") || normalized.contains("CANCEL");
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
|
||||
+4
@@ -34,4 +34,8 @@ public class SimilarAsinHistoryItemVo {
|
||||
private Integer rowCount;
|
||||
@Schema(description = "历史记录创建时间,ISO 本地时间字符串。", example = "2026-04-26T10:30:00")
|
||||
private String createdAt;
|
||||
@Schema(description = "任务开始时间,ISO 本地时间字符串。当前等价于 biz_file_task.created_at(用户点解析创建任务时刻)。", example = "2026-04-26T10:00:00")
|
||||
private String startedAt;
|
||||
@Schema(description = "任务结束时间,ISO 本地时间字符串。SUCCESS/FAILED 时回填,未结束为空。", example = "2026-04-26T10:10:00")
|
||||
private String finishedAt;
|
||||
}
|
||||
|
||||
+645
-105
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user