左栏商品名显示成光款号(如 PLTK016)的根因是双层解析不一致:api 写路径按 首括号对解析产出「童装…(DTG180) PLTK016」,admin 展示解析按末括号取品名 误显示成 PLTK016。 - admin parseLinkName 对齐 api 首括号对解析 + 无 SKU 段中文品名守卫, cleanLinkName 剥离 ASCII 型号限定词(中文括号内容保留) - api 新增 cleanGoodDisplayName/describePureSkuGoodName,接入 create/update/ batchCreate(batchCreate 补上缺失的 normalize);纯款号按 SDS 分类名补描述 - 新增幂等存量修复脚本 fix:good-names(默认 dry-run,--apply 写库) - 已执行:V2 栈 34 条限定词名、V1 栈 213 条原始链接名规范化,复跑幂等 0 Tests: api 22 suites/199 passed, admin 27 passed, tsc clean
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
/**
|
|
* 存量修复脚本(幂等):把纯款号商品名(如 `PLTK016`)按主链接 SDS 分类名
|
|
* 补成「描述名 款号」(如 `童装纯色插肩短袖T恤 PLTK016`)。
|
|
*
|
|
* 运行:
|
|
* pnpm --filter @inkreach/api fix:good-names # dry-run,只打印清单
|
|
* pnpm --filter @inkreach/api fix:good-names -- --apply # 实际写库
|
|
* origin_goods.good_name 为 SDS 纯镜像(每小时同步覆盖),本脚本只改 goods.good_name。
|
|
*/
|
|
import { PrismaService } from '../src/prisma/prisma.service';
|
|
import { SyncService } from '../src/sync/sync.service';
|
|
import { FamilyRecomputeService } from '../src/product-families/family-recompute.service';
|
|
import { GoodsService } from '../src/goods/goods.service';
|
|
|
|
async function main() {
|
|
const dryRun = !process.argv.includes('--apply');
|
|
const prisma = new PrismaService();
|
|
await prisma.onModuleInit();
|
|
const recompute = new FamilyRecomputeService(prisma);
|
|
// 回填路径不触发详情同步,SyncService 仅作占位依赖
|
|
const goods = new GoodsService(
|
|
prisma,
|
|
{ queueProductDetailSync: async () => undefined } as unknown as SyncService,
|
|
recompute,
|
|
);
|
|
|
|
const result = await goods.backfillPureSkuGoodNames({ dryRun });
|
|
const mode = dryRun ? 'DRY-RUN(未写库,加 --apply 执行)' : 'APPLIED';
|
|
console.log(`[fix:good-names] ${mode} renamed=${result.renamed} unmapped=${result.unmapped.length}`);
|
|
for (const r of result.renames) {
|
|
console.log(` #${r.id} ${r.from} -> ${r.to}`);
|
|
}
|
|
for (const u of result.unmapped) {
|
|
console.log(` #${u.id} ${u.from} -> (无分类映射,保留原名)`);
|
|
}
|
|
await prisma.onModuleDestroy();
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|