修复错误

This commit is contained in:
2025-07-21 22:02:42 +08:00
parent 525c681b6c
commit 8f3543afb5
33 changed files with 428 additions and 260 deletions

View File

@@ -1,4 +1,5 @@
using System.Diagnostics;
using AutoMapper;
using DMS.Core.Helper;
using DMS.Core.Interfaces.Repositories;
using DMS.Core.Models;
@@ -12,18 +13,44 @@ namespace DMS.Infrastructure.Repositories;
/// </summary>
public class MqttServerRepository : BaseRepository<DbMqttServer>, IMqttServerRepository
{
public MqttServerRepository(SqlSugarDbContext dbContext)
private readonly IMapper _mapper;
public MqttServerRepository(IMapper mapper, SqlSugarDbContext dbContext)
: base(dbContext)
{
_mapper = mapper;
}
public async Task<MqttServer> GetByIdAsync(int id) => throw new NotImplementedException();
public async Task<MqttServer> GetByIdAsync(int id)
{
var dbMqttServer = await base.GetByIdAsync(id);
return _mapper.Map<MqttServer>(dbMqttServer);
}
public async Task<List<MqttServer>> GetAllAsync() => throw new NotImplementedException();
public async Task<List<MqttServer>> GetAllAsync()
{
var dbList = await base.GetAllAsync();
return _mapper.Map<List<MqttServer>>(dbList);
}
public async Task<MqttServer> AddAsync(MqttServer entity) => throw new NotImplementedException();
public async Task<MqttServer> AddAsync(MqttServer entity)
{
var dbMqttServer = await base.AddAsync(_mapper.Map<DbMqttServer>(entity));
return _mapper.Map(dbMqttServer, entity);
}
public async Task<int> UpdateAsync(MqttServer entity) => throw new NotImplementedException();
public async Task<int> UpdateAsync(MqttServer entity) => await base.UpdateAsync(_mapper.Map<DbMqttServer>(entity));
public async Task<int> DeleteAsync(MqttServer entity) => throw new NotImplementedException();
public async Task<int> DeleteAsync(MqttServer entity) => await base.DeleteAsync(_mapper.Map<DbMqttServer>(entity));
public async Task<int> DeleteAsync(int id)
{
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;
}
}