using System.Diagnostics; using DMS.Core.Interfaces.Repositories; using DMS.Infrastructure.Data; using DMS.Infrastructure.Entities; /// /// 变量与MQTT服务器别名关联的数据仓库。 /// using AutoMapper; 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; /// /// 变量与MQTT服务器别名关联的数据仓库。 /// public class VariableMqttAliasRepository : BaseRepository, IVariableMqttAliasRepository { private readonly IMapper _mapper; public VariableMqttAliasRepository(IMapper mapper, SqlSugarDbContext dbContext) : base(dbContext) { _mapper = mapper; } public async Task GetByIdAsync(int id) { var dbVariableMqttAlias = await base.GetByIdAsync(id); return _mapper.Map(dbVariableMqttAlias); } public async Task> GetAllAsync() { var dbList = await base.GetAllAsync(); return _mapper.Map>(dbList); } public async Task AddAsync(VariableMqttAlias entity) { var dbVariableMqttAlias = await base.AddAsync(_mapper.Map(entity)); return _mapper.Map(dbVariableMqttAlias, entity); } public async Task UpdateAsync(VariableMqttAlias entity) => await base.UpdateAsync(_mapper.Map(entity)); public async Task DeleteAsync(VariableMqttAlias entity) => await base.DeleteAsync(_mapper.Map(entity)); public async Task DeleteAsync(int id) { var stopwatch = new Stopwatch(); stopwatch.Start(); var result = await Db.Deleteable(new VariableMqttAlias() { Id = id }) .ExecuteCommandAsync(); stopwatch.Stop(); NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } public new async Task> TakeAsync(int number) { var dbList = await base.TakeAsync(number); return _mapper.Map>(dbList); } }