添加项目文件。
This commit is contained in:
42
MoviconWebApi/API/DeviceAlarmApi/Mapper.cs
Normal file
42
MoviconWebApi/API/DeviceAlarmApi/Mapper.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using MoviconWebApi.Entities;
|
||||
|
||||
namespace MoviconWebApi.API.DeviceAlarmApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备报警数据映射器
|
||||
/// </summary>
|
||||
public static class DeviceAlarmMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// 将实体映射到响应模型
|
||||
/// </summary>
|
||||
public static DeviceAlarmResponse ToResponse(this DeviceAlarm entity)
|
||||
{
|
||||
return new DeviceAlarmResponse
|
||||
{
|
||||
DeviceCode = entity.DeviceCode,
|
||||
DeviceName = entity.DeviceName,
|
||||
DeviceState = entity.DeviceState,
|
||||
AlarmMessage = entity.AlarmMessage,
|
||||
StartTime = entity.StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
EndTime = entity.EndTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量映射
|
||||
/// </summary>
|
||||
public static List<DeviceAlarmResponse> ToResponseList(this IEnumerable<DeviceAlarm> entities)
|
||||
{
|
||||
return entities.Select(e => e.ToResponse()).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断报警是否活动
|
||||
/// </summary>
|
||||
public static bool IsActive(this DeviceAlarm entity)
|
||||
{
|
||||
return entity.EndTime == DateTime.MaxValue || entity.EndTime > DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user