using SqlSugar; namespace GSModbus.Database { /// /// Modbus主数据实体 - 存储从PLC读取的数据 /// [SugarTable("ModbusData")] public class ModbusDataEntity { /// /// 主键ID /// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long Id { get; set; } /// /// 数据读取时间 /// [SugarColumn(IsNullable = false, ColumnDescription = "数据读取时间")] public DateTime ReadTime { get; set; } /// /// 项目名称(来自配置) /// [SugarColumn(Length = 100, IsNullable = false, ColumnDescription = "项目名称")] public string ProjectName { get; set; } = string.Empty; /// /// PLC IP地址 /// [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "PLC IP地址")] public string PlcIpAddress { get; set; } = string.Empty; /// /// 控制信号数据(JSON格式) /// [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "控制信号数据JSON")] public string? ControlSignalsJson { get; set; } /// /// 产品数据(JSON格式) /// [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "产品数据JSON")] public string? ProductDataJson { get; set; } /// /// 测量数据(JSON格式) /// [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "测量数据JSON")] public string? MeasurementDataJson { get; set; } /// /// 原始寄存器数据(JSON格式,用于调试) /// [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "原始寄存器数据JSON")] public string? RawRegistersJson { get; set; } /// /// 数据创建时间 /// [SugarColumn(IsNullable = false, ColumnDescription = "记录创建时间")] public DateTime CreatedAt { get; set; } = DateTime.Now; } /// /// 通信日志实体 - 记录通信状态和统计信息 /// [SugarTable("CommunicationLog")] public class CommunicationLogEntity { /// /// 主键ID /// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long Id { get; set; } /// /// 日志时间 /// [SugarColumn(IsNullable = false, ColumnDescription = "日志时间")] public DateTime LogTime { get; set; } /// /// 项目名称 /// [SugarColumn(Length = 100, IsNullable = false, ColumnDescription = "项目名称")] public string ProjectName { get; set; } = string.Empty; /// /// PLC IP地址 /// [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "PLC IP地址")] public string PlcIpAddress { get; set; } = string.Empty; /// /// 事件类型(Connected, Disconnected, DataReceived, Error等) /// [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "事件类型")] public string EventType { get; set; } = string.Empty; /// /// 事件描述 /// [SugarColumn(Length = 500, IsNullable = true, ColumnDescription = "事件描述")] public string? EventDescription { get; set; } /// /// 是否成功 /// [SugarColumn(IsNullable = false, ColumnDescription = "是否成功")] public bool IsSuccess { get; set; } /// /// 耗时(毫秒) /// [SugarColumn(IsNullable = true, ColumnDescription = "操作耗时毫秒")] public int? DurationMs { get; set; } /// /// 附加数据(JSON格式) /// [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "附加数据JSON")] public string? AdditionalDataJson { get; set; } } /// /// 错误日志实体 - 记录通信和处理错误 /// [SugarTable("ErrorLog")] public class ErrorLogEntity { /// /// 主键ID /// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long Id { get; set; } /// /// 错误发生时间 /// [SugarColumn(IsNullable = false, ColumnDescription = "错误发生时间")] public DateTime ErrorTime { get; set; } /// /// 项目名称 /// [SugarColumn(Length = 100, IsNullable = false, ColumnDescription = "项目名称")] public string ProjectName { get; set; } = string.Empty; /// /// PLC IP地址 /// [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "PLC IP地址")] public string PlcIpAddress { get; set; } = string.Empty; /// /// 错误类型 /// [SugarColumn(Length = 100, IsNullable = false, ColumnDescription = "错误类型")] public string ErrorType { get; set; } = string.Empty; /// /// 错误消息 /// [SugarColumn(Length = 1000, IsNullable = false, ColumnDescription = "错误消息")] public string ErrorMessage { get; set; } = string.Empty; /// /// 异常堆栈信息 /// [SugarColumn(ColumnDataType = "TEXT", IsNullable = true, ColumnDescription = "异常堆栈信息")] public string? StackTrace { get; set; } /// /// 错误严重级别(Critical, High, Medium, Low) /// [SugarColumn(Length = 20, IsNullable = false, ColumnDescription = "错误严重级别")] public string Severity { get; set; } = "Medium"; /// /// 重试次数 /// [SugarColumn(IsNullable = false, ColumnDescription = "重试次数")] public int RetryCount { get; set; } = 0; /// /// 是否已解决 /// [SugarColumn(IsNullable = false, ColumnDescription = "是否已解决")] public bool IsResolved { get; set; } = false; } /// /// 统计数据实体 - 记录通信统计信息 /// [SugarTable("Statistics")] public class StatisticsEntity { /// /// 主键ID /// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] public long Id { get; set; } /// /// 统计时间 /// [SugarColumn(IsNullable = false, ColumnDescription = "统计时间")] public DateTime StatisticsTime { get; set; } /// /// 项目名称 /// [SugarColumn(Length = 100, IsNullable = false, ColumnDescription = "项目名称")] public string ProjectName { get; set; } = string.Empty; /// /// PLC IP地址 /// [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "PLC IP地址")] public string PlcIpAddress { get; set; } = string.Empty; /// /// 连接尝试总数 /// [SugarColumn(IsNullable = false, ColumnDescription = "连接尝试总数")] public int TotalConnectionAttempts { get; set; } /// /// 连接成功总数 /// [SugarColumn(IsNullable = false, ColumnDescription = "连接成功总数")] public int SuccessfulConnections { get; set; } /// /// 数据读取总数 /// [SugarColumn(IsNullable = false, ColumnDescription = "数据读取总数")] public int TotalDataReads { get; set; } /// /// 数据读取成功总数 /// [SugarColumn(IsNullable = false, ColumnDescription = "数据读取成功总数")] public int SuccessfulDataReads { get; set; } /// /// 错误总数 /// [SugarColumn(IsNullable = false, ColumnDescription = "错误总数")] public int TotalErrors { get; set; } /// /// 平均响应时间(毫秒) /// [SugarColumn(IsNullable = false, ColumnDescription = "平均响应时间毫秒")] public double AverageResponseTimeMs { get; set; } /// /// 最大响应时间(毫秒) /// [SugarColumn(IsNullable = false, ColumnDescription = "最大响应时间毫秒")] public int MaxResponseTimeMs { get; set; } /// /// 最小响应时间(毫秒) /// [SugarColumn(IsNullable = false, ColumnDescription = "最小响应时间毫秒")] public int MinResponseTimeMs { get; set; } /// /// 连接成功率 /// [SugarColumn(IsNullable = false, ColumnDescription = "连接成功率")] public double ConnectionSuccessRate { get; set; } /// /// 数据读取成功率 /// [SugarColumn(IsNullable = false, ColumnDescription = "数据读取成功率")] public double DataReadSuccessRate { get; set; } /// /// 统计时间范围开始 /// [SugarColumn(IsNullable = false, ColumnDescription = "统计时间范围开始")] public DateTime PeriodStart { get; set; } /// /// 统计时间范围结束 /// [SugarColumn(IsNullable = false, ColumnDescription = "统计时间范围结束")] public DateTime PeriodEnd { get; set; } } /// /// 事件类型常量 /// public static class EventTypes { public const string Connected = "Connected"; public const string Disconnected = "Disconnected"; public const string DataReceived = "DataReceived"; public const string ConnectionError = "ConnectionError"; public const string DataReadError = "DataReadError"; public const string ConfigurationLoaded = "ConfigurationLoaded"; public const string SystemStarted = "SystemStarted"; public const string SystemStopped = "SystemStopped"; } /// /// 错误严重级别常量 /// public static class ErrorSeverity { public const string Critical = "Critical"; // 系统无法继续运行 public const string High = "High"; // 功能受到严重影响 public const string Medium = "Medium"; // 功能受到影响但可继续 public const string Low = "Low"; // 轻微问题,不影响主要功能 } }