按照软件设计文档开始重构代码01

This commit is contained in:
2025-07-21 14:35:17 +08:00
parent a7b0a5d108
commit 29a2d44319
127 changed files with 12265 additions and 1586 deletions

View File

@@ -1,92 +1,56 @@
using SqlSugar;
using SqlSugar.DbConvert;
using S7.Net;
using DMS.Core.Enums;
using DMS.Infrastructure.Entities;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的设备实体。
/// 设备实体类,对应数据库中的 Devices 表
/// </summary>
[SugarTable("Device")]
[SugarTable("Devices")]
public class DbDevice
{
/// <summary>
/// 设备的描述信息
/// 设备ID主键且自增
/// </summary>
[SugarColumn(IsNullable = true)]
public string? Description { get; set; }
/// <summary>
/// 设备的类型。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public DeviceType DeviceType { get; set; }
/// <summary>
/// 设备的唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 设备的IP地址
/// </summary>
public string Ip { get; set; }
/// <summary>
/// 表示设备是否处于活动状态。
/// </summary>
public bool IsActive { get; set; }
/// <summary>
/// 表示设备是否正在运行。
/// </summary>
public bool IsRuning { get; set; }
/// <summary>
/// 设备的名称。
/// 设备名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 设备的端口号
/// 设备通信协议类型,对应 ProtocolType 枚举
/// </summary>
public int Prot { get; set; }
public ProtocolType Protocol { get; set; }
/// <summary>
/// PLC的CPU类型
/// 设备IP地址
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", IsNullable = true, SqlParameterDbType = typeof(EnumToStringConvert))]
public CpuType CpuType { get; set; }
public string IpAddress { get; set; }
/// <summary>
/// PLC的机架号。
/// 设备端口号。
/// </summary>
[SugarColumn(IsNullable = true)]
public short Rack { get; set; }
public int Port { get; set; }
/// <summary>
/// PLC的槽号
/// 设备机架号 (针对PLC等设备)
/// </summary>
/// [SugarColumn(IsNullable = true)]
public short Slot { get; set; }
public int Rack { get; set; }
/// <summary>
/// 设备的通信协议类型
/// 设备槽号 (针对PLC等设备)
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public ProtocolType ProtocolType { get; set; }
public int Slot { get; set; }
/// <summary>
/// OPC UA Endpoint URL。
/// OPC UA服务器的URL地址
/// </summary>
[SugarColumn(IsNullable = true)]
public string? OpcUaEndpointUrl { get; set; }
public string OpcUaServerUrl { get; set; }
/// <summary>
/// 设备关联的变量表列表
/// 设备是否激活/启用
/// </summary>
[Navigate(NavigateType.OneToMany, nameof(DbVariableTable.DeviceId))]
[SugarColumn(IsNullable = true)]
public List<DbVariableTable>? VariableTables { get; set; }
public bool IsActive { get; set; }
}

View File

@@ -1,56 +1,25 @@
using DMS.Core.Enums;
using SqlSugar;
using SqlSugar.DbConvert;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的菜单实体。
/// </summary>
[SugarTable("Menu")]
[SugarTable("Menus")]
public class DbMenu
{
/// <summary>
/// 菜单项关联的数据。
/// </summary>
[SugarColumn(IsIgnore = true)]
public object? Data { get; set; }
/// <summary>
/// 菜单项关联的数据ID。
/// </summary>
public int DataId { get; set; }
/// <summary>
/// 菜单项的图标。
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 菜单项的唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 子菜单项列表。
/// </summary>
[SugarColumn(IsIgnore = true)]
public List<DbMenu> Items { get; set; }
[SugarColumn(IsNullable = true)]
public int? ParentId { get; set; }
/// <summary>
/// 菜单项的名称。
/// </summary>
public string Name { get; set; }
public string Header { get; set; }
/// <summary>
/// 父菜单项的ID。
/// </summary>
public int ParentId { get; set; }
public string Icon { get; set; }
/// <summary>
/// 菜单项的类型。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public MenuType Type { get; set; }
public string TargetViewKey { get; set; }
[SugarColumn(IsNullable = true)]
public string NavigationParameter { get; set; }
public List<DbMenu> Childrens { get; set; }
public int DisplayOrder { get; set; }
}

