添加了 Mqtt 的界面和添加对话框

This commit is contained in:
2025-07-04 22:39:44 +08:00
parent 8325717b95
commit f86ce8194b
12 changed files with 452 additions and 14 deletions

View File

@@ -3,6 +3,8 @@ using System.Diagnostics;
using System.Threading.Tasks;
using NLog;
using PMSWPF.Data.Entities;
using PMSWPF.Models;
using PMSWPF.Extensions;
namespace PMSWPF.Data.Repositories;
@@ -18,7 +20,7 @@ public class MqttRepository
/// </summary>
/// <param name="id">主键ID</param>
/// <returns></returns>
public async Task<DbMqtt> GetByIdAsync(int id)
public async Task<Mqtt> GetById(int id)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -27,7 +29,7 @@ public class MqttRepository
var result = await _db.Queryable<DbMqtt>().In(id).SingleAsync();
stopwatch.Stop();
Logger.Info($"根据ID '{id}' 获取Mqtt配置耗时{stopwatch.ElapsedMilliseconds}ms");
return result;
return result.CopyTo<Mqtt>();
}
}
@@ -35,7 +37,7 @@ public class MqttRepository
/// 获取所有Mqtt配置
/// </summary>
/// <returns></returns>
public async Task<List<DbMqtt>> GetAllAsync()
public async Task<List<Mqtt>> GetAll()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -44,7 +46,7 @@ public class MqttRepository
var result = await _db.Queryable<DbMqtt>().ToListAsync();
stopwatch.Stop();
Logger.Info($"获取所有Mqtt配置耗时{stopwatch.ElapsedMilliseconds}ms");
return result;
return result.CopyTo<List<Mqtt>>();
}
}
@@ -53,13 +55,13 @@ public class MqttRepository
/// </summary>
/// <param name="mqtt">Mqtt实体</param>
/// <returns></returns>
public async Task<int> AddAsync(DbMqtt mqtt)
public async Task<int> Add(Mqtt mqtt)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Insertable(mqtt).ExecuteReturnIdentityAsync();
var result = await _db.Insertable(mqtt.CopyTo<DbMqtt>()).ExecuteReturnIdentityAsync();
stopwatch.Stop();
Logger.Info($"新增Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
@@ -71,13 +73,13 @@ public class MqttRepository
/// </summary>
/// <param name="mqtt">Mqtt实体</param>
/// <returns></returns>
public async Task<int> UpdateAsync(DbMqtt mqtt)
public async Task<int> Edit(Mqtt mqtt)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Updateable(mqtt).ExecuteCommandAsync();
var result = await _db.Updateable(mqtt.CopyTo<DbMqtt>()).ExecuteCommandAsync();
stopwatch.Stop();
Logger.Info($"更新Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
@@ -87,17 +89,17 @@ public class MqttRepository
/// <summary>
/// 根据ID删除Mqtt配置
/// </summary>
/// <param name="id">主键ID</param>
/// <param name="mqtt">Mqtt实体</param>
/// <returns></returns>
public async Task<int> DeleteAsync(int id)
public async Task<int> Delete(Mqtt mqtt)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var _db = DbContext.GetInstance())
{
var result = await _db.Deleteable<DbMqtt>().In(id).ExecuteCommandAsync();
var result = await _db.Deleteable<DbMqtt>().In(mqtt.Id).ExecuteCommandAsync();
stopwatch.Stop();
Logger.Info($"删除Mqtt配置ID '{id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
Logger.Info($"删除Mqtt配置ID '{mqtt.Id}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
}