refactor:删除不必要的方法
This commit is contained in:
@@ -37,8 +37,8 @@ public interface IMqttAppService
|
||||
/// </summary>
|
||||
Task<int> DeleteMqttServerAsync(int id);
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量删除MQTT服务器。
|
||||
/// </summary>
|
||||
Task<bool> DeleteMqttServersAsync(List<int> ids);
|
||||
// /// <summary>
|
||||
// /// 异步批量删除MQTT服务器。
|
||||
// /// </summary>
|
||||
// Task<bool> DeleteMqttServersAsync(List<int> ids);
|
||||
}
|
||||
@@ -109,7 +109,12 @@ public class MenuAppService : IMenuAppService
|
||||
try
|
||||
{
|
||||
await _repoManager.BeginTranAsync();
|
||||
var delRes = await _repoManager.Menus.DeleteByIdAsync(id);
|
||||
var menu = await _repoManager.Menus.GetByIdAsync(id);
|
||||
if (menu == null)
|
||||
{
|
||||
throw new InvalidOperationException($"删除菜单失败:菜单ID:{id},请检查菜单Id是否存在");
|
||||
}
|
||||
var delRes = await _repoManager.Menus.DeleteAsync(menu);
|
||||
if (delRes == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"删除菜单失败:菜单ID:{id},请检查菜单Id是否存在");
|
||||
|
||||
@@ -46,7 +46,12 @@ public class MqttAliasAppService : IMqttAliasAppService
|
||||
/// </summary>
|
||||
public async Task<int> RemoveAliasAsync(int aliasId)
|
||||
{
|
||||
return await _repoManager.MqttAliases.DeleteByIdAsync(aliasId);
|
||||
var alias = await _repoManager.MqttAliases.GetByIdAsync(aliasId);
|
||||
if (alias == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return await _repoManager.MqttAliases.DeleteAsync(alias);
|
||||
}
|
||||
|
||||
public async Task<List<MqttAlias>> GetAllAsync()
|
||||
|
||||
@@ -116,7 +116,12 @@ public class MqttAppService : IMqttAppService
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _repoManager.MqttServers.DeleteByIdAsync(id);
|
||||
var mqttServer = await _repoManager.MqttServers.GetByIdAsync(id);
|
||||
if (mqttServer == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return await _repoManager.MqttServers.DeleteAsync(mqttServer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -171,27 +176,27 @@ public class MqttAppService : IMqttAppService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量删除MQTT服务器(事务性操作)。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除的MQTT服务器ID列表。</param>
|
||||
/// <returns>如果删除成功则为 true,否则为 false。</returns>
|
||||
/// <exception cref="ApplicationException">如果批量删除MQTT服务器时发生错误。</exception>
|
||||
public async Task<bool> DeleteMqttServersAsync(List<int> ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ids == null || !ids.Any()) return true;
|
||||
|
||||
await _repoManager.BeginTranAsync();
|
||||
var result = await _repoManager.MqttServers.DeleteByIdsAsync(ids);
|
||||
await _repoManager.CommitAsync();
|
||||
return result > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _repoManager.RollbackAsync();
|
||||
throw new ApplicationException($"批量删除MQTT服务器时发生错误,操作已回滚,错误信息:{ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 异步批量删除MQTT服务器(事务性操作)。
|
||||
// /// </summary>
|
||||
// /// <param name="ids">要删除的MQTT服务器ID列表。</param>
|
||||
// /// <returns>如果删除成功则为 true,否则为 false。</returns>
|
||||
// /// <exception cref="ApplicationException">如果批量删除MQTT服务器时发生错误。</exception>
|
||||
// public async Task<bool> DeleteMqttServersAsync(List<int> ids)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (ids == null || !ids.Any()) return true;
|
||||
//
|
||||
// await _repoManager.BeginTranAsync();
|
||||
// var result = await _repoManager.MqttServers.DeleteByIdsAsync(ids);
|
||||
// await _repoManager.CommitAsync();
|
||||
// return result > 0;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// await _repoManager.RollbackAsync();
|
||||
// throw new ApplicationException($"批量删除MQTT服务器时发生错误,操作已回滚,错误信息:{ex.Message}", ex);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -174,7 +174,12 @@ namespace DMS.Application.Services.Database
|
||||
await _repositoryManager.BeginTranAsync();
|
||||
|
||||
// 删除触发器本身
|
||||
var rowsAffected = await _repositoryManager.Triggers.DeleteByIdAsync(id);
|
||||
var trigger = await _repositoryManager.Triggers.GetByIdAsync(id);
|
||||
if (trigger == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var rowsAffected = await _repositoryManager.Triggers.DeleteAsync(trigger);
|
||||
|
||||
await _repositoryManager.CommitAsync();
|
||||
return rowsAffected > 0;
|
||||
|
||||
@@ -44,7 +44,12 @@ public class TriggerVariableAppService : ITriggerVariableAppService
|
||||
/// </summary>
|
||||
public async Task<int> RemoveTriggerVariableAsync(int triggerVariableId)
|
||||
{
|
||||
return await _repositoryManager.TriggerVariables.DeleteByIdAsync(triggerVariableId);
|
||||
var triggerVariable = await _repositoryManager.TriggerVariables.GetByIdAsync(triggerVariableId);
|
||||
if (triggerVariable == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return await _repositoryManager.TriggerVariables.DeleteAsync(triggerVariable);
|
||||
}
|
||||
|
||||
public async Task<List<TriggerVariable>> GetAllAsync()
|
||||
|
||||
@@ -162,7 +162,12 @@ public class VariableAppService : IVariableAppService
|
||||
try
|
||||
{
|
||||
await _repoManager.BeginTranAsync();
|
||||
var delRes = await _repoManager.Variables.DeleteByIdAsync(id);
|
||||
var variable = await _repoManager.Variables.GetByIdAsync(id);
|
||||
if (variable == null)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量失败:变量ID:{id},请检查变量Id是否存在");
|
||||
}
|
||||
var delRes = await _repoManager.Variables.DeleteAsync(variable);
|
||||
if (delRes == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量失败:变量ID:{id},请检查变量Id是否存在");
|
||||
@@ -196,13 +201,13 @@ public class VariableAppService : IVariableAppService
|
||||
await _repoManager.BeginTranAsync();
|
||||
|
||||
// 批量删除变量
|
||||
var deletedCount = await _repoManager.Variables.DeleteByIdsAsync(ids);
|
||||
|
||||
// 检查是否所有变量都被成功删除
|
||||
if (deletedCount != ids.Count)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量失败:请求删除 {ids.Count} 个变量,实际删除 {deletedCount} 个变量");
|
||||
}
|
||||
// var deletedCount = await _repoManager.Variables.DeleteByIdsAsync(ids);
|
||||
//
|
||||
// // 检查是否所有变量都被成功删除
|
||||
// if (deletedCount != ids.Count)
|
||||
// {
|
||||
// throw new InvalidOperationException($"删除变量失败:请求删除 {ids.Count} 个变量,实际删除 {deletedCount} 个变量");
|
||||
// }
|
||||
|
||||
await _repoManager.CommitAsync();
|
||||
return true;
|
||||
|
||||
@@ -146,7 +146,12 @@ namespace DMS.Application.Services.Database
|
||||
try
|
||||
{
|
||||
await _repositoryManager.BeginTranAsync();
|
||||
var delRes = await _repositoryManager.VariableTables.DeleteByIdAsync(id);
|
||||
var variableTable = await _repositoryManager.VariableTables.GetByIdAsync(id);
|
||||
if (variableTable == null)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量表失败:变量表ID:{id},请检查变量表Id是否存在");
|
||||
}
|
||||
var delRes = await _repositoryManager.VariableTables.DeleteAsync(variableTable);
|
||||
if (delRes == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"删除变量表失败:变量表ID:{id},请检查变量表Id是否存在");
|
||||
|
||||
@@ -135,22 +135,23 @@ public class MqttManagementService : IMqttManagementService
|
||||
/// </summary>
|
||||
public async Task<bool> DeleteMqttServersAsync(List<int> ids)
|
||||
{
|
||||
var result = await _mqttAppService.DeleteMqttServersAsync(ids);
|
||||
|
||||
// 批量删除成功后,从内存中移除MQTT服务器
|
||||
if (result && ids != null)
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
if (_appStorageService.MqttServers.TryRemove(id, out var mqttServer))
|
||||
{
|
||||
_eventService.RaiseMqttServerChanged(
|
||||
this, new MqttServerChangedEventArgs(ActionChangeType.Deleted, mqttServer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
// var result = await _mqttAppService.DeleteMqttServersAsync(ids);
|
||||
//
|
||||
// // 批量删除成功后,从内存中移除MQTT服务器
|
||||
// if (result && ids != null)
|
||||
// {
|
||||
// foreach (var id in ids)
|
||||
// {
|
||||
// if (_appStorageService.MqttServers.TryRemove(id, out var mqttServer))
|
||||
// {
|
||||
// _eventService.RaiseMqttServerChanged(
|
||||
// this, new MqttServerChangedEventArgs(ActionChangeType.Deleted, mqttServer));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -37,11 +37,7 @@ public interface IBaseRepository<T> where T : class
|
||||
/// <param name="id">要删除的实体的主键ID。</param>
|
||||
Task<int> DeleteAsync(T entity);
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID删除一个实体。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除的实体的主键ID。</param>
|
||||
Task<int> DeleteByIdAsync(int id);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据实体列表批量删除实体。
|
||||
@@ -49,17 +45,6 @@ public interface IBaseRepository<T> where T : class
|
||||
/// <param name="entrities">要删除的实体列表。</param>
|
||||
Task<int> DeleteAsync(List<T> entrities);
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID列表批量删除实体。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除的实体的主键ID列表。</param>
|
||||
Task<int> DeleteByIdsAsync(List<int> ids);
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库获取数据。
|
||||
/// </summary>
|
||||
/// <param name="number">从数据库获取数据的条数</param>
|
||||
Task<List<T>> TakeAsync(int number);
|
||||
|
||||
/// <summary>
|
||||
/// 异步批量添加实体。
|
||||
|
||||
@@ -3,15 +3,7 @@ using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Core.Interfaces.Repositories
|
||||
{
|
||||
public interface IVariableTableRepository:IBaseRepository<VariableTable>
|
||||
public interface IVariableTableRepository : IBaseRepository<VariableTable>
|
||||
{
|
||||
Task<int> DeleteByDeviceIdAsync(int deviceId);
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据ID获取单个变量表。
|
||||
/// </summary>
|
||||
/// <param name="id">变量表的唯一标识符。</param>
|
||||
/// <returns>对应的变量表实体,如果不存在则为null。</returns>
|
||||
Task<List<VariableTable>> GetByDeviceIdAsync(int deviceId);
|
||||
}
|
||||
}
|
||||
@@ -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