fix(brand-label): 品牌标签清洗抽公共件,六模块读写两端统一过出口

PublishBrandLabel 从 publish 私有件搬入 common/util/BrandLabel(三条守卫尺子随迁:
唯一副本、实体写出不许绕过、解析端不许重复实现),品牌列的读入与出件两端都走这一处。

读入端接上:asincache 缓存落库、invalidasin 人工黑名单(先洗再判空——键对不上是静默失效,
比脏值出件更难发现)、appearancepatent resolveBrand(两条取值分支同一个串)、collectdata
入库、shopdatacrawl copyRow/sameRow/rowDedupKey(键与值分家会让同一行跨分片重复出件)、
撞款解析与 re-baseline、dedupe 按表头名只洗品牌列。
写出端接上:publish/similarasin×2/appearancepatent/collectdata/撞款 csv+xlsx/shopdatacrawl。

rows-snapshot golden 里品牌格去掉首尾空格:正本 strip 自 2026-10-08 就含 trim,
Java/Python/MySQL 三处同形,不是这次新加的行为。

门禁:后端 mvn -o test 4594 例 0 红。BrandTaskService(含四张 sheet 出件与解析端匹配)
因同仓另一路在飞改动未动,见 docs/audit/BACKLOG.md B5。
This commit is contained in:
2026-10-20 22:35:25 +08:00
parent e855801237
commit cdef922251
34 changed files with 456 additions and 49 deletions
@@ -1,34 +0,0 @@
package com.nanri.aiimage.modules.publish.service;
import java.util.regex.Pattern;
/**
* 上架链路上品牌值的唯一清洗出口:剥掉 {@code Brand: } 这类"字段标签 + 冒号"前缀。
*
* <p>亚马逊详情页把卖家名渲染成 "Brand: XXX",用户从页面复制进 Excel 就会带上前缀。
* 该值进 WIPO 品牌库查询时会被当 Solr 字段限定符({@code undefined field Brand} → 上游 500),
* 10-08 单日被顶着重跑 30 轮、连带把品牌全局锁持到 1h45m,压死 11 个别的用户的任务。
*
* <p>清洗必须落在这里而不是某个调用点:{@code biz_publish_item.brand} 有两个写入来源
* (服务端 Excel 解析、客户端结果分片回传 {@code replaceRows}),历史上只堵了前者,
* 后者在任务完成时整表删后重插,把脏值又写回去。
*/
public final class PublishBrandLabel {
/**
* 只剥行首的一个标签,且要求冒号紧跟其后:{@code Brands: NIKE} 与 {@code Brand: NIKE: X}
* 都是真实品牌写法,不能顺手裁掉。
*/
private static final Pattern LABEL_PREFIX = Pattern.compile(
"(?i)^\\s*(?:brand|品牌|marke|marca|marque|marka)\\s*[::]\\s*");
private PublishBrandLabel() {
}
public static String strip(String value) {
if (value == null || value.isEmpty()) {
return value;
}
return LABEL_PREFIX.matcher(value).replaceFirst("").trim();
}
}
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.common.exception.TaskOwnerMismatchException;
import com.nanri.aiimage.common.util.BrandLabel;
import com.nanri.aiimage.config.InstanceMetadata;
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
@@ -1830,7 +1831,7 @@ public class PublishTaskService extends AbstractFileTaskPipeline<PublishRowDto>
entity.setSourceId(row.getSourceId());
entity.setAsin(row.getAsin());
entity.setCountry(row.getCountry());
entity.setBrand(PublishBrandLabel.strip(row.getBrand()));
entity.setBrand(BrandLabel.strip(row.getBrand()));
entity.setPriceValue(row.getPrice());
entity.setStatusValue(row.getStatus());
entity.setSyncStatus(row.getSyncStatus());
@@ -1,6 +1,7 @@
package com.nanri.aiimage.modules.publish.service;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.common.util.BrandLabel;
import com.nanri.aiimage.common.util.ExcelStreamReader;
import com.nanri.aiimage.common.util.SxssfWorkbookWriter;
import com.nanri.aiimage.modules.publish.model.dto.PublishRowDto;
@@ -169,7 +170,7 @@ public class PublishWorkbookService {
row.setSourceId(values.get(0));
row.setAsin(values.get(1));
row.setCountry(values.get(2));
row.setBrand(PublishBrandLabel.strip(values.get(3)));
row.setBrand(BrandLabel.strip(values.get(3)));
row.setPrice(values.get(4));
return row;
}
@@ -194,7 +195,7 @@ public class PublishWorkbookService {
setText(row, 0, value.getSourceId());
setText(row, 1, value.getAsin());
setText(row, 2, publishCountry);
setText(row, 3, value.getBrand());
setText(row, 3, BrandLabel.strip(value.getBrand()));
setPrice(row, 4, value.getPrice());
setText(row, 5, value.getStatus());
setText(row, 6, value.getSyncStatus());