fix(上架品牌): 清洗挪到 biz_publish_item 唯一写库出口,回传重插不再灌回脏值
上一笔 15e04511 只堵了服务端解析 Excel 那一个入口。现网取证(10-09 01:3x,主机A 业务库)显示
脏值有两个来源:7 个脏值任务里 5 个的行创建时间等于任务完成时刻,即任务完成时
PublishTaskService.replaceRows 用客户端回传的分片整表删后重插写回的路径。也就是说每完成一个
上架任务,"Brand:" 就会从回传值里再落库一次,存量清洗会被自己顶回去。
改为:新增 PublishBrandLabel 作为标签正则的唯一持有者,insertRows 写实体前清洗(replaceRows
与解析路径都汇到这里),PublishWorkbookService 删掉本地那份正则改为委派。
配套 PublishBrandLabelTest 5 例:标签形状与反例("Brands: NIKE"、"Super Brand: Nike"、
"Brand: NIKE: X")、publish 模块内 entity.setBrand 出口必须走清洗、全模块只允许一份标签正则。
四条变异实跑全杀(去锚 / strip 原值返回 / 出口不清洗 / 解析层另抄正则);publish 相关
11 个测试类 101 例在独立 worktree 跑绿。
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1933,7 +1933,7 @@ public class PublishTaskService {
|
||||
entity.setSourceId(row.getSourceId());
|
||||
entity.setAsin(row.getAsin());
|
||||
entity.setCountry(row.getCountry());
|
||||
entity.setBrand(row.getBrand());
|
||||
entity.setBrand(PublishBrandLabel.strip(row.getBrand()));
|
||||
entity.setPriceValue(row.getPrice());
|
||||
entity.setStatusValue(row.getStatus());
|
||||
entity.setSyncStatus(row.getSyncStatus());
|
||||
|
||||
+1
-17
@@ -170,7 +170,7 @@ public class PublishWorkbookService {
|
||||
row.setSourceId(values.get(0));
|
||||
row.setAsin(values.get(1));
|
||||
row.setCountry(values.get(2));
|
||||
row.setBrand(stripBrandLabel(values.get(3)));
|
||||
row.setBrand(PublishBrandLabel.strip(values.get(3)));
|
||||
row.setPrice(values.get(4));
|
||||
return row;
|
||||
}
|
||||
@@ -293,22 +293,6 @@ public class PublishWorkbookService {
|
||||
return value.isBlank() ? "publish" : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 剥掉亚马逊 byline 残留的「Brand:」标签前缀。
|
||||
*
|
||||
* 这类值送进 WIPO 品牌查询会被当成 Solr 字段限定符,返回
|
||||
* isError / status 500 / undefined field Brand(2026-10-08 主机 A 实测 19,247 次,
|
||||
* 不带前缀的查询 0 次)。只剥开头一次:值中间的冒号属品牌自身内容,
|
||||
* "Brands:" 也不是标签。
|
||||
*/
|
||||
private String stripBrandLabel(String value) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return value;
|
||||
}
|
||||
return value.replaceFirst(
|
||||
"(?i)^\\s*(?:brand|品牌|marke|marca|marque|marka)\\s*[::]\\s*", "").trim();
|
||||
}
|
||||
|
||||
private String normalize(String value) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user