refactor:删除不必要的方法
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq.Expressions;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
@@ -121,42 +119,6 @@ public abstract class BaseRepository<TEntity>
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID (Guid类型) 获取单个实体。
|
||||
/// </summary>
|
||||
/// <param name="id">实体的主键 ID (Guid类型)。</param>
|
||||
/// <returns>返回找到的实体,如果未找到则返回 null。</returns>
|
||||
public virtual async Task<TEntity> GetByIdAsync(Guid id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var entity = await _dbContext.GetInstance().Queryable<TEntity>()
|
||||
.In(id)
|
||||
.FirstAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"GetById {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步判断是否存在满足条件的实体。
|
||||
/// </summary>
|
||||
/// <param name="expression">查询条件的 Lambda 表达式。</param>
|
||||
/// <returns>如果存在则返回 true,否则返回 false。</returns>
|
||||
public virtual async Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> expression)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Queryable<TEntity>()
|
||||
.AnyAsync(expression);
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Exists {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步开始数据库事务。
|
||||
@@ -186,38 +148,8 @@ public abstract class BaseRepository<TEntity>
|
||||
await _dbContext.GetInstance().RollbackTranAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的实体。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的实体数量。</param>
|
||||
/// <returns>包含指定数量实体对象的列表。</returns>
|
||||
public virtual async Task<List<TEntity>> TakeAsync(int number)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var entity = await _dbContext.GetInstance().Queryable<TEntity>().Take(number).ToListAsync();
|
||||
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"TakeAsync {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID 删除单个实体。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除的实体的主键 ID。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable<TEntity>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"DeleteById {typeof(TEntity).Name}, ID: {id}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<TEntity>> AddBatchAsync(List<TEntity> entities)
|
||||
{
|
||||
@@ -238,20 +170,4 @@ public abstract class BaseRepository<TEntity>
|
||||
return retrunEntities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID 列表批量删除实体。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除的实体主键 ID 列表。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable<TEntity>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"DeleteByIds {typeof(TEntity).Name}, Count: {ids.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -73,37 +73,8 @@ public class DeviceRepository : BaseRepository<DbDevice>, IDeviceRepository
|
||||
/// </summary>
|
||||
/// <param name="model">要删除的设备实体。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteAsync(Core.Models.Device model) => await base.DeleteAsync(new List<DbDevice> { _mapper.Map<DbDevice>(model) });
|
||||
public async Task<int> DeleteAsync(Device model) => await base.DeleteAsync(new List<DbDevice> { _mapper.Map<DbDevice>(model) });
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除设备。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除设备的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbDevice() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbDevice)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的设备。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的设备数量。</param>
|
||||
/// <returns>包含指定数量设备实体的列表。</returns>
|
||||
public new async Task<List<Core.Models.Device>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<Core.Models.Device>>(dbList);
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<Device>> AddBatchAsync(List<Device> entities)
|
||||
{
|
||||
|
||||
@@ -111,37 +111,9 @@ namespace DMS.Infrastructure.Repositories
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailAccount>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailAccount>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailAccount>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailAccount>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailAccount>>(dbEntities);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
|
||||
@@ -87,37 +87,9 @@ namespace DMS.Infrastructure.Repositories
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailLog>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailLog>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailLog>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailLog>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailLog>>(dbEntities);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
|
||||
@@ -87,37 +87,8 @@ namespace DMS.Infrastructure.Repositories
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailMessage>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailMessage>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailMessage>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailMessage>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailMessage>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
|
||||
@@ -87,37 +87,8 @@ namespace DMS.Infrastructure.Repositories
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailTemplate>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
return await Db.Deleteable<DbEmailTemplate>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
public async Task<List<EmailTemplate>> TakeAsync(int number)
|
||||
{
|
||||
var dbEntities = await Db.Queryable<DbEmailTemplate>()
|
||||
.Take(number)
|
||||
.ToListAsync();
|
||||
|
||||
return _mapper.Map<List<EmailTemplate>>(dbEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
|
||||
@@ -90,21 +90,7 @@ public class MenuRepository : BaseRepository<DbMenu>, IMenuRepository
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteAsync(MenuBean entity) => await base.DeleteAsync(new List<DbMenu> { _mapper.Map<DbMenu>(entity) });
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除菜单。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除菜单的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbMenu { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据菜单ID删除菜单树(包括子菜单)。
|
||||
@@ -161,16 +147,6 @@ public class MenuRepository : BaseRepository<DbMenu>, IMenuRepository
|
||||
return _mapper.Map<MenuBean>(dbMenu);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的菜单。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的菜单数量。</param>
|
||||
/// <returns>包含指定数量菜单实体的列表。</returns>
|
||||
public new async Task<List<MenuBean>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<MenuBean>>(dbList);
|
||||
}
|
||||
|
||||
public async Task<List<MenuBean>> AddBatchAsync(List<MenuBean> entities)
|
||||
{
|
||||
|
||||
@@ -77,33 +77,8 @@ public class MqttAliasRepository : BaseRepository<DbMqttAlias>, IMqttAliasReposi
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteAsync(MqttAlias entity) => await base.DeleteAsync(new List<DbMqttAlias> { _mapper.Map<DbMqttAlias>(entity) });
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除变量与MQTT别名关联。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除变量与MQTT别名关联的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbMqttAlias() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbMqttAlias)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的变量与MQTT别名关联。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的变量与MQTT别名关联数量。</param>
|
||||
/// <returns>包含指定数量变量与MQTT别名关联实体的列表。</returns>
|
||||
public new async Task<List<MqttAlias>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<MqttAlias>>(dbList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<MqttAlias>> AddBatchAsync(List<MqttAlias> entities)
|
||||
{
|
||||
|
||||
@@ -74,34 +74,8 @@ public class MqttServerRepository : BaseRepository<DbMqttServer>, IMqttServerRep
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteAsync(MqttServer entity) => await base.DeleteAsync(new List<DbMqttServer> { _mapper.Map<DbMqttServer>(entity) });
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除MQTT服务器。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除MQTT服务器的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbMqttServer() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbMqttServer)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的MQTT服务器。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的MQTT服务器数量。</param>
|
||||
/// <returns>包含指定数量MQTT服务器实体的列表。</returns>
|
||||
public new async Task<List<MqttServer>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<MqttServer>>(dbList);
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<MqttServer>> AddBatchAsync(List<MqttServer> entities)
|
||||
{
|
||||
var dbEntities = _mapper.Map<List<DbMqttServer>>(entities);
|
||||
|
||||
@@ -100,28 +100,8 @@ public class NlogRepository : BaseRepository<DbNlog>, INlogRepository
|
||||
return await base.DeleteAsync(new List<DbNlog> { dbEntity });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个Nlog日志条目。
|
||||
/// 注意:直接删除数据库日志表记录通常不推荐,除非是清理过期日志。
|
||||
/// 此方法主要用于满足接口契约,实际使用应谨慎。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除的Nlog日志条目的ID。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public new async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
return await base.DeleteByIdsAsync(new List<int>(){id});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的Nlog日志条目。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的条目数量。</param>
|
||||
/// <returns>包含指定数量Nlog日志实体的列表。</returns>
|
||||
public new async Task<List<Core.Models.Nlog>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<Core.Models.Nlog>>(dbList);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加Nlog日志条目。
|
||||
|
||||
@@ -85,32 +85,8 @@ namespace DMS.Infrastructure.Repositories
|
||||
return await base.DeleteAsync(new List<DbTrigger> { _mapper.Map<DbTrigger>(entity) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除触发器定义。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除触发器定义的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbTrigger() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbTrigger)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的触发器定义。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的触发器定义数量。</param>
|
||||
/// <returns>包含指定数量触发器定义实体的列表。</returns>
|
||||
public new async Task<List<Trigger>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<Trigger>>(dbList);
|
||||
}
|
||||
|
||||
public async Task<List<Trigger>> AddBatchAsync(List<Trigger> entities)
|
||||
{
|
||||
|
||||
@@ -77,32 +77,8 @@ public class TriggerVariableRepository : BaseRepository<DbTriggerVariable>, ITri
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteAsync(TriggerVariable entity) => await base.DeleteAsync(new List<DbTriggerVariable> { _mapper.Map<DbTriggerVariable>(entity) });
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除触发器与变量关联。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除触发器与变量关联的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbTriggerVariable() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbTriggerVariable)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的触发器与变量关联。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的触发器与变量关联数量。</param>
|
||||
/// <returns>包含指定数量触发器与变量关联实体的列表。</returns>
|
||||
public new async Task<List<TriggerVariable>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<TriggerVariable>>(dbList);
|
||||
}
|
||||
|
||||
public async Task<List<TriggerVariable>> AddBatchAsync(List<TriggerVariable> entities)
|
||||
{
|
||||
|
||||
@@ -77,33 +77,7 @@ public class UserRepository : BaseRepository<DbUser>, IUserRepository
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteAsync(User entity) => await base.DeleteAsync(new List<DbUser> { _mapper.Map<DbUser>(entity) });
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除用户。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除用户的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbUser() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbUser)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的用户。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的用户数量。</param>
|
||||
/// <returns>包含指定数量用户实体的列表。</returns>
|
||||
public new async Task<List<User>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<User>>(dbList);
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<User>> AddBatchAsync(List<User> entities)
|
||||
{
|
||||
|
||||
@@ -76,33 +76,7 @@ public class VariableHistoryRepository : BaseRepository<DbVariableHistory>, IVar
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteAsync(VariableHistory entity) => await base.DeleteAsync(new List<DbVariableHistory> { _mapper.Map<DbVariableHistory>(entity) });
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除变量历史记录。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除变量历史记录的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbVariableHistory() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbVariableHistory)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的变量历史记录。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的变量历史记录数量。</param>
|
||||
/// <returns>包含指定数量变量历史实体的列表。</returns>
|
||||
public new async Task<List<VariableHistory>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<VariableHistory>>(dbList);
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<VariableHistory>> AddBatchAsync(List<VariableHistory> entities)
|
||||
{
|
||||
|
||||
@@ -93,50 +93,7 @@ public class VariableRepository : BaseRepository<DbVariable>, IVariableRepositor
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除变量。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除变量的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable(new DbVariable() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbVariable)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除变量。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除变量的唯一标识符列表。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable<DbVariable>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbVariable)},Count={ids.Count},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的变量。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的变量数量。</param>
|
||||
/// <returns>包含指定数量变量实体的列表。</returns>
|
||||
public new async Task<List<Variable>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<Variable>>(dbList);
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<Variable>> AddBatchAsync(List<Variable> entities)
|
||||
{
|
||||
|
||||
@@ -99,36 +99,6 @@ public class VariableTableRepository : BaseRepository<DbVariableTable>, IVariabl
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除变量表。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除变量表的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
//删除变量表中的所有变量
|
||||
await _variableRepository.DeleteByVariableTableIdAsync(id);
|
||||
//删除变量表
|
||||
var result = await _dbContext.GetInstance()
|
||||
.Deleteable(new DbVariableTable() { Id = id })
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete {typeof(DbVariableTable)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的变量表。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的变量表数量。</param>
|
||||
/// <returns>包含指定数量变量表实体的列表。</returns>
|
||||
public new async Task<List<VariableTable>> TakeAsync(int number)
|
||||
{
|
||||
var dbList = await base.TakeAsync(number);
|
||||
return _mapper.Map<List<VariableTable>>(dbList);
|
||||
}
|
||||
|
||||
public async Task<List<VariableTable>> AddBatchAsync(List<VariableTable> entities)
|
||||
{
|
||||
@@ -137,27 +107,6 @@ public class VariableTableRepository : BaseRepository<DbVariableTable>, IVariabl
|
||||
return _mapper.Map<List<VariableTable>>(addedEntities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据设备ID删除所有关联的变量表。
|
||||
/// </summary>
|
||||
/// <param name="deviceId">设备的唯一标识符。</param>
|
||||
/// <returns>受影响的行数。</returns>
|
||||
public async Task<int> DeleteByDeviceIdAsync(int deviceId)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
int result = 0;
|
||||
var variableTables = await GetByDeviceIdAsync(deviceId);
|
||||
foreach (var variableTable in variableTables)
|
||||
{
|
||||
var res= await DeleteByIdAsync(variableTable.Id);
|
||||
result += res;
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Delete VariableTable by DeviceId={deviceId}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据实体列表批量删除变量表。
|
||||
|
||||
Reference in New Issue
Block a user