Files
DMS/DMS.Infrastructure/Repositories/MqttRepository.cs

56 lines
1.5 KiB
C#
Raw Normal View History

2025-07-03 13:53:29 +08:00
using System.Diagnostics;
using AutoMapper;
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;
namespace DMS.Infrastructure.Repositories;
/// <summary>
/// Mqtt仓储类用于操作DbMqtt实体
/// </summary>
public class MqttRepository : BaseRepository<DbMqttServer>
{
2025-07-03 13:53:29 +08:00
public MqttRepository(SqlSugarDbContext dbContext)
: base(dbContext)
{
}
/// <summary>
/// 根据ID获取Mqtt配置
/// </summary>
/// <param name="id">主键ID</param>
/// <returns></returns>
public override async Task<DbMqttServer> GetByIdAsync(int id)
{
2025-07-03 13:53:29 +08:00
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
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");
return result;
}
/// <summary>
/// 获取所有Mqtt配置
/// </summary>
/// <returns></returns>
public override async Task<List<DbMqttServer>> GetAllAsync()
{
2025-07-03 13:53:29 +08:00
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var result = await Db.Queryable<DbMqttServer>()
2025-07-19 11:11:01 +08:00
.ToListAsync();
stopwatch.Stop();
NlogHelper.Info($"获取所有Mqtt配置耗时{stopwatch.ElapsedMilliseconds}ms");
return result;
}
2025-07-19 11:11:01 +08:00
}