merge(dev_jacy): 修复企微报告表零日期

This commit is contained in:
2026-09-02 22:19:44 +08:00
3 changed files with 40 additions and 11 deletions
@@ -34,12 +34,15 @@ async function main() {
['monthly', '经营月报', 9],
];
for (const [kind, name, hour] of seeds) {
await prisma.$executeRaw`
INSERT IGNORE INTO wecom_report_push
(kind, name, webhook_url, enabled, send_hour, send_minute, send_weekday, send_month_day)
VALUES
(${kind}, ${name}, ${PLACEHOLDER}, 0, ${hour}, 0, 1, 1)
`;
await prisma.$executeRawUnsafe(
`INSERT IGNORE INTO wecom_report_push
(kind, name, webhook_url, enabled, send_hour, send_minute, send_weekday, send_month_day, created_at, updated_at)
VALUES (?, ?, ?, 0, ?, 0, 1, 1, CURRENT_TIMESTAMP(3), CURRENT_TIMESTAMP(3))`,
kind,
name,
PLACEHOLDER,
hour,
);
}
console.log('migrate-wecom-report done');
}
+1 -1
View File
@@ -561,7 +561,7 @@ model WecomReportPush {
lastSentPeriod String? @map("last_sent_period") @db.VarChar(16)
lastSentAt DateTime? @map("last_sent_at") @db.DateTime(3)
createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3)
updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.DateTime(3)
@@map("wecom_report_push")
}
@@ -61,6 +61,7 @@ type ReportRow = WecomReportPush;
@Injectable()
export class AdminWecomReportsService implements OnModuleInit {
private readonly logger = new Logger(AdminWecomReportsService.name);
private defaultsReady = false;
constructor(
private readonly prisma: PrismaService,
@@ -77,11 +78,36 @@ export class AdminWecomReportsService implements OnModuleInit {
}
}
/**
* 早期 INSERT IGNORE 未写 updated_atPrisma db push 的列又无默认值,
* MySQL 会落成 0000-00-00,后续 Prisma 读行即报 invalid datetime。
*/
private async repairZeroDatetimes(): Promise<void> {
await this.prisma.$executeRawUnsafe(`
UPDATE wecom_report_push
SET created_at = CURRENT_TIMESTAMP(3)
WHERE CAST(created_at AS CHAR) REGEXP '^0000|-00-'
`);
await this.prisma.$executeRawUnsafe(`
UPDATE wecom_report_push
SET updated_at = CURRENT_TIMESTAMP(3)
WHERE CAST(updated_at AS CHAR) REGEXP '^0000|-00-'
`);
await this.prisma.$executeRawUnsafe(`
UPDATE wecom_report_push
SET last_sent_at = NULL
WHERE last_sent_at IS NOT NULL AND CAST(last_sent_at AS CHAR) REGEXP '^0000|-00-'
`);
}
async ensureDefaults(): Promise<void> {
if (this.defaultsReady) return;
await this.repairZeroDatetimes();
for (const seed of KIND_SEED) {
await this.prisma.wecomReportPush.upsert({
where: { kind: seed.kind },
create: {
const existing = await this.prisma.wecomReportPush.findUnique({ where: { kind: seed.kind } });
if (existing) continue;
await this.prisma.wecomReportPush.create({
data: {
kind: seed.kind,
name: seed.name,
webhookUrl: WECOM_STORE_AUDIT_PLACEHOLDER_WEBHOOK,
@@ -91,9 +117,9 @@ export class AdminWecomReportsService implements OnModuleInit {
sendWeekday: 1,
sendMonthDay: 1,
},
update: {},
});
}
this.defaultsReady = true;
}
parseKind(raw: string): WecomReportKind {