提交登录修改
This commit is contained in:
+52
-2
@@ -355,9 +355,14 @@ public class SimilarAsinCozeClient {
|
||||
List<String> urls = rows.stream().map(this::primaryImageUrl).toList();
|
||||
List<List<String>> urlLists = rows.stream().map(this::imageUrls).toList();
|
||||
|
||||
List<Map<String, Object>> items = buildItemObjects(asins, titles, skus, urls, urlLists);
|
||||
logCozeItemsDiff(rows, items);
|
||||
Map<String, Object> parameters = new LinkedHashMap<>();
|
||||
parameters.put("items", buildItemObjects(asins, titles, skus, urls, urlLists));
|
||||
parameters.put("prompt", prompt == null ? "" : prompt);
|
||||
parameters.put("items", items);
|
||||
// 前端没填 prompt 就一律不向 Coze 透传该字段,避免无关默认提示词污染工作流。
|
||||
if (prompt != null && !prompt.isBlank()) {
|
||||
parameters.put("prompt", prompt);
|
||||
}
|
||||
// legacy flag:当线上 coze 工作流回退到老契约时,把环境变量
|
||||
// AIIMAGE_SIMILAR_ASIN_COZE_INCLUDE_LEGACY_API_KEY=true 即可重新塞 api_key。
|
||||
boolean includeLegacyApiKey = properties.isCozeIncludeLegacyApiKey();
|
||||
@@ -367,6 +372,51 @@ public class SimilarAsinCozeClient {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印每一行 row 在送入 Coze 前后的关键字段,便于排查 Python -> Java -> Coze 的字段是否被改写。
|
||||
* 对照点:asin / url / urls(size+样例) / title / sku;以及组装到 Coze 后的 url / target_urls。
|
||||
*/
|
||||
private void logCozeItemsDiff(List<SimilarAsinResultRowDto> rows, List<Map<String, Object>> items) {
|
||||
if (rows == null || items == null) {
|
||||
return;
|
||||
}
|
||||
int size = Math.min(rows.size(), items.size());
|
||||
log.info("[similar-asin] coze items diff start batchSize={}", size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
SimilarAsinResultRowDto row = rows.get(i);
|
||||
Map<String, Object> item = items.get(i);
|
||||
if (row == null || item == null) {
|
||||
continue;
|
||||
}
|
||||
List<String> rowUrls = safeUrls(row.getUrls());
|
||||
String rowUrl = safeText(row.getUrl());
|
||||
Object outUrl = item.get("url");
|
||||
Object outTargetUrls = item.get("target_urls");
|
||||
int outTargetSize = (outTargetUrls instanceof List<?> list) ? list.size() : 0;
|
||||
boolean urlMatch = String.valueOf(outUrl == null ? "" : outUrl).equals(rowUrl);
|
||||
boolean targetMatch = (outTargetUrls instanceof List<?> outList)
|
||||
&& outList.size() == rowUrls.size()
|
||||
&& outList.equals(rowUrls);
|
||||
log.info("[similar-asin] coze item idx={} asin={} title={} sku={} rowUrl={} rowUrlsSize={} rowUrlsHead={} rowUrlsTail={} outUrl={} outTargetSize={} outTargetHead={} outTargetTail={} urlMatch={} targetUrlsMatch={}",
|
||||
i,
|
||||
safeText(row.getAsin()),
|
||||
abbreviate(safeText(row.getTitle()), 80),
|
||||
safeText(row.getSku()),
|
||||
abbreviate(rowUrl, 200),
|
||||
rowUrls.size(),
|
||||
rowUrls.isEmpty() ? "" : abbreviate(rowUrls.get(0), 200),
|
||||
rowUrls.size() <= 1 ? "" : abbreviate(rowUrls.get(rowUrls.size() - 1), 200),
|
||||
abbreviate(String.valueOf(outUrl == null ? "" : outUrl), 200),
|
||||
outTargetSize,
|
||||
(outTargetUrls instanceof List<?> headList && !headList.isEmpty())
|
||||
? abbreviate(String.valueOf(headList.get(0)), 200) : "",
|
||||
(outTargetUrls instanceof List<?> tailList && tailList.size() > 1)
|
||||
? abbreviate(String.valueOf(tailList.get(tailList.size() - 1)), 200) : "",
|
||||
urlMatch,
|
||||
targetMatch);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> maskCozeRequestBody(Map<String, Object> body) {
|
||||
Map<String, Object> masked = new LinkedHashMap<>(body);
|
||||
|
||||
+39
-41
@@ -9,14 +9,11 @@ import lombok.Data;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Schema(description = "相似ASIN检测单行商品数据")
|
||||
public class SimilarAsinResultRowDto {
|
||||
private static final int MAX_IMAGE_URLS = 24;
|
||||
|
||||
@Schema(description = "来源文件 key。多文件回传时用于避免行结果串到别的文件。", example = "uploads/20260426/similar_asin_17.xlsx")
|
||||
private String sourceFileKey;
|
||||
@@ -47,10 +44,10 @@ public class SimilarAsinResultRowDto {
|
||||
@Schema(description = "商品价格。来自 Excel 解析或 Python 回传。", example = "12.29")
|
||||
private String price;
|
||||
|
||||
@Schema(description = "兼容旧链路的首个图片 URL。新链路允许 url 传字符串或数组;数组会同步写入 urls。", example = "https://webstatic.aiproxy.vip/output/20260425/103322/demo.jpg")
|
||||
@Schema(description = "商品主图 URL。Python 端解析的代表图。允许传字符串或数组(数组取首个非空),与 urls 互不影响。", example = "https://webstatic.aiproxy.vip/output/20260425/103322/demo.jpg")
|
||||
private String url;
|
||||
|
||||
@Schema(description = "商品图片 URL 列表,最多保留 24 个非空地址。请求中也可以直接把 url 传成数组。", example = "[\"https://webstatic.aiproxy.vip/output/20260425/103322/demo.jpg\"]")
|
||||
@Schema(description = "同类商品图 URL 列表。Python 端原样回传,后端不再去重/截断/与 url 互写。", example = "[\"https://webstatic.aiproxy.vip/output/20260425/103322/demo.jpg\"]")
|
||||
private List<String> urls = new ArrayList<>();
|
||||
|
||||
@Schema(description = "商品标题。Java 调用 Coze 时会放入 title_list;为空时会回退使用 ASIN。", example = "Women Floral Dress Summer Casual")
|
||||
@@ -125,11 +122,7 @@ public class SimilarAsinResultRowDto {
|
||||
private String puzzleImg2;
|
||||
|
||||
public String getUrl() {
|
||||
if (url != null && !url.isBlank()) {
|
||||
return url;
|
||||
}
|
||||
List<String> normalized = getUrls();
|
||||
return normalized.isEmpty() ? "" : normalized.get(0);
|
||||
return url == null ? "" : url;
|
||||
}
|
||||
|
||||
@JsonSetter("url")
|
||||
@@ -140,20 +133,24 @@ public class SimilarAsinResultRowDto {
|
||||
"image", "img", "pic", "picture", "link", "imageLink", "image_link"
|
||||
})
|
||||
public void setUrl(Object value) {
|
||||
List<String> normalized = normalizeUrls(value);
|
||||
this.urls = normalized;
|
||||
// 仅写 url 字段;不再回写 urls,遵循"url 主图 / urls 同类图"语义。
|
||||
// 兼容历史输入:若传入数组/集合,仅取第一个非空值作为 url,不影响 urls。
|
||||
if (value == null) {
|
||||
this.url = "";
|
||||
return;
|
||||
}
|
||||
if (value instanceof String text) {
|
||||
this.url = text.trim();
|
||||
return;
|
||||
}
|
||||
List<String> normalized = new ArrayList<>();
|
||||
appendUrls(normalized, value);
|
||||
this.url = normalized.isEmpty() ? "" : normalized.get(0);
|
||||
}
|
||||
|
||||
public List<String> getUrls() {
|
||||
List<String> normalized = normalizeUrls(urls);
|
||||
if (url != null && !url.isBlank() && normalized.stream().noneMatch(url.trim()::equals)) {
|
||||
List<String> combined = new ArrayList<>(normalized.size() + 1);
|
||||
combined.add(url.trim());
|
||||
combined.addAll(normalized);
|
||||
return limitUrls(combined);
|
||||
}
|
||||
return normalized;
|
||||
// 直接返回 Python 回传的 urls,不再把 url 强推到首位、不去重、不截断。
|
||||
return cleanUrls(urls);
|
||||
}
|
||||
|
||||
@JsonSetter("urls")
|
||||
@@ -166,19 +163,18 @@ public class SimilarAsinResultRowDto {
|
||||
"图片链接", "商品图片", "商品主图", "主图", "主图链接"
|
||||
})
|
||||
public void setUrls(Object urls) {
|
||||
List<String> normalized = normalizeUrls(urls);
|
||||
// 仅写 urls 字段;不再回写 url,避免 url/urls 交叉污染。
|
||||
List<String> normalized = new ArrayList<>();
|
||||
appendUrls(normalized, urls);
|
||||
this.urls = normalized;
|
||||
this.url = normalized.isEmpty() ? "" : normalized.get(0);
|
||||
}
|
||||
|
||||
public boolean hasImageUrl() {
|
||||
return !getUrls().isEmpty();
|
||||
}
|
||||
|
||||
private static List<String> normalizeUrls(Object value) {
|
||||
List<String> result = new ArrayList<>();
|
||||
appendUrls(result, value);
|
||||
return limitUrls(result);
|
||||
// url(主图)和 urls(同类商品图)任一存在即可作为可送 Coze 的素材。
|
||||
if (url != null && !url.isBlank()) {
|
||||
return true;
|
||||
}
|
||||
return !cleanUrls(urls).isEmpty();
|
||||
}
|
||||
|
||||
private static void appendUrls(List<String> result, Object value) {
|
||||
@@ -214,19 +210,21 @@ public class SimilarAsinResultRowDto {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> limitUrls(List<String> values) {
|
||||
Set<String> deduplicated = new LinkedHashSet<>();
|
||||
if (values != null) {
|
||||
for (String value : values) {
|
||||
if (value == null || value.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
deduplicated.add(value.trim());
|
||||
if (deduplicated.size() >= MAX_IMAGE_URLS) {
|
||||
break;
|
||||
}
|
||||
private static List<String> cleanUrls(List<String> values) {
|
||||
// 仅做空值过滤与 trim,不去重、不截断,原样保留 Python 回传顺序与数量。
|
||||
if (values == null || values.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> result = new ArrayList<>(values.size());
|
||||
for (String value : values) {
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
if (!trimmed.isBlank()) {
|
||||
result.add(trimmed);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(deduplicated);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+47
-7
@@ -1301,11 +1301,56 @@ public class SimilarAsinTaskService {
|
||||
rows.add(row);
|
||||
}
|
||||
}
|
||||
logPythonInboundRows(rows);
|
||||
return rows;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印 Python 端回传给 Java 的每一行 row 关键字段,确认 url(主图)/ urls(同类商品图)/ title / sku
|
||||
* 是否按预期到达。该日志与 SimilarAsinCozeClient 的 coze items diff 日志成对,
|
||||
* 便于排查"Python 回传了什么、Java 又把什么发到 Coze"。
|
||||
*/
|
||||
private void logPythonInboundRows(List<SimilarAsinResultRowDto> rows) {
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
log.info("[similar-asin] python inbound start size={}", rows.size());
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
SimilarAsinResultRowDto row = rows.get(i);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String url = row.getUrl();
|
||||
List<String> urls = row.getUrls();
|
||||
log.info("[similar-asin] python inbound idx={} groupKey={} rowToken={} id={} asin={} country={} title={} sku={} url={} urlsSize={} urlsHead={} urlsTail={}",
|
||||
i,
|
||||
normalize(row.getGroupKey()),
|
||||
normalize(row.getRowToken()),
|
||||
normalize(row.getId()),
|
||||
normalize(row.getAsin()),
|
||||
normalize(row.getCountry()),
|
||||
abbreviateForLog(row.getTitle(), 80),
|
||||
normalize(row.getSku()),
|
||||
abbreviateForLog(url, 200),
|
||||
urls == null ? 0 : urls.size(),
|
||||
urls == null || urls.isEmpty() ? "" : abbreviateForLog(urls.get(0), 200),
|
||||
urls == null || urls.size() <= 1 ? "" : abbreviateForLog(urls.get(urls.size() - 1), 200));
|
||||
}
|
||||
}
|
||||
|
||||
private String abbreviateForLog(String value, int maxLength) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
if (maxLength <= 0 || trimmed.length() <= maxLength) {
|
||||
return trimmed;
|
||||
}
|
||||
return trimmed.substring(0, maxLength) + "...";
|
||||
}
|
||||
|
||||
private int allRowCount(FileTaskEntity task) {
|
||||
try {
|
||||
SimilarAsinParsedPayloadDto payload = readParsedPayload(task);
|
||||
@@ -1634,13 +1679,8 @@ public class SimilarAsinTaskService {
|
||||
if (parsedRow == null) {
|
||||
return row;
|
||||
}
|
||||
if (normalize(row.getUrl()).isBlank()) {
|
||||
String parsedUrl = firstNonBlank(parsedRow.getUrl(), readValueByHeader(parsedRow,
|
||||
"url", "rul", "image", "img", "pic", "picture", "link"));
|
||||
if (!normalize(parsedUrl).isBlank()) {
|
||||
row.setUrl(parsedUrl);
|
||||
}
|
||||
}
|
||||
// 不再回填 url:Python 端会同时回传 url(主图)与 urls(同类商品图),
|
||||
// 缺失场景应在 Python 侧定位,Java 不再合成新的 url 字段以避免覆盖原始数据。
|
||||
if (normalize(row.getTitle()).isBlank()) {
|
||||
row.setTitle(parsedRow.getTitle());
|
||||
}
|
||||
|
||||
+14
-7
@@ -58,11 +58,13 @@ public class SimilarAsinImageEmbedder {
|
||||
static final int DOWNLOAD_TIMEOUT_SECONDS = 5;
|
||||
static final int DOWNLOAD_MAX_RETRY = 1;
|
||||
static final int DOWNLOAD_POOL_SIZE = 8;
|
||||
public static final float IMAGE_ROW_HEIGHT_POINTS = 150f;
|
||||
public static final int IMAGE_COL_WIDTH_CHARS = 30;
|
||||
static final int TARGET_LONG_EDGE_PX = 300;
|
||||
static final float JPEG_QUALITY = 0.85f;
|
||||
static final int MAX_THUMB_SIZE_BYTES = 40 * 1024;
|
||||
// B 方案:单元格放大到 Excel 上限附近(255 char ≈ 1785 px / 409.5 pt ≈ 546 px),保持 16:9 显示空间。
|
||||
public static final float IMAGE_ROW_HEIGHT_POINTS = 409f;
|
||||
public static final int IMAGE_COL_WIDTH_CHARS = 80;
|
||||
// 源图长边 1280 px 给 Excel 缩放/打印留余量;q=0.75 + 300KB 出口硬上限主动控制单图体积。
|
||||
static final int TARGET_LONG_EDGE_PX = 1280;
|
||||
static final float JPEG_QUALITY = 0.75f;
|
||||
static final int MAX_THUMB_SIZE_BYTES = 300 * 1024;
|
||||
static final int MAX_DOWNLOAD_BYTES = 5 * 1024 * 1024;
|
||||
static final int MAX_DECODE_PIXELS = 6000 * 6000;
|
||||
|
||||
@@ -150,6 +152,9 @@ public class SimilarAsinImageEmbedder {
|
||||
anchor.setRow2(rowIdx + 1);
|
||||
anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
|
||||
patriarch.createPicture(anchor, picIdx);
|
||||
// POI 已经把缩略图字节复制进 picture pool(B 副本),此时移除 taskImageCache 里的 A 副本可立刻释放。
|
||||
// 同 URL 行内重复出现概率较低,且 cache 仍承担同任务跨行去重收益(首次 miss 时已经 put 过)。
|
||||
taskImageCache.remove(trimmedUrl);
|
||||
} catch (RuntimeException ex) {
|
||||
log.warn("[similar-asin][image] embed-fail url={} err={}", trimmedUrl, ex.getMessage());
|
||||
row.createCell(colIdx).setCellValue(trimmedUrl);
|
||||
@@ -440,8 +445,10 @@ public class SimilarAsinImageEmbedder {
|
||||
}
|
||||
|
||||
/**
|
||||
* resize 出口字节硬上限保护:worst case 6000 行 × 3 列 × 40KB × 2 副本 = 1440MB;
|
||||
* 因此线上限制建议结合 `taskImageCache` 命中率与单任务行数评估,超出预算需缩小 MAX_THUMB_SIZE_BYTES 或限制行数。
|
||||
* resize 出口字节硬上限保护:B 方案下单图最坏 ~300KB;POI picture pool 在 SXSSFWorkbook.dispose() 前不会 spill 到临时文件,
|
||||
* 因此 N 行 × 3 列 × 300KB 全量驻留堆。配合 -Xmx2048M:≈1500 行 × 3 列 ≈ 1.32GB picture pool,已逼近安全水位;
|
||||
* embed() 成功后会立刻 taskImageCache.remove() 释放 A 副本,B 副本(picture pool)仍随 workbook 生命周期驻留。
|
||||
* 超过 ~1500 行需要降低 MAX_THUMB_SIZE_BYTES 或调小 TARGET_LONG_EDGE_PX,必要时再考虑拆任务。
|
||||
*/
|
||||
public static class ResizeOversizeException extends ResizeException {
|
||||
private final String url;
|
||||
|
||||
Reference in New Issue
Block a user