2025-07-21 22:02:42 +08:00
|
|
|
using System.Diagnostics;
|
2025-07-21 18:49:49 +08:00
|
|
|
using DMS.Core.Interfaces.Repositories;
|
2025-07-19 11:11:01 +08:00
|
|
|
using DMS.Infrastructure.Data;
|
2025-07-21 18:49:49 +08:00
|
|
|
using DMS.Infrastructure.Entities;
|
2025-07-17 17:27:16 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 变量与MQTT服务器别名关联的数据仓库。
|
|
|
|
|
/// </summary>
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using DMS.Core.Helper;
|
|
|
|
|
using DMS.Core.Interfaces.Repositories;
|
|
|
|
|
using DMS.Core.Models;
|
|
|
|
|
using DMS.Infrastructure.Data;
|
|
|
|
|
using DMS.Infrastructure.Entities;
|
|
|
|
|
|
2025-07-18 22:21:16 +08:00
|
|
|
namespace DMS.Infrastructure.Repositories;
|
2025-07-17 17:27:16 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-21 18:49:49 +08:00
|
|
|
/// 变量与MQTT服务器别名关联的数据仓库。
|
2025-07-17 17:27:16 +08:00
|
|
|
/// </summary>
|
2025-07-21 18:49:49 +08:00
|
|
|
public class VariableMqttAliasRepository : BaseRepository<DbVariableMqttAlias>, IVariableMqttAliasRepository
|
2025-07-17 17:27:16 +08:00
|
|
|
{
|
2025-07-21 22:02:42 +08:00
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
|
|
|
|
public VariableMqttAliasRepository(IMapper mapper, SqlSugarDbContext dbContext)
|
2025-07-19 14:36:34 +08:00
|
|
|
: base(dbContext)
|
2025-07-17 17:27:16 +08:00
|
|
|
{
|
2025-07-21 22:02:42 +08:00
|
|
|
_mapper = mapper;
|
2025-07-17 17:27:16 +08:00
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<VariableMqttAlias> GetByIdAsync(int id)
|
|
|
|
|
{
|
|
|
|
|
var dbVariableMqttAlias = await base.GetByIdAsync(id);
|
|
|
|
|
return _mapper.Map<VariableMqttAlias>(dbVariableMqttAlias);
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<List<VariableMqttAlias>> GetAllAsync()
|
|
|
|
|
{
|
|
|
|
|
var dbList = await base.GetAllAsync();
|
|
|
|
|
return _mapper.Map<List<VariableMqttAlias>>(dbList);
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<VariableMqttAlias> AddAsync(VariableMqttAlias entity)
|
|
|
|
|
{
|
|
|
|
|
var dbVariableMqttAlias = await base.AddAsync(_mapper.Map<DbVariableMqttAlias>(entity));
|
|
|
|
|
return _mapper.Map(dbVariableMqttAlias, entity);
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<int> UpdateAsync(VariableMqttAlias entity) => await base.UpdateAsync(_mapper.Map<DbVariableMqttAlias>(entity));
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<int> DeleteAsync(VariableMqttAlias entity) => await base.DeleteAsync(_mapper.Map<DbVariableMqttAlias>(entity));
|
|
|
|
|
|
|
|
|
|
public async Task<int> 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;
|
|
|
|
|
}
|
2025-07-22 21:36:33 +08:00
|
|
|
|
|
|
|
|
public new async Task<List<VariableMqttAlias>> TakeAsync(int number)
|
|
|
|
|
{
|
|
|
|
|
var dbList = await base.TakeAsync(number);
|
|
|
|
|
return _mapper.Map<List<VariableMqttAlias>>(dbList);
|
|
|
|
|
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
}
|