Merge remote-tracking branch 'origin/master'(告警中心/通知模块 与 产品/物模型模块 合并,EntityMapper.cs 保留双方映射区域)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-09-03 17:33:12 +08:00
co-authored by Claude Code
40 changed files with 4360 additions and 7 deletions
+270
View File
@@ -665,5 +665,275 @@ namespace Model.Mapper
};
}
#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&lt;AlertMessageEntity&gt; → List&lt;AlertMessageDto&gt;
/// </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 → AlertNotifyChannelDtoSecret 脱敏:不回传明文,仅标记 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&lt;AlertNotifyChannelEntity&gt; → List&lt;AlertNotifyChannelDto&gt;
/// </summary>
public static List<AlertNotifyChannelDto> ToDtoList(this List<AlertNotifyChannelEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertNotifyChannelDto>();
}
/// <summary>
/// AlertNotifyChannelDto → AlertNotifyChannelEntityIsDel/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&lt;AlertNotifyRuleEntity&gt; → List&lt;AlertNotifyRuleDto&gt;
/// </summary>
public static List<AlertNotifyRuleDto> ToDtoList(this List<AlertNotifyRuleEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertNotifyRuleDto>();
}
/// <summary>
/// AlertNotifyRuleDto → AlertNotifyRuleEntityIsDel/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&lt;AlertNotifyLogEntity&gt; → List&lt;AlertNotifyLogDto&gt;
/// </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&lt;AlertOutboxEntity&gt; → List&lt;AlertOutboxItemDto&gt;
/// </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&lt;DutyRosterEntity&gt; → List&lt;DutyRosterDto&gt;
/// </summary>
public static List<DutyRosterDto> ToDtoList(this List<DutyRosterEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<DutyRosterDto>();
}
/// <summary>
/// DutyRosterDto → DutyRosterEntityIsDel/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
}
}