1 feat: 将 OpcUaEndpointUrl 移动到 Device 并更新 OpcUaBackgroundService

2 将 OpcUaEndpointUrl 属性从 VariableData 和 DbVariableData 移动到 Device 和 DbDevice。
3 更新 OpcUaBackgroundService 以从关联的 Device 对象中检索 OpcUaEndpointUrl。
4 确保 DataServices 和 VarDataRepository 正确加载关联的 VariableTable 和 Device 数据。
5 在 VariableData 模型中添加 VariableTable 属性以正确解析。
This commit is contained in:
2025-07-08 20:19:06 +08:00
parent 07253aed65
commit 5dd0ed8e39
11 changed files with 96 additions and 20 deletions

View File

@@ -79,6 +79,12 @@ public class DbDevice
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
public ProtocolType ProtocolType { get; set; }
/// <summary>
/// OPC UA Endpoint URL。
/// </summary>
[SugarColumn(IsNullable = true)]
public string? OpcUaEndpointUrl { get; set; }
/// <summary>
/// 设备关联的变量表列表。
/// </summary>

View File

@@ -89,7 +89,7 @@ public class DeviceRepository
/// </summary>
/// <param name="id">设备ID。</param>
/// <returns>对应的DbDevice对象。</returns>
public async Task<DbDevice> GetById(int id)
public async Task<Device> GetById(int id)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -99,7 +99,7 @@ public class DeviceRepository
.FirstAsync(p => p.Id == id);
stopwatch.Stop();
NlogHelper.Info($"根据ID '{id}' 获取设备耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
return result.CopyTo<Device>();
}
}
@@ -252,4 +252,6 @@ public class DeviceRepository
await _menuRepository.AddVarTableMenu(addDevice, addDeviceMenuId, db);
return addDevice.CopyTo<Device>();
}
}

View File

@@ -46,6 +46,8 @@ public class VarDataRepository
using (var _db = DbContext.GetInstance())
{
var result = await _db.Queryable<DbVariableData>()
.Includes(d => d.VariableTable)
.Includes(d => d.VariableTable.Device)
.ToListAsync();
stopwatch.Stop();
NlogHelper.Info($"获取所有VariableData耗时{stopwatch.ElapsedMilliseconds}ms");