2025-07-03 13:53:29 +08:00
|
|
|
|
using System.Diagnostics;
|
2025-07-15 22:18:37 +08:00
|
|
|
|
using AutoMapper;
|
2025-07-18 22:21:16 +08:00
|
|
|
|
using DMS.Infrastructure.Entities;
|
|
|
|
|
|
using DMS.Core.Enums;
|
2025-07-19 09:25:01 +08:00
|
|
|
|
using DMS.Core.Helper;
|
|
|
|
|
|
using DMS.Core.Models;
|
|
|
|
|
|
using DMS.Infrastructure.Data;
|
2025-07-19 11:11:01 +08:00
|
|
|
|
using DMS.Infrastructure.Interfaces;
|
2025-07-03 08:17:27 +08:00
|
|
|
|
|
2025-07-18 22:21:16 +08:00
|
|
|
|
namespace DMS.Infrastructure.Repositories;
|
2025-07-03 08:17:27 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Mqtt仓储类,用于操作DbMqtt实体
|
|
|
|
|
|
/// </summary>
|
2025-07-21 14:35:17 +08:00
|
|
|
|
public class MqttRepository : BaseRepository<DbMqttServer>
|
2025-07-03 08:17:27 +08:00
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
|
public MqttRepository(SqlSugarDbContext dbContext)
|
|
|
|
|
|
: base(dbContext)
|
2025-07-05 18:35:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-03 08:17:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据ID获取Mqtt配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">主键ID</param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-21 14:35:17 +08:00
|
|
|
|
public override async Task<DbMqttServer> GetByIdAsync(int id)
|
2025-07-03 08:17:27 +08:00
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
|
stopwatch.Start();
|
2025-07-21 14:35:17 +08:00
|
|
|
|
var result = await Db.Queryable<DbMqttServer>()
|
2025-07-19 11:11:01 +08:00
|
|
|
|
.In(id)
|
|
|
|
|
|
.SingleAsync();
|
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
|
NlogHelper.Info($"根据ID '{id}' 获取Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
|
2025-07-19 14:36:34 +08:00
|
|
|
|
return result;
|
2025-07-03 08:17:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取所有Mqtt配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2025-07-21 14:35:17 +08:00
|
|
|
|
public override async Task<List<DbMqttServer>> GetAllAsync()
|
2025-07-03 08:17:27 +08:00
|
|
|
|
{
|
2025-07-03 13:53:29 +08:00
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
|
stopwatch.Start();
|
2025-07-21 14:35:17 +08:00
|
|
|
|
var result = await Db.Queryable<DbMqttServer>()
|
2025-07-19 11:11:01 +08:00
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
|
NlogHelper.Info($"获取所有Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms");
|
2025-07-19 14:36:34 +08:00
|
|
|
|
return result;
|
2025-07-03 08:17:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-19 11:11:01 +08:00
|
|
|
|
|
2025-07-03 08:17:27 +08:00
|
|
|
|
}
|