using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace Service.Interface { /// /// 通知消息(Notifier 统一入参:与具体渠道报文格式解耦) /// public class AlertNotifyMessage { /// /// 消息标题 /// public string Title { get; set; } = "设备告警"; /// /// 消息正文(markdown 语法,各 Notifier 按需降级为纯文本) /// public string Content { get; set; } = string.Empty; /// /// @ 手机号列表(钉钉/企微支持;飞书文本追加展示) /// public List AtMobiles { get; set; } = new(); } /// /// 通知发送结果 /// public class NotifyResult { /// /// 是否成功 /// public bool Success { get; set; } /// /// 错误信息(失败时填写,含渠道响应原文摘要) /// public string? ErrorMsg { get; set; } public static NotifyResult Ok() => new() { Success = true }; public static NotifyResult Fail(string msg) => new() { Success = false, ErrorMsg = msg }; } /// /// 告警通知渠道发送器抽象(一期:飞书/钉钉/企微 Webhook 机器人) /// 扩展新渠道(如短信网关)只需实现本接口并在 DependencyInjection.AddAlertNotification 注册,调用方零改动 /// public interface IAlertNotifier { /// /// 本发送器支持的渠道类型 /// Model.Entity.Inspection.NotifyChannelTypeEnum ChannelType { get; } /// /// 发送消息 /// /// 统一通知消息 /// 渠道 Webhook 地址 /// 加签密钥(可空:未开启加签) /// 取消令牌 Task SendAsync(AlertNotifyMessage message, string webhookUrl, string? secret, CancellationToken ct = default); } }