通知告警规则引擎
This commit is contained in:
@@ -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<AlertRuleEntity> → List<AlertRuleDto>
|
||||
/// </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<DataForwardRuleEntity> → List<DataForwardRuleDto>
|
||||
/// </summary>
|
||||
public static List<DataForwardRuleDto> ToDtoList(this List<DataForwardRuleEntity> entities)
|
||||
{
|
||||
return entities?.Select(e => e.ToDto()).ToList() ?? new List<DataForwardRuleDto>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 反向转换 DTO → Entity(前端入参转实体入库用,Id 由 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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user