From 687263193311490ba20d030fca2ae808c6a3a791 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Tue, 21 Oct 2025 12:27:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E4=BF=AE=E5=A4=8D=E4=BB=93=E5=82=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=92=8C=E5=AE=9E=E7=8E=B0=E4=B8=AD=E7=9A=84?= =?UTF-8?q?DeleteAsync=E6=96=B9=E6=B3=95=E9=97=AE=E9=A2=98=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20=20=20=20=20=E2=94=82=20=201.=20?= =?UTF-8?q?=E4=B8=BAIBaseRepository=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0Del?= =?UTF-8?q?eteByIdsAsync=E6=96=B9=E6=B3=95=E5=AE=9A=E4=B9=89=20=202.=20?= =?UTF-8?q?=E4=B8=BA=E6=89=80=E6=9C=89=E4=BB=93=E5=82=A8=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=B1=BB=E6=B7=BB=E5=8A=A0DeleteByIdsAsync=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20=203.=20=E4=BF=AE=E5=A4=8DDeviceAppService?= =?UTF-8?q?=E4=B8=ADdeviceId=E6=9C=AA=E5=AE=9A=E4=B9=89=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=204.=20=E4=BF=AE=E5=A4=8DDeviceManagementService?= =?UTF-8?q?=E4=B8=ADDeleteDeviceByIdAsync=E6=96=B9=E6=B3=95=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98=20=205.=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=80=E6=9C=89=E4=BB=93=E5=82=A8=E7=B1=BB?= =?UTF-8?q?=E4=B8=ADDeleteAsync(List)=E6=96=B9=E6=B3=95=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=206.=20=E4=BF=AE=E5=A4=8DEmail=E7=9B=B8=E5=85=B3=E4=BB=93?= =?UTF-8?q?=E5=82=A8=E7=B1=BB=E4=B8=ADDeleteable=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Database/DeviceAppService.cs | 24 ++++--- .../Management/DeviceManagementService.cs | 6 +- .../Repositories/IBaseRepository.cs | 6 ++ .../Repositories/AlarmHistoryRepository.cs | 20 ++++++ .../Repositories/BaseRepository.cs | 62 ++++++++----------- .../Repositories/DeviceRepository.cs | 15 ++++- .../Repositories/EmailAccountRepository.cs | 10 +++ .../Repositories/EmailLogRepository.cs | 10 +++ .../Repositories/EmailMessageRepository.cs | 10 +++ .../Repositories/EmailTemplateRepository.cs | 10 +++ .../Repositories/MenuRepository.cs | 13 +++- .../Repositories/MqttAliasRepository.cs | 13 +++- .../Repositories/MqttServerRepository.cs | 13 +++- .../Repositories/NlogRepository.cs | 13 +++- .../Repositories/TriggerRepository.cs | 13 +++- .../Repositories/TriggerVariableRepository.cs | 13 +++- .../Repositories/UserRepository.cs | 13 +++- .../Repositories/VariableHistoryRepository.cs | 13 +++- .../Repositories/VariableRepository.cs | 13 +++- .../Repositories/VariableTableRepository.cs | 13 +++- 20 files changed, 243 insertions(+), 60 deletions(-) diff --git a/DMS.Application/Services/Database/DeviceAppService.cs b/DMS.Application/Services/Database/DeviceAppService.cs index 93864e7..02fc376 100644 --- a/DMS.Application/Services/Database/DeviceAppService.cs +++ b/DMS.Application/Services/Database/DeviceAppService.cs @@ -34,7 +34,8 @@ public class DeviceAppService : IDeviceAppService /// /// 设备ID。 /// 设备数据传输对象。 - public async Task GetDeviceByIdAsync(int id) { + public async Task GetDeviceByIdAsync(int id) + { var device = await _repoManager.Devices.GetByIdAsync(id); return device; } @@ -81,8 +82,10 @@ public class DeviceAppService : IDeviceAppService dto.VariableTable = await _repoManager.VariableTables.AddAsync(dto.VariableTable); if (dto.VariableTable == null || dto.VariableTable.Id == 0) { - throw new InvalidOperationException($"添加设备变量表失败,设备:{dto.Device.Name},变量表:{dto?.VariableTable?.Name}"); + throw new InvalidOperationException( + $"添加设备变量表失败,设备:{dto.Device.Name},变量表:{dto?.VariableTable?.Name}"); } + dto.VariableTable.Device = dto.Device; // 假设有设备菜单 @@ -127,13 +130,14 @@ public class DeviceAppService : IDeviceAppService } _mapper.Map(device, existingDevice); - int res=await _repoManager.Devices.UpdateAsync(existingDevice); - var menu=await _repoManager.Menus.GetMenuByTargetIdAsync(MenuType.DeviceMenu, device.Id); + int res = await _repoManager.Devices.UpdateAsync(existingDevice); + var menu = await _repoManager.Menus.GetMenuByTargetIdAsync(MenuType.DeviceMenu, device.Id); if (menu != null) { menu.Header = device.Name; - await _repoManager.Menus.UpdateAsync(menu); + await _repoManager.Menus.UpdateAsync(menu); } + await _repoManager.CommitAsync(); return res; } @@ -157,13 +161,14 @@ public class DeviceAppService : IDeviceAppService throw new InvalidOperationException($"删除设备失败:设备ID:{device.Id},请检查设备Id是否存在"); } +// 删除关联的变量 + await _repoManager.Variables.DeleteByVariableTableIdAsync(device.Id); // 删除关联的变量表 await _repoManager.VariableTables.DeleteAsync(device.VariableTables); - // 删除关联的变量 - await _repoManager.Variables.DeleteByVariableTableIdAsync(deviceId); - + + // 删除关联的菜单树 - await _repoManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.DeviceMenu,deviceId); + await _repoManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.DeviceMenu, device.Id); await _repoManager.CommitAsync(); return true; @@ -174,7 +179,6 @@ public class DeviceAppService : IDeviceAppService // 可以在此记录日志 throw new ApplicationException($"删除设备时发生错误,操作已回滚,错误信息:{ex.Message}", ex); } - } /// diff --git a/DMS.Application/Services/Management/DeviceManagementService.cs b/DMS.Application/Services/Management/DeviceManagementService.cs index b0f2c2b..64f99b5 100644 --- a/DMS.Application/Services/Management/DeviceManagementService.cs +++ b/DMS.Application/Services/Management/DeviceManagementService.cs @@ -103,12 +103,12 @@ public class DeviceManagementService : IDeviceManagementService /// public async Task DeleteAsync(Device device) { - var result = await _deviceAppService.DeleteDeviceByIdAsync(device); + var result = await _deviceAppService.DeleteAsync(device); // 删除成功后,从内存中移除设备 if (result ) { - if (_appStorageService.Devices.TryGetValue(deviceId, out var deviceInStorage)) + if (_appStorageService.Devices.TryGetValue(device.Id, out var deviceInStorage)) { foreach (var variableTable in deviceInStorage.VariableTables) { @@ -120,7 +120,7 @@ public class DeviceManagementService : IDeviceManagementService _appStorageService.VariableTables.TryRemove(variableTable.Id, out _); } - _appStorageService.Devices.TryRemove(deviceId, out _); + _appStorageService.Devices.TryRemove(device.Id, out _); _eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Deleted, deviceInStorage)); } diff --git a/DMS.Core/Interfaces/Repositories/IBaseRepository.cs b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs index 05afad6..ed5ddf7 100644 --- a/DMS.Core/Interfaces/Repositories/IBaseRepository.cs +++ b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs @@ -43,6 +43,12 @@ public interface IBaseRepository where T : class /// 要删除的实体的主键ID。 Task DeleteByIdAsync(int id); + /// + /// 异步根据实体列表批量删除实体。 + /// + /// 要删除的实体列表。 + Task DeleteAsync(List entrities); + /// /// 异步根据ID列表批量删除实体。 /// diff --git a/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs b/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs index d197027..713e34c 100644 --- a/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs +++ b/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs @@ -23,5 +23,25 @@ namespace DMS.Infrastructure.Repositories // .Where(a => !a.IsAcknowledged) // .ToListAsync(); // } + + /// + /// 异步删除单个报警历史记录。 + /// + /// 要删除的报警历史实体。 + /// 受影响的行数。 + public async Task DeleteAsync(AlarmHistory entity) + { + return await base.DeleteAsync(new List { entity }); + } + + /// + /// 异步根据实体列表批量删除报警历史记录。 + /// + /// 要删除的报警历史实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + return await base.DeleteAsync(entities); + } } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/BaseRepository.cs b/DMS.Infrastructure/Repositories/BaseRepository.cs index 7edd60f..7ae460a 100644 --- a/DMS.Infrastructure/Repositories/BaseRepository.cs +++ b/DMS.Infrastructure/Repositories/BaseRepository.cs @@ -68,19 +68,21 @@ public abstract class BaseRepository return result; } + + /// - /// 异步删除一个实体。 + /// 异步批量删除实体。 /// - /// 要删除的实体对象。 + /// 要删除的实体列表。 /// 返回受影响的行数。 - public virtual async Task DeleteAsync(TEntity entity) + public virtual async Task DeleteAsync(List entities) { var stopwatch = new Stopwatch(); stopwatch.Start(); - var result = await _dbContext.GetInstance().Deleteable(entity) + var result = await _dbContext.GetInstance().Deleteable(entities) .ExecuteCommandAsync(); stopwatch.Stop(); - _logger.LogInformation($"Delete {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); + _logger.LogInformation($"DeleteAsync Batch {typeof(TEntity).Name}, Count: {entities.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } @@ -136,38 +138,9 @@ public abstract class BaseRepository return entity; } - /// - /// 异步根据主键 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; - } + + - /// - /// 异步根据指定条件获取单个实体。 - /// - /// 查询条件的 Lambda 表达式。 - /// 返回满足条件的第一个实体,如果未找到则返回 null。 - public virtual async Task GetByConditionAsync(Expression> expression) - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var entity = await _dbContext.GetInstance().Queryable() - .FirstAsync(expression); - stopwatch.Stop(); - _logger.LogInformation($"GetByCondition {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); - return entity; - } /// /// 异步判断是否存在满足条件的实体。 @@ -264,4 +237,21 @@ 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 937ca8f..4ab6b0c 100644 --- a/DMS.Infrastructure/Repositories/DeviceRepository.cs +++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs @@ -73,7 +73,7 @@ public class DeviceRepository : BaseRepository, IDeviceRepository /// /// 要删除的设备实体。 /// 受影响的行数。 - public async Task DeleteAsync(Core.Models.Device model) => await base.DeleteAsync(_mapper.Map(model)); + public async Task DeleteAsync(Core.Models.Device model) => await base.DeleteAsync(new List { _mapper.Map(model) }); /// /// 异步根据ID删除设备。 @@ -91,6 +91,8 @@ public class DeviceRepository : BaseRepository, IDeviceRepository return result; } + + /// /// 异步获取指定数量的设备。 /// @@ -109,4 +111,15 @@ public class DeviceRepository : BaseRepository, IDeviceRepository var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除设备。 + /// + /// 要删除的设备实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/EmailAccountRepository.cs b/DMS.Infrastructure/Repositories/EmailAccountRepository.cs index 2cf7321..40d2f0a 100644 --- a/DMS.Infrastructure/Repositories/EmailAccountRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailAccountRepository.cs @@ -160,5 +160,15 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(insertedEntities); } + + /// + /// 异步根据实体列表批量删除实体。 + /// + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Deleteable(dbEntities) + .ExecuteCommandAsync(); + } } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/EmailLogRepository.cs b/DMS.Infrastructure/Repositories/EmailLogRepository.cs index 482ecef..c2498d4 100644 --- a/DMS.Infrastructure/Repositories/EmailLogRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailLogRepository.cs @@ -160,5 +160,15 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(dbEntities); } + + /// + /// 异步根据实体列表批量删除实体。 + /// + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Deleteable(dbEntities) + .ExecuteCommandAsync(); + } } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/EmailMessageRepository.cs b/DMS.Infrastructure/Repositories/EmailMessageRepository.cs index 49b51cd..8dc1079 100644 --- a/DMS.Infrastructure/Repositories/EmailMessageRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailMessageRepository.cs @@ -160,5 +160,15 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(dbEntities); } + + /// + /// 异步根据实体列表批量删除实体。 + /// + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Deleteable(dbEntities) + .ExecuteCommandAsync(); + } } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs b/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs index 5b8d836..121ce12 100644 --- a/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs @@ -160,5 +160,15 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(dbEntities); } + + /// + /// 异步根据实体列表批量删除实体。 + /// + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Deleteable(dbEntities) + .ExecuteCommandAsync(); + } } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs index 3c5f214..5640f1e 100644 --- a/DMS.Infrastructure/Repositories/MenuRepository.cs +++ b/DMS.Infrastructure/Repositories/MenuRepository.cs @@ -88,7 +88,7 @@ public class MenuRepository : BaseRepository, IMenuRepository /// /// 要删除的菜单实体。 /// 受影响的行数。 - public async Task DeleteAsync(MenuBean entity) => await base.DeleteAsync(_mapper.Map(entity)); + public async Task DeleteAsync(MenuBean entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); /// /// 异步根据ID删除菜单。 @@ -178,4 +178,15 @@ public class MenuRepository : BaseRepository, IMenuRepository var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除菜单。 + /// + /// 要删除的菜单实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs index f6ef1d4..26ad942 100644 --- a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs +++ b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs @@ -75,7 +75,7 @@ public class MqttAliasRepository : BaseRepository, IMqttAliasReposi /// /// 要删除的变量与MQTT别名关联实体。 /// 受影响的行数。 - public async Task DeleteAsync(MqttAlias entity) => await base.DeleteAsync(_mapper.Map(entity)); + public async Task DeleteAsync(MqttAlias entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); /// /// 异步根据ID删除变量与MQTT别名关联。 @@ -111,4 +111,15 @@ public class MqttAliasRepository : BaseRepository, IMqttAliasReposi var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除变量与MQTT别名关联。 + /// + /// 要删除的变量与MQTT别名关联实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/MqttServerRepository.cs b/DMS.Infrastructure/Repositories/MqttServerRepository.cs index 1a30151..51070c1 100644 --- a/DMS.Infrastructure/Repositories/MqttServerRepository.cs +++ b/DMS.Infrastructure/Repositories/MqttServerRepository.cs @@ -72,7 +72,7 @@ public class MqttServerRepository : BaseRepository, IMqttServerRep /// /// 要删除的MQTT服务器实体。 /// 受影响的行数。 - public async Task DeleteAsync(MqttServer entity) => await base.DeleteAsync(_mapper.Map(entity)); + public async Task DeleteAsync(MqttServer entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); /// /// 异步根据ID删除MQTT服务器。 @@ -108,4 +108,15 @@ public class MqttServerRepository : BaseRepository, IMqttServerRep var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除MQTT服务器。 + /// + /// 要删除的MQTT服务器实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/NlogRepository.cs b/DMS.Infrastructure/Repositories/NlogRepository.cs index 795e843..bde1b27 100644 --- a/DMS.Infrastructure/Repositories/NlogRepository.cs +++ b/DMS.Infrastructure/Repositories/NlogRepository.cs @@ -97,7 +97,7 @@ public class NlogRepository : BaseRepository, INlogRepository public new async Task DeleteAsync(Core.Models.Nlog entity) { var dbEntity = _mapper.Map(entity); - return await base.DeleteAsync(dbEntity); + return await base.DeleteAsync(new List { dbEntity }); } /// @@ -136,4 +136,15 @@ public class NlogRepository : BaseRepository, INlogRepository var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除Nlog日志条目。 + /// + /// 要删除的Nlog日志实体列表。 + /// 受影响的行数。 + public new async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/TriggerRepository.cs b/DMS.Infrastructure/Repositories/TriggerRepository.cs index e683f30..40a3c40 100644 --- a/DMS.Infrastructure/Repositories/TriggerRepository.cs +++ b/DMS.Infrastructure/Repositories/TriggerRepository.cs @@ -82,7 +82,7 @@ namespace DMS.Infrastructure.Repositories /// 受影响的行数。 public async Task DeleteAsync(Trigger entity) { - return await base.DeleteAsync(_mapper.Map(entity)); + return await base.DeleteAsync(new List { _mapper.Map(entity) }); } /// @@ -118,5 +118,16 @@ namespace DMS.Infrastructure.Repositories var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除触发器定义。 + /// + /// 要删除的触发器定义实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs index 0377824..974fff0 100644 --- a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs +++ b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs @@ -75,7 +75,7 @@ public class TriggerVariableRepository : BaseRepository, ITri /// /// 要删除的触发器与变量关联实体。 /// 受影响的行数。 - public async Task DeleteAsync(TriggerVariable entity) => await base.DeleteAsync(_mapper.Map(entity)); + public async Task DeleteAsync(TriggerVariable entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); /// /// 异步根据ID删除触发器与变量关联。 @@ -110,4 +110,15 @@ public class TriggerVariableRepository : BaseRepository, ITri var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除触发器与变量关联。 + /// + /// 要删除的触发器与变量关联实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/UserRepository.cs b/DMS.Infrastructure/Repositories/UserRepository.cs index 61c9139..f860113 100644 --- a/DMS.Infrastructure/Repositories/UserRepository.cs +++ b/DMS.Infrastructure/Repositories/UserRepository.cs @@ -75,7 +75,7 @@ public class UserRepository : BaseRepository, IUserRepository /// /// 要删除的用户实体。 /// 受影响的行数。 - public async Task DeleteAsync(User entity) => await base.DeleteAsync(_mapper.Map(entity)); + public async Task DeleteAsync(User entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); /// /// 异步根据ID删除用户。 @@ -111,4 +111,15 @@ public class UserRepository : BaseRepository, IUserRepository var addedEntities = await base.AddBatchAsync(dbEntities); return _mapper.Map>(addedEntities); } + + /// + /// 异步根据实体列表批量删除用户。 + /// + /// 要删除的用户实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs index 462fc0c..1fa7cc3 100644 --- a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs @@ -74,7 +74,7 @@ public class VariableHistoryRepository : BaseRepository, IVar /// /// 要删除的变量历史实体。 /// 受影响的行数。 - public async Task DeleteAsync(VariableHistory entity) => await base.DeleteAsync(_mapper.Map(entity)); + public async Task DeleteAsync(VariableHistory entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); /// /// 异步根据ID删除变量历史记录。 @@ -184,4 +184,15 @@ public class VariableHistoryRepository : BaseRepository, IVar var dbList = await query.ToListAsync(); return _mapper.Map>(dbList); } + + /// + /// 异步根据实体列表批量删除变量历史记录。 + /// + /// 要删除的变量历史实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VariableRepository.cs b/DMS.Infrastructure/Repositories/VariableRepository.cs index a825b98..8af93e0 100644 --- a/DMS.Infrastructure/Repositories/VariableRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableRepository.cs @@ -73,7 +73,7 @@ public class VariableRepository : BaseRepository, IVariableRepositor /// /// 要删除的变量实体。 /// 受影响的行数。 - public async Task DeleteAsync(Variable entity) => await base.DeleteAsync(_mapper.Map(entity)); + public async Task DeleteAsync(Variable entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); /// @@ -186,4 +186,15 @@ public class VariableRepository : BaseRepository, IVariableRepositor _logger.LogInformation($"Batch update {typeof(DbVariable)}, Count={dbVariables.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } + + /// + /// 异步根据实体列表批量删除变量。 + /// + /// 要删除的变量实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VariableTableRepository.cs b/DMS.Infrastructure/Repositories/VariableTableRepository.cs index 86dbfc8..626f0d0 100644 --- a/DMS.Infrastructure/Repositories/VariableTableRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableTableRepository.cs @@ -95,7 +95,7 @@ public class VariableTableRepository : BaseRepository, IVariabl //删除变量表中的所有变量 await _variableRepository.DeleteByVariableTableIdAsync(entity.Id); //删除变量表 - return await base.DeleteAsync(_mapper.Map(entity)); + return await base.DeleteAsync(new List { _mapper.Map(entity) }); } @@ -158,4 +158,15 @@ public class VariableTableRepository : BaseRepository, IVariabl _logger.LogInformation($"Delete VariableTable by DeviceId={deviceId}, 耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } + + /// + /// 异步根据实体列表批量删除变量表。 + /// + /// 要删除的变量表实体列表。 + /// 受影响的行数。 + public async Task DeleteAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.DeleteAsync(dbEntities); + } } \ No newline at end of file