fix(categories): 分类名去括号——同步入库整段删除括号段
左侧分类树/官网分类名的括号段(型号限定词(JSA002)与内容性括号 (黑+卡其)/(短裤 & 长裤))整段删除。分类名每小时被 SDS 同步覆盖, 清洗落在 syncCategories 入库路径(cleanCategoryDisplayName,款号 token 保留,剥空守卫),另附幂等存量脚本 fix:category-names。 已执行:V1/V2 各 33 条分类名去括号,复跑幂等 0。注意 api 容器重建 部署前旧镜像的下一轮同步会把名称写回原文,部署后自动恢复干净。 Tests: api 23 suites/206 passed(含新增 category-name.spec 7 例),tsc clean
This commit is contained in:
@@ -24,6 +24,24 @@ export interface CategorySyncResult {
|
||||
deletedStale: number;
|
||||
}
|
||||
|
||||
/** 全角/半角括号段(非嵌套),分类名清洗用 */
|
||||
const PAREN_GROUP = /([^()()]*)|\([^()()]*\)/g;
|
||||
|
||||
/**
|
||||
* 分类展示名清洗:删除所有括号段(型号限定词如 `(JSA002)`、内容性括号如
|
||||
* `(黑+卡其)`/`(短裤 & 长裤)`,整段删除),折叠多余空白。剥空(名称仅剩
|
||||
* 括号段)时原样返回。分类名每小时被 SDS 同步覆盖,清洗必须在此入库路径生效
|
||||
* 才能持久;款号 token(如 `DG001`)不受影响。
|
||||
*/
|
||||
export function cleanCategoryDisplayName(name: string | null | undefined): string | null | undefined {
|
||||
if (!name) return name;
|
||||
let cleaned = name.replace(PAREN_GROUP, ' ');
|
||||
// 嵌套/残缺括号剥除后可能留下空括号对
|
||||
cleaned = cleaned.replace(/(\s*)|\(\s*\)/g, ' ');
|
||||
cleaned = cleaned.replace(/\s+/g, ' ').trim();
|
||||
return cleaned || name;
|
||||
}
|
||||
|
||||
export interface ProductSyncResult {
|
||||
inserted: number;
|
||||
updated: number;
|
||||
@@ -185,7 +203,7 @@ export class SyncService {
|
||||
await tx.category.create({
|
||||
data: {
|
||||
sdsCategoryId: node.sdsId,
|
||||
categoryName: node.name,
|
||||
categoryName: cleanCategoryDisplayName(node.name) ?? node.name,
|
||||
categoryIcon: node.icon ?? null,
|
||||
},
|
||||
});
|
||||
@@ -194,7 +212,7 @@ export class SyncService {
|
||||
await tx.category.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
categoryName: node.name,
|
||||
categoryName: cleanCategoryDisplayName(node.name) ?? node.name,
|
||||
categoryIcon: node.icon ?? null,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user