设备管理模块方法转换为DTO模式,修复long类型接收雪花ID丢失精度的问题
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Model.Mapper
|
||||
CreateTime = entity.CreateTime,
|
||||
Code = entity.Code,
|
||||
Name = entity.Name,
|
||||
CategoryId = entity.CategoryId,
|
||||
CategoryId = entity.CategoryId.ToString(),
|
||||
Type = entity.Type,
|
||||
Brand = entity.Brand,
|
||||
Model = entity.Model,
|
||||
@@ -71,6 +71,54 @@ namespace Model.Mapper
|
||||
{
|
||||
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,
|
||||
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 设备附件
|
||||
@@ -85,7 +133,7 @@ namespace Model.Mapper
|
||||
Id = entity.Id.ToString(),
|
||||
IsDel = entity.IsDel,
|
||||
CreateTime = entity.CreateTime,
|
||||
EquipmentId = entity.EquipmentId,
|
||||
EquipmentId = entity.EquipmentId.ToString(),
|
||||
FileName = entity.FileName,
|
||||
FileType = entity.FileType,
|
||||
FileExt = entity.FileExt,
|
||||
@@ -117,7 +165,7 @@ namespace Model.Mapper
|
||||
Id = entity.Id.ToString(),
|
||||
IsDel = entity.IsDel,
|
||||
CreateTime = entity.CreateTime,
|
||||
ParentId = entity.ParentId,
|
||||
ParentId = entity.ParentId.ToString(),
|
||||
Name = entity.Name,
|
||||
Code = entity.Code,
|
||||
Level = entity.Level,
|
||||
@@ -147,7 +195,7 @@ namespace Model.Mapper
|
||||
Id = entity.Id.ToString(),
|
||||
IsDel = entity.IsDel,
|
||||
CreateTime = entity.CreateTime,
|
||||
EquipmentId = entity.EquipmentId,
|
||||
EquipmentId = entity.EquipmentId.ToString(),
|
||||
FromStatus = entity.FromStatus,
|
||||
ToStatus = entity.ToStatus,
|
||||
ChangeTime = entity.ChangeTime,
|
||||
|
||||
Reference in New Issue
Block a user