View File

@@ -1,95 +0,0 @@
using DMS.Core.Enums;
using SqlSugar;
using SqlSugar.DbConvert;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的MQTT配置实体。
/// </summary>
[SugarTable("Mqtt")]
public class DbMqtt
{
/// <summary>
/// MQTT客户端ID。
/// </summary>
public string ClientID { get; set; } = String.Empty;
/// <summary>
/// 创建时间。
/// </summary>
public DateTime CreateTime { get; set; } = DateTime.Now;
/// <summary>
/// MQTT主机。
/// </summary>
public string Host { get; set; }
/// <summary>
/// MQTT配置的唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
public int Id { get; set; }
/// <summary>
/// 是否启用此MQTT配置。
/// </summary>
public bool IsActive { get; set; }
/// <summary>
/// 是否设置为默认MQTT客户端。
/// </summary>
public int IsDefault { get; set; }
/// <summary>
/// MQTT客户端名字。
/// </summary>
public string Name { get; set; }
/// <summary>
/// MQTT客户端登录密码。
/// </summary>
[SugarColumn(IsNullable = true)]
public string PassWord { get; set; } = String.Empty;
/// <summary>
/// Mqtt平台类型。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public MqttPlatform Platform { get; set; }
/// <summary>
/// MQTT主机端口。
/// </summary>
public int Port { get; set; }
/// <summary>
/// MQTT发布主题。
/// </summary>
[SugarColumn(IsNullable = true)]
public string PublishTopic { get; set; } = String.Empty;
/// <summary>
/// MQTT备注。
/// </summary>
[SugarColumn(IsNullable = true)]
public string Remark { get; set; } = String.Empty;
/// <summary>
/// MQTT订阅主题。
/// </summary>
[SugarColumn(IsNullable = true)]
public string SubTopic { get; set; } = String.Empty;
/// <summary>
/// MQTT客户端登录用户名。
/// </summary>
[SugarColumn(IsNullable = true)]
public string UserName { get; set; } = String.Empty;
/// <summary>
/// 关联的变量数据列表。
/// </summary>
[Navigate(NavigateType.OneToMany, nameof(DbVariableMqtt.MqttId))]
public List<DbVariableMqtt>? VariableMqtts { get; set; }
}

View File

