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