Skip to content
bitzorcas
EN

Reference

通知模块

多通道通知系统 — 应用内收件箱,支持偏好管理、模板化通知、投递适配器端口和 CAP 事件发布。

Last updated

Notifications 模块提供应用内通知收件箱,配备多通道投递抽象、偏好管理和模板化通知。

端点

端点方法描述
/api/notificationsGET分页收件箱列表
/api/notifications/{id}/readPOST标记已读
/api/notifications/read-allPOST全部标记已读
/api/notifications/preferencesGET/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

另见