2025-07-21 22:02:42 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
using DMS.Core.Interfaces.Repositories;
|
|
|
|
|
using DMS.Core.Models;
|
|
|
|
|
using DMS.Infrastructure.Data;
|
|
|
|
|
using DMS.Infrastructure.Entities;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using DMS.Core.Helper;
|
2025-07-21 18:49:49 +08:00
|
|
|
using DMS.Core.Interfaces.Repositories;
|
|
|
|
|
using DMS.Core.Models;
|
|
|
|
|
using DMS.Infrastructure.Data;
|
|
|
|
|
using DMS.Infrastructure.Entities;
|
|
|
|
|
|
|
|
|
|
namespace DMS.Infrastructure.Repositories;
|
|
|
|
|
|
|
|
|
|
public class VariableTableRepository : BaseRepository<DbVariableTable>, IVariableTableRepository
|
|
|
|
|
{
|
2025-07-21 22:02:42 +08:00
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
|
|
|
|
public VariableTableRepository(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<VariableTable> GetByIdAsync(int id)
|
|
|
|
|
{
|
|
|
|
|
var dbVariableTable = await base.GetByIdAsync(id);
|
|
|
|
|
return _mapper.Map<VariableTable>(dbVariableTable);
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<List<VariableTable>> GetAllAsync()
|
|
|
|
|
{
|
|
|
|
|
var dbList = await base.GetAllAsync();
|
|
|
|
|
return _mapper.Map<List<VariableTable>>(dbList);
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<VariableTable> AddAsync(VariableTable entity)
|
|
|
|
|
{
|
|
|
|
|
var dbVariableTable = await base.AddAsync(_mapper.Map<DbVariableTable>(entity));
|
|
|
|
|
return _mapper.Map(dbVariableTable, entity);
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<int> UpdateAsync(VariableTable entity) => await base.UpdateAsync(_mapper.Map<DbVariableTable>(entity));
|
2025-07-21 18:49:49 +08:00
|
|
|
|
2025-07-21 22:02:42 +08:00
|
|
|
public async Task<int> DeleteAsync(VariableTable entity) => await base.DeleteAsync(_mapper.Map<DbVariableTable>(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 VariableTable() { 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<VariableTable>> TakeAsync(int number)
|
|
|
|
|
{
|
|
|
|
|
var dbList = await base.TakeAsync(number);
|
|
|
|
|
return _mapper.Map<List<VariableTable>>(dbList);
|
|
|
|
|
|
|
|
|
|
}
|
2025-07-24 18:09:46 +08:00
|
|
|
|
|
|
|
|
public async Task<int> DeleteByDeviceIdAsync(int deviceId)
|
|
|
|
|
{
|
|
|
|
|
var stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
|
|
|
|
var result = await Db.Deleteable<DbVariableTable>()
|
|
|
|
|
.Where(it => it.DeviceId == deviceId)
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
NlogHelper.Info($"Delete VariableTable by DeviceId={deviceId}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2025-07-21 18:49:49 +08:00
|
|
|
}
|