Files
DMS/DMS.Infrastructure/Repositories/MqttServerRepository.cs

63 lines
1.9 KiB
C#
Raw Normal View History

2025-07-21 18:49:49 +08:00
using System.Diagnostics;
2025-07-21 22:02:42 +08:00
using AutoMapper;
2025-07-21 18:49:49 +08:00
using DMS.Core.Helper;
using DMS.Core.Interfaces.Repositories;
using DMS.Core.Models;
using DMS.Infrastructure.Data;
using DMS.Infrastructure.Entities;
namespace DMS.Infrastructure.Repositories;
/// <summary>
/// Mqtt仓储类用于操作DbMqtt实体
/// </summary>
public class MqttServerRepository : BaseRepository<DbMqttServer>, IMqttServerRepository
{
2025-07-21 22:02:42 +08:00
private readonly IMapper _mapper;
public MqttServerRepository(IMapper mapper, SqlSugarDbContext dbContext)
2025-07-21 18:49:49 +08:00
: base(dbContext)
{
2025-07-21 22:02:42 +08:00
_mapper = mapper;
2025-07-21 18:49:49 +08:00
}
2025-07-21 22:02:42 +08:00
public async Task<MqttServer> GetByIdAsync(int id)
{
var dbMqttServer = await base.GetByIdAsync(id);
return _mapper.Map<MqttServer>(dbMqttServer);
}
2025-07-21 18:49:49 +08:00
2025-07-21 22:02:42 +08:00
public async Task<List<MqttServer>> GetAllAsync()
{
var dbList = await base.GetAllAsync();
return _mapper.Map<List<MqttServer>>(dbList);
}
2025-07-21 18:49:49 +08:00
2025-07-21 22:02:42 +08:00
public async Task<MqttServer> AddAsync(MqttServer entity)
{
var dbMqttServer = await base.AddAsync(_mapper.Map<DbMqttServer>(entity));
return _mapper.Map(dbMqttServer, entity);
}
2025-07-21 18:49:49 +08:00
2025-07-21 22:02:42 +08:00
public async Task<int> UpdateAsync(MqttServer entity) => await base.UpdateAsync(_mapper.Map<DbMqttServer>(entity));
2025-07-21 18:49:49 +08:00
2025-07-21 22:02:42 +08:00
public async Task<int> DeleteAsync(MqttServer entity) => await base.DeleteAsync(_mapper.Map<DbMqttServer>(entity));
2025-07-24 18:09:46 +08:00
public async Task<int> DeleteByIdAsync(int id)
2025-07-21 22:02:42 +08:00
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var result = await Db.Deleteable(new MqttServer() { Id = id })
.ExecuteCommandAsync();
stopwatch.Stop();
NlogHelper.Info($"Delete {typeof(MqttServer)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
2025-07-22 21:36:33 +08:00
public new async Task<List<MqttServer>> TakeAsync(int number)
{
var dbList = await base.TakeAsync(number);
return _mapper.Map<List<MqttServer>>(dbList);
}
2025-07-21 18:49:49 +08:00
}