fix(product-families): sort price-matrix option arrays by canonical display order
printCounts/crafts/logistics were materialized in first-encounter order (originGoods had no orderBy), so the H5 print/craft/logistics button groups rendered in an unstable, per-family arbitrary order. Add OPTION_DISPLAY_ORDER (单面→双面, 烫画→直喷→不打印, 不包邮→包邮) and stable-sort the aggregated arrays before materializing; out-of-vocabulary free-text labels (e.g. 海运) sink to the end preserving encounter order. Fix traversal order with orderBy id asc so recomputes are fully deterministic. Add recompute:families script for one-off re-materialize.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 全量族重算(一次性维护脚本):
|
||||
* 逐族调用 FamilyRecomputeService.recomputeFamily,刷新物化字段
|
||||
* (并集尺码表/包装规则 + 五维价格矩阵,含选项组词表序排序)。
|
||||
* autoManaged=false 的族内部只置 stale,不会覆盖人工物化字段。
|
||||
*
|
||||
* 运行:pnpm --filter @inkreach/api recompute:families
|
||||
*/
|
||||
import { PrismaService } from '../src/prisma/prisma.service';
|
||||
import { FamilyRecomputeService } from '../src/product-families/family-recompute.service';
|
||||
|
||||
async function main() {
|
||||
const prisma = new PrismaService();
|
||||
await prisma.onModuleInit();
|
||||
const recompute = new FamilyRecomputeService(prisma);
|
||||
|
||||
const families = await prisma.productFamily.findMany({
|
||||
select: { id: true },
|
||||
orderBy: { id: 'asc' },
|
||||
});
|
||||
let ok = 0;
|
||||
let failed = 0;
|
||||
for (const { id } of families) {
|
||||
try {
|
||||
await recompute.recomputeFamily(id);
|
||||
ok++;
|
||||
} catch (error) {
|
||||
failed++;
|
||||
console.error(`family ${id} recompute failed: ${String(error)}`);
|
||||
}
|
||||
}
|
||||
console.log(`[recompute:families] total=${families.length} ok=${ok} failed=${failed}`);
|
||||
await prisma.onModuleDestroy();
|
||||
if (failed > 0) process.exit(1);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user