From e2cf3c3d7eb46698811dee4077b8b319b02672b9 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 2 Jan 2026 05:56:43 -0800 Subject: [PATCH] =?UTF-8?q?fix(admin-service):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=9F=A5=E8=AF=A2=E6=97=B6publishedAt?= =?UTF-8?q?=E4=B8=BAnull=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:当 publishedAt 为 NULL(表示立即发布)时,Prisma 的 `publishedAt: { lte: now }` 条件不匹配,导致通知无法显示 修复:将查询条件改为 OR 逻辑: - publishedAt 为 null(立即发布) - publishedAt <= now(定时发布且已到时间) 影响的方法: - findNotificationsForUser - countUnreadForUser - markAllAsRead 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../notification.repository.impl.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/backend/services/admin-service/src/infrastructure/persistence/repositories/notification.repository.impl.ts b/backend/services/admin-service/src/infrastructure/persistence/repositories/notification.repository.impl.ts index d2f7bef2..70c10c2e 100644 --- a/backend/services/admin-service/src/infrastructure/persistence/repositories/notification.repository.impl.ts +++ b/backend/services/admin-service/src/infrastructure/persistence/repositories/notification.repository.impl.ts @@ -146,11 +146,13 @@ export class NotificationRepositoryImpl implements NotificationRepository { const notifications = await this.prisma.notification.findMany({ where: { isEnabled: true, - publishedAt: { lte: now }, - OR: [{ expiresAt: null }, { expiresAt: { gt: now } }], ...(params.type && { type: params.type }), - // 目标用户筛选 AND: [ + // publishedAt 为 null 表示立即发布,或者 publishedAt <= now + { OR: [{ publishedAt: null }, { publishedAt: { lte: now } }] }, + // expiresAt 为 null 表示永不过期,或者 expiresAt > now + { OR: [{ expiresAt: null }, { expiresAt: { gt: now } }] }, + // 目标用户筛选 { OR: [ // ALL: 发给所有人 @@ -204,13 +206,15 @@ export class NotificationRepositoryImpl implements NotificationRepository { const count = await this.prisma.notification.count({ where: { isEnabled: true, - publishedAt: { lte: now }, - OR: [{ expiresAt: null }, { expiresAt: { gt: now } }], readRecords: { none: { userSerialNum }, }, - // 目标用户筛选 AND: [ + // publishedAt 为 null 表示立即发布,或者 publishedAt <= now + { OR: [{ publishedAt: null }, { publishedAt: { lte: now } }] }, + // expiresAt 为 null 表示永不过期,或者 expiresAt > now + { OR: [{ expiresAt: null }, { expiresAt: { gt: now } }] }, + // 目标用户筛选 { OR: [ { targetType: 'ALL' }, @@ -265,12 +269,15 @@ export class NotificationRepositoryImpl implements NotificationRepository { const unreadNotifications = await this.prisma.notification.findMany({ where: { isEnabled: true, - publishedAt: { lte: now }, - OR: [{ expiresAt: null }, { expiresAt: { gt: now } }], readRecords: { none: { userSerialNum }, }, AND: [ + // publishedAt 为 null 表示立即发布,或者 publishedAt <= now + { OR: [{ publishedAt: null }, { publishedAt: { lte: now } }] }, + // expiresAt 为 null 表示永不过期,或者 expiresAt > now + { OR: [{ expiresAt: null }, { expiresAt: { gt: now } }] }, + // 目标用户筛选 { OR: [ { targetType: 'ALL' },