This commit is contained in:
“hsc”
2026-09-04 17:38:57 +08:00
67 changed files with 5971 additions and 30 deletions
+221
View File
@@ -0,0 +1,221 @@
namespace Model.Entity.Inspection
{
/// <summary>
/// 告警级别(与规则引擎 AlertRuleEntity.AlarmLevel 字符串"信息/警告/紧急"保持一致)
/// </summary>
public enum AlertLevelEnum
{
/// <summary>
/// 信息
/// </summary>
Info = 1,
/// <summary>
/// 警告
/// </summary>
Warning = 2,
/// <summary>
/// 紧急
/// </summary>
Urgent = 3
}
/// <summary>
/// 告警状态(闭环流转:未确认 → 已确认 → 已处理 → 已关闭;可忽略/转工单)
/// </summary>
public enum AlertStatusEnum
{
/// <summary>
/// 未确认
/// </summary>
Unacknowledged = 1,
/// <summary>
/// 已确认
/// </summary>
Acknowledged = 2,
/// <summary>
/// 已处理
/// </summary>
Handled = 3,
/// <summary>
/// 已关闭
/// </summary>
Closed = 4,
/// <summary>
/// 已忽略
/// </summary>
Ignored = 5,
/// <summary>
/// 已转工单
/// </summary>
ToWorkOrder = 6
}
/// <summary>
/// 告警来源(标识上报模块,便于其它模块调用与统计)
/// </summary>
public enum AlertSourceEnum
{
/// <summary>
/// 规则引擎
/// </summary>
RuleEngine = 1,
/// <summary>
/// 自动巡检
/// </summary>
AutoPatrol = 2,
/// <summary>
/// 数据看板
/// </summary>
Dashboard = 3,
/// <summary>
/// 数据采集
/// </summary>
Collection = 4,
/// <summary>
/// 手动/API 上报
/// </summary>
Manual = 5,
/// <summary>
/// 其它
/// </summary>
Other = 99
}
/// <summary>
/// 告警类型
/// </summary>
public enum AlertTypeEnum
{
/// <summary>
/// 阈值超限
/// </summary>
ThresholdExceed = 1,
/// <summary>
/// 设备离线
/// </summary>
DeviceOffline = 2,
/// <summary>
/// 通讯故障
/// </summary>
CommFault = 3,
/// <summary>
/// 巡检异常
/// </summary>
PatrolAbnormal = 4,
/// <summary>
/// 自定义
/// </summary>
Custom = 99
}
/// <summary>
/// 通知渠道类型(一期仅支持飞书/钉钉/企微 Webhook 机器人)
/// </summary>
public enum NotifyChannelTypeEnum
{
/// <summary>
/// 飞书
/// </summary>
Feishu = 1,
/// <summary>
/// 钉钉
/// </summary>
DingTalk = 2,
/// <summary>
/// 企业微信
/// </summary>
WeCom = 3
}
/// <summary>
/// 渠道推送模式
/// </summary>
public enum NotifyPushModeEnum
{
/// <summary>
/// 直连推送(服务器可直接访问外网 Webhook)
/// </summary>
Direct = 1,
/// <summary>
/// Outbox 中转(跨网场景:内网写发件箱,跳板机 AlertBridge 拉取后在外网推送)
/// </summary>
Outbox = 2
}
/// <summary>
/// 跨网发件箱状态
/// </summary>
public enum OutboxStatusEnum
{
/// <summary>
/// 待推送
/// </summary>
Pending = 1,
/// <summary>
/// 已拉取(跳板机取走,等待回写结果)
/// </summary>
Pulled = 2,
/// <summary>
/// 推送成功
/// </summary>
Success = 3,
/// <summary>
/// 推送失败
/// </summary>
Failed = 4
}
/// <summary>
/// 告警级别枚举 ↔ 规则引擎字符串 映射工具
/// </summary>
public static class AlertLevelMap
{
/// <summary>
/// 字符串(信息/警告/紧急)→ 枚举,无法识别时默认 Info
/// </summary>
public static AlertLevelEnum FromString(string level)
{
return level?.Trim() switch
{
"警告" => AlertLevelEnum.Warning,
"紧急" => AlertLevelEnum.Urgent,
_ => AlertLevelEnum.Info
};
}
/// <summary>
/// 枚举 → 字符串(信息/警告/紧急)
/// </summary>
public static string ToLabel(AlertLevelEnum level)
{
return level switch
{
AlertLevelEnum.Warning => "警告",
AlertLevelEnum.Urgent => "紧急",
_ => "信息"
};
}
}
}
@@ -0,0 +1,151 @@
using SqlSugar;
using System;
namespace Model.Entity.Inspection
{
/// <summary>
/// 告警消息(消息告警模块核心表:所有模块的告警统一汇聚于此,支持确认/处理/关闭闭环)
/// </summary>
public class AlertMessageEntity : BaseEntity
{
#region
/// <summary>
/// 告警来源(规则引擎/自动巡检/看板/数采/手动等)
/// </summary>
[SugarColumn(ColumnDescription = "告警来源")]
public AlertSourceEnum Source { get; set; } = AlertSourceEnum.Manual;
/// <summary>
/// 关联告警规则Id(来源为规则引擎时填写,0表示无)
/// </summary>
[SugarColumn(ColumnDescription = "关联告警规则Id")]
public long RuleId { get; set; }
/// <summary>
/// 设备编号
/// </summary>
[SugarColumn(ColumnDescription = "设备编号", Length = 64, IsNullable = true)]
public string DeviceCode { get; set; }
/// <summary>
/// 设备名称
/// </summary>
[SugarColumn(ColumnDescription = "设备名称", Length = 128, IsNullable = true)]
public string DeviceName { get; set; }
/// <summary>
/// 设备类型(如 TemperatureBox,与规则引擎 DeviceType 对齐)
/// </summary>
[SugarColumn(ColumnDescription = "设备类型", Length = 64, IsNullable = true)]
public string DeviceType { get; set; }
/// <summary>
/// 测点/监测指标(如 Temperature、Humidity
/// </summary>
[SugarColumn(ColumnDescription = "测点指标", Length = 64, IsNullable = true)]
public string Metric { get; set; }
/// <summary>
/// 告警类型(超限/离线/通讯故障/巡检异常/自定义)
/// </summary>
[SugarColumn(ColumnDescription = "告警类型")]
public AlertTypeEnum AlertType { get; set; } = AlertTypeEnum.ThresholdExceed;
#endregion
#region
/// <summary>
/// 告警级别(信息/警告/紧急,与规则引擎三级一致)
/// </summary>
[SugarColumn(ColumnDescription = "告警级别")]
public AlertLevelEnum AlertLevel { get; set; } = AlertLevelEnum.Info;
/// <summary>
/// 当前值(触发告警时的实际值)
/// </summary>
[SugarColumn(ColumnDescription = "当前值", IsNullable = true)]
public double? CurrentValue { get; set; }
/// <summary>
/// 阈值(规则阈值,可空)
/// </summary>
[SugarColumn(ColumnDescription = "阈值", IsNullable = true)]
public double? ThresholdValue { get; set; }
/// <summary>
/// 告警内容描述
/// </summary>
[SugarColumn(ColumnDescription = "告警内容", Length = 500, IsNullable = true)]
public string Content { get; set; }
/// <summary>
/// 通知模板编码(预留:对接通知模板模块,空表示使用内置模板)
/// </summary>
[SugarColumn(ColumnDescription = "通知模板编码", Length = 64, IsNullable = true)]
public string TemplateCode { get; set; }
#endregion
#region
/// <summary>
/// 触发次数(合并窗口内同设备同测点同类型告警的累计次数)
/// </summary>
[SugarColumn(ColumnDescription = "触发次数")]
public int TriggerCount { get; set; } = 1;
/// <summary>
/// 首次告警时间
/// </summary>
[SugarColumn(ColumnDescription = "首次告警时间")]
public DateTime FirstAlertTime { get; set; }
/// <summary>
/// 最近告警时间
/// </summary>
[SugarColumn(ColumnDescription = "最近告警时间")]
public DateTime LastAlertTime { get; set; }
#endregion
#region
/// <summary>
/// 告警状态(未确认/已确认/已处理/已关闭/已忽略/已转工单)
/// </summary>
[SugarColumn(ColumnDescription = "告警状态")]
public AlertStatusEnum AlertStatus { get; set; } = AlertStatusEnum.Unacknowledged;
/// <summary>
/// 确认人
/// </summary>
[SugarColumn(ColumnDescription = "确认人", Length = 50, IsNullable = true)]
public string AckBy { get; set; }
/// <summary>
/// 确认时间
/// </summary>
[SugarColumn(ColumnDescription = "确认时间", IsNullable = true)]
public DateTime? AckTime { get; set; }
/// <summary>
/// 处理人
/// </summary>
[SugarColumn(ColumnDescription = "处理人", Length = 50, IsNullable = true)]
public string HandleBy { get; set; }
/// <summary>
/// 处理时间
/// </summary>
[SugarColumn(ColumnDescription = "处理时间", IsNullable = true)]
public DateTime? HandleTime { get; set; }
/// <summary>
/// 处理备注
/// </summary>
[SugarColumn(ColumnDescription = "处理备注", Length = 500, IsNullable = true)]
public string HandleRemark { get; set; }
/// <summary>
/// 关联工单Id(预留二期运维工单模块,0表示未转工单)
/// </summary>
[SugarColumn(ColumnDescription = "关联工单Id")]
public long WorkOrderId { get; set; }
#endregion
}
}
@@ -0,0 +1,52 @@
using SqlSugar;
namespace Model.Entity.Inspection
{
/// <summary>
/// 告警通知渠道(飞书/钉钉/企微 Webhook 机器人配置)
/// </summary>
public class AlertNotifyChannelEntity : BaseEntity
{
/// <summary>
/// 渠道类型(1飞书/2钉钉/3企微)
/// </summary>
[SugarColumn(ColumnDescription = "渠道类型")]
public NotifyChannelTypeEnum ChannelType { get; set; }
/// <summary>
/// 渠道名称(如:设备告警-研发飞书群)
/// </summary>
[SugarColumn(ColumnDescription = "渠道名称", Length = 100)]
public string Name { get; set; }
/// <summary>
/// Webhook 地址
/// </summary>
[SugarColumn(ColumnDescription = "Webhook地址", Length = 500)]
public string WebhookUrl { get; set; }
/// <summary>
/// 加签密钥(钉钉/飞书机器人开启加签时填写,企微机器人无此项)
/// </summary>
[SugarColumn(ColumnDescription = "加签密钥", Length = 200, IsNullable = true)]
public string Secret { get; set; }
/// <summary>
/// 推送模式(1直连推送/2Outbox跨网中转)
/// </summary>
[SugarColumn(ColumnDescription = "推送模式")]
public NotifyPushModeEnum PushMode { get; set; } = NotifyPushModeEnum.Direct;
/// <summary>
/// 是否启用
/// </summary>
[SugarColumn(ColumnDescription = "是否启用")]
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnDescription = "备注", Length = 500, IsNullable = true)]
public string Remark { get; set; }
}
}
@@ -0,0 +1,65 @@
using SqlSugar;
using System;
namespace Model.Entity.Inspection
{
/// <summary>
/// 告警通知推送日志(每次向渠道推送的结果记录,失败可追溯)
/// </summary>
public class AlertNotifyLogEntity : BaseEntity
{
/// <summary>
/// 告警消息Id(关联 AlertMessageEntity.Id0表示渠道测试推送)
/// </summary>
[SugarColumn(ColumnDescription = "告警消息Id")]
public long AlertId { get; set; }
/// <summary>
/// 渠道类型(1飞书/2钉钉/3企微)
/// </summary>
[SugarColumn(ColumnDescription = "渠道类型")]
public NotifyChannelTypeEnum ChannelType { get; set; }
/// <summary>
/// 渠道Id(关联 AlertNotifyChannelEntity.Id
/// </summary>
[SugarColumn(ColumnDescription = "渠道Id")]
public long ChannelId { get; set; }
/// <summary>
/// 推送目标(Webhook 地址脱敏展示)
/// </summary>
[SugarColumn(ColumnDescription = "推送目标", Length = 200, IsNullable = true)]
public string Target { get; set; }
/// <summary>
/// 推送内容摘要
/// </summary>
[SugarColumn(ColumnDescription = "推送内容", Length = 1000, IsNullable = true)]
public string Content { get; set; }
/// <summary>
/// 是否成功
/// </summary>
[SugarColumn(ColumnDescription = "是否成功")]
public bool Success { get; set; }
/// <summary>
/// 错误信息
/// </summary>
[SugarColumn(ColumnDescription = "错误信息", Length = 500, IsNullable = true)]
public string ErrorMsg { get; set; }
/// <summary>
/// 重试次数
/// </summary>
[SugarColumn(ColumnDescription = "重试次数")]
public int RetryCount { get; set; }
/// <summary>
/// 推送时间
/// </summary>
[SugarColumn(ColumnDescription = "推送时间")]
public DateTime NotifyTime { get; set; }
}
}
@@ -0,0 +1,58 @@
using SqlSugar;
namespace Model.Entity.Inspection
{
/// <summary>
/// 告警通知规则(按告警级别配置通知渠道与接收人,支持值班排班关联与静默期)
/// </summary>
public class AlertNotifyRuleEntity : BaseEntity
{
/// <summary>
/// 规则名称
/// </summary>
[SugarColumn(ColumnDescription = "规则名称", Length = 100)]
public string RuleName { get; set; }
/// <summary>
/// 适用告警级别(信息/警告/紧急)
/// </summary>
[SugarColumn(ColumnDescription = "适用告警级别")]
public AlertLevelEnum AlertLevel { get; set; }
/// <summary>
/// 通知渠道Id(关联 AlertNotifyChannelEntity.Id
/// </summary>
[SugarColumn(ColumnDescription = "通知渠道Id")]
public long ChannelId { get; set; }
/// <summary>
/// 接收人(@手机号/企微账号,逗号分隔,可空表示不@)
/// </summary>
[SugarColumn(ColumnDescription = "接收人", Length = 500, IsNullable = true)]
public string Receivers { get; set; }
/// <summary>
/// 是否通知当班值班人(按告警时间查值班排班表)
/// </summary>
[SugarColumn(ColumnDescription = "是否通知值班人")]
public bool NotifyDutyPerson { get; set; }
/// <summary>
/// 静默期(分钟):同一告警合并窗口内重复触发时,静默期内不重复推送,0表示每次必推
/// </summary>
[SugarColumn(ColumnDescription = "静默期分钟")]
public int SilenceMinutes { get; set; } = 5;
/// <summary>
/// 是否启用
/// </summary>
[SugarColumn(ColumnDescription = "是否启用")]
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnDescription = "备注", Length = 500, IsNullable = true)]
public string Remark { get; set; }
}
}
@@ -0,0 +1,61 @@
using SqlSugar;
using System;
namespace Model.Entity.Inspection
{
/// <summary>
/// 跨网推送发件箱(内网只写此表;跳板机上的 AlertBridge 控制台程序轮询拉取,
/// 在外网推送飞书/钉钉/企微后回写结果,实现工控内网与即时通讯软件的隔离穿透)
/// </summary>
public class AlertOutboxEntity : BaseEntity
{
/// <summary>
/// 告警消息Id(关联 AlertMessageEntity.Id
/// </summary>
[SugarColumn(ColumnDescription = "告警消息Id")]
public long AlertId { get; set; }
/// <summary>
/// 渠道Id(关联 AlertNotifyChannelEntity.Id
/// </summary>
[SugarColumn(ColumnDescription = "渠道Id")]
public long ChannelId { get; set; }
/// <summary>
/// 完整推送报文(自包含 JSON:渠道类型/WebhookUrl/Secret/标题/内容/@列表,
/// AlertBridge 拉取后无需再查任何配置即可直接推送)
/// </summary>
[SugarColumn(ColumnDescription = "推送报文", ColumnDataType = "text", IsNullable = true)]
public string Payload { get; set; }
/// <summary>
/// 状态(1待推送/2已拉取/3成功/4失败)
/// </summary>
[SugarColumn(ColumnDescription = "状态")]
public OutboxStatusEnum Status { get; set; } = OutboxStatusEnum.Pending;
/// <summary>
/// 重试次数(AlertBridge 推送失败回写时累加)
/// </summary>
[SugarColumn(ColumnDescription = "重试次数")]
public int RetryCount { get; set; }
/// <summary>
/// 拉取时间
/// </summary>
[SugarColumn(ColumnDescription = "拉取时间", IsNullable = true)]
public DateTime? PullTime { get; set; }
/// <summary>
/// 完成时间(成功/失败回写时间)
/// </summary>
[SugarColumn(ColumnDescription = "完成时间", IsNullable = true)]
public DateTime? FinishTime { get; set; }
/// <summary>
/// 结果信息(失败原因等)
/// </summary>
[SugarColumn(ColumnDescription = "结果信息", Length = 500, IsNullable = true)]
public string ResultMsg { get; set; }
}
}
@@ -8,6 +8,24 @@ namespace Model.Entity.Inspection
/// </summary>
public class AlertRuleEntity : BaseEntity
{
/// <summary>
/// 归属类型(0=全局/旧数据;1=产品 2=设备)
/// </summary>
[SugarColumn(ColumnDescription = "归属类型", DefaultValue = "0")]
public byte OwnerType { get; set; }
/// <summary>
/// 归属对象IdProductEntity.Id / IotDeviceEntity.Id0 表示全局)
/// </summary>
[SugarColumn(ColumnDescription = "归属对象Id", DefaultValue = "0")]
public long OwnerId { get; set; }
/// <summary>
/// 绑定点编码(关联物模型点 Code;为空表示整产品/设备级规则)
/// </summary>
[SugarColumn(ColumnDescription = "绑定点编码", Length = 64, IsNullable = true)]
public string? PointCode { get; set; }
/// <summary>
/// 规则名称
/// </summary>
@@ -0,0 +1,35 @@
using SqlSugar;
using System;
namespace Model.Entity.Inspection
{
/// <summary>
/// 值班排班(按天排班;通知规则勾选"通知值班人"时按告警日期匹配当班人)
/// </summary>
public class DutyRosterEntity : BaseEntity
{
/// <summary>
/// 值班日期(当天 00:00:00
/// </summary>
[SugarColumn(ColumnDescription = "值班日期")]
public DateTime DutyDate { get; set; }
/// <summary>
/// 值班人姓名
/// </summary>
[SugarColumn(ColumnDescription = "值班人", Length = 50)]
public string PersonName { get; set; }
/// <summary>
/// 联系电话(用于钉钉/企微 @ 手机号)
/// </summary>
[SugarColumn(ColumnDescription = "联系电话", Length = 30, IsNullable = true)]
public string Phone { get; set; }
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnDescription = "备注", Length = 500, IsNullable = true)]
public string Remark { get; set; }
}
}