搭建消息告警模块以及跨网推送服务,支持企微,飞书,钉钉通知
This commit is contained in:
@@ -476,5 +476,275 @@ namespace Model.Mapper
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<DeviceLogDto>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 告警消息
|
||||
/// <summary>
|
||||
/// AlertMessageEntity → AlertMessageDto
|
||||
/// </summary>
|
||||
public static AlertMessageDto ToDto(this AlertMessageEntity entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
return new AlertMessageDto
|
||||
{
|
||||
Id = entity.Id.ToString(),
|
||||
CreateTime = entity.CreateTime,
|
||||
Source = entity.Source,
|
||||
RuleId = entity.RuleId.ToString(),
|
||||
DeviceCode = entity.DeviceCode,
|
||||
DeviceName = entity.DeviceName,
|
||||
DeviceType = entity.DeviceType,
|
||||
Metric = entity.Metric,
|
||||
AlertType = entity.AlertType,
|
||||
AlertLevel = entity.AlertLevel,
|
||||
CurrentValue = entity.CurrentValue,
|
||||
ThresholdValue = entity.ThresholdValue,
|
||||
Content = entity.Content,
|
||||
TemplateCode = entity.TemplateCode,
|
||||
TriggerCount = entity.TriggerCount,
|
||||
FirstAlertTime = entity.FirstAlertTime,
|
||||
LastAlertTime = entity.LastAlertTime,
|
||||
AlertStatus = entity.AlertStatus,
|
||||
AckBy = entity.AckBy,
|
||||
AckTime = entity.AckTime,
|
||||
HandleBy = entity.HandleBy,
|
||||
HandleTime = entity.HandleTime,
|
||||
HandleRemark = entity.HandleRemark,
|
||||
WorkOrderId = entity.WorkOrderId.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List<AlertMessageEntity> → List<AlertMessageDto>
|
||||
/// </summary>
|
||||
public static List<AlertMessageDto> ToDtoList(this List<AlertMessageEntity> entities)
|
||||
{
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertMessageDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AlertRaiseDto → AlertMessageEntity(告警中心上报入参映射;
|
||||
/// 状态/闭环/聚合字段由服务端初始化,不接受调用方指定)
|
||||
/// </summary>
|
||||
public static AlertMessageEntity ToEntity(this AlertRaiseDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
return new AlertMessageEntity
|
||||
{
|
||||
Source = dto.Source,
|
||||
RuleId = dto.RuleId,
|
||||
DeviceCode = dto.DeviceCode,
|
||||
DeviceName = dto.DeviceName,
|
||||
DeviceType = dto.DeviceType,
|
||||
Metric = dto.Metric,
|
||||
AlertType = dto.AlertType,
|
||||
AlertLevel = dto.AlertLevel,
|
||||
CurrentValue = dto.CurrentValue,
|
||||
ThresholdValue = dto.ThresholdValue,
|
||||
Content = dto.Content,
|
||||
TemplateCode = dto.TemplateCode
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 告警通知渠道
|
||||
/// <summary>
|
||||
/// AlertNotifyChannelEntity → AlertNotifyChannelDto(Secret 脱敏:不回传明文,仅标记 HasSecret)
|
||||
/// </summary>
|
||||
public static AlertNotifyChannelDto ToDto(this AlertNotifyChannelEntity entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
return new AlertNotifyChannelDto
|
||||
{
|
||||
Id = entity.Id.ToString(),
|
||||
CreateTime = entity.CreateTime,
|
||||
ChannelType = entity.ChannelType,
|
||||
Name = entity.Name,
|
||||
WebhookUrl = entity.WebhookUrl,
|
||||
Secret = null,
|
||||
HasSecret = !string.IsNullOrWhiteSpace(entity.Secret),
|
||||
PushMode = entity.PushMode,
|
||||
IsEnabled = entity.IsEnabled,
|
||||
Remark = entity.Remark
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List<AlertNotifyChannelEntity> → List<AlertNotifyChannelDto>
|
||||
/// </summary>
|
||||
public static List<AlertNotifyChannelDto> ToDtoList(this List<AlertNotifyChannelEntity> entities)
|
||||
{
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertNotifyChannelDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AlertNotifyChannelDto → AlertNotifyChannelEntity(IsDel/CreateTime 不映射)
|
||||
/// </summary>
|
||||
public static AlertNotifyChannelEntity ToEntity(this AlertNotifyChannelDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
return new AlertNotifyChannelEntity
|
||||
{
|
||||
Id = ParseId(dto.Id),
|
||||
ChannelType = dto.ChannelType,
|
||||
Name = dto.Name,
|
||||
WebhookUrl = dto.WebhookUrl,
|
||||
Secret = dto.Secret,
|
||||
PushMode = dto.PushMode,
|
||||
IsEnabled = dto.IsEnabled,
|
||||
Remark = dto.Remark
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 告警通知规则
|
||||
/// <summary>
|
||||
/// AlertNotifyRuleEntity → AlertNotifyRuleDto
|
||||
/// </summary>
|
||||
public static AlertNotifyRuleDto ToDto(this AlertNotifyRuleEntity entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
return new AlertNotifyRuleDto
|
||||
{
|
||||
Id = entity.Id.ToString(),
|
||||
CreateTime = entity.CreateTime,
|
||||
RuleName = entity.RuleName,
|
||||
AlertLevel = entity.AlertLevel,
|
||||
ChannelId = entity.ChannelId.ToString(),
|
||||
Receivers = entity.Receivers,
|
||||
NotifyDutyPerson = entity.NotifyDutyPerson,
|
||||
SilenceMinutes = entity.SilenceMinutes,
|
||||
IsEnabled = entity.IsEnabled,
|
||||
Remark = entity.Remark
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List<AlertNotifyRuleEntity> → List<AlertNotifyRuleDto>
|
||||
/// </summary>
|
||||
public static List<AlertNotifyRuleDto> ToDtoList(this List<AlertNotifyRuleEntity> entities)
|
||||
{
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertNotifyRuleDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AlertNotifyRuleDto → AlertNotifyRuleEntity(IsDel/CreateTime 不映射)
|
||||
/// </summary>
|
||||
public static AlertNotifyRuleEntity ToEntity(this AlertNotifyRuleDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
return new AlertNotifyRuleEntity
|
||||
{
|
||||
Id = ParseId(dto.Id),
|
||||
RuleName = dto.RuleName,
|
||||
AlertLevel = dto.AlertLevel,
|
||||
ChannelId = ParseId(dto.ChannelId),
|
||||
Receivers = dto.Receivers,
|
||||
NotifyDutyPerson = dto.NotifyDutyPerson,
|
||||
SilenceMinutes = dto.SilenceMinutes,
|
||||
IsEnabled = dto.IsEnabled,
|
||||
Remark = dto.Remark
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 告警通知日志
|
||||
/// <summary>
|
||||
/// AlertNotifyLogEntity → AlertNotifyLogDto
|
||||
/// </summary>
|
||||
public static AlertNotifyLogDto ToDto(this AlertNotifyLogEntity entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
return new AlertNotifyLogDto
|
||||
{
|
||||
Id = entity.Id.ToString(),
|
||||
AlertId = entity.AlertId.ToString(),
|
||||
ChannelType = entity.ChannelType,
|
||||
ChannelId = entity.ChannelId.ToString(),
|
||||
Target = entity.Target,
|
||||
Content = entity.Content,
|
||||
Success = entity.Success,
|
||||
ErrorMsg = entity.ErrorMsg,
|
||||
RetryCount = entity.RetryCount,
|
||||
NotifyTime = entity.NotifyTime
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List<AlertNotifyLogEntity> → List<AlertNotifyLogDto>
|
||||
/// </summary>
|
||||
public static List<AlertNotifyLogDto> ToDtoList(this List<AlertNotifyLogEntity> entities)
|
||||
{
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertNotifyLogDto>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 跨网发件箱
|
||||
/// <summary>
|
||||
/// AlertOutboxEntity → AlertOutboxItemDto
|
||||
/// </summary>
|
||||
public static AlertOutboxItemDto ToDto(this AlertOutboxEntity entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
return new AlertOutboxItemDto
|
||||
{
|
||||
Id = entity.Id.ToString(),
|
||||
AlertId = entity.AlertId.ToString(),
|
||||
ChannelId = entity.ChannelId.ToString(),
|
||||
Payload = entity.Payload,
|
||||
RetryCount = entity.RetryCount
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List<AlertOutboxEntity> → List<AlertOutboxItemDto>
|
||||
/// </summary>
|
||||
public static List<AlertOutboxItemDto> ToDtoList(this List<AlertOutboxEntity> entities)
|
||||
{
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertOutboxItemDto>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 值班排班
|
||||
/// <summary>
|
||||
/// DutyRosterEntity → DutyRosterDto
|
||||
/// </summary>
|
||||
public static DutyRosterDto ToDto(this DutyRosterEntity entity)
|
||||
{
|
||||
if (entity == null) return null;
|
||||
return new DutyRosterDto
|
||||
{
|
||||
Id = entity.Id.ToString(),
|
||||
CreateTime = entity.CreateTime,
|
||||
DutyDate = entity.DutyDate,
|
||||
PersonName = entity.PersonName,
|
||||
Phone = entity.Phone,
|
||||
Remark = entity.Remark
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List<DutyRosterEntity> → List<DutyRosterDto>
|
||||
/// </summary>
|
||||
public static List<DutyRosterDto> ToDtoList(this List<DutyRosterEntity> entities)
|
||||
{
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<DutyRosterDto>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DutyRosterDto → DutyRosterEntity(IsDel/CreateTime 不映射)
|
||||
/// </summary>
|
||||
public static DutyRosterEntity ToEntity(this DutyRosterDto dto)
|
||||
{
|
||||
if (dto == null) return null;
|
||||
return new DutyRosterEntity
|
||||
{
|
||||
Id = ParseId(dto.Id),
|
||||
DutyDate = dto.DutyDate.Date,
|
||||
PersonName = dto.PersonName,
|
||||
Phone = dto.Phone,
|
||||
Remark = dto.Remark
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user