梳理了所有的Db,DTO,ItemViewModel的属性
This commit is contained in:
@@ -45,13 +45,13 @@ public class DbDevice
|
||||
/// 设备机架号 (针对PLC等设备)。
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int Rack { get; set; }
|
||||
public short Rack { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备槽号 (针对PLC等设备)。
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int Slot { get; set; }
|
||||
public short Slot { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -76,6 +76,9 @@ public class DbDevice
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public bool IsRunning { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 此设备包含的变量表集合。
|
||||
/// </summary>
|
||||
|
||||
@@ -11,10 +11,14 @@ public class DbVariable
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int DataType { get; set; } // 对应 SignalType 枚举
|
||||
public int PollLevel { get; set; } // 对应 PollLevelType 枚举
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
public SignalType SignalType { get; set; } // 对应 SignalType 枚举
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
public PollLevelType PollLevel { get; set; } // 对应 PollLevelType 枚举
|
||||
public bool IsActive { get; set; }
|
||||
public int VariableTableId { get; set; }
|
||||
public string DataValue { get; set; }
|
||||
public string DisplayValue { get; set; }
|
||||
public string S7Address { get; set; }
|
||||
public string OpcUaNodeId { get; set; }
|
||||
public bool IsHistoryEnabled { get; set; }
|
||||
@@ -32,4 +36,6 @@ public class DbVariable
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
public string UpdatedBy { get; set; }
|
||||
public bool IsModified { get; set; }
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
public OpcUaUpdateType OpcUaUpdateType { get; set; }
|
||||
}
|
||||
@@ -254,7 +254,7 @@ public static class ExcelHelper
|
||||
{
|
||||
DMS.Core.Models.Variable variable = new DMS.Core.Models.Variable();
|
||||
variable.Name = dataRow["Name"].ToString();
|
||||
variable.DataType = (DMS.Core.Enums.SignalType)Enum.Parse(typeof(DMS.Core.Enums.SignalType), SiemensHelper.S7ToCSharpTypeString(dataRow["Data Type"].ToString()));
|
||||
variable.SignalType = (DMS.Core.Enums.SignalType)Enum.Parse(typeof(DMS.Core.Enums.SignalType), SiemensHelper.S7ToCSharpTypeString(dataRow["Data Type"].ToString()));
|
||||
var exS7Addr = dataRow["Logical Address"].ToString();
|
||||
if (exS7Addr.StartsWith("%"))
|
||||
{
|
||||
|
||||
@@ -22,16 +22,9 @@ public class MappingProfile : Profile
|
||||
|
||||
// --- 变量表映射 (List中的元素) ---
|
||||
CreateMap<DbVariableTable, VariableTable>()
|
||||
.ForMember(dest => dest.Variables, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Device, opt => opt.Ignore())
|
||||
.ReverseMap();
|
||||
|
||||
CreateMap<DbVariable, Variable>()
|
||||
.ForMember(dest => dest.VariableTable, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.MqttAliases, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.DataValue, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.DisplayValue, opt => opt.Ignore())
|
||||
.ReverseMap();
|
||||
CreateMap<DbVariable, Variable>().ReverseMap();
|
||||
// --- MQTT 和 变量数据 映射 ---
|
||||
CreateMap<DbMqttServer, MqttServer>()
|
||||
.ForMember(dest => dest.VariableAliases, opt => opt.Ignore())
|
||||
|
||||
@@ -369,12 +369,12 @@ public class OpcUaBackgroundService : BackgroundService
|
||||
foreach (var variable in variableList)
|
||||
{
|
||||
if (stoppingToken.IsCancellationRequested) return;
|
||||
|
||||
if (!PollingIntervals.TryGetValue(variable.PollLevelType, out var interval) || (DateTime.Now - variable.UpdateTime) < interval)
|
||||
|
||||
if (!PollingIntervals.TryGetValue(variable.PollLevel, out var interval) || (DateTime.Now - variable.UpdatedAt) < interval)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
await ReadAndProcessOpcUaVariableAsync(session, variable, stoppingToken);
|
||||
}
|
||||
}
|
||||
@@ -437,7 +437,7 @@ public class OpcUaBackgroundService : BackgroundService
|
||||
// 更新变量的原始数据值和显示值。
|
||||
variable.DataValue = value.ToString();
|
||||
variable.DisplayValue = value.ToString(); // 或者根据需要进行格式化
|
||||
variable.UpdateTime = DateTime.Now;
|
||||
variable.UpdatedAt = DateTime.Now;
|
||||
// Console.WriteLine($"OpcUa后台服务轮询变量:{variable.Name},值:{variable.DataValue}");
|
||||
// 将更新后的数据推入处理队列。
|
||||
await _dataProcessingService.EnqueueAsync(variable);
|
||||
|
||||
@@ -230,14 +230,14 @@ public class S7BackgroundService : BackgroundService
|
||||
|
||||
// 获取变量的轮询间隔。
|
||||
if (!PollingIntervals.TryGetValue(
|
||||
variable.PollLevelType, out var interval))
|
||||
variable.PollLevel, out var interval))
|
||||
{
|
||||
_logger.LogInformation($"未知轮询级别 {variable.PollLevelType},跳过变量 {variable.Name}。");
|
||||
_logger.LogInformation($"未知轮询级别 {variable.PollLevel},跳过变量 {variable.Name}。");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查是否达到轮询时间。
|
||||
if ((DateTime.Now - variable.UpdateTime) < interval)
|
||||
if ((DateTime.Now - variable.UpdatedAt) < interval)
|
||||
continue; // 未到轮询时间,跳过。
|
||||
|
||||
dataItemsToRead[variable.Id] = DataItem.FromAddress(variable.S7Address);
|
||||
@@ -299,7 +299,7 @@ public class S7BackgroundService : BackgroundService
|
||||
// 更新变量的原始数据值和显示值。
|
||||
variable.DataValue = dataItem.Value.ToString();
|
||||
variable.DisplayValue = dataItem.Value.ToString();
|
||||
variable.UpdateTime = DateTime.Now;
|
||||
variable.UpdatedAt = DateTime.Now;
|
||||
// Console.WriteLine($"S7后台服务轮询变量:{variable.Name},值:{variable.DataValue}");
|
||||
// 将更新后的数据推入处理队列。
|
||||
await _dataProcessingService.EnqueueAsync(variable);
|
||||
@@ -406,7 +406,7 @@ public class S7BackgroundService : BackgroundService
|
||||
int totalVariableCount = 0;
|
||||
foreach (var device in s7Devices)
|
||||
{
|
||||
device.IsRuning = true;
|
||||
// device.IsRuning = true;
|
||||
_s7Devices.AddOrUpdate(device.Id, device, (key, oldValue) => device);
|
||||
|
||||
// 过滤出当前设备和S7协议相关的变量。
|
||||
|
||||
Reference in New Issue
Block a user