@@ -0,0 +1,23 @@
using SqlSugar;
namespace DMS.Infrastructure.Entities;
[SugarTable("MqttServers")]
public class DbMqttServer
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string ServerName { get; set; }
public string BrokerAddress { get; set; }
public int Port { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public bool IsActive { get; set; }
public string SubscribeTopic { get; set; }
public string PublishTopic { get; set; }
public string ClientId { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? ConnectedAt { get; set; }
public long ConnectionDuration { get; set; }
public string MessageFormat { get; set; }
}

View File

@@ -1,79 +1,51 @@
using SqlSugar;
using System;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的NLog日志实体
/// 数据库实体:对应数据库中的 Logs 表,用于存储应用程序日志。
/// </summary>
[SugarTable("nlog")]
[SugarTable("Logs")]
public class DbNlog
{
/// <summary>
/// 日志调用位置。
/// </summary>
public string Callsite { get; set; }
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// 日志调用行号
/// 日志记录的时间戳
/// </summary>
public int CallsiteLineNumber { get; set; }
public DateTime Logged { get; set; }
/// <summary>
/// 异常信息
/// </summary>
[SugarColumn(IsNullable = true, ColumnDataType = "text")]
public string Exception { get; set; }
/// <summary>
/// 日志的唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
public int Id { get; set; }
/// <summary>
/// 日志级别。
/// 日志级别 (e.g., "Info", "Warn", "Error", "Debug")
/// </summary>
public string Level { get; set; }
/// <summary>
/// 日志记录器名称
/// </summary>
public string Logger { get; set; }
/// <summary>
/// 日志时间。
/// </summary>
public DateTime LogTime { get; set; }
/// <summary>
/// 日志消息内容。
/// 日志消息主体
/// </summary>
[SugarColumn(Length = -1)] // 映射为NVARCHAR(MAX)或类似类型
public string Message { get; set; }
/// <summary>
/// 线程ID
/// 异常信息包括堆栈跟踪。如果无异常则为null
/// </summary>
public int ThreadID { get; set; }
[SugarColumn(IsNullable = true, Length = -1)]
public string Exception { get; set; }
/// <summary>
/// 线程名称
/// 记录日志的调用点信息 (文件路径:行号)
/// </summary>
[SugarColumn(IsNullable = true)]
public string ThreadName { get; set; }
public string CallSite { get; set; }
/// <summary>
/// 线程名称
/// 记录日志的方法名
/// </summary>
[SugarColumn(IsNullable = true)]
public string CallerFilePath { get; set; }
public string MethodName { get; set; }
/// <summary>
/// 线程名称
/// (用于聚合) 此条日志在指定时间窗口内被触发的总次数。默认为1
/// </summary>
[SugarColumn(IsNullable = true)]
public int CallerLineNumber { get; set; }
/// <summary>
/// 线程名称。
/// </summary>
[SugarColumn(IsNullable = true)]
public string CallerMember { get; set; }
public int AggregatedCount { get; set; } = 1;
}

View File

@@ -2,22 +2,13 @@
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的用户实体。
/// </summary>
[SugarTable("User")]
[SugarTable("Users")]
public class DbUser
{
/// <summary>
/// 用户的唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public string Address { get; set; }
public string Username { get; set; }
public string PasswordHash { get; set; }
public string Role { get; set; }
public bool IsActive { get; set; }
}

View File

@@ -1,172 +1,30 @@
using DMS.Core.Enums;
using SqlSugar;
using SqlSugar.DbConvert;
using SqlSugar;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的变量数据实体。
/// </summary>
[SugarTable("VarData")]
[SugarTable("Variables")]
public class DbVariable
{
/// <summary>
/// 变量唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 变量名称。
/// </summary>
public string Name { get; set; }
/// <summary>
/// 节点ID用于标识变量在设备或系统中的唯一路径。
/// </summary>
[SugarColumn(IsNullable = true)]
public string NodeId { get; set; } = String.Empty;
/// <summary>
/// 节点ID用于标识变量在设备或系统中的唯一路径。
/// </summary>
[SugarColumn(IsNullable = true)]
public string S7Address { get; set; } = String.Empty;
/// <summary>
/// OPC UA Endpoint URL。
/// </summary>
[SugarColumn(IsNullable = true)]
public string? OpcUaEndpointUrl { get; set; }
/// <summary>
/// OPC UA Node ID。
/// </summary>
[SugarColumn(IsNullable = true)]
public string? OpcUaNodeId { get; set; }
/// <summary>
/// 变量描述。
/// </summary>
[SugarColumn(IsNullable = true)]
public string? Description { get; set; }
/// <summary>
/// 协议类型例如Modbus、OPC UA等。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public ProtocolType ProtocolType { get; set; }
/// <summary>
/// 信号类型,例如模拟量、数字量等。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", IsNullable = true, SqlParameterDbType = typeof(EnumToStringConvert))]
public SignalType SignalType { get; set; }
/// <summary>
/// 数据类型例如Int、Float、String等。
/// </summary>
public string DataType { get; set; } = String.Empty;
/// <summary>
/// 变量当前原始数据值。
/// </summary>
public string DataValue { get; set; } = String.Empty;
/// <summary>
/// 变量经过转换或格式化后的显示值。
/// </summary>
public string DisplayValue { get; set; } = String.Empty;
/// <summary>
/// 指示变量是否处于激活状态。
/// </summary>
public string Address { get; set; }
public int DataType { get; set; } // 对应 SignalType 枚举
public int PollLevel { get; set; } // 对应 PollLevelType 枚举
public bool IsActive { get; set; }
/// <summary>
/// 指示是否需要保存变量数据。
/// </summary>
public bool IsSave { get; set; }
/// <summary>
/// 指示是否需要对变量进行报警监测。
/// </summary>
public bool IsAlarm { get; set; }
/// <summary>
/// 轮询级别例如1秒、5秒等。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)",IsNullable =true, SqlParameterDbType = typeof(EnumToStringConvert))]
public PollLevelType PollLevelType { get; set; }
/// <summary>
/// OPC UA更新类型例如轮询或订阅。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", IsNullable = true, SqlParameterDbType = typeof(EnumToStringConvert))]
public OpcUaUpdateType OpcUaUpdateType { get; set; }
/// <summary>
/// 指示变量是否已被逻辑删除。
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// 报警的最大值阈值。
/// </summary>
public double AlarmMax { get; set; }
/// <summary>
/// 报警的最小值阈值。
/// </summary>
public double AlarmMin { get; set; }
/// <summary>
/// 数据转换规则或表达式。
/// </summary>
public string Converstion { get; set; } = String.Empty;
/// <summary>
/// 数据保存的范围或阈值。
/// </summary>
public double SaveRange { get; set; }
/// <summary>
/// 变量数据最后更新时间。
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime CreateTime { get; set; }
/// <summary>
/// 变量数据最后更新时间。
/// </summary>
public DateTime UpdateTime { get; set; } = DateTime.Now;
/// <summary>
/// 最后更新变量数据的用户。
/// </summary>
[SugarColumn(IsNullable = true)]
public DbUser? UpdateUser { get; set; }
/// <summary>
/// 关联的变量表ID。
/// </summary>
public int VariableTableId { get; set; }
/// <summary>
/// 关联的变量表实体。
/// </summary>
[Navigate(NavigateType.ManyToOne, nameof(VariableTableId))]
public DbVariableTable? VariableTable { get; set; }
/// <summary>
/// 关联的MQTT配置列表。
/// </summary>
[Navigate(NavigateType.OneToMany, nameof(DbVariableMqtt.VariableId))]
public List<DbVariableMqtt>? VariableMqtts { get; set; }
/// <summary>
/// 关联的历史记录列表。
/// </summary>
[Navigate(NavigateType.OneToMany, nameof(DbVariableHistory.VariableId))]
public List<DbVariableHistory>? HistoryRecords { get; set; }
public string OpcUaNodeId { get; set; }
public bool IsHistoryEnabled { get; set; }
public double HistoryDeadband { get; set; }
public bool IsAlarmEnabled { get; set; }
public double AlarmMinValue { get; set; }
public double AlarmMaxValue { get; set; }
public double AlarmDeadband { get; set; }
public int Protocol { get; set; } // 对应 ProtocolType 枚举
public int CSharpDataType { get; set; } // 对应 CSharpDataType 枚举
public string ConversionFormula { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public string UpdatedBy { get; set; }
public bool IsModified { get; set; }
}

View File

@@ -1,49 +1,13 @@
using System;
using SqlSugar;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的变量数据历史实体。
/// </summary>
[SugarTable("VarDataHistory")]
[SugarTable("VariableHistories")]
public class DbVariableHistory
{
/// <summary>
/// 历史记录唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 变量名称。
/// </summary>
public string Name { get; set; }
/// <summary>
/// 节点ID用于标识变量在设备或系统中的唯一路径。
/// </summary>
[SugarColumn(IsNullable = true)]
public string NodeId { get; set; } = String.Empty;
/// <summary>
/// 变量当前原始数据值。
/// </summary>
public string DataValue { get; set; } = String.Empty;
/// <summary>
/// 关联的DbVariableData的ID。
/// </summary>
public long Id { get; set; }
public int VariableId { get; set; }
/// <summary>
/// 关联的DbVariableData实体。
/// </summary>
[Navigate(NavigateType.ManyToOne, nameof(VariableId))]
public DbVariable? Variable { get; set; }
/// <summary>
/// 历史记录的时间戳。
/// </summary>
public DateTime Timestamp { get; set; } = DateTime.Now;
public string Value { get; set; }
public DateTime Timestamp { get; set; }
}

View File

@@ -1,54 +0,0 @@
using System;
using SqlSugar;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示变量数据与MQTT服务器之间的关联实体包含MQTT别名。
/// </summary>
[SugarTable("VariableMqtt")]
public class DbVariableMqtt
{
/// <summary>
/// 关联的唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 关联的变量数据ID。
/// </summary>
public int VariableId { get; set; }
/// <summary>
/// 关联的MQTT服务器ID。
/// </summary>
public int MqttId { get; set; }
/// <summary>
/// 变量在该MQTT服务器上的别名。
/// </summary>
public string MqttAlias { get; set; } = string.Empty;
/// <summary>
/// 创建时间。
/// </summary>
public DateTime CreateTime { get; set; } = DateTime.Now;
/// <summary>
/// 更新时间。
/// </summary>
public DateTime UpdateTime { get; set; } = DateTime.Now;
/// <summary>
/// 导航属性:关联的变量数据。
/// </summary>
[Navigate(NavigateType.ManyToOne, nameof(VariableId))]
public DbVariable? Variable { get; set; }
/// <summary>
/// 导航属性关联的MQTT服务器。
/// </summary>
[Navigate(NavigateType.ManyToOne, nameof(MqttId))]
public DbMqtt? Mqtt { get; set; }
}

View File

@@ -0,0 +1,28 @@
using SqlSugar;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 数据库实体:对应数据库中的 VariableMqttAliases 表。
/// </summary>
[SugarTable("VariableMqttAliases")]
public class DbVariableMqttAlias
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 外键,指向 Variables 表的 Id。
/// </summary>
public int VariableId { get; set; }
/// <summary>
/// 外键,指向 MqttServers 表的 Id。
/// </summary>
public int MqttServerId { get; set; }
/// <summary>
/// 针对此特定[变量-服务器]连接的发布别名。
/// </summary>
public string Alias { get; set; }
}

View File

@@ -1,58 +1,15 @@
using DMS.Core.Enums;
using SqlSugar;
using SqlSugar.DbConvert;
using SqlSugar;
namespace DMS.Infrastructure.Entities;
/// <summary>
/// 表示数据库中的变量表实体。
/// </summary>
[SugarTable("VariableTable")]
[SugarTable("VariableTables")]
public class DbVariableTable
{
/// <summary>
/// 变量表中包含的数据变量列表。
/// </summary>
[Navigate(NavigateType.OneToMany, nameof(DbVariable.VariableTableId))]
public List<DbVariable>? Variables { get; set; }
/// <summary>
/// 变量表关联的设备。
/// </summary>
[Navigate(NavigateType.ManyToOne, nameof(DeviceId))]
public DbDevice? Device { get; set; }
/// <summary>
/// 变量表关联的设备ID。
/// </summary>
[SugarColumn(IsNullable = true)]
public int? DeviceId { get; set; }
/// <summary>
/// 变量表描述。
/// </summary>
[SugarColumn(IsNullable = true)]
public string? Description { get; set; }
/// <summary>
/// 变量表的唯一标识符。
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] //数据库是自增才配自增
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 表示变量表是否处于活动状态。
/// </summary>
public bool IsActive { get; set; }
/// <summary>
/// 变量表名称。
/// </summary>
public string Name { get; set; }
/// <summary>
/// 变量表使用的协议类型。
/// </summary>
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public ProtocolType ProtocolType { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
public int DeviceId { get; set; }
public int Protocol { get; set; } // 对应 ProtocolType 枚举
}