Notifications 模块提供应用内通知收件箱,配备多通道投递抽象、偏好管理和模板化通知。
端点
| 端点 | 方法 | 描述 |
|---|---|---|
/api/notifications | GET | 分页收件箱列表 |
/api/notifications/{id}/read | POST | 标记已读 |
/api/notifications/read-all | POST | 全部标记已读 |
/api/notifications/preferences | GET/PUT | 用户通知偏好 |
架构
NotificationEndpoints │ ▼NotificationService │ ├── INotificationRepository → SqlSugarNotificationRepository ├── INotificationPreferenceStore → AllowAllNotificationPreferenceStore ├── INotificationDeliveryAdapter → NullNotificationDeliveryAdapter └── INotificationTemplateStore → (基于配置)核心组件
NotificationService
创建和投递通知的核心服务:
public class NotificationService{ // 创建通知 → 持久化到收件箱 + 触发投递 public Task CreateAsync(string userId, NotificationTemplate template, CancellationToken ct);
// 标记单个通知已读 public Task MarkReadAsync(Guid notificationId, CancellationToken ct);
// 查询用户收件箱 public Task<NotificationInboxPage> GetInboxAsync(string userId, int page, int pageSize, CancellationToken ct);}NotificationTemplate
public class NotificationTemplate{ public string Title { get; } public string Body { get; } public string Category { get; } // system, chat, ticket, billing 等 public Dictionary<string, string> Variables { get; }}NotificationPreference
public class NotificationPreference{ public string Category { get; } public bool InApp { get; } public bool Email { get; } public bool Sms { get; } public bool Push { get; }}Notification 实体
public class NotificationEntity : TenantSoftDeleteEntityBase{ public string UserId { get; set; } public string Title { get; set; } public string Body { get; set; } public string Category { get; set; } public bool IsRead { get; set; } public DateTimeOffset? ReadAt { get; set; }}投递通道
| 通道 | 实现 | 状态 |
|---|---|---|
| 应用内收件箱 | SqlSugarNotificationRepository | ✅ 已实现 |
| 邮件 | NullNotificationDeliveryAdapter | 📋 计划中 |
| 短信 | N/A | 📋 计划中 |
| 推送 | N/A | 📋 计划中 |
事件集成
通知由其他模块的集成事件触发:
工单创建 → ticket.created 事件 → NotificationService聊天提及 → chat.mention 事件 → NotificationService计费告警 → billing.overdue 事件 → NotificationService