diff --git a/DMS.Application/Interfaces/Database/IMqttAppService.cs b/DMS.Application/Interfaces/Database/IMqttAppService.cs index fb11471..91d13a8 100644 --- a/DMS.Application/Interfaces/Database/IMqttAppService.cs +++ b/DMS.Application/Interfaces/Database/IMqttAppService.cs @@ -37,8 +37,8 @@ public interface IMqttAppService /// Task DeleteMqttServerAsync(int id); - /// - /// 异步批量删除MQTT服务器。 - /// - Task DeleteMqttServersAsync(List ids); + // /// + // /// 异步批量删除MQTT服务器。 + // /// + // Task DeleteMqttServersAsync(List ids); } \ No newline at end of file diff --git a/DMS.Application/Services/Database/MenuAppService.cs b/DMS.Application/Services/Database/MenuAppService.cs index 0f1e225..c92778f 100644 --- a/DMS.Application/Services/Database/MenuAppService.cs +++ b/DMS.Application/Services/Database/MenuAppService.cs @@ -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是否存在"); diff --git a/DMS.Application/Services/Database/MqttAliasAppService.cs b/DMS.Application/Services/Database/MqttAliasAppService.cs index a02e3cc..5c72015 100644 --- a/DMS.Application/Services/Database/MqttAliasAppService.cs +++ b/DMS.Application/Services/Database/MqttAliasAppService.cs @@ -46,7 +46,12 @@ public class MqttAliasAppService : IMqttAliasAppService /// public async Task 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> GetAllAsync() diff --git a/DMS.Application/Services/Database/MqttAppService.cs b/DMS.Application/Services/Database/MqttAppService.cs index 4f1cfda..add35d6 100644 --- a/DMS.Application/Services/Database/MqttAppService.cs +++ b/DMS.Application/Services/Database/MqttAppService.cs @@ -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 } } - /// - /// 异步批量删除MQTT服务器(事务性操作)。 - /// - /// 要删除的MQTT服务器ID列表。 - /// 如果删除成功则为 true,否则为 false。 - /// 如果批量删除MQTT服务器时发生错误。 - public async Task DeleteMqttServersAsync(List 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); - } - } + // /// + // /// 异步批量删除MQTT服务器(事务性操作)。 + // /// + // /// 要删除的MQTT服务器ID列表。 + // /// 如果删除成功则为 true,否则为 false。 + // /// 如果批量删除MQTT服务器时发生错误。 + // public async Task DeleteMqttServersAsync(List 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); + // } + // } } \ No newline at end of file diff --git a/DMS.Application/Services/Database/TriggerAppService.cs b/DMS.Application/Services/Database/TriggerAppService.cs index 32a3bbb..4172863 100644 --- a/DMS.Application/Services/Database/TriggerAppService.cs +++ b/DMS.Application/Services/Database/TriggerAppService.cs @@ -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; diff --git a/DMS.Application/Services/Database/TriggerVariableAppService.cs b/DMS.Application/Services/Database/TriggerVariableAppService.cs index 8dc4075..f79fd65 100644 --- a/DMS.Application/Services/Database/TriggerVariableAppService.cs +++ b/DMS.Application/Services/Database/TriggerVariableAppService.cs @@ -44,7 +44,12 @@ public class TriggerVariableAppService : ITriggerVariableAppService /// public async Task 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> GetAllAsync() diff --git a/DMS.Application/Services/Database/VariableAppService.cs b/DMS.Application/Services/Database/VariableAppService.cs index 7a24261..62229b9 100644 --- a/DMS.Application/Services/Database/VariableAppService.cs +++ b/DMS.Application/Services/Database/VariableAppService.cs @@ -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; diff --git a/DMS.Application/Services/Database/VariableTableAppService.cs b/DMS.Application/Services/Database/VariableTableAppService.cs index 6557e8d..5299954 100644 --- a/DMS.Application/Services/Database/VariableTableAppService.cs +++ b/DMS.Application/Services/Database/VariableTableAppService.cs @@ -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是否存在"); diff --git a/DMS.Application/Services/Management/MqttManagementService.cs b/DMS.Application/Services/Management/MqttManagementService.cs index 052a845..958b9c6 100644 --- a/DMS.Application/Services/Management/MqttManagementService.cs +++ b/DMS.Application/Services/Management/MqttManagementService.cs @@ -135,22 +135,23 @@ public class MqttManagementService : IMqttManagementService /// public async Task DeleteMqttServersAsync(List 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; } /// diff --git a/DMS.Core/Interfaces/Repositories/IBaseRepository.cs b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs index ed5ddf7..f4c3fba 100644 --- a/DMS.Core/Interfaces/Repositories/IBaseRepository.cs +++ b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs @@ -37,11 +37,7 @@ public interface IBaseRepository where T : class /// 要删除的实体的主键ID。 Task DeleteAsync(T entity); - /// - /// 异步根据ID删除一个实体。 - /// - /// 要删除的实体的主键ID。 - Task DeleteByIdAsync(int id); + /// /// 异步根据实体列表批量删除实体。 @@ -49,17 +45,6 @@ public interface IBaseRepository where T : class /// 要删除的实体列表。 Task DeleteAsync(List entrities); - /// - /// 异步根据ID列表批量删除实体。 - /// - /// 要删除的实体的主键ID列表。 - Task DeleteByIdsAsync(List ids); - - /// - /// 从数据库获取数据。 - /// - /// 从数据库获取数据的条数 - Task> TakeAsync(int number); /// /// 异步批量添加实体。 diff --git a/DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs b/DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs index e3deffe..869d87b 100644 --- a/DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs +++ b/DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs @@ -3,15 +3,7 @@ using DMS.Core.Models; namespace DMS.Core.Interfaces.Repositories { - public interface IVariableTableRepository:IBaseRepository + public interface IVariableTableRepository : IBaseRepository { - Task DeleteByDeviceIdAsync(int deviceId); - - /// - /// 异步根据ID获取单个变量表。 - /// - /// 变量表的唯一标识符。 - /// 对应的变量表实体,如果不存在则为null。 - Task> GetByDeviceIdAsync(int deviceId); } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/BaseRepository.cs b/DMS.Infrastructure/Repositories/BaseRepository.cs index 7ae460a..19194fd 100644 --- a/DMS.Infrastructure/Repositories/BaseRepository.cs +++ b/DMS.Infrastructure/Repositories/BaseRepository.cs @@ -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 return entity; } - /// - /// 异步根据主键 ID (Guid类型) 获取单个实体。 - /// - /// 实体的主键 ID (Guid类型)。 - /// 返回找到的实体,如果未找到则返回 null。 - public virtual async Task GetByIdAsync(Guid id) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var entity = await _dbContext.GetInstance().Queryable() - .In(id) - .FirstAsync(); - stopwatch.Stop(); - _logger.LogInformation($"GetById {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); - return entity; - } - - - - - - /// - /// 异步判断是否存在满足条件的实体。 - /// - /// 查询条件的 Lambda 表达式。 - /// 如果存在则返回 true,否则返回 false。 - public virtual async Task ExistsAsync(Expression> expression) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await _dbContext.GetInstance().Queryable() - .AnyAsync(expression); - stopwatch.Stop(); - _logger.LogInformation($"Exists {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } /// /// 异步开始数据库事务。 @@ -186,38 +148,8 @@ public abstract class BaseRepository await _dbContext.GetInstance().RollbackTranAsync(); } - /// - /// 异步获取指定数量的实体。 - /// - /// 要获取的实体数量。 - /// 包含指定数量实体对象的列表。 - public virtual async Task> TakeAsync(int number) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var entity = await _dbContext.GetInstance().Queryable().Take(number).ToListAsync(); - - stopwatch.Stop(); - _logger.LogInformation($"TakeAsync {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); - return entity; - } - /// - /// 异步根据主键 ID 删除单个实体。 - /// - /// 要删除的实体的主键 ID。 - /// 返回受影响的行数。 - public virtual async Task DeleteByIdAsync(int id) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await _dbContext.GetInstance().Deleteable() - .In(id) - .ExecuteCommandAsync(); - stopwatch.Stop(); - _logger.LogInformation($"DeleteById {typeof(TEntity).Name}, ID: {id}, 耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } + public async Task> AddBatchAsync(List entities) { @@ -238,20 +170,4 @@ public abstract class BaseRepository return retrunEntities; } - /// - /// 异步根据主键 ID 列表批量删除实体。 - /// - /// 要删除的实体主键 ID 列表。 - /// 返回受影响的行数。 - public virtual async Task DeleteByIdsAsync(List ids) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await _dbContext.GetInstance().Deleteable() - .In(ids) - .ExecuteCommandAsync(); - stopwatch.Stop(); - _logger.LogInformation($"DeleteByIds {typeof(TEntity).Name}, Count: {ids.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/DeviceRepository.cs b/DMS.Infrastructure/Repositories/DeviceRepository.cs index 4ab6b0c..02ca7e4 100644 --- a/DMS.Infrastructure/Repositories/DeviceRepository.cs +++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs @@ -73,37 +73,8 @@ public class DeviceRepository : BaseRepository, IDeviceRepository /// /// 要删除的设备实体。 /// 受影响的行数。 - public async Task DeleteAsync(Core.Models.Device model) => await base.DeleteAsync(new List { _mapper.Map(model) }); + public async Task DeleteAsync(Device model) => await base.DeleteAsync(new List { _mapper.Map(model) }); - /// - /// 异步根据ID删除设备。 - /// - /// 要删除设备的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } - - - - /// - /// 异步获取指定数量的设备。 - /// - /// 要获取的设备数量。 - /// 包含指定数量设备实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - - } public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/EmailAccountRepository.cs b/DMS.Infrastructure/Repositories/EmailAccountRepository.cs index 40d2f0a..37571bb 100644 --- a/DMS.Infrastructure/Repositories/EmailAccountRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailAccountRepository.cs @@ -111,37 +111,9 @@ namespace DMS.Infrastructure.Repositories .ExecuteCommandAsync(); } - /// - /// 异步根据ID删除一个实体。 - /// - public async Task DeleteByIdAsync(int id) - { - return await Db.Deleteable() - .In(id) - .ExecuteCommandAsync(); - } - /// - /// 异步根据ID列表批量删除实体。 - /// - public async Task DeleteByIdsAsync(List ids) - { - return await Db.Deleteable() - .In(ids) - .ExecuteCommandAsync(); - } - /// - /// 从数据库获取数据。 - /// - public async Task> TakeAsync(int number) - { - var dbEntities = await Db.Queryable() - .Take(number) - .ToListAsync(); - - return _mapper.Map>(dbEntities); - } + /// /// 异步批量添加实体。 diff --git a/DMS.Infrastructure/Repositories/EmailLogRepository.cs b/DMS.Infrastructure/Repositories/EmailLogRepository.cs index c2498d4..71147ed 100644 --- a/DMS.Infrastructure/Repositories/EmailLogRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailLogRepository.cs @@ -87,37 +87,9 @@ namespace DMS.Infrastructure.Repositories .ExecuteCommandAsync(); } - /// - /// 异步根据ID删除一个实体。 - /// - public async Task DeleteByIdAsync(int id) - { - return await Db.Deleteable() - .In(id) - .ExecuteCommandAsync(); - } - /// - /// 异步根据ID列表批量删除实体。 - /// - public async Task DeleteByIdsAsync(List ids) - { - return await Db.Deleteable() - .In(ids) - .ExecuteCommandAsync(); - } - /// - /// 从数据库获取数据。 - /// - public async Task> TakeAsync(int number) - { - var dbEntities = await Db.Queryable() - .Take(number) - .ToListAsync(); - - return _mapper.Map>(dbEntities); - } + /// /// 异步批量添加实体。 diff --git a/DMS.Infrastructure/Repositories/EmailMessageRepository.cs b/DMS.Infrastructure/Repositories/EmailMessageRepository.cs index 8dc1079..fa8db6a 100644 --- a/DMS.Infrastructure/Repositories/EmailMessageRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailMessageRepository.cs @@ -87,37 +87,8 @@ namespace DMS.Infrastructure.Repositories .ExecuteCommandAsync(); } - /// - /// 异步根据ID删除一个实体。 - /// - public async Task DeleteByIdAsync(int id) - { - return await Db.Deleteable() - .In(id) - .ExecuteCommandAsync(); - } - /// - /// 异步根据ID列表批量删除实体。 - /// - public async Task DeleteByIdsAsync(List ids) - { - return await Db.Deleteable() - .In(ids) - .ExecuteCommandAsync(); - } - /// - /// 从数据库获取数据。 - /// - public async Task> TakeAsync(int number) - { - var dbEntities = await Db.Queryable() - .Take(number) - .ToListAsync(); - - return _mapper.Map>(dbEntities); - } /// /// 异步批量添加实体。 diff --git a/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs b/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs index 121ce12..3c09600 100644 --- a/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs @@ -87,37 +87,8 @@ namespace DMS.Infrastructure.Repositories .ExecuteCommandAsync(); } - /// - /// 异步根据ID删除一个实体。 - /// - public async Task DeleteByIdAsync(int id) - { - return await Db.Deleteable() - .In(id) - .ExecuteCommandAsync(); - } - /// - /// 异步根据ID列表批量删除实体。 - /// - public async Task DeleteByIdsAsync(List ids) - { - return await Db.Deleteable() - .In(ids) - .ExecuteCommandAsync(); - } - /// - /// 从数据库获取数据。 - /// - public async Task> TakeAsync(int number) - { - var dbEntities = await Db.Queryable() - .Take(number) - .ToListAsync(); - - return _mapper.Map>(dbEntities); - } /// /// 异步批量添加实体。 diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs index 5640f1e..e684dc4 100644 --- a/DMS.Infrastructure/Repositories/MenuRepository.cs +++ b/DMS.Infrastructure/Repositories/MenuRepository.cs @@ -90,21 +90,7 @@ public class MenuRepository : BaseRepository, IMenuRepository /// 受影响的行数。 public async Task DeleteAsync(MenuBean entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - /// - /// 异步根据ID删除菜单。 - /// - /// 要删除菜单的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } + /// /// 异步根据菜单ID删除菜单树(包括子菜单)。 @@ -161,16 +147,6 @@ public class MenuRepository : BaseRepository, IMenuRepository return _mapper.Map(dbMenu); } - /// - /// 异步获取指定数量的菜单。 - /// - /// 要获取的菜单数量。 - /// 包含指定数量菜单实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - } public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs index 26ad942..d2f84cb 100644 --- a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs +++ b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs @@ -77,33 +77,8 @@ public class MqttAliasRepository : BaseRepository, IMqttAliasReposi /// 受影响的行数。 public async Task DeleteAsync(MqttAlias entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - /// - /// 异步根据ID删除变量与MQTT别名关联。 - /// - /// 要删除变量与MQTT别名关联的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } - - /// - /// 异步获取指定数量的变量与MQTT别名关联。 - /// - /// 要获取的变量与MQTT别名关联数量。 - /// 包含指定数量变量与MQTT别名关联实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - } + public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/MqttServerRepository.cs b/DMS.Infrastructure/Repositories/MqttServerRepository.cs index 51070c1..bf4ed95 100644 --- a/DMS.Infrastructure/Repositories/MqttServerRepository.cs +++ b/DMS.Infrastructure/Repositories/MqttServerRepository.cs @@ -74,34 +74,8 @@ public class MqttServerRepository : BaseRepository, IMqttServerRep /// 受影响的行数。 public async Task DeleteAsync(MqttServer entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - /// - /// 异步根据ID删除MQTT服务器。 - /// - /// 要删除MQTT服务器的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } + - /// - /// 异步获取指定数量的MQTT服务器。 - /// - /// 要获取的MQTT服务器数量。 - /// 包含指定数量MQTT服务器实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - - } - public async Task> AddBatchAsync(List entities) { var dbEntities = _mapper.Map>(entities); diff --git a/DMS.Infrastructure/Repositories/NlogRepository.cs b/DMS.Infrastructure/Repositories/NlogRepository.cs index bde1b27..ca19592 100644 --- a/DMS.Infrastructure/Repositories/NlogRepository.cs +++ b/DMS.Infrastructure/Repositories/NlogRepository.cs @@ -100,28 +100,8 @@ public class NlogRepository : BaseRepository, INlogRepository return await base.DeleteAsync(new List { dbEntity }); } - /// - /// 异步根据ID删除一个Nlog日志条目。 - /// 注意:直接删除数据库日志表记录通常不推荐,除非是清理过期日志。 - /// 此方法主要用于满足接口契约,实际使用应谨慎。 - /// - /// 要删除的Nlog日志条目的ID。 - /// 受影响的行数。 - public new async Task DeleteByIdAsync(int id) - { - return await base.DeleteByIdsAsync(new List(){id}); - } - /// - /// 异步获取指定数量的Nlog日志条目。 - /// - /// 要获取的条目数量。 - /// 包含指定数量Nlog日志实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - } + /// /// 异步批量添加Nlog日志条目。 diff --git a/DMS.Infrastructure/Repositories/TriggerRepository.cs b/DMS.Infrastructure/Repositories/TriggerRepository.cs index 40a3c40..e1188e2 100644 --- a/DMS.Infrastructure/Repositories/TriggerRepository.cs +++ b/DMS.Infrastructure/Repositories/TriggerRepository.cs @@ -85,32 +85,8 @@ namespace DMS.Infrastructure.Repositories return await base.DeleteAsync(new List { _mapper.Map(entity) }); } - /// - /// 异步根据ID删除触发器定义。 - /// - /// 要删除触发器定义的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } + - /// - /// 异步获取指定数量的触发器定义。 - /// - /// 要获取的触发器定义数量。 - /// 包含指定数量触发器定义实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - } public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs index 974fff0..fe0abfc 100644 --- a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs +++ b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs @@ -77,32 +77,8 @@ public class TriggerVariableRepository : BaseRepository, ITri /// 受影响的行数。 public async Task DeleteAsync(TriggerVariable entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - /// - /// 异步根据ID删除触发器与变量关联。 - /// - /// 要删除触发器与变量关联的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } + - /// - /// 异步获取指定数量的触发器与变量关联。 - /// - /// 要获取的触发器与变量关联数量。 - /// 包含指定数量触发器与变量关联实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - } public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/UserRepository.cs b/DMS.Infrastructure/Repositories/UserRepository.cs index f860113..7300783 100644 --- a/DMS.Infrastructure/Repositories/UserRepository.cs +++ b/DMS.Infrastructure/Repositories/UserRepository.cs @@ -77,33 +77,7 @@ public class UserRepository : BaseRepository, IUserRepository /// 受影响的行数。 public async Task DeleteAsync(User entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - /// - /// 异步根据ID删除用户。 - /// - /// 要删除用户的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } - /// - /// 异步获取指定数量的用户。 - /// - /// 要获取的用户数量。 - /// 包含指定数量用户实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - - } public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs index 1fa7cc3..5c4f215 100644 --- a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs @@ -76,33 +76,7 @@ public class VariableHistoryRepository : BaseRepository, IVar /// 受影响的行数。 public async Task DeleteAsync(VariableHistory entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - /// - /// 异步根据ID删除变量历史记录。 - /// - /// 要删除变量历史记录的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } - /// - /// 异步获取指定数量的变量历史记录。 - /// - /// 要获取的变量历史记录数量。 - /// 包含指定数量变量历史实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - - } public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/VariableRepository.cs b/DMS.Infrastructure/Repositories/VariableRepository.cs index 8af93e0..a4b127d 100644 --- a/DMS.Infrastructure/Repositories/VariableRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableRepository.cs @@ -93,50 +93,7 @@ public class VariableRepository : BaseRepository, IVariableRepositor return result; } - /// - /// 异步根据ID删除变量。 - /// - /// 要删除变量的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } - /// - /// 异步根据ID列表批量删除变量。 - /// - /// 要删除变量的唯一标识符列表。 - /// 受影响的行数。 - public async Task DeleteByIdsAsync(List ids) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await _dbContext.GetInstance().Deleteable() - .In(ids) - .ExecuteCommandAsync(); - stopwatch.Stop(); - _logger.LogInformation($"Delete {typeof(DbVariable)},Count={ids.Count},耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } - - /// - /// 异步获取指定数量的变量。 - /// - /// 要获取的变量数量。 - /// 包含指定数量变量实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - - } public async Task> AddBatchAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/VariableTableRepository.cs b/DMS.Infrastructure/Repositories/VariableTableRepository.cs index 626f0d0..16877bc 100644 --- a/DMS.Infrastructure/Repositories/VariableTableRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableTableRepository.cs @@ -99,36 +99,6 @@ public class VariableTableRepository : BaseRepository, IVariabl } - /// - /// 异步根据ID删除变量表。 - /// - /// 要删除变量表的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } - - /// - /// 异步获取指定数量的变量表。 - /// - /// 要获取的变量表数量。 - /// 包含指定数量变量表实体的列表。 - public new async Task> TakeAsync(int number) - { - var dbList = await base.TakeAsync(number); - return _mapper.Map>(dbList); - } public async Task> AddBatchAsync(List entities) { @@ -137,27 +107,6 @@ public class VariableTableRepository : BaseRepository, IVariabl return _mapper.Map>(addedEntities); } - /// - /// 异步根据设备ID删除所有关联的变量表。 - /// - /// 设备的唯一标识符。 - /// 受影响的行数。 - public async Task 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; - } /// /// 异步根据实体列表批量删除变量表。