2025-07-02 22:07:16 +08:00
|
|
|
using iNKORE.UI.WPF.Modern.Common.IconKeys;
|
2025-07-02 12:01:20 +08:00
|
|
|
using PMSWPF.Data.Entities;
|
2025-07-02 22:07:16 +08:00
|
|
|
using PMSWPF.Enums;
|
2025-07-02 12:01:20 +08:00
|
|
|
using PMSWPF.Extensions;
|
|
|
|
|
using PMSWPF.Models;
|
2025-07-02 22:07:16 +08:00
|
|
|
using SqlSugar;
|
2025-07-03 13:53:29 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
using NLog;
|
2025-07-02 12:01:20 +08:00
|
|
|
|
|
|
|
|
namespace PMSWPF.Data.Repositories;
|
|
|
|
|
|
|
|
|
|
public class VarTableRepository
|
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2025-07-02 12:01:20 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加变量表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="varTable"></param>
|
|
|
|
|
/// <returns>变量表的ID</returns>
|
|
|
|
|
public async Task<int> Add(VariableTable varTable)
|
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
2025-07-02 12:01:20 +08:00
|
|
|
using (var db = DbContext.GetInstance())
|
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
var result = await db.Insertable<DbVariableTable>(varTable.CopyTo<DbVariableTable>())
|
2025-07-02 22:07:16 +08:00
|
|
|
.ExecuteReturnIdentityAsync();
|
2025-07-03 13:53:29 +08:00
|
|
|
stopwatch.Stop();
|
|
|
|
|
Logger.Info($"添加变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
|
|
|
return result;
|
2025-07-02 12:01:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-02 18:33:08 +08:00
|
|
|
|
2025-07-02 22:07:16 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加默认变量表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="db"></param>
|
|
|
|
|
/// <param name="dbDevice"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DbVariableTable> AddDeviceDefVarTable(DbDevice dbDevice, SqlSugarClient db)
|
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
2025-07-02 22:07:16 +08:00
|
|
|
// 添加默认变量表
|
|
|
|
|
dbDevice.VariableTables = new List<DbVariableTable>();
|
|
|
|
|
var dbVariableTable = new DbVariableTable();
|
|
|
|
|
dbVariableTable.IsActive = true;
|
|
|
|
|
dbVariableTable.DeviceId=dbDevice.Id;
|
|
|
|
|
dbVariableTable.Name = "默认变量表";
|
|
|
|
|
dbVariableTable.Description = "默认变量表";
|
|
|
|
|
dbVariableTable.ProtocolType = dbDevice.ProtocolType;
|
|
|
|
|
dbDevice.VariableTables.Add(dbVariableTable);
|
2025-07-03 13:53:29 +08:00
|
|
|
var result = await db.Insertable<DbVariableTable>(dbVariableTable).ExecuteReturnEntityAsync();
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
Logger.Info($"添加设备 '{dbDevice.Name}' 的默认变量表耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
|
|
|
return result;
|
2025-07-02 22:07:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-07-02 18:33:08 +08:00
|
|
|
public async Task<int> Edit(VariableTable variableTable)
|
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
2025-07-02 18:33:08 +08:00
|
|
|
using (var db = DbContext.GetInstance())
|
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
var result = await db.Updateable<DbVariableTable>(variableTable.CopyTo<DbVariableTable>()).ExecuteCommandAsync();
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
Logger.Info($"编辑变量表 '{variableTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
|
|
|
return result;
|
2025-07-02 18:33:08 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-02 22:07:16 +08:00
|
|
|
}
|