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

58 lines
1.7 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<DbMqtt>
{
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<DbMqtt> GetByIdAsync(int id)
{
2025-07-03 13:53:29 +08:00
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
2025-07-19 11:11:01 +08:00
var result = await Db.Queryable<DbMqtt>()
.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<DbMqtt>> GetAllAsync()
{
2025-07-03 13:53:29 +08:00
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
2025-07-19 11:11:01 +08:00
var result = await Db.Queryable<DbMqtt>()
.Includes(m => m.VariableMqtts, vm => vm.Variable)
.Includes(m => m.VariableMqtts, vm => vm.Mqtt)
.ToListAsync();
stopwatch.Stop();
NlogHelper.Info($"获取所有Mqtt配置耗时{stopwatch.ElapsedMilliseconds}ms");
return result;
}
2025-07-19 11:11:01 +08:00
}