添加设备类、设备日志类、设备服务类、设备控制器

This commit is contained in:
2026-08-28 17:28:16 +08:00
parent 6c20630a40
commit cfa8e78d33
11 changed files with 667 additions and 23 deletions
+47
View File
@@ -0,0 +1,47 @@
using SqlSugar;
namespace Model.Entity.Config
{
/// <summary>
/// 设备日志(每台设备独享的日志记录)
/// 记录设备的通讯、连接、数据采集等运行日志,按设备查询
/// </summary>
public class DeviceLogEntity : BaseEntity
{
/// <summary>
/// 设备Id(关联 IotDeviceEntity.Id
/// </summary>
[SugarColumn(ColumnDescription = "设备Id")]
public long DeviceId { get; set; }
/// <summary>
/// 设备编号(冗余便于查询展示)
/// </summary>
[SugarColumn(ColumnDescription = "设备编号", Length = 64)]
public string? DeviceCode { get; set; }
/// <summary>
/// 日志级别(Info/Warn/Error
/// </summary>
[SugarColumn(ColumnDescription = "日志级别", Length = 16)]
public string? Level { get; set; } = "Info";
/// <summary>
/// 日志类型(连接/通讯/采集/指令/系统)
/// </summary>
[SugarColumn(ColumnDescription = "日志类型", Length = 32)]
public string? LogType { get; set; }
/// <summary>
/// 日志内容
/// </summary>
[SugarColumn(ColumnDescription = "日志内容", ColumnDataType = "text")]
public string? Message { get; set; }
/// <summary>
/// 记录时间(日志产生时间,用于时间线展示)
/// </summary>
[SugarColumn(ColumnDescription = "记录时间")]
public DateTime LogTime { get; set; }
}
}
+97
View File
@@ -0,0 +1,97 @@
using SqlSugar;
namespace Model.Entity.Config
{
/// <summary>
/// IOT 设备(IOT设备注册与管理 - 设备管理)
/// 一台设备 = 一个从站实例,通过所属网关(IP:端口 或 串口)通讯
/// </summary>
public class IotDeviceEntity : BaseEntity
{
#region
/// <summary>
/// 设备编号(唯一)
/// </summary>
[SugarColumn(ColumnDescription = "设备编号", Length = 64)]
public string Code { get; set; }
/// <summary>
/// 设备名称
/// </summary>
[SugarColumn(ColumnDescription = "设备名称", Length = 100)]
public string Name { get; set; }
/// <summary>
/// 设备类型(型号,如 温度箱/充放电柜,对应 DeviceCommand 驱动类)
/// </summary>
[SugarColumn(ColumnDescription = "设备类型", Length = 64)]
public string DeviceType { get; set; }
/// <summary>
/// 所属网关Code(对应网关实体/通道的标识,连接时据此刻查找 IP/端口/串口)
/// </summary>
[SugarColumn(ColumnDescription = "所属网关Code", Length = 64)]
public string GatewayCode { get; set; }
/// <summary>
/// 从站地址(协议从站号,网关下区分设备)
/// </summary>
[SugarColumn(ColumnDescription = "从站地址")]
public byte SlaveId { get; set; }
/// <summary>
/// 制造商
/// </summary>
[SugarColumn(ColumnDescription = "制造商", Length = 100, IsNullable = true)]
public string? Manufacturer { get; set; }
/// <summary>
/// 设备描述
/// </summary>
[SugarColumn(ColumnDescription = "设备描述", Length = 500, IsNullable = true)]
public string? Description { get; set; }
#endregion
#region
/// <summary>
/// 通讯协议类型(ModbusTcp/ModbusRtu/S7/Tcp/Serial
/// </summary>
[SugarColumn(ColumnDescription = "通讯协议类型")]
public IotDeviceProtocolEnum ProtocolType { get; set; } = IotDeviceProtocolEnum.ModbusTcp;
/// <summary>
/// 是否启用采集(停用则采集调度跳过该设备)
/// </summary>
[SugarColumn(ColumnDescription = "是否启用")]
public bool IsEnabled { get; set; } = true;
#endregion
#region
/// <summary>
/// 在线状态
/// </summary>
[SugarColumn(ColumnDescription = "在线状态")]
public IotDeviceOnlineStatusEnum OnlineStatus { get; set; } = IotDeviceOnlineStatusEnum.Offline;
/// <summary>
/// 最后采集时间
/// </summary>
[SugarColumn(ColumnDescription = "最后采集时间", IsNullable = true)]
public DateTime? LastCollectTime { get; set; }
/// <summary>
/// 最近错误信息(通讯异常时记录)
/// </summary>
[SugarColumn(ColumnDescription = "最近错误", Length = 500, IsNullable = true)]
public string? LastError { get; set; }
#endregion
#region
/// <summary>
/// 备注
/// </summary>
[SugarColumn(ColumnDescription = "备注", Length = 500, IsNullable = true)]
public string? Remark { get; set; }
#endregion
}
}
+59
View File
@@ -0,0 +1,59 @@
namespace Model.Entity.Config
{
/// <summary>
/// 设备通讯协议类型(决定使用 DeviceCommand 中哪类驱动)
/// </summary>
public enum IotDeviceProtocolEnum
{
/// <summary>
/// Modbus TCP(网口,IP + 端口 + 从站地址)
/// </summary>
ModbusTcp = 1,
/// <summary>
/// Modbus RTU(串口,COM 口 + 波特率 + 从站地址)
/// </summary>
ModbusRtu = 2,
/// <summary>
/// 西门子 S7 协议
/// </summary>
S7 = 3,
/// <summary>
/// 自定义 TCP 协议
/// </summary>
Tcp = 4,
/// <summary>
/// 串口自定义协议
/// </summary>
Serial = 5
}
/// <summary>
/// 设备在线状态
/// </summary>
public enum IotDeviceOnlineStatusEnum
{
/// <summary>
/// 离线
/// </summary>
Offline = 0,
/// <summary>
/// 在线
/// </summary>
Online = 1,
/// <summary>
/// 连接中(网关已连,设备待确认)
/// </summary>
Connecting = 2,
/// <summary>
/// 通讯异常
/// </summary>
Fault = 3
}
}