diff --git a/DMS.Core/Interfaces/Repositories/IBaseRepository.cs b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs index 4e4d645..d5d584e 100644 --- a/DMS.Core/Interfaces/Repositories/IBaseRepository.cs +++ b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs @@ -39,6 +39,13 @@ public interface IBaseRepository where T : class + /// + /// 异步批量更新实体。 + /// + /// 要更新的实体列表。 + Task UpdateAsync(List entities); + + /// /// 异步根据实体列表批量删除实体。 /// diff --git a/DMS.Infrastructure/Repositories/BaseRepository.cs b/DMS.Infrastructure/Repositories/BaseRepository.cs index f017a8e..b5c986a 100644 --- a/DMS.Infrastructure/Repositories/BaseRepository.cs +++ b/DMS.Infrastructure/Repositories/BaseRepository.cs @@ -151,6 +151,24 @@ public abstract class BaseRepository + + /// + /// 异步批量更新实体。 + /// + /// 要更新的实体列表。 + /// 返回受影响的行数。 + public virtual async Task UpdateAsync(List entities) + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + var result = await _dbContext.GetInstance().Updateable(entities) + .ExecuteCommandAsync(); + stopwatch.Stop(); + _logger.LogInformation($"UpdateAsync Batch {typeof(TEntity).Name}, Count: {entities.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms"); + return result; + } + + public async Task> AddAsync(List entities) { var stopwatch = new Stopwatch(); @@ -165,7 +183,6 @@ public abstract class BaseRepository stopwatch.Stop(); _logger.LogInformation($"AddBatchAsync {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); - return retrunEntities; } diff --git a/DMS.Infrastructure/Repositories/DeviceRepository.cs b/DMS.Infrastructure/Repositories/DeviceRepository.cs index 103d3d0..9b81af3 100644 --- a/DMS.Infrastructure/Repositories/DeviceRepository.cs +++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs @@ -83,6 +83,18 @@ public class DeviceRepository : BaseRepository, IDeviceRepository return _mapper.Map>(addedEntities); } + /// + /// 异步批量更新设备。 + /// + /// 要更新的设备实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除设备。 /// diff --git a/DMS.Infrastructure/Repositories/EmailAccountRepository.cs b/DMS.Infrastructure/Repositories/EmailAccountRepository.cs index 0db437a..aedf201 100644 --- a/DMS.Infrastructure/Repositories/EmailAccountRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailAccountRepository.cs @@ -133,6 +133,17 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(insertedEntities); } + /// + /// 异步批量更新实体。 + /// + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Updateable(dbEntities) + .ExecuteCommandAsync(); + } + + /// /// 异步根据实体列表批量删除实体。 /// diff --git a/DMS.Infrastructure/Repositories/EmailLogRepository.cs b/DMS.Infrastructure/Repositories/EmailLogRepository.cs index 6a854b9..3b6d67d 100644 --- a/DMS.Infrastructure/Repositories/EmailLogRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailLogRepository.cs @@ -133,6 +133,17 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(dbEntities); } + /// + /// 异步批量更新实体。 + /// + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Updateable(dbEntities) + .ExecuteCommandAsync(); + } + + /// /// 异步根据实体列表批量删除实体。 /// diff --git a/DMS.Infrastructure/Repositories/EmailMessageRepository.cs b/DMS.Infrastructure/Repositories/EmailMessageRepository.cs index 845271a..105beec 100644 --- a/DMS.Infrastructure/Repositories/EmailMessageRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailMessageRepository.cs @@ -132,6 +132,17 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(dbEntities); } + /// + /// 异步批量更新实体。 + /// + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Updateable(dbEntities) + .ExecuteCommandAsync(); + } + + /// /// 异步根据实体列表批量删除实体。 /// diff --git a/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs b/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs index f660c97..e59b6ce 100644 --- a/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs +++ b/DMS.Infrastructure/Repositories/EmailTemplateRepository.cs @@ -132,6 +132,17 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(dbEntities); } + /// + /// 异步批量更新实体。 + /// + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await Db.Updateable(dbEntities) + .ExecuteCommandAsync(); + } + + /// /// 异步根据实体列表批量删除实体。 /// diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs index bd39e59..1a303cb 100644 --- a/DMS.Infrastructure/Repositories/MenuRepository.cs +++ b/DMS.Infrastructure/Repositories/MenuRepository.cs @@ -155,6 +155,18 @@ public class MenuRepository : BaseRepository, IMenuRepository return _mapper.Map>(addedEntities); } + /// + /// 异步批量更新菜单。 + /// + /// 要更新的菜单实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除菜单。 /// diff --git a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs index 688bf26..3d035fd 100644 --- a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs +++ b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs @@ -87,6 +87,18 @@ public class MqttAliasRepository : BaseRepository, IMqttAliasReposi return _mapper.Map>(addedEntities); } + /// + /// 异步批量更新变量与MQTT别名关联。 + /// + /// 要更新的变量与MQTT别名关联实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除变量与MQTT别名关联。 /// diff --git a/DMS.Infrastructure/Repositories/MqttServerRepository.cs b/DMS.Infrastructure/Repositories/MqttServerRepository.cs index 05db5b8..7022fb6 100644 --- a/DMS.Infrastructure/Repositories/MqttServerRepository.cs +++ b/DMS.Infrastructure/Repositories/MqttServerRepository.cs @@ -83,6 +83,18 @@ public class MqttServerRepository : BaseRepository, IMqttServerRep return _mapper.Map>(addedEntities); } + /// + /// 异步批量更新MQTT服务器。 + /// + /// 要更新的MQTT服务器实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除MQTT服务器。 /// diff --git a/DMS.Infrastructure/Repositories/NlogRepository.cs b/DMS.Infrastructure/Repositories/NlogRepository.cs index 134763d..350e50e 100644 --- a/DMS.Infrastructure/Repositories/NlogRepository.cs +++ b/DMS.Infrastructure/Repositories/NlogRepository.cs @@ -117,6 +117,18 @@ public class NlogRepository : BaseRepository, INlogRepository return _mapper.Map>(addedEntities); } + /// + /// 异步批量更新Nlog日志条目。 + /// + /// 要更新的Nlog日志实体列表。 + /// 受影响的行数。 + public new async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除Nlog日志条目。 /// diff --git a/DMS.Infrastructure/Repositories/TriggerRepository.cs b/DMS.Infrastructure/Repositories/TriggerRepository.cs index a9c2379..0373c33 100644 --- a/DMS.Infrastructure/Repositories/TriggerRepository.cs +++ b/DMS.Infrastructure/Repositories/TriggerRepository.cs @@ -95,6 +95,18 @@ namespace DMS.Infrastructure.Repositories return _mapper.Map>(addedEntities); } + /// + /// 异步批量更新触发器定义。 + /// + /// 要更新的触发器定义实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除触发器定义。 /// diff --git a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs index e9b5abd..8aa870a 100644 --- a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs +++ b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs @@ -87,6 +87,18 @@ public class TriggerVariableRepository : BaseRepository, ITri return _mapper.Map>(addedEntities); } + /// + /// 异步批量更新触发器与变量关联。 + /// + /// 要更新的触发器与变量关联实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除触发器与变量关联。 /// diff --git a/DMS.Infrastructure/Repositories/UserRepository.cs b/DMS.Infrastructure/Repositories/UserRepository.cs index f4a8b17..c5abf7f 100644 --- a/DMS.Infrastructure/Repositories/UserRepository.cs +++ b/DMS.Infrastructure/Repositories/UserRepository.cs @@ -76,8 +76,13 @@ public class UserRepository : BaseRepository, IUserRepository /// 要删除的用户实体。 /// 受影响的行数。 public async Task DeleteAsync(User entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - - + + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + public async Task> AddAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs index 9a8117f..52f3c0b 100644 --- a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs @@ -75,8 +75,13 @@ public class VariableHistoryRepository : BaseRepository, IVar /// 要删除的变量历史实体。 /// 受影响的行数。 public async Task DeleteAsync(VariableHistory entity) => await base.DeleteAsync(new List { _mapper.Map(entity) }); - - + + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + public async Task> AddAsync(List entities) { diff --git a/DMS.Infrastructure/Repositories/VariableRepository.cs b/DMS.Infrastructure/Repositories/VariableRepository.cs index 835eba3..e536b1b 100644 --- a/DMS.Infrastructure/Repositories/VariableRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableRepository.cs @@ -144,6 +144,18 @@ public class VariableRepository : BaseRepository, IVariableRepositor return result; } + /// + /// 异步批量更新变量。 + /// + /// 要更新的变量实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除变量。 /// diff --git a/DMS.Infrastructure/Repositories/VariableTableRepository.cs b/DMS.Infrastructure/Repositories/VariableTableRepository.cs index a446444..5a51603 100644 --- a/DMS.Infrastructure/Repositories/VariableTableRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableTableRepository.cs @@ -108,6 +108,18 @@ public class VariableTableRepository : BaseRepository, IVariabl } + /// + /// 异步批量更新变量表。 + /// + /// 要更新的变量表实体列表。 + /// 受影响的行数。 + public async Task UpdateAsync(List entities) + { + var dbEntities = _mapper.Map>(entities); + return await base.UpdateAsync(dbEntities); + } + + /// /// 异步根据实体列表批量删除变量表。 ///