fix: 修复上行归属并实现签名质量日报优化
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// Offline operator entry point. No SMS, detection, notification or history overwrite is performed.
|
||||
import { createRequire } from 'node:module';
|
||||
import assert from 'node:assert/strict';
|
||||
const args = Object.fromEntries(process.argv.slice(2).map((a) => a.replace(/^--/, '').split('=')));
|
||||
const url = new URL(process.env.DATABASE_URL || '');
|
||||
assert(
|
||||
args.host && args.host === url.hostname,
|
||||
'Supply --host matching DATABASE_URL and an explicitly authorized target',
|
||||
);
|
||||
assert(args.dates, 'Supply --dates=YYYY-MM-DD,YYYY-MM-DD; no implicit historical range');
|
||||
const dates = [...new Set(args.dates.split(','))];
|
||||
assert(dates.length <= 366, 'At most 366 explicitly selected days per invocation');
|
||||
process.env.NODE_ENV = 'test'; // Disable all automatic schedulers; this script only creates the report writer.
|
||||
const require = createRequire(new URL('../../api/package.json', import.meta.url));
|
||||
require('reflect-metadata');
|
||||
const { PrismaService } = require('./dist/prisma/prisma.service');
|
||||
const { SignatureAnalyticsService } = require('./dist/signature-analytics/signature-analytics.service');
|
||||
const { analyticsDate, databaseDay, todayKey } = require('./dist/signature-analytics/analytics-date');
|
||||
const db = new PrismaService();
|
||||
try {
|
||||
for (const day of dates) {
|
||||
analyticsDate(day);
|
||||
assert(day < todayKey(), 'Only complete natural days may be backfilled');
|
||||
const current = await db.signatureAnalyticsDay.findUnique({ where: { businessDate: databaseDay(day) } });
|
||||
assert(!current?.publishedGenerationId, `${day}: published report exists; overwriting is forbidden`);
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
host: url.hostname,
|
||||
dates,
|
||||
execute: args.execute === 'yes',
|
||||
provenance: 'backfill-current-source',
|
||||
}),
|
||||
);
|
||||
if (args.execute === 'yes') {
|
||||
const writer = new SignatureAnalyticsService(db);
|
||||
for (const day of dates) console.log(JSON.stringify(await writer.generate(day, true)));
|
||||
}
|
||||
} finally {
|
||||
await db.onModuleDestroy();
|
||||
}
|
||||
Reference in New Issue
Block a user