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' },