From 525c681b6c71311879d9937e06fdb926af0ff845 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Mon, 21 Jul 2025 18:49:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interfaces/IDeviceAppService.cs | 3 +- DMS.Application/Services/DeviceAppService.cs | 10 +-- DMS.Application/Services/MenuService.cs | 51 +++++++++--- .../Services/MqttAliasAppService.cs | 51 +++++++++--- DMS.Application/Services/MqttAppService.cs | 51 +++++++++--- .../Services/VariableAppService.cs | 51 +++++++++--- DMS.Core/Enums/DeviceType.cs | 2 + .../Interfaces/IDatabaseService.cs | 4 +- DMS.Core/Interfaces/IDeviceRepository.cs | 23 ------ DMS.Core/Interfaces/IMenuRepository.cs | 8 -- DMS.Core/Interfaces/IMqttServerRepository.cs | 13 --- DMS.Core/Interfaces/IRepositoryManager.cs | 20 +++-- DMS.Core/Interfaces/IUserRepository.cs | 13 --- .../Interfaces/IVariableHistoryRepository.cs | 8 -- .../IVariableMqttAliasRepository.cs | 21 ----- DMS.Core/Interfaces/IVariableRepository.cs | 13 --- .../Interfaces/IVariableTableRepository.cs | 8 -- .../{ => Repositories}/IBaseRepository.cs | 8 +- .../Repositories/IDeviceRepository.cs | 10 +++ .../Repositories/IMenuRepository.cs | 10 +++ .../Repositories/IMqttServerRepository.cs | 11 +++ .../Repositories/IUserRepository.cs | 9 ++ .../IVariableHistoryRepository.cs | 8 ++ .../IVariableMqttAliasRepository.cs | 9 ++ .../Repositories/IVariableRepository.cs | 10 +++ .../Repositories/IVariableTableRepository.cs | 11 +++ DMS.Infrastructure.UnitTests/FakerHelper.cs | 34 ++++---- .../DeviceRepository_Test.cs | 48 +++++++++++ DMS.Infrastructure/DMS.Infrastructure.csproj | 4 + DMS.Infrastructure/Data/SqlSugarDbContext.cs | 3 - DMS.Infrastructure/Entities/DbDevice.cs | 21 +++++ .../Interfaces/IDeviceRepository.cs | 20 ----- .../Interfaces/IDeviceService.cs | 12 --- .../Interfaces/IMenuRepository.cs | 19 ----- .../Interfaces/IMqttRepository.cs | 20 ----- .../Interfaces/IUserRepository.cs | 18 ---- .../Interfaces/IVarDataRepository.cs | 18 ---- .../Interfaces/IVarTableRepository.cs | 20 ----- .../IVariableMqttAliasRepository.cs | 18 ---- .../Repositories/BaseRepository.cs | 82 ++++++++++--------- .../Repositories/DeviceRepository.cs | 37 +++++++-- .../Repositories/MenuRepository.cs | 44 +++++----- .../Repositories/MqttRepository.cs | 56 ------------- .../Repositories/MqttServerRepository.cs | 29 +++++++ .../Repositories/RepositoryManager.cs | 46 +++++++++++ .../Repositories/UserRepository.cs | 20 +++-- .../Repositories/VarTableRepository.cs | 18 ---- .../Repositories/VariableHistoryRepository.cs | 24 ++++++ .../VariableMqttAliasRepository.cs | 22 +++-- ...ataRepository.cs => VariableRepository.cs} | 56 ++++--------- .../Repositories/VariableTableRepository.cs | 24 ++++++ DMS.Infrastructure/Services/BaseService.cs | 14 ++-- .../Services/DatabaseInitializerService.cs | 3 +- DMS.Infrastructure/Services/DeviceService.cs | 7 +- DMS.Infrastructure/Services/MqttService.cs | 5 +- DMS.Infrastructure/Services/VarDataService.cs | 4 +- .../Services/VarTableService.cs | 4 +- 57 files changed, 628 insertions(+), 558 deletions(-) rename {DMS.Infrastructure => DMS.Core}/Interfaces/IDatabaseService.cs (62%) delete mode 100644 DMS.Core/Interfaces/IDeviceRepository.cs delete mode 100644 DMS.Core/Interfaces/IMenuRepository.cs delete mode 100644 DMS.Core/Interfaces/IMqttServerRepository.cs delete mode 100644 DMS.Core/Interfaces/IUserRepository.cs delete mode 100644 DMS.Core/Interfaces/IVariableHistoryRepository.cs delete mode 100644 DMS.Core/Interfaces/IVariableMqttAliasRepository.cs delete mode 100644 DMS.Core/Interfaces/IVariableRepository.cs delete mode 100644 DMS.Core/Interfaces/IVariableTableRepository.cs rename DMS.Core/Interfaces/{ => Repositories}/IBaseRepository.cs (87%) create mode 100644 DMS.Core/Interfaces/Repositories/IDeviceRepository.cs create mode 100644 DMS.Core/Interfaces/Repositories/IMenuRepository.cs create mode 100644 DMS.Core/Interfaces/Repositories/IMqttServerRepository.cs create mode 100644 DMS.Core/Interfaces/Repositories/IUserRepository.cs create mode 100644 DMS.Core/Interfaces/Repositories/IVariableHistoryRepository.cs create mode 100644 DMS.Core/Interfaces/Repositories/IVariableMqttAliasRepository.cs create mode 100644 DMS.Core/Interfaces/Repositories/IVariableRepository.cs create mode 100644 DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs create mode 100644 DMS.Infrastructure.UnitTests/Repositories_Test/DeviceRepository_Test.cs delete mode 100644 DMS.Infrastructure/Interfaces/IDeviceRepository.cs delete mode 100644 DMS.Infrastructure/Interfaces/IDeviceService.cs delete mode 100644 DMS.Infrastructure/Interfaces/IMenuRepository.cs delete mode 100644 DMS.Infrastructure/Interfaces/IMqttRepository.cs delete mode 100644 DMS.Infrastructure/Interfaces/IUserRepository.cs delete mode 100644 DMS.Infrastructure/Interfaces/IVarDataRepository.cs delete mode 100644 DMS.Infrastructure/Interfaces/IVarTableRepository.cs delete mode 100644 DMS.Infrastructure/Interfaces/IVariableMqttAliasRepository.cs delete mode 100644 DMS.Infrastructure/Repositories/MqttRepository.cs create mode 100644 DMS.Infrastructure/Repositories/MqttServerRepository.cs create mode 100644 DMS.Infrastructure/Repositories/RepositoryManager.cs delete mode 100644 DMS.Infrastructure/Repositories/VarTableRepository.cs create mode 100644 DMS.Infrastructure/Repositories/VariableHistoryRepository.cs rename DMS.Infrastructure/Repositories/{VarDataRepository.cs => VariableRepository.cs} (74%) create mode 100644 DMS.Infrastructure/Repositories/VariableTableRepository.cs diff --git a/DMS.Application/Interfaces/IDeviceAppService.cs b/DMS.Application/Interfaces/IDeviceAppService.cs index 067044a..786817c 100644 --- a/DMS.Application/Interfaces/IDeviceAppService.cs +++ b/DMS.Application/Interfaces/IDeviceAppService.cs @@ -1,5 +1,6 @@ using DMS.Application.DTOs; using DMS.Core.Enums; +using DMS.Core.Models; namespace DMS.Application.Interfaces; @@ -33,7 +34,7 @@ public interface IDeviceAppService /// /// 异步删除一个设备。 /// - Task DeleteDeviceAsync(int id); + Task DeleteDeviceAsync(Device device); /// /// 异步切换设备的激活状态。 diff --git a/DMS.Application/Services/DeviceAppService.cs b/DMS.Application/Services/DeviceAppService.cs index b0298e7..ae0a40e 100644 --- a/DMS.Application/Services/DeviceAppService.cs +++ b/DMS.Application/Services/DeviceAppService.cs @@ -1,9 +1,9 @@ using AutoMapper; -using DMS.Core.Interfaces; using DMS.Core.Models; using DMS.Application.DTOs; using DMS.Application.Interfaces; using DMS.Core.Enums; +using DMS.Core.Interfaces; namespace DMS.Application.Services; @@ -49,7 +49,7 @@ public class DeviceAppService : IDeviceAppService { try { - _repoManager.BeginTransaction(); + _repoManager.BeginTranAsync(); var device = _mapper.Map(dto.Device); device.IsActive = true; // 默认激活 @@ -101,9 +101,9 @@ public class DeviceAppService : IDeviceAppService /// /// 异步删除一个设备。 /// - public async Task DeleteDeviceAsync(int id) + public async Task DeleteDeviceAsync(Device device) { - await _repoManager.Devices.DeleteAsync(id); + await _repoManager.Devices.DeleteAsync(device); await _repoManager.CommitAsync(); } @@ -127,7 +127,7 @@ public class DeviceAppService : IDeviceAppService /// public async Task> GetDevicesByProtocolAsync(ProtocolType protocol) { - var devices = await _repoManager.Devices.GetActiveDevicesWithDetailsAsync(protocol); + var devices = await _repoManager.Devices.GetAllAsync(); return _mapper.Map>(devices); } } \ No newline at end of file diff --git a/DMS.Application/Services/MenuService.cs b/DMS.Application/Services/MenuService.cs index 8d92a20..e2a1127 100644 --- a/DMS.Application/Services/MenuService.cs +++ b/DMS.Application/Services/MenuService.cs @@ -34,27 +34,54 @@ public class MenuService : IMenuService public async Task CreateMenuAsync(MenuBeanDto menuDto) { - var menu = _mapper.Map(menuDto); - await _repoManager.Menus.AddAsync(menu); - await _repoManager.CommitAsync(); - return menu.Id; + try + { + _repoManager.BeginTranAsync(); + var menu = _mapper.Map(menuDto); + await _repoManager.Menus.AddAsync(menu); + await _repoManager.CommitAsync(); + return menu.Id; + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("创建菜单时发生错误,操作已回滚。", ex); + } } public async Task UpdateMenuAsync(MenuBeanDto menuDto) { - var menu = await _repoManager.Menus.GetByIdAsync(menuDto.Id); - if (menu == null) + try { - throw new ApplicationException($"Menu with ID {menuDto.Id} not found."); + _repoManager.BeginTranAsync(); + var menu = await _repoManager.Menus.GetByIdAsync(menuDto.Id); + if (menu == null) + { + throw new ApplicationException($"Menu with ID {menuDto.Id} not found."); + } + _mapper.Map(menuDto, menu); + await _repoManager.Menus.UpdateAsync(menu); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("更新菜单时发生错误,操作已回滚。", ex); } - _mapper.Map(menuDto, menu); - await _repoManager.Menus.UpdateAsync(menu); - await _repoManager.CommitAsync(); } public async Task DeleteMenuAsync(int id) { - await _repoManager.Menus.DeleteAsync(id); - await _repoManager.CommitAsync(); + try + { + _repoManager.BeginTranAsync(); + await _repoManager.Menus.DeleteAsync(id); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("删除菜单时发生错误,操作已回滚。", ex); + } } } \ No newline at end of file diff --git a/DMS.Application/Services/MqttAliasAppService.cs b/DMS.Application/Services/MqttAliasAppService.cs index 17d493d..cb44425 100644 --- a/DMS.Application/Services/MqttAliasAppService.cs +++ b/DMS.Application/Services/MqttAliasAppService.cs @@ -34,27 +34,54 @@ public class MqttAliasAppService : IMqttAliasAppService public async Task CreateMqttAliasAsync(VariableMqttAliasDto mqttAliasDto) { - var mqttAlias = _mapper.Map(mqttAliasDto); - await _repoManager.VariableMqttAliases.AddAsync(mqttAlias); - await _repoManager.CommitAsync(); - return mqttAlias.Id; + try + { + _repoManager.BeginTranAsync(); + var mqttAlias = _mapper.Map(mqttAliasDto); + await _repoManager.VariableMqttAliases.AddAsync(mqttAlias); + await _repoManager.CommitAsync(); + return mqttAlias.Id; + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("创建MQTT别名时发生错误,操作已回滚。", ex); + } } public async Task UpdateMqttAliasAsync(VariableMqttAliasDto mqttAliasDto) { - var mqttAlias = await _repoManager.VariableMqttAliases.GetByIdAsync(mqttAliasDto.Id); - if (mqttAlias == null) + try { - throw new ApplicationException($"MQTT Alias with ID {mqttAliasDto.Id} not found."); + _repoManager.BeginTranAsync(); + var mqttAlias = await _repoManager.VariableMqttAliases.GetByIdAsync(mqttAliasDto.Id); + if (mqttAlias == null) + { + throw new ApplicationException($"MQTT Alias with ID {mqttAliasDto.Id} not found."); + } + _mapper.Map(mqttAliasDto, mqttAlias); + await _repoManager.VariableMqttAliases.UpdateAsync(mqttAlias); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("更新MQTT别名时发生错误,操作已回滚。", ex); } - _mapper.Map(mqttAliasDto, mqttAlias); - await _repoManager.VariableMqttAliases.UpdateAsync(mqttAlias); - await _repoManager.CommitAsync(); } public async Task DeleteMqttAliasAsync(int id) { - await _repoManager.VariableMqttAliases.DeleteAsync(id); - await _repoManager.CommitAsync(); + try + { + _repoManager.BeginTranAsync(); + await _repoManager.VariableMqttAliases.DeleteAsync(id); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("删除MQTT别名时发生错误,操作已回滚。", ex); + } } } \ No newline at end of file diff --git a/DMS.Application/Services/MqttAppService.cs b/DMS.Application/Services/MqttAppService.cs index 021c1c8..abfeca8 100644 --- a/DMS.Application/Services/MqttAppService.cs +++ b/DMS.Application/Services/MqttAppService.cs @@ -34,27 +34,54 @@ public class MqttAppService : IMqttAppService public async Task CreateMqttServerAsync(MqttServerDto mqttServerDto) { - var mqttServer = _mapper.Map(mqttServerDto); - await _repoManager.MqttServers.AddAsync(mqttServer); - await _repoManager.CommitAsync(); - return mqttServer.Id; + try + { + _repoManager.BeginTranAsync(); + var mqttServer = _mapper.Map(mqttServerDto); + await _repoManager.MqttServers.AddAsync(mqttServer); + await _repoManager.CommitAsync(); + return mqttServer.Id; + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("创建MQTT服务器时发生错误,操作已回滚。", ex); + } } public async Task UpdateMqttServerAsync(MqttServerDto mqttServerDto) { - var mqttServer = await _repoManager.MqttServers.GetByIdAsync(mqttServerDto.Id); - if (mqttServer == null) + try { - throw new ApplicationException($"MQTT Server with ID {mqttServerDto.Id} not found."); + _repoManager.BeginTranAsync(); + var mqttServer = await _repoManager.MqttServers.GetByIdAsync(mqttServerDto.Id); + if (mqttServer == null) + { + throw new ApplicationException($"MQTT Server with ID {mqttServerDto.Id} not found."); + } + _mapper.Map(mqttServerDto, mqttServer); + await _repoManager.MqttServers.UpdateAsync(mqttServer); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("更新MQTT服务器时发生错误,操作已回滚。", ex); } - _mapper.Map(mqttServerDto, mqttServer); - await _repoManager.MqttServers.UpdateAsync(mqttServer); - await _repoManager.CommitAsync(); } public async Task DeleteMqttServerAsync(int id) { - await _repoManager.MqttServers.DeleteAsync(id); - await _repoManager.CommitAsync(); + try + { + _repoManager.BeginTranAsync(); + await _repoManager.MqttServers.DeleteAsync(id); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("删除MQTT服务器时发生错误,操作已回滚。", ex); + } } } \ No newline at end of file diff --git a/DMS.Application/Services/VariableAppService.cs b/DMS.Application/Services/VariableAppService.cs index 0bb7afb..36335ae 100644 --- a/DMS.Application/Services/VariableAppService.cs +++ b/DMS.Application/Services/VariableAppService.cs @@ -34,27 +34,54 @@ public class VariableAppService : IVariableAppService public async Task CreateVariableAsync(VariableDto variableDto) { - var variable = _mapper.Map(variableDto); - await _repoManager.Variables.AddAsync(variable); - await _repoManager.CommitAsync(); - return variable.Id; + try + { + _repoManager.BeginTranAsync(); + var variable = _mapper.Map(variableDto); + await _repoManager.Variables.AddAsync(variable); + await _repoManager.CommitAsync(); + return variable.Id; + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("创建变量时发生错误,操作已回滚。", ex); + } } public async Task UpdateVariableAsync(VariableDto variableDto) { - var variable = await _repoManager.Variables.GetByIdAsync(variableDto.Id); - if (variable == null) + try { - throw new ApplicationException($"Variable with ID {variableDto.Id} not found."); + _repoManager.BeginTranAsync(); + var variable = await _repoManager.Variables.GetByIdAsync(variableDto.Id); + if (variable == null) + { + throw new ApplicationException($"Variable with ID {variableDto.Id} not found."); + } + _mapper.Map(variableDto, variable); + await _repoManager.Variables.UpdateAsync(variable); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("更新变量时发生错误,操作已回滚。", ex); } - _mapper.Map(variableDto, variable); - await _repoManager.Variables.UpdateAsync(variable); - await _repoManager.CommitAsync(); } public async Task DeleteVariableAsync(int id) { - await _repoManager.Variables.DeleteAsync(id); - await _repoManager.CommitAsync(); + try + { + _repoManager.BeginTranAsync(); + await _repoManager.Variables.DeleteAsync(id); + await _repoManager.CommitAsync(); + } + catch (Exception ex) + { + await _repoManager.RollbackAsync(); + throw new ApplicationException("删除变量时发生错误,操作已回滚。", ex); + } } } \ No newline at end of file diff --git a/DMS.Core/Enums/DeviceType.cs b/DMS.Core/Enums/DeviceType.cs index 90d4c15..90379c2 100644 --- a/DMS.Core/Enums/DeviceType.cs +++ b/DMS.Core/Enums/DeviceType.cs @@ -5,5 +5,7 @@ namespace DMS.Core.Enums; public enum DeviceType { [Description("西门子PLC")] SiemensPLC, + [Description("OpcUa设备")] OpcUa, + [Description("Modbus TCP设备")] ModbusTCP, [Description("三菱PLC")] MelsecPLC } \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IDatabaseService.cs b/DMS.Core/Interfaces/IDatabaseService.cs similarity index 62% rename from DMS.Infrastructure/Interfaces/IDatabaseService.cs rename to DMS.Core/Interfaces/IDatabaseService.cs index 6f29b47..6d0d713 100644 --- a/DMS.Infrastructure/Interfaces/IDatabaseService.cs +++ b/DMS.Core/Interfaces/IDatabaseService.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace DMS.Infrastructure.Interfaces +namespace DMS.Core.Interfaces { public interface IDatabaseService { diff --git a/DMS.Core/Interfaces/IDeviceRepository.cs b/DMS.Core/Interfaces/IDeviceRepository.cs deleted file mode 100644 index 68b7ba0..0000000 --- a/DMS.Core/Interfaces/IDeviceRepository.cs +++ /dev/null @@ -1,23 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -/// -/// 继承自IBaseRepository,提供设备相关的特定数据查询功能。 -/// -public interface IDeviceRepository : IBaseRepository -{ - /// - /// 异步获取所有激活的设备,并级联加载其下的变量表和变量。 - /// 这是后台轮询服务需要的主要数据。 - /// - /// 包含完整层级结构的激活设备列表。 - Task> GetActiveDevicesWithDetailsAsync(ProtocolType protocol); - - /// - /// 异步根据设备ID获取设备及其所有详细信息(变量表、变量、MQTT别名等)。 - /// - /// 设备ID。 - /// 包含详细信息的设备对象。 - Task GetDeviceWithDetailsAsync(int deviceId); -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IMenuRepository.cs b/DMS.Core/Interfaces/IMenuRepository.cs deleted file mode 100644 index e6ec653..0000000 --- a/DMS.Core/Interfaces/IMenuRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -public interface IMenuRepository : IBaseRepository -{ - // 可以添加特定于菜单的查询方法,例如获取所有菜单项 -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IMqttServerRepository.cs b/DMS.Core/Interfaces/IMqttServerRepository.cs deleted file mode 100644 index 2932de2..0000000 --- a/DMS.Core/Interfaces/IMqttServerRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -public interface IMqttServerRepository : IBaseRepository -{ - /// - /// 异步获取一个MQTT服务器及其关联的所有变量别名。 - /// - /// MQTT服务器ID。 - /// 包含变量别名信息的MQTT服务器对象。 - Task GetMqttServerWithVariableAliasesAsync(int serverId); -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IRepositoryManager.cs b/DMS.Core/Interfaces/IRepositoryManager.cs index 8c0e3c0..f676902 100644 --- a/DMS.Core/Interfaces/IRepositoryManager.cs +++ b/DMS.Core/Interfaces/IRepositoryManager.cs @@ -1,3 +1,5 @@ +using DMS.Core.Interfaces.Repositories; + namespace DMS.Core.Interfaces; /// @@ -10,47 +12,47 @@ public interface IRepositoryManager : IDisposable /// 获取设备仓储的实例。 /// 所有通过此管理器获取的仓储都共享同一个数据库上下文和事务。 /// - IDeviceRepository Devices { get; } + IDeviceRepository Devices { get; set; } /// /// 获取变量表仓储的实例。 /// - IVariableTableRepository VariableTables { get; } + IVariableTableRepository VariableTables { get; set; } /// /// 获取变量仓储的实例。 /// - IVariableRepository Variables { get; } + IVariableRepository Variables { get; set; } /// /// 获取MQTT服务器仓储的实例。 /// - IMqttServerRepository MqttServers { get; } + IMqttServerRepository MqttServers { get; set; } /// /// 获取变量MQTT别名仓储的实例。 /// - IVariableMqttAliasRepository VariableMqttAliases { get; } + IVariableMqttAliasRepository VariableMqttAliases { get; set; } /// /// 获取菜单仓储的实例。 /// - IMenuRepository Menus { get; } + IMenuRepository Menus { get; set; } /// /// 获取变量历史仓储的实例。 /// - IVariableHistoryRepository VariableHistories { get; } + IVariableHistoryRepository VariableHistories { get; set; } /// /// 获取用户仓储的实例。 /// - IUserRepository Users { get; } + IUserRepository Users { get; set; } /// /// 开始一个新的数据库事务。 /// - void BeginTransaction(); + Task BeginTranAsync(); /// /// 异步提交当前事务中的所有变更。 diff --git a/DMS.Core/Interfaces/IUserRepository.cs b/DMS.Core/Interfaces/IUserRepository.cs deleted file mode 100644 index 5b049ff..0000000 --- a/DMS.Core/Interfaces/IUserRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -public interface IUserRepository : IBaseRepository -{ - /// - /// 异步根据用户名获取用户。 - /// - /// 用户名。 - /// 用户对象,如果不存在则为null。 - Task GetByUsernameAsync(string username); -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IVariableHistoryRepository.cs b/DMS.Core/Interfaces/IVariableHistoryRepository.cs deleted file mode 100644 index bb174fc..0000000 --- a/DMS.Core/Interfaces/IVariableHistoryRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -public interface IVariableHistoryRepository : IBaseRepository -{ - // 可以添加特定于VariableHistory的查询方法 -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs b/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs deleted file mode 100644 index 5451164..0000000 --- a/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -public interface IVariableMqttAliasRepository : IBaseRepository -{ - /// - /// 异步获取指定变量的所有MQTT别名关联,并加载关联的MQTT服务器信息。 - /// - /// 变量ID。 - /// 指定变量的所有MQTT别名关联列表。 - Task> GetAliasesForVariableAsync(int variableId); - - /// - /// 异步根据变量ID和MQTT服务器ID获取特定的MQTT别名关联。 - /// - /// 变量ID。 - /// MQTT服务器ID。 - /// 匹配的VariableMqttAlias对象,如果不存在则为null。 - Task GetByVariableAndServerAsync(int variableId, int mqttServerId); -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IVariableRepository.cs b/DMS.Core/Interfaces/IVariableRepository.cs deleted file mode 100644 index 7a2e658..0000000 --- a/DMS.Core/Interfaces/IVariableRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -public interface IVariableRepository : IBaseRepository -{ - /// - /// 异步获取一个变量及其关联的所有MQTT别名和对应的MQTT服务器信息。 - /// - /// 变量ID。 - /// 包含别名和服务器信息的变量对象。 - Task GetVariableWithMqttAliasesAsync(int variableId); -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IVariableTableRepository.cs b/DMS.Core/Interfaces/IVariableTableRepository.cs deleted file mode 100644 index ae22c19..0000000 --- a/DMS.Core/Interfaces/IVariableTableRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using DMS.Core.Models; - -namespace DMS.Core.Interfaces; - -public interface IVariableTableRepository : IBaseRepository -{ - // 可以添加特定于VariableTable的查询方法 -} \ No newline at end of file diff --git a/DMS.Core/Interfaces/IBaseRepository.cs b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs similarity index 87% rename from DMS.Core/Interfaces/IBaseRepository.cs rename to DMS.Core/Interfaces/Repositories/IBaseRepository.cs index 8e31442..dedf0e9 100644 --- a/DMS.Core/Interfaces/IBaseRepository.cs +++ b/DMS.Core/Interfaces/Repositories/IBaseRepository.cs @@ -1,4 +1,4 @@ -namespace DMS.Core.Interfaces; +namespace DMS.Core.Interfaces.Repositories; /// /// 提供泛型数据访问操作的基础仓储接口。 @@ -23,17 +23,17 @@ public interface IBaseRepository where T : class /// 异步添加一个新实体。 /// /// 要添加的实体。 - Task AddAsync(T entity); + Task AddAsync(T entity); /// /// 异步更新一个已存在的实体。 /// /// 要更新的实体。 - Task UpdateAsync(T entity); + Task UpdateAsync(T entity); /// /// 异步根据ID删除一个实体。 /// /// 要删除的实体的主键ID。 - Task DeleteAsync(int id); + Task DeleteAsync(T entity); } \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IDeviceRepository.cs b/DMS.Core/Interfaces/Repositories/IDeviceRepository.cs new file mode 100644 index 0000000..df47456 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IDeviceRepository.cs @@ -0,0 +1,10 @@ + +using DMS.Core.Models; + +namespace DMS.Core.Interfaces.Repositories +{ + public interface IDeviceRepository:IBaseRepository + { + + } +} \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IMenuRepository.cs b/DMS.Core/Interfaces/Repositories/IMenuRepository.cs new file mode 100644 index 0000000..d02a657 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IMenuRepository.cs @@ -0,0 +1,10 @@ + +using DMS.Core.Models; + +namespace DMS.Core.Interfaces.Repositories +{ + public interface IMenuRepository:IBaseRepository + { + + } +} \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IMqttServerRepository.cs b/DMS.Core/Interfaces/Repositories/IMqttServerRepository.cs new file mode 100644 index 0000000..a5742d8 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IMqttServerRepository.cs @@ -0,0 +1,11 @@ + +using DMS.Core.Models; + +namespace DMS.Core.Interfaces.Repositories +{ + public interface IMqttServerRepository:IBaseRepository + { + + } + +} \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IUserRepository.cs b/DMS.Core/Interfaces/Repositories/IUserRepository.cs new file mode 100644 index 0000000..705f8c8 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IUserRepository.cs @@ -0,0 +1,9 @@ +using DMS.Core.Models; + +namespace DMS.Core.Interfaces.Repositories +{ + public interface IUserRepository:IBaseRepository + { + + } +} \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IVariableHistoryRepository.cs b/DMS.Core/Interfaces/Repositories/IVariableHistoryRepository.cs new file mode 100644 index 0000000..cbdd3e5 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IVariableHistoryRepository.cs @@ -0,0 +1,8 @@ +using DMS.Core.Models; + +namespace DMS.Core.Interfaces.Repositories; + +public interface IVariableHistoryRepository:IBaseRepository +{ + +} \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IVariableMqttAliasRepository.cs b/DMS.Core/Interfaces/Repositories/IVariableMqttAliasRepository.cs new file mode 100644 index 0000000..aae3bd9 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IVariableMqttAliasRepository.cs @@ -0,0 +1,9 @@ + +namespace DMS.Core.Interfaces.Repositories +{ + public interface IVariableMqttAliasRepository:IBaseRepository + { + + + } +} \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IVariableRepository.cs b/DMS.Core/Interfaces/Repositories/IVariableRepository.cs new file mode 100644 index 0000000..c5da0c3 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IVariableRepository.cs @@ -0,0 +1,10 @@ + +using DMS.Core.Models; + +namespace DMS.Core.Interfaces.Repositories +{ + public interface IVariableRepository:IBaseRepository + { + + } +} \ No newline at end of file diff --git a/DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs b/DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs new file mode 100644 index 0000000..aa97445 --- /dev/null +++ b/DMS.Core/Interfaces/Repositories/IVariableTableRepository.cs @@ -0,0 +1,11 @@ + +using DMS.Core.Models; + +namespace DMS.Core.Interfaces.Repositories +{ + public interface IVariableTableRepository:IBaseRepository + { + + + } +} \ No newline at end of file diff --git a/DMS.Infrastructure.UnitTests/FakerHelper.cs b/DMS.Infrastructure.UnitTests/FakerHelper.cs index b1c6cb7..366053c 100644 --- a/DMS.Infrastructure.UnitTests/FakerHelper.cs +++ b/DMS.Infrastructure.UnitTests/FakerHelper.cs @@ -10,23 +10,23 @@ namespace DMS.Infrastructure.UnitTests { public static class FakerHelper { - // public static DbDevice FakeDbDevice() - // { - // // var dbDevice = new Faker() - // // .RuleFor(d => d.Name, f => f.Commerce.ProductName()) - // // .RuleFor(d => d.Description, f => f.Commerce.ProductDescription()) - // // .RuleFor(d => d.Ip, f => f.Internet.Ip()) - // // .Generate(); - // // dbDevice.Prot = 102; - // // dbDevice.ProtocolType = Core.Enums.ProtocolType.S7; - // // dbDevice.Slot = 1; - // // dbDevice.Rack = 0; - // // dbDevice.CpuType = S7.Net.CpuType.S71200; - // // dbDevice.DeviceType = Core.Enums.DeviceType.SiemensPLC; - // - // - // return dbDevice; - // } + public static DbDevice FakeDbDevice() + { + var dbDevice = new Faker() + .RuleFor(d => d.Name, f => f.Commerce.ProductName()) + .RuleFor(d => d.Description, f => f.Commerce.ProductDescription()) + .RuleFor(d => d.IpAddress, f => f.Internet.Ip()) + .RuleFor(d => d.OpcUaServerUrl, f => f.Internet.Url()) + .Generate(); + dbDevice.Port = 102; + dbDevice.Protocol = ProtocolType.S7; + dbDevice.Slot = 1; + dbDevice.Rack = 0; + dbDevice.CpuType = "S7-1200"; + dbDevice.DeviceType = Core.Enums.DeviceType.SiemensPLC; + + return dbDevice; + } // public static DbVariableTable FakeDbVariableTable() // { diff --git a/DMS.Infrastructure.UnitTests/Repositories_Test/DeviceRepository_Test.cs b/DMS.Infrastructure.UnitTests/Repositories_Test/DeviceRepository_Test.cs new file mode 100644 index 0000000..f751849 --- /dev/null +++ b/DMS.Infrastructure.UnitTests/Repositories_Test/DeviceRepository_Test.cs @@ -0,0 +1,48 @@ +using DMS.Config; +using DMS.Infrastructure.Data; +using DMS.Infrastructure.Entities; +using DMS.Infrastructure.Repositories; + +namespace DMS.Infrastructure.UnitTests.Repositories_Test; + +public class DeviceRepository_Test +{ + private readonly DeviceRepository _deviceRepository; + + public DeviceRepository_Test() + { + AppSettings appSettings = new AppSettings(); + appSettings.Database.Database = "dms_test"; + var dbContext = new SqlSugarDbContext(appSettings); + dbContext.GetInstance() + .DbMaintenance.CreateDatabase(); + dbContext.GetInstance() + .CodeFirst.InitTables(); + // dbContext.GetInstance() + // .DbMaintenance.CreateIndex("Devices", new[] { "name" }, true); + _deviceRepository = new DeviceRepository(dbContext); + } + + [Fact] + public async Task AddAsync_Test() + { + var dbDevice = FakerHelper.FakeDbDevice(); + var resDevice = await _deviceRepository.AddAsync(dbDevice); + var res = await _deviceRepository.GetByIdAsync(resDevice.Id); + + Assert.NotNull(res); + } + + [Fact] + public async Task UpdateAsync_Test() + { + var dbDevice = FakerHelper.FakeDbDevice(); + var resDevice = await _deviceRepository.AddAsync(dbDevice); + + var res2 = await _deviceRepository.GetByIdAsync(resDevice.Id); + res2.Name = "HaHa"; + var res = await _deviceRepository.UpdateAsync(res2); + + Assert.Equal(res, 1); + } +} \ No newline at end of file diff --git a/DMS.Infrastructure/DMS.Infrastructure.csproj b/DMS.Infrastructure/DMS.Infrastructure.csproj index d175684..a5753e7 100644 --- a/DMS.Infrastructure/DMS.Infrastructure.csproj +++ b/DMS.Infrastructure/DMS.Infrastructure.csproj @@ -24,4 +24,8 @@ + + + + diff --git a/DMS.Infrastructure/Data/SqlSugarDbContext.cs b/DMS.Infrastructure/Data/SqlSugarDbContext.cs index 947321b..351b204 100644 --- a/DMS.Infrastructure/Data/SqlSugarDbContext.cs +++ b/DMS.Infrastructure/Data/SqlSugarDbContext.cs @@ -1,8 +1,5 @@ using DMS.Config; -using DMS.Infrastructure.Interfaces; using SqlSugar; -using System; -using System.Threading.Tasks; namespace DMS.Infrastructure.Data; diff --git a/DMS.Infrastructure/Entities/DbDevice.cs b/DMS.Infrastructure/Entities/DbDevice.cs index fde339e..be72383 100644 --- a/DMS.Infrastructure/Entities/DbDevice.cs +++ b/DMS.Infrastructure/Entities/DbDevice.cs @@ -1,4 +1,6 @@ +using DMS.Core.Enums; using SqlSugar; +using SqlSugar.DbConvert; namespace DMS.Infrastructure.Entities; @@ -18,10 +20,16 @@ public class DbDevice /// 设备名称。 /// public string Name { get; set; } + /// + /// 设备描述。 + /// + [SugarColumn(IsNullable = true)] + public string Description { get; set; } /// /// 设备通信协议类型,对应 ProtocolType 枚举。 /// + [SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))] public ProtocolType Protocol { get; set; } /// @@ -37,16 +45,29 @@ public class DbDevice /// /// 设备机架号 (针对PLC等设备)。 /// + [SugarColumn(IsNullable = true)] public int Rack { get; set; } /// /// 设备槽号 (针对PLC等设备)。 /// + [SugarColumn(IsNullable = true)] public int Slot { get; set; } + + /// + /// + /// + public string CpuType { get; set; } + /// + /// 设备槽号 (针对PLC等设备)。 + /// + [SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))] + public DeviceType DeviceType { get; set; } /// /// OPC UA服务器的URL地址。 /// + [SugarColumn(IsNullable = true)] public string OpcUaServerUrl { get; set; } /// diff --git a/DMS.Infrastructure/Interfaces/IDeviceRepository.cs b/DMS.Infrastructure/Interfaces/IDeviceRepository.cs deleted file mode 100644 index 070b997..0000000 --- a/DMS.Infrastructure/Interfaces/IDeviceRepository.cs +++ /dev/null @@ -1,20 +0,0 @@ -using DMS.Core.Models; -using SqlSugar; -using System.Collections.Generic; -using System.Threading.Tasks; -using DMS.Infrastructure.Entities; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IDeviceRepository - { - Task AddAsync(DbDevice model); - Task UpdateAsync(DbDevice model); - Task DeleteAsync(DbDevice model); - Task> GetAllAsync(); - Task GetByIdAsync(int id); - Task BeginTranAsync(); - Task CommitTranAsync(); - Task RollbackTranAsync(); - } -} \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IDeviceService.cs b/DMS.Infrastructure/Interfaces/IDeviceService.cs deleted file mode 100644 index 1c46af8..0000000 --- a/DMS.Infrastructure/Interfaces/IDeviceService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using DMS.Core.Models; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IDeviceService - { - Task AddAsync(Device device); - Task> GetAllAsync(); - } -} \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IMenuRepository.cs b/DMS.Infrastructure/Interfaces/IMenuRepository.cs deleted file mode 100644 index 7b1c07a..0000000 --- a/DMS.Infrastructure/Interfaces/IMenuRepository.cs +++ /dev/null @@ -1,19 +0,0 @@ -using DMS.Core.Models; -using DMS.Core.Enums; -using System.Collections.Generic; -using System.Threading.Tasks; -using DMS.Infrastructure.Entities; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IMenuRepository - { - Task DeleteAsync(DbMenu menu); - Task> GetMenuTreesAsync(); - Task AddAsync(DbMenu menu); - Task UpdateAsync(DbMenu menu); - Task BeginTranAsync(); - Task CommitTranAsync(); - Task RollbackTranAsync(); - } -} \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IMqttRepository.cs b/DMS.Infrastructure/Interfaces/IMqttRepository.cs deleted file mode 100644 index 0dda48c..0000000 --- a/DMS.Infrastructure/Interfaces/IMqttRepository.cs +++ /dev/null @@ -1,20 +0,0 @@ -using DMS.Core.Models; -using DMS.Infrastructure.Entities; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IMqttRepository - { - Task GetByIdAsync(int id); - Task> GetAllAsync(); - Task AddAsync(DbMqttServer mqtt); - Task UpdateAsync(DbMqttServer mqtt); - Task DeleteAsync(DbMqttServer mqtt); - Task BeginTranAsync(); - Task CommitTranAsync(); - Task RollbackTranAsync(); - } - -} \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IUserRepository.cs b/DMS.Infrastructure/Interfaces/IUserRepository.cs deleted file mode 100644 index 361f5eb..0000000 --- a/DMS.Infrastructure/Interfaces/IUserRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -using DMS.Core.Models; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IUserRepository - { - Task GetByIdAsync(int id); - Task> GetAllAsync(); - Task AddAsync(User user); - Task UpdateAsync(User user); - Task DeleteAsync(int id); - Task BeginTranAsync(); - Task CommitTranAsync(); - Task RollbackTranAsync(); - } -} \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IVarDataRepository.cs b/DMS.Infrastructure/Interfaces/IVarDataRepository.cs deleted file mode 100644 index 356826b..0000000 --- a/DMS.Infrastructure/Interfaces/IVarDataRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using DMS.Core.Models; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IVarDataRepository - { - Task GetByIdAsync(int id); - Task> GetAllAsync(); - Task AddAsync(Variable variable); - Task UpdateAsync(Variable variable); - Task DeleteAsync(Variable variable); - Task BeginTranAsync(); - Task CommitTranAsync(); - Task RollbackTranAsync(); - } -} \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IVarTableRepository.cs b/DMS.Infrastructure/Interfaces/IVarTableRepository.cs deleted file mode 100644 index 24cc164..0000000 --- a/DMS.Infrastructure/Interfaces/IVarTableRepository.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using DMS.Core.Models; -using DMS.Infrastructure.Entities; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IVarTableRepository - { - Task AddAsync(DbVariableTable varTable); - Task UpdateAsync(DbVariableTable variableTable); - Task DeleteAsync(DbVariableTable variableTable); - Task> GetAllAsync(); - Task GetByIdAsync(int id); - Task BeginTranAsync(); - Task CommitTranAsync(); - Task RollbackTranAsync(); - - } -} \ No newline at end of file diff --git a/DMS.Infrastructure/Interfaces/IVariableMqttAliasRepository.cs b/DMS.Infrastructure/Interfaces/IVariableMqttAliasRepository.cs deleted file mode 100644 index 7762a6b..0000000 --- a/DMS.Infrastructure/Interfaces/IVariableMqttAliasRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -using DMS.Core.Models; -using System.Collections.Generic; -using System.Threading.Tasks; -using DMS.Infrastructure.Entities; - -namespace DMS.Infrastructure.Interfaces -{ - public interface IVariableMqttAliasRepository - { - Task GetByIdAsync(int variableDataId, int mqttId); - Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias); - Task DeleteAsync(int variableDataId, int mqttId); - Task BeginTranAsync(); - Task CommitTranAsync(); - Task RollbackTranAsync(); - - } -} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/BaseRepository.cs b/DMS.Infrastructure/Repositories/BaseRepository.cs index 7b93145..f7359b2 100644 --- a/DMS.Infrastructure/Repositories/BaseRepository.cs +++ b/DMS.Infrastructure/Repositories/BaseRepository.cs @@ -1,15 +1,13 @@ -using AutoMapper; -using DMS.Core.Helper; -using DMS.Infrastructure.Interfaces; -using DMS.Infrastructure.Data; -using SqlSugar; using System.Diagnostics; using System.Linq.Expressions; +using DMS.Core.Helper; +using DMS.Infrastructure.Data; +using SqlSugar; namespace DMS.Infrastructure.Repositories; /// -/// 通用仓储基类,封装了对实体对象的常用 CRUD 操作。 +/// 通用仓储基类,封装了对实体对象的常用 CRUD 操作。 /// /// 实体类型,必须是引用类型且具有无参构造函数。 public abstract class BaseRepository @@ -17,121 +15,132 @@ public abstract class BaseRepository { private readonly SqlSugarDbContext _dbContext; - /// - /// 获取当前事务的 SqlSugarClient 实例,用于数据库操作。 - /// - protected SqlSugarClient Db => _dbContext.GetInstance(); - /// - /// 初始化 BaseRepository 的新实例。 + /// 初始化 BaseRepository 的新实例。 /// /// 事务管理对象,通过依赖注入提供。 protected BaseRepository(SqlSugarDbContext dbContext) { - this._dbContext = dbContext; + _dbContext = dbContext; } /// - /// 异步添加一个新实体。 + /// 获取当前事务的 SqlSugarClient 实例,用于数据库操作。 + /// + protected SqlSugarClient Db + { + get { return _dbContext.GetInstance(); } + } + + /// + /// 异步添加一个新实体。 /// /// 要添加的实体对象。 /// 返回已添加的实体对象(可能包含数据库生成的主键等信息)。 public virtual async Task AddAsync(TEntity entity) { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); - var result = await Db.Insertable(entity).ExecuteReturnEntityAsync(); + var result = await Db.Insertable(entity) + .ExecuteReturnEntityAsync(); stopwatch.Stop(); NlogHelper.Info($"Add {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } /// - /// 异步更新一个现有实体。 + /// 异步更新一个现有实体。 /// /// 要更新的实体对象。 /// 返回受影响的行数。 public virtual async Task UpdateAsync(TEntity entity) { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); - var result = await Db.Updateable(entity).ExecuteCommandAsync(); + var result = await Db.Updateable(entity) + .ExecuteCommandAsync(); stopwatch.Stop(); NlogHelper.Info($"Update {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } /// - /// 异步删除一个实体。 + /// 异步删除一个实体。 /// /// 要删除的实体对象。 /// 返回受影响的行数。 public virtual async Task DeleteAsync(TEntity entity) { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); - var result = await Db.Deleteable(entity).ExecuteCommandAsync(); + var result = await Db.Deleteable(entity) + .ExecuteCommandAsync(); stopwatch.Stop(); NlogHelper.Info($"Delete {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; } /// - /// 异步获取所有实体。 + /// 异步获取所有实体。 /// /// 返回包含所有实体的列表。 public virtual async Task> GetAllAsync() { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); - var entities = await Db.Queryable().ToListAsync(); + var entities = await Db.Queryable() + .ToListAsync(); stopwatch.Stop(); NlogHelper.Info($"GetAll {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); return entities; } - + /// - /// 异步根据主键 ID 获取单个实体。 + /// 异步根据主键 ID 获取单个实体。 /// /// 实体的主键 ID。 /// 返回找到的实体,如果未找到则返回 null。 public virtual async Task GetByIdAsync(int id) { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); - var entity = await Db.Queryable().In(id).FirstAsync(); + var entity = await Db.Queryable() + .In(id) + .FirstAsync(); stopwatch.Stop(); NlogHelper.Info($"GetById {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); return entity; } /// - /// 异步根据指定条件获取单个实体。 + /// 异步根据指定条件获取单个实体。 /// /// 查询条件的 Lambda 表达式。 /// 返回满足条件的第一个实体,如果未找到则返回 null。 public virtual async Task GetByConditionAsync(Expression> expression) { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); - var entity = await Db.Queryable().FirstAsync(expression); + var entity = await Db.Queryable() + .FirstAsync(expression); stopwatch.Stop(); NlogHelper.Info($"GetByCondition {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); return entity; } /// - /// 异步判断是否存在满足条件的实体。 + /// 异步判断是否存在满足条件的实体。 /// /// 查询条件的 Lambda 表达式。 /// 如果存在则返回 true,否则返回 false。 public virtual async Task ExistsAsync(Expression> expression) { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); - var result = await Db.Queryable().AnyAsync(expression); + var result = await Db.Queryable() + .AnyAsync(expression); stopwatch.Stop(); NlogHelper.Info($"Exists {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms"); return result; @@ -148,9 +157,8 @@ public abstract class BaseRepository } - public async Task RollbackTranAsync() { await Db.RollbackTranAsync(); } -} +} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/DeviceRepository.cs b/DMS.Infrastructure/Repositories/DeviceRepository.cs index 258d2df..c33d243 100644 --- a/DMS.Infrastructure/Repositories/DeviceRepository.cs +++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs @@ -1,22 +1,41 @@ -using System.Diagnostics; using AutoMapper; -using DMS.Infrastructure.Entities; -using DMS.Core.Enums; -using DMS.Core.Helper; +using DMS.Core.Interfaces.Repositories; using DMS.Core.Models; using DMS.Infrastructure.Data; -using SqlSugar; -using DMS.Infrastructure.Interfaces; +using DMS.Infrastructure.Entities; namespace DMS.Infrastructure.Repositories; -public class DeviceRepository : BaseRepository,IDeviceRepository +public class DeviceRepository : BaseRepository, IDeviceRepository { + private readonly IMapper _mapper; - public DeviceRepository(SqlSugarDbContext dbContext) + public DeviceRepository(IMapper mapper, SqlSugarDbContext dbContext) : base(dbContext) { - + _mapper = mapper; } + public async Task> GetAllAsync() + { + var dbList = await base.GetAllAsync(); + return _mapper.Map>(dbList); + } + + public async Task GetByIdAsync(int id) + { + var dbDevice = await base.GetByIdAsync(id); + return _mapper.Map(dbDevice); + } + + public async Task AddAsync(Device model) + { + var dbDevice = await base.AddAsync(_mapper.Map(model)); + return _mapper.Map(dbDevice, model); + } + + public async Task UpdateAsync(Device model) => await base.UpdateAsync(_mapper.Map(model)); + + + public async Task DeleteAsync(Device model) => await base.DeleteAsync(_mapper.Map(model)); } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs index 765e289..6732bfa 100644 --- a/DMS.Infrastructure/Repositories/MenuRepository.cs +++ b/DMS.Infrastructure/Repositories/MenuRepository.cs @@ -1,49 +1,43 @@ using System.Diagnostics; -using SqlSugar; using AutoMapper; -using DMS.Infrastructure.Entities; -using DMS.Core.Enums; using DMS.Core.Helper; +using DMS.Core.Interfaces.Repositories; using DMS.Core.Models; using DMS.Infrastructure.Data; -using DMS.Infrastructure.Interfaces; +using DMS.Infrastructure.Entities; namespace DMS.Infrastructure.Repositories; -public class MenuRepository : BaseRepository,IMenuRepository +public class MenuRepository : BaseRepository, IMenuRepository { - public MenuRepository(SqlSugarDbContext dbContext) + private readonly IMapper _mapper; + + public MenuRepository(IMapper mapper, SqlSugarDbContext dbContext) : base(dbContext) { + _mapper = mapper; } - public async Task> GetMenuTreesAsync() + + public async Task> GetMenuTreesAsync() { - Stopwatch stopwatch = new Stopwatch(); + var stopwatch = new Stopwatch(); stopwatch.Start(); var dbMenuTree = await Db.Queryable() .ToTreeAsync(dm => dm.Childrens, dm => dm.ParentId, 0); stopwatch.Stop(); NlogHelper.Info($"获取菜单树耗时:{stopwatch.ElapsedMilliseconds}ms"); - return dbMenuTree; + return _mapper.Map>(dbMenuTree); } - // /// - // /// 编辑菜单,支持事务 - // /// - // /// - // /// - // - // public async Task GetMenuByDataIdAsync(int dataId, MenuType menuType) - // { - // Stopwatch stopwatch = new Stopwatch(); - // stopwatch.Start(); - // var result = await Db.Queryable() - // .FirstAsync(m => m.DataId == dataId && m.Type == menuType); - // stopwatch.Stop(); - // NlogHelper.Info($"根据DataId '{dataId}' 和 MenuType '{menuType}' 获取菜单耗时:{stopwatch.ElapsedMilliseconds}ms"); - // return result; - // } + public async Task GetByIdAsync(int id) => throw new NotImplementedException(); + public async Task> GetAllAsync() => throw new NotImplementedException(); + + public async Task AddAsync(MenuBean entity) => throw new NotImplementedException(); + + public async Task UpdateAsync(MenuBean entity) => throw new NotImplementedException(); + + public async Task DeleteAsync(MenuBean entity) => throw new NotImplementedException(); } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/MqttRepository.cs b/DMS.Infrastructure/Repositories/MqttRepository.cs deleted file mode 100644 index bbdbd1c..0000000 --- a/DMS.Infrastructure/Repositories/MqttRepository.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Diagnostics; -using AutoMapper; -using DMS.Infrastructure.Entities; -using DMS.Core.Enums; -using DMS.Core.Helper; -using DMS.Core.Models; -using DMS.Infrastructure.Data; -using DMS.Infrastructure.Interfaces; - -namespace DMS.Infrastructure.Repositories; - -/// -/// Mqtt仓储类,用于操作DbMqtt实体 -/// -public class MqttRepository : BaseRepository -{ - - public MqttRepository(SqlSugarDbContext dbContext) - : base(dbContext) - { - } - - /// - /// 根据ID获取Mqtt配置 - /// - /// 主键ID - /// - public override async Task GetByIdAsync(int id) - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await Db.Queryable() - .In(id) - .SingleAsync(); - stopwatch.Stop(); - NlogHelper.Info($"根据ID '{id}' 获取Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } - - /// - /// 获取所有Mqtt配置 - /// - /// - public override async Task> GetAllAsync() - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await Db.Queryable() - .ToListAsync(); - stopwatch.Stop(); - NlogHelper.Info($"获取所有Mqtt配置耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } - - -} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/MqttServerRepository.cs b/DMS.Infrastructure/Repositories/MqttServerRepository.cs new file mode 100644 index 0000000..65d82f6 --- /dev/null +++ b/DMS.Infrastructure/Repositories/MqttServerRepository.cs @@ -0,0 +1,29 @@ +using System.Diagnostics; +using DMS.Core.Helper; +using DMS.Core.Interfaces.Repositories; +using DMS.Core.Models; +using DMS.Infrastructure.Data; +using DMS.Infrastructure.Entities; + +namespace DMS.Infrastructure.Repositories; + +/// +/// Mqtt仓储类,用于操作DbMqtt实体 +/// +public class MqttServerRepository : BaseRepository, IMqttServerRepository +{ + public MqttServerRepository(SqlSugarDbContext dbContext) + : base(dbContext) + { + } + + public async Task GetByIdAsync(int id) => throw new NotImplementedException(); + + public async Task> GetAllAsync() => throw new NotImplementedException(); + + public async Task AddAsync(MqttServer entity) => throw new NotImplementedException(); + + public async Task UpdateAsync(MqttServer entity) => throw new NotImplementedException(); + + public async Task DeleteAsync(MqttServer entity) => throw new NotImplementedException(); +} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/RepositoryManager.cs b/DMS.Infrastructure/Repositories/RepositoryManager.cs new file mode 100644 index 0000000..fb90adf --- /dev/null +++ b/DMS.Infrastructure/Repositories/RepositoryManager.cs @@ -0,0 +1,46 @@ +using DMS.Core.Interfaces; +using DMS.Core.Interfaces.Repositories; +using DMS.Infrastructure.Data; +using SqlSugar; + +namespace DMS.Infrastructure.Repositories; + +public class RepositoryManager : IRepositoryManager +{ + private readonly SqlSugarClient _db; + private readonly SqlSugarDbContext _dbContext; + + public RepositoryManager(SqlSugarDbContext dbContext) + { + _dbContext = dbContext; + _db = dbContext.GetInstance(); + + Devices = new DeviceRepository(dbContext); + VariableTables = new VariableTableRepository(dbContext); + Variables = new VariableRepository(dbContext); + MqttServers = new MqttServerRepository(dbContext); + VariableMqttAliases = new VariableMqttAliasRepository(dbContext); + Menus = new MenuRepository(dbContext); + VariableHistories = new VariableHistoryRepository(dbContext); + Users = new UserRepository(dbContext); + } + + public void Dispose() + { + _db.Close(); + } + + public IDeviceRepository Devices { get; set; } + public IVariableTableRepository VariableTables { get; set; } + public IVariableRepository Variables { get; set; } + public IMqttServerRepository MqttServers { get; set; } + public IVariableMqttAliasRepository VariableMqttAliases { get; set; } + public IMenuRepository Menus { get; set; } + public IVariableHistoryRepository VariableHistories { get; set; } + public IUserRepository Users { get; set; } + public async Task BeginTranAsync() => await _db.BeginTranAsync(); + + public async Task CommitAsync() => await _db.CommitTranAsync(); + + public async Task RollbackAsync() => await _db.RollbackTranAsync(); +} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/UserRepository.cs b/DMS.Infrastructure/Repositories/UserRepository.cs index fc2bb12..024207c 100644 --- a/DMS.Infrastructure/Repositories/UserRepository.cs +++ b/DMS.Infrastructure/Repositories/UserRepository.cs @@ -1,18 +1,28 @@ -using AutoMapper; +using DMS.Core.Interfaces; +using DMS.Core.Interfaces.Repositories; using DMS.Core.Models; -using DMS.Infrastructure.Interfaces; -using DMS.Infrastructure.Entities; using DMS.Infrastructure.Data; +using DMS.Infrastructure.Entities; namespace DMS.Infrastructure.Repositories; /// -/// 用户仓储类,用于操作DbUser实体 +/// 用户仓储类,用于操作DbUser实体 /// -public class UserRepository : BaseRepository +public class UserRepository : BaseRepository, IUserRepository { public UserRepository(SqlSugarDbContext dbContext) : base(dbContext) { } + + public async Task GetByIdAsync(int id) => throw new NotImplementedException(); + + public async Task> GetAllAsync() => throw new NotImplementedException(); + + public async Task AddAsync(User entity) => throw new NotImplementedException(); + + public async Task UpdateAsync(User entity) => throw new NotImplementedException(); + + public async Task DeleteAsync(User entity) => throw new NotImplementedException(); } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VarTableRepository.cs b/DMS.Infrastructure/Repositories/VarTableRepository.cs deleted file mode 100644 index e4cce35..0000000 --- a/DMS.Infrastructure/Repositories/VarTableRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -using AutoMapper; -using DMS.Core.Models; -using DMS.Infrastructure.Interfaces; -using DMS.Infrastructure.Entities; -using System.Diagnostics; -using DMS.Infrastructure.Data; - -namespace DMS.Infrastructure.Repositories; - -public class VarTableRepository : BaseRepository, IVarTableRepository -{ - public VarTableRepository(SqlSugarDbContext dbContext) - : base(dbContext) - { - } - - -} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs new file mode 100644 index 0000000..7150ed8 --- /dev/null +++ b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs @@ -0,0 +1,24 @@ +using DMS.Core.Interfaces.Repositories; +using DMS.Core.Models; +using DMS.Infrastructure.Data; +using DMS.Infrastructure.Entities; + +namespace DMS.Infrastructure.Repositories; + +public class VariableHistoryRepository : BaseRepository, IVariableHistoryRepository +{ + public VariableHistoryRepository(SqlSugarDbContext dbContext) + : base(dbContext) + { + } + + public async Task GetByIdAsync(int id) => throw new NotImplementedException(); + + public async Task> GetAllAsync() => throw new NotImplementedException(); + + public async Task AddAsync(VariableHistory entity) => throw new NotImplementedException(); + + public async Task UpdateAsync(VariableHistory entity) => throw new NotImplementedException(); + + public async Task DeleteAsync(VariableHistory entity) => throw new NotImplementedException(); +} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs b/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs index 6fc6350..93e6854 100644 --- a/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs @@ -1,18 +1,26 @@ -using AutoMapper; -using DMS.Core.Models; -using DMS.Infrastructure.Interfaces; -using DMS.Infrastructure.Entities; +using DMS.Core.Interfaces.Repositories; using DMS.Infrastructure.Data; +using DMS.Infrastructure.Entities; namespace DMS.Infrastructure.Repositories; /// -/// 变量与MQTT服务器别名关联的数据仓库。 +/// 变量与MQTT服务器别名关联的数据仓库。 /// -public class VariableMqttAliasRepository : BaseRepository +public class VariableMqttAliasRepository : BaseRepository, IVariableMqttAliasRepository { public VariableMqttAliasRepository(SqlSugarDbContext dbContext) : base(dbContext) { } -} + + public async Task GetByIdAsync(int id) => throw new NotImplementedException(); + + public async Task> GetAllAsync() => throw new NotImplementedException(); + + public async Task AddAsync(VariableMqttAlias entity) => throw new NotImplementedException(); + + public async Task UpdateAsync(VariableMqttAlias entity) => throw new NotImplementedException(); + + public async Task DeleteAsync(VariableMqttAlias entity) => throw new NotImplementedException(); +} \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VarDataRepository.cs b/DMS.Infrastructure/Repositories/VariableRepository.cs similarity index 74% rename from DMS.Infrastructure/Repositories/VarDataRepository.cs rename to DMS.Infrastructure/Repositories/VariableRepository.cs index 58ec545..8f7e49a 100644 --- a/DMS.Infrastructure/Repositories/VarDataRepository.cs +++ b/DMS.Infrastructure/Repositories/VariableRepository.cs @@ -1,56 +1,21 @@ -using AutoMapper; -using DMS.Core.Models; -using DMS.Infrastructure.Interfaces; using System.Diagnostics; -using DMS.Infrastructure.Entities; +using DMS.Core.Interfaces.Repositories; +using DMS.Core.Models; using DMS.Infrastructure.Data; +using DMS.Infrastructure.Entities; namespace DMS.Infrastructure.Repositories; /// -/// VariableData仓储类,用于操作DbVariableData实体 +/// VariableData仓储类,用于操作DbVariableData实体 /// -public class VarDataRepository : BaseRepository +public class VariableRepository : BaseRepository, IVariableRepository { - public VarDataRepository(SqlSugarDbContext dbContext) + public VariableRepository(SqlSugarDbContext dbContext) : base(dbContext) { } - - - public override async Task> GetAllAsync() - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await Db.Queryable() - .ToListAsync(); - stopwatch.Stop(); - //NlogHelper.Info($"获取所有VariableData耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } - - public async Task> GetByVariableTableIdAsync(int varTableId) - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await Db.Queryable() - .Where(d => d.VariableTableId == varTableId) - .ToListAsync(); - stopwatch.Stop(); - //NlogHelper.Info($"获取变量表的所有变量{result.Count()}个耗时:{stopwatch.ElapsedMilliseconds}ms"); - return result; - } - - - - - - - // public VarDataRepository(IMapper _mapper) - // { - // _mapper = _mapper; - // } /* /// @@ -134,4 +99,13 @@ public class VarDataRepository : BaseRepository } } */ + public async Task GetByIdAsync(int id) => throw new NotImplementedException(); + + public async Task> GetAllAsync() => throw new NotImplementedException(); + + public async Task AddAsync(Variable entity) => throw new NotImplementedException(); + + public async Task UpdateAsync(Variable entity) => throw new NotImplementedException(); + + public async Task DeleteAsync(Variable entity) => throw new NotImplementedException(); } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/VariableTableRepository.cs b/DMS.Infrastructure/Repositories/VariableTableRepository.cs new file mode 100644 index 0000000..b5d8d66 --- /dev/null +++ b/DMS.Infrastructure/Repositories/VariableTableRepository.cs @@ -0,0 +1,24 @@ +using DMS.Core.Interfaces.Repositories; +using DMS.Core.Models; +using DMS.Infrastructure.Data; +using DMS.Infrastructure.Entities; + +namespace DMS.Infrastructure.Repositories; + +public class VariableTableRepository : BaseRepository, IVariableTableRepository +{ + public VariableTableRepository(SqlSugarDbContext dbContext) + : base(dbContext) + { + } + + public async Task GetByIdAsync(int id) => throw new NotImplementedException(); + + public async Task> GetAllAsync() => throw new NotImplementedException(); + + public async Task AddAsync(VariableTable entity) => throw new NotImplementedException(); + + public async Task UpdateAsync(VariableTable entity) => throw new NotImplementedException(); + + public async Task DeleteAsync(VariableTable entity) => throw new NotImplementedException(); +} \ No newline at end of file diff --git a/DMS.Infrastructure/Services/BaseService.cs b/DMS.Infrastructure/Services/BaseService.cs index 4f24274..1aa8822 100644 --- a/DMS.Infrastructure/Services/BaseService.cs +++ b/DMS.Infrastructure/Services/BaseService.cs @@ -15,17 +15,17 @@ namespace DMS.Infrastructure.Services where TRepository : BaseRepository { protected readonly IMapper _mapper; - protected readonly TRepository _repository; + protected readonly TRepository ServerRepository; /// /// 初始化 BaseService 的新实例。 /// /// AutoMapper 实例,用于对象映射。 - /// 仓储实例,用于数据访问。 - protected BaseService(IMapper mapper, TRepository repository) + /// 仓储实例,用于数据访问。 + protected BaseService(IMapper mapper, TRepository serverRepository) { _mapper = mapper; - _repository = repository; + ServerRepository = serverRepository; } /// @@ -36,7 +36,7 @@ namespace DMS.Infrastructure.Services public virtual async Task AddAsync(TModel model) { var entity = _mapper.Map(model); - return await _repository.AddAsync(entity); + return await ServerRepository.AddAsync(entity); } /// @@ -47,7 +47,7 @@ namespace DMS.Infrastructure.Services public virtual async Task UpdateAsync(TModel model) { var entity = _mapper.Map(model); - return await _repository.UpdateAsync(entity); + return await ServerRepository.UpdateAsync(entity); } /// @@ -58,7 +58,7 @@ namespace DMS.Infrastructure.Services public virtual async Task DeleteAsync(TModel model) { var entity = _mapper.Map(model); - return await _repository.DeleteAsync(entity); + return await ServerRepository.DeleteAsync(entity); } } } diff --git a/DMS.Infrastructure/Services/DatabaseInitializerService.cs b/DMS.Infrastructure/Services/DatabaseInitializerService.cs index bf1f54b..d4a7ba6 100644 --- a/DMS.Infrastructure/Services/DatabaseInitializerService.cs +++ b/DMS.Infrastructure/Services/DatabaseInitializerService.cs @@ -7,10 +7,11 @@ using SqlSugar; using System; using System.Linq; using System.Threading.Tasks; +using DMS.Core.Interfaces; namespace DMS.Infrastructure.Services { - public class DatabaseInitializerService : DMS.Infrastructure.Interfaces.IDatabaseService + public class DatabaseInitializerService : IDatabaseService { private readonly SqlSugarClient _db; diff --git a/DMS.Infrastructure/Services/DeviceService.cs b/DMS.Infrastructure/Services/DeviceService.cs index ee58a78..3c37870 100644 --- a/DMS.Infrastructure/Services/DeviceService.cs +++ b/DMS.Infrastructure/Services/DeviceService.cs @@ -4,7 +4,6 @@ using DMS.Core.Models; using DMS.Infrastructure.Data; using DMS.Infrastructure.Entities; using DMS.Infrastructure.Repositories; -using DMS.Infrastructure.Interfaces; using SqlSugar; using System; using System.Collections.Generic; @@ -12,6 +11,8 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using System.Collections.Concurrent; +using DMS.Core.Interfaces; +using DMS.Core.Interfaces.Repositories; namespace DMS.Infrastructure.Services { @@ -19,7 +20,7 @@ namespace DMS.Infrastructure.Services { private readonly IDeviceRepository _deviceRepository; private readonly IMenuRepository _menuRepository; - private readonly IVarTableRepository _varTableRepository; + private readonly IVariableTableRepository _variableTableRepository; private readonly IMapper _mapper; @@ -60,7 +61,7 @@ namespace DMS.Infrastructure.Services // dbVariableTable.Description = "默认变量表"; // dbVariableTable.DeviceId = addDevice.Id; // dbVariableTable.ProtocolType = addDevice.ProtocolType; - // var dbAddVarTable= await _varTableRepository.AddAsync(dbVariableTable); + // var dbAddVarTable= await _variableTableRepository.AddAsync(dbVariableTable); // if (addDevice.VariableTables==null) // { // addDevice.VariableTables= new List(); diff --git a/DMS.Infrastructure/Services/MqttService.cs b/DMS.Infrastructure/Services/MqttService.cs index afd2ac0..7d84552 100644 --- a/DMS.Infrastructure/Services/MqttService.cs +++ b/DMS.Infrastructure/Services/MqttService.cs @@ -4,7 +4,6 @@ using DMS.Core.Helper; using DMS.Core.Models; using DMS.Infrastructure.Data; using DMS.Infrastructure.Entities; -using DMS.Infrastructure.Interfaces; using DMS.Infrastructure.Repositories; using SqlSugar; using System; @@ -14,9 +13,9 @@ using System.Threading.Tasks; namespace DMS.Infrastructure.Services { - public class MqttService:BaseService + public class MqttService:BaseService { - public MqttService(IMapper mapper, MqttRepository repository) : base(mapper, repository) + public MqttService(IMapper mapper, MqttServerRepository serverRepository) : base(mapper, serverRepository) { } } diff --git a/DMS.Infrastructure/Services/VarDataService.cs b/DMS.Infrastructure/Services/VarDataService.cs index 590f584..1cc73da 100644 --- a/DMS.Infrastructure/Services/VarDataService.cs +++ b/DMS.Infrastructure/Services/VarDataService.cs @@ -13,11 +13,11 @@ using DMS.Infrastructure.Repositories; namespace DMS.Infrastructure.Services { - public class VarDataService : BaseService + public class VarDataService : BaseService { private readonly IMapper _mapper; - public VarDataService(IMapper mapper, VarDataRepository repository) : base(mapper, repository) + public VarDataService(IMapper mapper, VariableRepository repository) : base(mapper, repository) { _mapper = mapper; } diff --git a/DMS.Infrastructure/Services/VarTableService.cs b/DMS.Infrastructure/Services/VarTableService.cs index c3cd46b..d696f39 100644 --- a/DMS.Infrastructure/Services/VarTableService.cs +++ b/DMS.Infrastructure/Services/VarTableService.cs @@ -5,9 +5,9 @@ using DMS.Infrastructure.Repositories; namespace DMS.Infrastructure.Services; -public class VarTableService : BaseService +public class VarTableService : BaseService { - public VarTableService(IMapper mapper, VarTableRepository repository) : base(mapper, repository) + public VarTableService(IMapper mapper, VariableTableRepository repository) : base(mapper, repository) { } } \ No newline at end of file