2025-07-21 22:02:42 +08:00
|
|
|
using System.Diagnostics;
|
2025-07-15 22:18:37 +08:00
|
|
|
using AutoMapper;
|
2025-07-21 22:02:42 +08:00
|
|
|
using DMS.Core.Helper;
|
2025-07-21 18:49:49 +08:00
|
|
|
using DMS.Core.Interfaces.Repositories;
|
2025-07-19 09:25:01 +08:00
|
|
|
using DMS.Core.Models;
|
|
|
|
|
using DMS.Infrastructure.Data;
|
2025-07-21 18:49:49 +08:00
|
|
|
using DMS.Infrastructure.Entities;
|
2025-06-10 22:13:06 +08:00
|
|
|
|
2025-07-18 22:21:16 +08:00
|
|
|
namespace DMS.Infrastructure.Repositories;
|
2025-06-10 22:13:06 +08:00
|
|
|
|
2025-07-21 18:49:49 +08:00
|
|
|
public class DeviceRepository : BaseRepository<DbDevice>, IDeviceRepository
|
2025-06-10 22:13:06 +08:00
|
|
|
{
|
2025-07-21 18:49:49 +08:00
|
|
|
private readonly IMapper _mapper;
|
2025-07-02 22:07:16 +08:00
|
|
|
|
2025-07-21 18:49:49 +08:00
|
|
|
public DeviceRepository(IMapper mapper, SqlSugarDbContext dbContext)
|
2025-07-19 22:29:50 +08:00
|
|
|
: base(dbContext)
|
2025-06-24 20:48:38 +08:00
|
|
|
{
|
2025-07-21 18:49:49 +08:00
|
|
|
_mapper = mapper;
|
2025-06-10 22:13:06 +08:00
|
|
|
}
|
2025-06-23 17:01:06 +08:00
|
|
|
|
2025-07-24 15:07:03 +08:00
|
|
|
public async Task<List<Core.Models.Device>> GetAllAsync()
|
2025-07-21 18:49:49 +08:00
|
|
|
{
|
|
|
|
|
var dbList = await base.GetAllAsync();
|
2025-07-24 15:07:03 +08:00
|
|
|
return _mapper.Map<List<Core.Models.Device>>(dbList);
|
2025-07-21 18:49:49 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-24 15:07:03 +08:00
|
|
|
public async Task<Core.Models.Device> GetByIdAsync(int id)
|
2025-07-21 18:49:49 +08:00
|
|
|
{
|
|
|
|
|
var dbDevice = await base.GetByIdAsync(id);
|
2025-07-24 15:07:03 +08:00
|
|
|
return _mapper.Map<Core.Models.Device>(dbDevice);
|
2025-07-21 18:49:49 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-24 15:07:03 +08:00
|
|
|
public async Task<Core.Models.Device> AddAsync(Core.Models.Device model)
|
2025-07-21 18:49:49 +08:00
|
|
|
{
|
|
|
|
|
var dbDevice = await base.AddAsync(_mapper.Map<DbDevice>(model));
|
|
|
|
|
return _mapper.Map(dbDevice, model);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-24 15:07:03 +08:00
|
|
|
public async Task<int> UpdateAsync(Core.Models.Device model) => await base.UpdateAsync(_mapper.Map<DbDevice>(model));
|
2025-07-21 18:49:49 +08:00
|
|
|
|
|
|
|
|
|
2025-07-24 15:07:03 +08:00
|
|
|
public async Task<int> DeleteAsync(Core.Models.Device model) => await base.DeleteAsync(_mapper.Map<DbDevice>(model));
|
2025-07-21 22:02:42 +08:00
|
|
|
|
|
|
|
|
public async Task<int> DeleteAsync(int id)
|
|
|
|
|
{
|
|
|
|
|
var stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
|
|
|
|
var result = await Db.Deleteable(new DbDevice() { Id = id })
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
NlogHelper.Info($"Delete {typeof(DbDevice)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2025-07-22 21:36:33 +08:00
|
|
|
|
2025-07-24 15:07:03 +08:00
|
|
|
public new async Task<List<Core.Models.Device>> TakeAsync(int number)
|
2025-07-22 21:36:33 +08:00
|
|
|
{
|
|
|
|
|
var dbList = await base.TakeAsync(number);
|
2025-07-24 15:07:03 +08:00
|
|
|
return _mapper.Map<List<Core.Models.Device>>(dbList);
|
2025-07-22 21:36:33 +08:00
|
|
|
|
|
|
|
|
}
|
2025-06-10 22:13:06 +08:00
|
|
|
}
|