通知告警规则引擎

This commit is contained in:
“hsc”
2026-08-28 15:20:52 +08:00
parent 01f51fa3b4
commit d9b079142b
12 changed files with 904 additions and 7 deletions
+255
View File
@@ -194,5 +194,260 @@ namespace Model.Mapper
return entities?.Select(e => e.ToDto()).ToList() ?? new List<TemperatureBoxDataDto>();
}
#endregion
#region
/// <summary>
/// AlertRuleEntity → AlertRuleDto
/// </summary>
public static AlertRuleDto ToDto(this AlertRuleEntity entity)
{
if (entity == null) return null;
return new AlertRuleDto
{
Id = entity.Id.ToString(),
IsDel = entity.IsDel,
CreateTime = entity.CreateTime,
RuleName = entity.RuleName,
DeviceType = entity.DeviceType,
Metric = entity.Metric,
Operator = entity.Operator,
Threshold = entity.Threshold,
AlarmLevel = entity.AlarmLevel,
Enabled = entity.Enabled,
TriggerCount = entity.TriggerCount,
LastAlarmTime = entity.LastAlarmTime,
Remark = entity.Remark
};
}
/// <summary>
/// List&lt;AlertRuleEntity&gt; → List&lt;AlertRuleDto&gt;
/// </summary>
public static List<AlertRuleDto> ToDtoList(this List<AlertRuleEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<AlertRuleDto>();
}
#endregion
#region
/// <summary>
/// DataForwardRuleEntity → DataForwardRuleDto
/// </summary>
public static DataForwardRuleDto ToDto(this DataForwardRuleEntity entity)
{
if (entity == null) return null;
return new DataForwardRuleDto
{
Id = entity.Id.ToString(),
IsDel = entity.IsDel,
CreateTime = entity.CreateTime,
ForwardName = entity.ForwardName,
SourceDeviceType = entity.SourceDeviceType,
ForwardInterval = entity.ForwardInterval,
NotifyType = entity.NotifyType,
TargetAddress = entity.TargetAddress,
Enabled = entity.Enabled,
LastForwardTime = entity.LastForwardTime,
Remark = entity.Remark
};
}
/// <summary>
/// List&lt;DataForwardRuleEntity&gt; → List&lt;DataForwardRuleDto&gt;
/// </summary>
public static List<DataForwardRuleDto> ToDtoList(this List<DataForwardRuleEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<DataForwardRuleDto>();
}
#endregion
#region DTO EntityId string long
/// <summary>
/// string Id 安全转 long(空/非法返回 0,新增时由雪花算法自动赋值)
/// </summary>
private static long ParseId(string id)
{
return long.TryParse(id, out var value) ? value : 0;
}
/// <summary>
/// EquipmentDto → EquipmentEntity
/// </summary>
public static EquipmentEntity ToEntity(this EquipmentDto dto)
{
if (dto == null) return null;
return new EquipmentEntity
{
Id = ParseId(dto.Id),
IsDel = dto.IsDel,
CreateTime = dto.CreateTime,
Code = dto.Code,
Name = dto.Name,
CategoryId = dto.CategoryId,
Type = dto.Type,
Brand = dto.Brand,
Model = dto.Model,
Specifications = dto.Specifications,
Manufacturer = dto.Manufacturer,
Supplier = dto.Supplier,
ImageUrl = dto.ImageUrl,
QrCode = dto.QrCode,
Description = dto.Description,
Department = dto.Department,
Location = dto.Location,
ResponsiblePerson = dto.ResponsiblePerson,
ContactPhone = dto.ContactPhone,
Custodian = dto.Custodian,
PurchaseDate = dto.PurchaseDate,
PurchasePrice = dto.PurchasePrice,
WarrantyExpireDate = dto.WarrantyExpireDate,
AcceptanceDate = dto.AcceptanceDate,
EnableDate = dto.EnableDate,
ServiceLifeYears = dto.ServiceLifeYears,
ScrapDate = dto.ScrapDate,
Status = dto.Status,
CalibrationStatus = dto.CalibrationStatus,
LastCalibrationDate = dto.LastCalibrationDate,
NextCalibrationDate = dto.NextCalibrationDate,
InspectionDate = dto.InspectionDate,
NextInspectionDate = dto.NextInspectionDate,
MaintenanceStatus = dto.MaintenanceStatus,
LastMaintenanceDate = dto.LastMaintenanceDate,
NextMaintenanceDate = dto.NextMaintenanceDate,
Remark = dto.Remark,
CreateBy = dto.CreateBy,
UpdateBy = dto.UpdateBy,
UpdateTime = dto.UpdateTime
};
}
/// <summary>
/// EquipmentAttachmentDto → EquipmentAttachmentEntity
/// </summary>
public static EquipmentAttachmentEntity ToEntity(this EquipmentAttachmentDto dto)
{
if (dto == null) return null;
return new EquipmentAttachmentEntity
{
Id = ParseId(dto.Id),
IsDel = dto.IsDel,
CreateTime = dto.CreateTime,
EquipmentId = dto.EquipmentId,
FileName = dto.FileName,
FileType = dto.FileType,
FileExt = dto.FileExt,
FileUrl = dto.FileUrl,
FileSize = dto.FileSize,
Uploader = dto.Uploader,
Remark = dto.Remark
};
}
/// <summary>
/// EquipmentCategoryDto → EquipmentCategoryEntity
/// </summary>
public static EquipmentCategoryEntity ToEntity(this EquipmentCategoryDto dto)
{
if (dto == null) return null;
return new EquipmentCategoryEntity
{
Id = ParseId(dto.Id),
IsDel = dto.IsDel,
CreateTime = dto.CreateTime,
ParentId = dto.ParentId,
Name = dto.Name,
Code = dto.Code,
Level = dto.Level,
Sort = dto.Sort,
Remark = dto.Remark
};
}
/// <summary>
/// EquipmentStatusRecordDto → EquipmentStatusRecordEntity
/// </summary>
public static EquipmentStatusRecordEntity ToEntity(this EquipmentStatusRecordDto dto)
{
if (dto == null) return null;
return new EquipmentStatusRecordEntity
{
Id = ParseId(dto.Id),
IsDel = dto.IsDel,
CreateTime = dto.CreateTime,
EquipmentId = dto.EquipmentId,
FromStatus = dto.FromStatus,
ToStatus = dto.ToStatus,
ChangeTime = dto.ChangeTime,
Operator = dto.Operator,
Remark = dto.Remark
};
}
/// <summary>
/// TemperatureBoxDataDto → TemperatureBoxDataEntity
/// </summary>
public static TemperatureBoxDataEntity ToEntity(this TemperatureBoxDataDto dto)
{
if (dto == null) return null;
return new TemperatureBoxDataEntity
{
Id = ParseId(dto.Id),
IsDel = dto.IsDel,
CreateTime = dto.CreateTime,
DeviceCode = dto.DeviceCode,
DeviceType = dto.DeviceType,
DeviceTemperature = dto.DeviceTemperature,
DeviceHumidity = dto.DeviceHumidity,
Status = dto.Status,
AlarmInfo = dto.AlarmInfo
};
}
/// <summary>
/// AlertRuleDto → AlertRuleEntity
/// </summary>
public static AlertRuleEntity ToEntity(this AlertRuleDto dto)
{
if (dto == null) return null;
return new AlertRuleEntity
{
Id = ParseId(dto.Id),
IsDel = dto.IsDel,
CreateTime = dto.CreateTime,
RuleName = dto.RuleName,
DeviceType = dto.DeviceType,
Metric = dto.Metric,
Operator = dto.Operator,
Threshold = dto.Threshold,
AlarmLevel = dto.AlarmLevel,
Enabled = dto.Enabled,
TriggerCount = dto.TriggerCount,
LastAlarmTime = dto.LastAlarmTime,
Remark = dto.Remark
};
}
/// <summary>
/// DataForwardRuleDto → DataForwardRuleEntity
/// </summary>
public static DataForwardRuleEntity ToEntity(this DataForwardRuleDto dto)
{
if (dto == null) return null;
return new DataForwardRuleEntity
{
Id = ParseId(dto.Id),
IsDel = dto.IsDel,
CreateTime = dto.CreateTime,
ForwardName = dto.ForwardName,
SourceDeviceType = dto.SourceDeviceType,
ForwardInterval = dto.ForwardInterval,
NotifyType = dto.NotifyType,
TargetAddress = dto.TargetAddress,
Enabled = dto.Enabled,
LastForwardTime = dto.LastForwardTime,
Remark = dto.Remark
};
}
#endregion
}
}