Files
IOT_API/Model/Mapper/EntityMapper.cs
T

1451 lines
54 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Model.Dto.Asset;
using Model.Dto.Config;
using Model.Dto.Inspection;
using Model.Dto.System;
using Model.Entity.Asset;
using Model.Entity.Config;
using Model.Entity.Inspection;
using Model.Entity.System;
namespace Model.Mapper
{
/// <summary>
/// Entity → DTO 映射器(统一在此处做实体到传输对象的转换)
/// 核心转换:雪花 Id 由 long 转 string,避免前端 JavaScript 大数精度丢失
/// 使用方法 给查询的数据后面加上.ToDtoList()或者.ToDto()
/// </summary>
public static class EntityMapper
{
#region 设备台账
/// <summary>
/// EquipmentEntity → EquipmentDto
/// </summary>
public static EquipmentDto ToDto(this EquipmentEntity entity)
{
if (entity == null) return null;
return new EquipmentDto
{
Id = entity.Id.ToString(),
IsDel = entity.IsDel,
CreateTime = entity.CreateTime,
Code = entity.Code,
Name = entity.Name,
CategoryId = entity.CategoryId.ToString(),
Type = entity.Type,
Brand = entity.Brand,
Model = entity.Model,
Specifications = entity.Specifications,
Manufacturer = entity.Manufacturer,
Supplier = entity.Supplier,
ImageUrl = entity.ImageUrl,
QrCode = entity.QrCode,
QrCodeUrl = entity.QrCodeUrl,
RfidCode = entity.RfidCode,
Description = entity.Description,
Department = entity.Department,
Location = entity.Location,
ResponsiblePerson = entity.ResponsiblePerson,
ContactPhone = entity.ContactPhone,
Custodian = entity.Custodian,
PurchaseDate = entity.PurchaseDate,
PurchasePrice = entity.PurchasePrice,
WarrantyExpireDate = entity.WarrantyExpireDate,
AcceptanceDate = entity.AcceptanceDate,
EnableDate = entity.EnableDate,
ServiceLifeYears = entity.ServiceLifeYears,
ScrapDate = entity.ScrapDate,
Status = entity.Status,
CalibrationStatus = entity.CalibrationStatus,
LastCalibrationDate = entity.LastCalibrationDate,
NextCalibrationDate = entity.NextCalibrationDate,
InspectionDate = entity.InspectionDate,
NextInspectionDate = entity.NextInspectionDate,
MaintenanceStatus = entity.MaintenanceStatus,
LastMaintenanceDate = entity.LastMaintenanceDate,
NextMaintenanceDate = entity.NextMaintenanceDate,
Remark = entity.Remark,
CreateBy = entity.CreateBy,
UpdateBy = entity.UpdateBy,
UpdateTime = entity.UpdateTime
};
}
/// <summary>
/// List&lt;EquipmentEntity&gt; → List&lt;EquipmentDto&gt;
/// </summary>
public static List<EquipmentDto> ToDtoList(this List<EquipmentEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<EquipmentDto>();
}
/// <summary>
/// EquipmentDto → EquipmentEntity(入参映射,用于新增/修改)
/// 安全约定:IsDel/CreateTime/UpdateTime 等服务端管控字段刻意不映射,防止过度绑定(over-binding);
/// Id 解析失败时为 0(新增时由雪花算法自动生成)
/// </summary>
public static EquipmentEntity ToEntity(this EquipmentDto dto)
{
if (dto == null) return null;
return new EquipmentEntity
{
Id = long.TryParse(dto.Id, out var id) ? id : 0,
Code = dto.Code,
Name = dto.Name,
CategoryId = long.TryParse(dto.CategoryId, out var categoryId) ? categoryId : 0,
Type = dto.Type,
Brand = dto.Brand,
Model = dto.Model,
Specifications = dto.Specifications,
Manufacturer = dto.Manufacturer,
Supplier = dto.Supplier,
ImageUrl = dto.ImageUrl,
QrCode = dto.QrCode,
QrCodeUrl = dto.QrCodeUrl,
RfidCode = dto.RfidCode,
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
};
}
#endregion
#region 设备附件
/// <summary>
/// EquipmentAttachmentEntity → EquipmentAttachmentDto
/// </summary>
public static EquipmentAttachmentDto ToDto(this EquipmentAttachmentEntity entity)
{
if (entity == null) return null;
return new EquipmentAttachmentDto
{
Id = entity.Id.ToString(),
IsDel = entity.IsDel,
CreateTime = entity.CreateTime,
EquipmentId = entity.EquipmentId.ToString(),
FileName = entity.FileName,
FileType = entity.FileType,
FileExt = entity.FileExt,
FileUrl = entity.FileUrl,
FileSize = entity.FileSize,
Uploader = entity.Uploader,
Remark = entity.Remark
};
}
/// <summary>
/// List&lt;EquipmentAttachmentEntity&gt; → List&lt;EquipmentAttachmentDto&gt;
/// </summary>
public static List<EquipmentAttachmentDto> ToDtoList(this List<EquipmentAttachmentEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<EquipmentAttachmentDto>();
}
#endregion
#region 设备分类
/// <summary>
/// EquipmentCategoryEntity → EquipmentCategoryDto
/// </summary>
public static EquipmentCategoryDto ToDto(this EquipmentCategoryEntity entity)
{
if (entity == null) return null;
return new EquipmentCategoryDto
{
Id = entity.Id.ToString(),
IsDel = entity.IsDel,
CreateTime = entity.CreateTime,
ParentId = entity.ParentId.ToString(),
Name = entity.Name,
Code = entity.Code,
Level = entity.Level,
Sort = entity.Sort,
Remark = entity.Remark
};
}
/// <summary>
/// List&lt;EquipmentCategoryEntity&gt; → List&lt;EquipmentCategoryDto&gt;
/// </summary>
public static List<EquipmentCategoryDto> ToDtoList(this List<EquipmentCategoryEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<EquipmentCategoryDto>();
}
#endregion
#region 设备状态记录
/// <summary>
/// EquipmentStatusRecordEntity → EquipmentStatusRecordDto
/// </summary>
public static EquipmentStatusRecordDto ToDto(this EquipmentStatusRecordEntity entity)
{
if (entity == null) return null;
return new EquipmentStatusRecordDto
{
Id = entity.Id.ToString(),
IsDel = entity.IsDel,
CreateTime = entity.CreateTime,
EquipmentId = entity.EquipmentId.ToString(),
FromStatus = entity.FromStatus,
ToStatus = entity.ToStatus,
ChangeTime = entity.ChangeTime,
Operator = entity.Operator,
Remark = entity.Remark
};
}
/// <summary>
/// List&lt;EquipmentStatusRecordEntity&gt; → List&lt;EquipmentStatusRecordDto&gt;
/// </summary>
public static List<EquipmentStatusRecordDto> ToDtoList(this List<EquipmentStatusRecordEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<EquipmentStatusRecordDto>();
}
#endregion
#region 温度箱看板数据
/// <summary>
/// TemperatureBoxDataEntity → TemperatureBoxDataDto
/// </summary>
public static TemperatureBoxDataDto ToDto(this TemperatureBoxDataEntity entity)
{
if (entity == null) return null;
return new TemperatureBoxDataDto
{
Id = entity.Id.ToString(),
IsDel = entity.IsDel,
CreateTime = entity.CreateTime,
DeviceCode = entity.DeviceCode,
DeviceType = entity.DeviceType,
DeviceTemperature = entity.DeviceTemperature,
DeviceHumidity = entity.DeviceHumidity,
Status = entity.Status,
AlarmInfo = entity.AlarmInfo
};
}
/// <summary>
/// List&lt;TemperatureBoxDataEntity&gt; → List&lt;TemperatureBoxDataDto&gt;
/// </summary>
public static List<TemperatureBoxDataDto> ToDtoList(this List<TemperatureBoxDataEntity> entities)
{
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(),
OwnerType = entity.OwnerType,
OwnerId = entity.OwnerId,
PointCode = entity.PointCode,
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 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>
/// <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),
OwnerType = dto.OwnerType,
OwnerId = dto.OwnerId,
PointCode = dto.PointCode,
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
#region IOT设备
/// <summary>
/// IotDeviceEntity → IotDeviceDto
/// </summary>
public static IotDeviceDto ToDto(this IotDeviceEntity entity)
{
if (entity == null) return null;
return new IotDeviceDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
DeviceType = entity.DeviceType,
ProductId = entity.ProductId.ToString(),
GatewayId = entity.GatewayId.ToString(),
SlaveId = entity.SlaveId,
Manufacturer = entity.Manufacturer,
Description = entity.Description,
ProtocolType = entity.ProtocolType,
IsEnabled = entity.IsEnabled,
OnlineStatus = entity.OnlineStatus,
LastCollectTime = entity.LastCollectTime,
LastError = entity.LastError,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
/// <summary>
/// List&lt;IotDeviceEntity&gt; → List&lt;IotDeviceDto&gt;
/// </summary>
public static List<IotDeviceDto> ToDtoList(this List<IotDeviceEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<IotDeviceDto>();
}
/// <summary>
/// IotDeviceDto → IotDeviceEntity(入参映射,IsDel/CreateTime/OnlineStatus 等服务端管控字段不映射)
/// </summary>
public static IotDeviceEntity ToEntity(this IotDeviceDto dto)
{
if (dto == null) return null;
return new IotDeviceEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
DeviceType = dto.DeviceType,
ProductId = ParseId(dto.ProductId),
GatewayId = ParseId(dto.GatewayId),
SlaveId = dto.SlaveId,
Manufacturer = dto.Manufacturer,
Description = dto.Description,
ProtocolType = dto.ProtocolType,
IsEnabled = dto.IsEnabled,
Remark = dto.Remark
};
}
#endregion
#region 设备日志
/// <summary>
/// DeviceLogEntity → DeviceLogDto
/// </summary>
public static DeviceLogDto ToDto(this DeviceLogEntity entity)
{
if (entity == null) return null;
return new DeviceLogDto
{
Id = entity.Id.ToString(),
DeviceId = entity.DeviceId.ToString(),
DeviceCode = entity.DeviceCode,
Level = entity.Level,
LogType = entity.LogType,
Message = entity.Message,
LogTime = entity.LogTime,
CreateTime = entity.CreateTime
};
}
/// <summary>
/// List&lt;DeviceLogEntity&gt; → List&lt;DeviceLogDto&gt;
/// </summary>
public static List<DeviceLogDto> ToDtoList(this List<DeviceLogEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<DeviceLogDto>();
}
#endregion
#region 网关
/// <summary>
/// GatewayEntity → GatewayDto
/// </summary>
public static GatewayDto ToDto(this GatewayEntity entity)
{
if (entity == null) return null;
return new GatewayDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
ProtocolType = (int)entity.ProtocolType,
Host = entity.Host,
Port = entity.Port,
ComPort = entity.ComPort,
BaudRate = entity.BaudRate,
DataBits = entity.DataBits,
StopBits = entity.StopBits,
Parity = entity.Parity,
CpuType = entity.CpuType,
Rack = entity.Rack,
Slot = entity.Slot,
IsEnabled = entity.IsEnabled,
OnlineStatus = entity.OnlineStatus,
LastConnectedTime = entity.LastConnectedTime,
LastError = entity.LastError,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
/// <summary>
/// List&lt;GatewayEntity&gt; → List&lt;GatewayDto&gt;
/// </summary>
public static List<GatewayDto> ToDtoList(this List<GatewayEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<GatewayDto>();
}
/// <summary>
/// GatewayDto → GatewayEntity(入参映射)
/// </summary>
public static GatewayEntity ToEntity(this GatewayDto dto)
{
if (dto == null) return null;
return new GatewayEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
ProtocolType = (IotDeviceProtocolEnum)dto.ProtocolType,
Host = dto.Host,
Port = dto.Port,
ComPort = dto.ComPort,
BaudRate = dto.BaudRate,
DataBits = dto.DataBits,
StopBits = dto.StopBits,
Parity = dto.Parity,
CpuType = dto.CpuType,
Rack = dto.Rack,
Slot = dto.Slot,
IsEnabled = dto.IsEnabled,
OnlineStatus = dto.OnlineStatus,
LastConnectedTime = dto.LastConnectedTime,
LastError = dto.LastError,
Remark = dto.Remark
};
}
/// <summary>
/// GatewayEntity → GatewayOptionDto(下拉选项)
/// </summary>
public static GatewayOptionDto ToOptionDto(this GatewayEntity entity)
{
if (entity == null) return null;
return new GatewayOptionDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name
};
}
/// <summary>
/// List&lt;GatewayEntity&gt; → List&lt;GatewayOptionDto&gt;
/// </summary>
public static List<GatewayOptionDto> ToOptionDtoList(this List<GatewayEntity> entities)
{
return entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<GatewayOptionDto>();
}
#endregion
#region 产品分类
/// <summary>
/// ProductCategoryEntity → ProductCategoryDto
/// </summary>
public static ProductCategoryDto ToDto(this ProductCategoryEntity entity)
{
if (entity == null) return null;
return new ProductCategoryDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
Sort = entity.Sort,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
/// <summary>
/// List&lt;ProductCategoryEntity&gt; → List&lt;ProductCategoryDto&gt;
/// </summary>
public static List<ProductCategoryDto> ToDtoList(this List<ProductCategoryEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<ProductCategoryDto>();
}
/// <summary>
/// ProductCategoryDto → ProductCategoryEntity(入参映射)
/// </summary>
public static ProductCategoryEntity ToEntity(this ProductCategoryDto dto)
{
if (dto == null) return null;
return new ProductCategoryEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
Sort = dto.Sort,
Remark = dto.Remark
};
}
#endregion
#region 产品
/// <summary>
/// ProductEntity → ProductDto
/// </summary>
public static ProductDto ToDto(this ProductEntity entity)
{
if (entity == null) return null;
return new ProductDto
{
Id = entity.Id.ToString(),
Model = entity.Model,
Name = entity.Name,
CategoryId = entity.CategoryId.ToString(),
Manufacturer = entity.Manufacturer,
Description = entity.Description,
ProtocolType = entity.ProtocolType,
MessageModel = entity.MessageModel,
IsEnabled = entity.IsEnabled,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
/// <summary>
/// List&lt;ProductEntity&gt; → List&lt;ProductDto&gt;
/// </summary>
public static List<ProductDto> ToDtoList(this List<ProductEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<ProductDto>();
}
/// <summary>
/// ProductDto → ProductEntity(入参映射,IsDel/CreateTime 等服务端管控字段不映射)
/// </summary>
public static ProductEntity ToEntity(this ProductDto dto)
{
if (dto == null) return null;
return new ProductEntity
{
Id = ParseId(dto.Id),
Model = dto.Model,
Name = dto.Name,
CategoryId = ParseId(dto.CategoryId),
Manufacturer = dto.Manufacturer,
Description = dto.Description,
ProtocolType = dto.ProtocolType,
MessageModel = dto.MessageModel,
IsEnabled = dto.IsEnabled,
Remark = dto.Remark
};
}
/// <summary>
/// ProductEntity → ProductOptionDto(下拉选项)
/// </summary>
public static ProductOptionDto ToOptionDto(this ProductEntity entity)
{
if (entity == null) return null;
return new ProductOptionDto
{
Id = entity.Id.ToString(),
Model = entity.Model,
Name = entity.Name
};
}
/// <summary>
/// List&lt;ProductEntity&gt; → List&lt;ProductOptionDto&gt;
/// </summary>
public static List<ProductOptionDto> ToOptionDtoList(this List<ProductEntity> entities)
{
return entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<ProductOptionDto>();
}
#endregion
#region 物模型点
/// <summary>
/// ThingModelPointEntity → ThingModelPointDto
/// </summary>
public static ThingModelPointDto ToDto(this ThingModelPointEntity entity)
{
if (entity == null) return null;
return new ThingModelPointDto
{
Id = entity.Id.ToString(),
OwnerType = entity.OwnerType,
OwnerId = entity.OwnerId.ToString(),
Code = entity.Code,
Name = entity.Name,
RegisterType = entity.RegisterType,
Rw = entity.Rw,
DataType = entity.DataType,
Address = entity.Address,
Scale = entity.Scale,
Offset = entity.Offset,
Unit = entity.Unit,
Enabled = entity.Enabled,
Sort = entity.Sort,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
/// <summary>
/// List&lt;ThingModelPointEntity&gt; → List&lt;ThingModelPointDto&gt;
/// </summary>
public static List<ThingModelPointDto> ToDtoList(this List<ThingModelPointEntity> entities)
{
return entities?.Select(e => e.ToDto()).ToList() ?? new List<ThingModelPointDto>();
}
/// <summary>
/// ThingModelPointDto → ThingModelPointEntity(入参映射)
/// </summary>
public static ThingModelPointEntity ToEntity(this ThingModelPointDto dto)
{
if (dto == null) return null;
return new ThingModelPointEntity
{
Id = ParseId(dto.Id),
OwnerType = dto.OwnerType,
OwnerId = ParseId(dto.OwnerId),
Code = dto.Code,
Name = dto.Name,
RegisterType = dto.RegisterType,
Rw = dto.Rw,
DataType = dto.DataType,
Address = dto.Address,
Scale = dto.Scale,
Offset = dto.Offset,
Unit = dto.Unit,
Enabled = dto.Enabled,
Sort = dto.Sort,
Remark = dto.Remark
};
}
#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
#region 用户
public static UserDto ToDto(this UserEntity entity)
{
if (entity == null) return null;
return new UserDto
{
Id = entity.Id.ToString(),
UserName = entity.UserName,
RealName = entity.RealName,
Email = entity.Email,
Phone = entity.Phone,
OrgId = entity.OrgId.ToString(),
Position = entity.Position,
SkillTags = entity.SkillTags,
IsEnabled = entity.IsEnabled,
LastLoginTime = entity.LastLoginTime,
Avatar = entity.Avatar,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
public static List<UserDto> ToDtoList(this List<UserEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<UserDto>();
public static UserEntity ToEntity(this UserDto dto)
{
if (dto == null) return null;
return new UserEntity
{
Id = ParseId(dto.Id),
UserName = dto.UserName,
RealName = dto.RealName,
Email = dto.Email,
Phone = dto.Phone,
OrgId = ParseId(dto.OrgId),
Position = dto.Position,
SkillTags = dto.SkillTags,
IsEnabled = dto.IsEnabled,
Avatar = dto.Avatar,
Remark = dto.Remark
};
}
public static UserOptionDto ToOptionDto(this UserEntity entity)
{
if (entity == null) return null;
return new UserOptionDto { Id = entity.Id.ToString(), UserName = entity.UserName, RealName = entity.RealName };
}
public static List<UserOptionDto> ToOptionDtoList(this List<UserEntity> entities)
=> entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<UserOptionDto>();
#endregion
#region 角色
public static RoleDto ToDto(this RoleEntity entity)
{
if (entity == null) return null;
return new RoleDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
DataScope = entity.DataScope,
IsSystem = entity.IsSystem,
Sort = entity.Sort,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
public static List<RoleDto> ToDtoList(this List<RoleEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<RoleDto>();
public static RoleEntity ToEntity(this RoleDto dto)
{
if (dto == null) return null;
return new RoleEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
DataScope = dto.DataScope,
IsSystem = dto.IsSystem,
Sort = dto.Sort,
Remark = dto.Remark
};
}
public static RoleOptionDto ToOptionDto(this RoleEntity entity)
{
if (entity == null) return null;
return new RoleOptionDto { Id = entity.Id.ToString(), Code = entity.Code, Name = entity.Name };
}
public static List<RoleOptionDto> ToOptionDtoList(this List<RoleEntity> entities)
=> entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<RoleOptionDto>();
#endregion
#region 权限
public static PermissionDto ToDto(this PermissionEntity entity)
{
if (entity == null) return null;
return new PermissionDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
Group = entity.Group,
IsSystem = entity.IsSystem,
Sort = entity.Sort
};
}
public static List<PermissionDto> ToDtoList(this List<PermissionEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<PermissionDto>();
public static PermissionEntity ToEntity(this PermissionDto dto)
{
if (dto == null) return null;
return new PermissionEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
Group = dto.Group,
IsSystem = dto.IsSystem,
Sort = dto.Sort
};
}
#endregion
#region 组织架构
public static OrgTreeDto ToTreeDto(this OrgEntity entity)
{
if (entity == null) return null;
return new OrgTreeDto
{
Id = entity.Id.ToString(),
ParentId = entity.ParentId.ToString(),
Name = entity.Name,
Code = entity.Code,
OrgType = entity.OrgType,
ShiftType = entity.ShiftType,
Leader = entity.Leader,
Phone = entity.Phone,
Sort = entity.Sort,
Remark = entity.Remark
};
}
public static OrgDto ToDto(this OrgEntity entity)
{
if (entity == null) return null;
return new OrgDto
{
Id = entity.Id.ToString(),
ParentId = entity.ParentId.ToString(),
Name = entity.Name,
Code = entity.Code,
OrgType = entity.OrgType,
ShiftType = entity.ShiftType,
Leader = entity.Leader,
Phone = entity.Phone,
Sort = entity.Sort,
Remark = entity.Remark
};
}
public static List<OrgDto> ToDtoList(this List<OrgEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<OrgDto>();
public static OrgEntity ToEntity(this OrgDto dto)
{
if (dto == null) return null;
return new OrgEntity
{
Id = ParseId(dto.Id),
ParentId = ParseId(dto.ParentId),
Name = dto.Name,
Code = dto.Code,
OrgType = (byte)dto.OrgType,
ShiftType = (byte)dto.ShiftType,
Leader = dto.Leader,
Phone = dto.Phone,
Sort = dto.Sort,
Remark = dto.Remark
};
}
public static OrgOptionDto ToOptionDto(this OrgEntity entity)
{
if (entity == null) return null;
return new OrgOptionDto { Id = entity.Id.ToString(), Name = entity.Name, OrgType = entity.OrgType };
}
public static List<OrgOptionDto> ToOptionDtoList(this List<OrgEntity> entities)
=> entities?.Select(e => e.ToOptionDto()).ToList() ?? new List<OrgOptionDto>();
#endregion
#region 审计日志
public static AuditLogDto ToDto(this AuditLogEntity entity)
{
if (entity == null) return null;
return new AuditLogDto
{
Id = entity.Id.ToString(),
UserId = entity.UserId.ToString(),
UserName = entity.UserName,
RoleId = entity.RoleId.ToString(),
RoleName = entity.RoleName,
OperationType = entity.OperationType,
OperationTarget = entity.OperationTarget,
TargetId = entity.TargetId.ToString(),
DeviceId = entity.DeviceId.ToString(),
OldValue = entity.OldValue,
NewValue = entity.NewValue,
Ip = entity.Ip,
Description = entity.Description,
OperateTime = entity.OperateTime,
CreateTime = entity.CreateTime
};
}
public static List<AuditLogDto> ToDtoList(this List<AuditLogEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<AuditLogDto>();
#endregion
#region 数据字典
/// <summary>
/// DictTypeEntity → DictTypeDto
/// </summary>
public static DictTypeDto ToDto(this DictTypeEntity entity)
{
if (entity == null) return null;
return new DictTypeDto
{
Id = entity.Id.ToString(),
Code = entity.Code,
Name = entity.Name,
Status = entity.Status,
Sort = entity.Sort,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
public static List<DictTypeDto> ToDtoList(this List<DictTypeEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<DictTypeDto>();
/// <summary>
/// DictTypeDto → DictTypeEntity(入参映射,IsDel/CreateTime 不映射)
/// </summary>
public static DictTypeEntity ToEntity(this DictTypeDto dto)
{
if (dto == null) return null;
return new DictTypeEntity
{
Id = ParseId(dto.Id),
Code = dto.Code,
Name = dto.Name,
Status = dto.Status,
Sort = dto.Sort,
Remark = dto.Remark
};
}
/// <summary>
/// DictItemEntity → DictItemDto
/// </summary>
public static DictItemDto ToDto(this DictItemEntity entity)
{
if (entity == null) return null;
return new DictItemDto
{
Id = entity.Id.ToString(),
TypeId = entity.TypeId.ToString(),
Code = entity.Code,
Name = entity.Name,
Sort = entity.Sort,
Status = entity.Status,
IsDefault = entity.IsDefault,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
public static List<DictItemDto> ToDtoList(this List<DictItemEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<DictItemDto>();
/// <summary>
/// DictItemDto → DictItemEntity(入参映射,CreateTime/IsDel 不映射;TypeId 由 Service 强制覆盖)
/// </summary>
public static DictItemEntity ToEntity(this DictItemDto dto)
{
if (dto == null) return null;
return new DictItemEntity
{
Id = ParseId(dto.Id),
TypeId = ParseId(dto.TypeId),
Code = dto.Code,
Name = dto.Name,
Sort = dto.Sort,
Status = dto.Status,
IsDefault = dto.IsDefault,
Remark = dto.Remark
};
}
#endregion
#region 系统参数
/// <summary>
/// SystemParamEntity → SystemParamDto
/// </summary>
public static SystemParamDto ToDto(this SystemParamEntity entity)
{
if (entity == null) return null;
return new SystemParamDto
{
Id = entity.Id.ToString(),
ParamKey = entity.ParamKey,
ParamName = entity.ParamName,
ParamValue = entity.ParamValue,
ParamType = entity.ParamType,
ParamOptions = entity.ParamOptions,
Unit = entity.Unit,
Group = entity.Group,
Sort = entity.Sort,
Remark = entity.Remark,
IsSystem = entity.IsSystem,
LastUpdateUser = entity.LastUpdateUser,
LastUpdateTime = entity.LastUpdateTime,
CreateTime = entity.CreateTime
};
}
public static List<SystemParamDto> ToDtoList(this List<SystemParamEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<SystemParamDto>();
/// <summary>
/// SystemParamDto → SystemParamEntity(入参映射,CreateTime/IsDel/LastUpdateUser/LastUpdateTime 不映射;由 Service 控管)
/// </summary>
public static SystemParamEntity ToEntity(this SystemParamDto dto)
{
if (dto == null) return null;
return new SystemParamEntity
{
Id = ParseId(dto.Id),
ParamKey = dto.ParamKey,
ParamName = dto.ParamName,
ParamValue = dto.ParamValue,
ParamType = dto.ParamType,
ParamOptions = dto.ParamOptions,
Unit = dto.Unit,
Group = dto.Group,
Sort = dto.Sort,
Remark = dto.Remark,
IsSystem = dto.IsSystem
};
}
#endregion
#region 文件存储配置
public static FileStorageConfigDto ToDto(this FileStorageConfigEntity entity)
{
if (entity == null) return null;
return new FileStorageConfigDto
{
Id = entity.Id.ToString(),
Provider = entity.Provider,
Name = entity.Name,
Endpoint = entity.Endpoint,
AccessKey = entity.AccessKey,
SecretKey = entity.SecretKey,
Bucket = entity.Bucket,
Region = entity.Region,
BasePath = entity.BasePath,
MaxSizeMB = entity.MaxSizeMB,
AllowedExts = entity.AllowedExts,
IsDefault = entity.IsDefault,
Status = entity.Status,
Remark = entity.Remark,
CreateTime = entity.CreateTime
};
}
public static List<FileStorageConfigDto> ToDtoList(this List<FileStorageConfigEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<FileStorageConfigDto>();
public static FileStorageConfigEntity ToEntity(this FileStorageConfigDto dto)
{
if (dto == null) return null;
return new FileStorageConfigEntity
{
Id = ParseId(dto.Id),
Provider = dto.Provider,
Name = dto.Name,
Endpoint = dto.Endpoint,
AccessKey = dto.AccessKey,
SecretKey = dto.SecretKey,
Bucket = dto.Bucket,
Region = dto.Region,
BasePath = dto.BasePath,
MaxSizeMB = dto.MaxSizeMB,
AllowedExts = dto.AllowedExts,
IsDefault = dto.IsDefault,
Status = dto.Status,
Remark = dto.Remark
};
}
#endregion
#region 文件上传记录
public static FileRecordDto ToDto(this FileRecordEntity entity)
{
if (entity == null) return null;
return new FileRecordDto
{
Id = entity.Id.ToString(),
FileName = entity.FileName,
OriginalName = entity.OriginalName,
Url = entity.Url,
Size = entity.Size,
Ext = entity.Ext,
Provider = entity.Provider,
StorageId = entity.StorageId.ToString(),
Uploader = entity.Uploader,
BizType = entity.BizType,
BizId = entity.BizId,
CreateTime = entity.CreateTime
};
}
public static List<FileRecordDto> ToDtoList(this List<FileRecordEntity> entities)
=> entities?.Select(e => e.ToDto()).ToList() ?? new List<FileRecordDto>();
#endregion
}
}