添加TakeAsync方法。
This commit is contained in:
@@ -42,4 +42,10 @@ public interface IBaseRepository<T> where T : class
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">要删除的实体的主键ID。</param>
|
/// <param name="id">要删除的实体的主键ID。</param>
|
||||||
Task<int> DeleteAsync(int id);
|
Task<int> DeleteAsync(int id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从数据库获取数据。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">从数据库获取数据的条数</param>
|
||||||
|
Task<List<T>> TakeAsync(int number);
|
||||||
}
|
}
|
||||||
@@ -48,4 +48,11 @@ public class DeviceServiceTest
|
|||||||
var addDevice= await _deviceService.AddAsync(_mapper.Map<Device>(dbDevice));
|
var addDevice= await _deviceService.AddAsync(_mapper.Map<Device>(dbDevice));
|
||||||
Assert.NotEqual(0, addDevice.Id);
|
Assert.NotEqual(0, addDevice.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task TakeAsync_Test()
|
||||||
|
{
|
||||||
|
var device= await _deviceService.TakeAsync(2);
|
||||||
|
Assert.Equal(2,device.Count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
namespace DMS.Infrastructure.UnitTests.Services_Test;
|
|
||||||
|
|
||||||
public class DeviceServer_Test
|
|
||||||
{
|
|
||||||
public DeviceServer_Test()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task AddDeviceAsync_Test()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using DMS.Core.Helper;
|
using DMS.Core.Helper;
|
||||||
|
using DMS.Core.Models;
|
||||||
using DMS.Infrastructure.Data;
|
using DMS.Infrastructure.Data;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
@@ -162,4 +163,15 @@ public abstract class BaseRepository<TEntity>
|
|||||||
{
|
{
|
||||||
await Db.RollbackTranAsync();
|
await Db.RollbackTranAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async Task<List<TEntity>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
|
var entity = await Db.Queryable<TEntity>().Take(number).ToListAsync();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
NlogHelper.Info($"TakeAsync {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -51,4 +51,11 @@ public class DeviceRepository : BaseRepository<DbDevice>, IDeviceRepository
|
|||||||
NlogHelper.Info($"Delete {typeof(DbDevice)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(DbDevice)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new async Task<List<Device>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<Device>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -64,4 +64,11 @@ public class MenuRepository : BaseRepository<DbMenu>, IMenuRepository
|
|||||||
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new async Task<List<MenuBean>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<MenuBean>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -53,4 +53,11 @@ public class MqttServerRepository : BaseRepository<DbMqttServer>, IMqttServerRep
|
|||||||
NlogHelper.Info($"Delete {typeof(MqttServer)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(MqttServer)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new async Task<List<MqttServer>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<MqttServer>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -64,4 +64,11 @@ public class UserRepository : BaseRepository<DbUser>, IUserRepository
|
|||||||
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new async Task<List<User>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<User>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -56,4 +56,12 @@ public class VariableHistoryRepository : BaseRepository<DbVariableHistory>, IVar
|
|||||||
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public new async Task<List<VariableHistory>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<VariableHistory>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +61,11 @@ public class VariableMqttAliasRepository : BaseRepository<DbVariableMqttAlias>,
|
|||||||
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new async Task<List<VariableMqttAlias>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<VariableMqttAlias>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -137,4 +137,11 @@ public class VariableRepository : BaseRepository<DbVariable>, IVariableRepositor
|
|||||||
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new async Task<List<Variable>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<Variable>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -56,4 +56,11 @@ public class VariableTableRepository : BaseRepository<DbVariableTable>, IVariabl
|
|||||||
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new async Task<List<VariableTable>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
var dbList = await base.TakeAsync(number);
|
||||||
|
return _mapper.Map<List<VariableTable>>(dbList);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -66,5 +66,9 @@ namespace DMS.Infrastructure.Services
|
|||||||
{
|
{
|
||||||
return await ServerRepository.GetByIdAsync(id);
|
return await ServerRepository.GetByIdAsync(id);
|
||||||
}
|
}
|
||||||
|
public virtual async Task<List<TModel>> TakeAsync(int number)
|
||||||
|
{
|
||||||
|
return await ServerRepository.TakeAsync(number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user