设备类添加产品字段、添加物模型类,新增产品CRUD方法

This commit is contained in:
2026-09-03 17:16:28 +08:00
parent cfa8e78d33
commit bcd6484f45
29 changed files with 1611 additions and 23 deletions
+189
View File
@@ -255,6 +255,9 @@ namespace Model.Mapper
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,
@@ -352,6 +355,9 @@ namespace Model.Mapper
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,
@@ -403,6 +409,7 @@ namespace Model.Mapper
Code = entity.Code,
Name = entity.Name,
DeviceType = entity.DeviceType,
ProductId = entity.ProductId.ToString(),
GatewayCode = entity.GatewayCode,
SlaveId = entity.SlaveId,
Manufacturer = entity.Manufacturer,
@@ -437,6 +444,7 @@ namespace Model.Mapper
Code = dto.Code,
Name = dto.Name,
DeviceType = dto.DeviceType,
ProductId = ParseId(dto.ProductId),
GatewayCode = dto.GatewayCode,
SlaveId = dto.SlaveId,
Manufacturer = dto.Manufacturer,
@@ -476,5 +484,186 @@ namespace Model.Mapper
return entities?.Select(e => e.ToDto()).ToList() ?? new List<DeviceLogDto>();
}
#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
}
}