diff --git a/DMS.Application/Services/DeviceAppService.cs b/DMS.Application/Services/DeviceAppService.cs
index e5759dc..9fbbd88 100644
--- a/DMS.Application/Services/DeviceAppService.cs
+++ b/DMS.Application/Services/DeviceAppService.cs
@@ -8,7 +8,8 @@ using DMS.Core.Interfaces;
namespace DMS.Application.Services;
///
-/// 实现设备管理的应用服务。
+/// 设备应用服务,负责处理设备相关的业务逻辑。
+/// 实现 接口。
///
public class DeviceAppService : IDeviceAppService
{
@@ -18,6 +19,8 @@ public class DeviceAppService : IDeviceAppService
///
/// 构造函数,通过依赖注入获取仓储管理器和AutoMapper实例。
///
+ /// 仓储管理器实例。
+ /// AutoMapper 实例。
public DeviceAppService(IRepositoryManager repoManager, IMapper mapper)
{
_repoManager = repoManager;
@@ -25,8 +28,10 @@ public class DeviceAppService : IDeviceAppService
}
///
- /// 异步根据ID获取设备DTO。
+ /// 异步根据ID获取设备数据传输对象。
///
+ /// 设备ID。
+ /// 设备数据传输对象。
public async Task GetDeviceByIdAsync(int id)
{
var device = await _repoManager.Devices.GetByIdAsync(id);
@@ -34,8 +39,9 @@ public class DeviceAppService : IDeviceAppService
}
///
- /// 异步获取所有设备DTO列表。
+ /// 异步获取所有设备数据传输对象列表。
///
+ /// 设备数据传输对象列表。
public async Task> GetAllDevicesAsync()
{
var devices = await _repoManager.Devices.GetAllAsync();
@@ -45,6 +51,10 @@ public class DeviceAppService : IDeviceAppService
///
/// 异步创建一个新设备及其关联的变量表和菜单(事务性操作)。
///
+ /// 包含设备、变量表和菜单信息的创建数据传输对象。
+ /// 新创建设备的ID。
+ /// 如果添加设备、设备菜单或变量表失败。
+ /// 如果创建设备时发生其他错误。
public async Task CreateDeviceWithDetailsAsync(CreateDeviceWithDetailsDto dto)
{
try
@@ -65,7 +75,7 @@ public class DeviceAppService : IDeviceAppService
if (dto.DeviceMenu != null)
{
var deviceMenu = _mapper.Map(dto.DeviceMenu);
- deviceMenu.ParentId = 2;
+ deviceMenu.ParentId = 2; // 假设父菜单ID为2
deviceMenu.MenuType = MenuType.DeviceMenu;
deviceMenu.TargetId = addDevice.Id;
addDeviceMenu = await _repoManager.Menus.AddAsync(deviceMenu);
@@ -92,7 +102,7 @@ public class DeviceAppService : IDeviceAppService
if (dto.VariableTableMenu != null)
{
var menu = _mapper.Map(dto.VariableTableMenu);
- menu.ParentId = addDeviceMenu.Id;
+ menu.ParentId = addDeviceMenu.Id; // 关联设备菜单作为父级
menu.MenuType = MenuType.VariableTableMenu;
menu.TargetId = addVariableTable.Id;
var addVariableTableMenu = await _repoManager.Menus.AddAsync(menu);
@@ -119,6 +129,9 @@ public class DeviceAppService : IDeviceAppService
///
/// 异步更新一个已存在的设备。
///
+ /// 要更新的设备数据传输对象。
+ /// 受影响的行数。
+ /// 如果找不到设备。
public async Task UpdateDeviceAsync(UpdateDeviceDto deviceDto)
{
await _repoManager.BeginTranAsync();
@@ -137,11 +150,20 @@ public class DeviceAppService : IDeviceAppService
///
/// 异步删除一个设备。
///
+ /// 要删除的设备实体。
+ /// 表示异步操作的任务。
public async Task DeleteDeviceAsync(Device device)
{
await DeleteDeviceByIdAsync(device.Id);
}
+ ///
+ /// 异步根据ID删除一个设备,包括其关联的变量表和菜单(事务性操作)。
+ ///
+ /// 要删除设备的ID。
+ /// 如果删除成功则为 true,否则为 false。
+ /// 如果删除设备失败。
+ /// 如果删除设备时发生其他错误。
public async Task DeleteDeviceByIdAsync(int deviceId)
{
try
@@ -153,8 +175,10 @@ public class DeviceAppService : IDeviceAppService
throw new InvalidOperationException($"删除设备失败:设备ID:{deviceId},请检查设备Id是否存在");
}
+ // 删除关联的变量表
await _repoManager.VariableTables.DeleteByDeviceIdAsync(deviceId);
+ // 删除关联的菜单树
await _repoManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.DeviceMenu,deviceId);
await _repoManager.CommitAsync();
@@ -172,6 +196,9 @@ public class DeviceAppService : IDeviceAppService
///
/// 异步切换设备的激活状态。
///
+ /// 设备的ID。
+ /// 表示异步操作的任务。
+ /// 如果找不到设备。
public async Task ToggleDeviceActiveStateAsync(int id)
{
var device = await _repoManager.Devices.GetByIdAsync(id);
@@ -188,6 +215,8 @@ public class DeviceAppService : IDeviceAppService
///
/// 异步获取指定协议类型的设备列表。
///
+ /// 协议类型。
+ /// 设备数据传输对象列表。
public async Task> GetDevicesByProtocolAsync(ProtocolType protocol)
{
var devices = await _repoManager.Devices.GetAllAsync();
diff --git a/DMS.Application/Services/InitializeService.cs b/DMS.Application/Services/InitializeService.cs
index cd37d7c..eb1a4bd 100644
--- a/DMS.Application/Services/InitializeService.cs
+++ b/DMS.Application/Services/InitializeService.cs
@@ -2,25 +2,41 @@ using DMS.Core.Interfaces.Repositories;
namespace DMS.Application.Services;
+///
+/// 初始化服务,负责应用程序启动时的数据库和菜单初始化。
+///
public class InitializeService
{
private readonly IInitializeRepository _repository;
+ ///
+ /// 构造函数,注入初始化仓储。
+ ///
+ /// 初始化仓储实例。
public InitializeService(IInitializeRepository repository )
{
_repository = repository;
}
+ ///
+ /// 初始化数据库表。
+ ///
public void InitializeTables()
{
_repository.InitializeTables();
}
+ ///
+ /// 初始化数据库表索引。
+ ///
public void InitializeTableIndex()
{
_repository.InitializeTableIndex();
}
+ ///
+ /// 初始化默认菜单。
+ ///
public void InitializeMenus()
{
_repository.InitializeMenus();
diff --git a/DMS.Application/Services/MenuService.cs b/DMS.Application/Services/MenuService.cs
index 9ed7a73..4c0efa7 100644
--- a/DMS.Application/Services/MenuService.cs
+++ b/DMS.Application/Services/MenuService.cs
@@ -7,36 +7,57 @@ using DMS.Application.Interfaces;
namespace DMS.Application.Services;
///
-/// 实现菜单管理的应用服务。
+/// 菜单应用服务,负责处理菜单相关的业务逻辑。
+/// 实现 接口。
///
public class MenuService : IMenuService
{
private readonly IRepositoryManager _repoManager;
private readonly IMapper _mapper;
+ ///
+ /// 构造函数,通过依赖注入获取仓储管理器和AutoMapper实例。
+ ///
+ /// 仓储管理器实例。
+ /// AutoMapper 实例。
public MenuService(IRepositoryManager repoManager, IMapper mapper)
{
_repoManager = repoManager;
_mapper = mapper;
}
+ ///
+ /// 异步根据ID获取菜单数据传输对象。
+ ///
+ /// 菜单ID。
+ /// 菜单数据传输对象。
public async Task GetMenuByIdAsync(int id)
{
var menu = await _repoManager.Menus.GetByIdAsync(id);
return _mapper.Map(menu);
}
+ ///
+ /// 异步获取所有菜单数据传输对象列表。
+ ///
+ /// 菜单数据传输对象列表。
public async Task> GetAllMenusAsync()
{
var menus = await _repoManager.Menus.GetAllAsync();
return _mapper.Map>(menus);
}
+ ///
+ /// 异步创建一个新菜单(事务性操作)。
+ ///
+ /// 要创建的菜单数据传输对象。
+ /// 新创建菜单的ID。
+ /// 如果创建菜单时发生错误。
public async Task CreateMenuAsync(MenuBeanDto menuDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var menu = _mapper.Map(menuDto);
await _repoManager.Menus.AddAsync(menu);
await _repoManager.CommitAsync();
@@ -49,11 +70,17 @@ public class MenuService : IMenuService
}
}
+ ///
+ /// 异步更新一个已存在的菜单(事务性操作)。
+ ///
+ /// 要更新的菜单数据传输对象。
+ /// 表示异步操作的任务。
+ /// 如果找不到菜单或更新菜单时发生错误。
public async Task UpdateMenuAsync(MenuBeanDto menuDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var menu = await _repoManager.Menus.GetByIdAsync(menuDto.Id);
if (menu == null)
{
@@ -70,11 +97,17 @@ public class MenuService : IMenuService
}
}
+ ///
+ /// 异步删除一个菜单(事务性操作)。
+ ///
+ /// 要删除菜单的ID。
+ /// 表示异步操作的任务。
+ /// 如果删除菜单时发生错误。
public async Task DeleteMenuAsync(int id)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
await _repoManager.Menus.DeleteByIdAsync(id);
await _repoManager.CommitAsync();
}
diff --git a/DMS.Application/Services/MqttAliasAppService.cs b/DMS.Application/Services/MqttAliasAppService.cs
index e0f072f..e936a20 100644
--- a/DMS.Application/Services/MqttAliasAppService.cs
+++ b/DMS.Application/Services/MqttAliasAppService.cs
@@ -7,36 +7,57 @@ using DMS.Application.Interfaces;
namespace DMS.Application.Services;
///
-/// 实现MQTT别名管理的应用服务。
+/// MQTT别名应用服务,负责处理MQTT别名相关的业务逻辑。
+/// 实现 接口。
///
public class MqttAliasAppService : IMqttAliasAppService
{
private readonly IRepositoryManager _repoManager;
private readonly IMapper _mapper;
+ ///
+ /// 构造函数,通过依赖注入获取仓储管理器和AutoMapper实例。
+ ///
+ /// 仓储管理器实例。
+ /// AutoMapper 实例。
public MqttAliasAppService(IRepositoryManager repoManager, IMapper mapper)
{
_repoManager = repoManager;
_mapper = mapper;
}
+ ///
+ /// 异步根据ID获取MQTT别名数据传输对象。
+ ///
+ /// MQTT别名ID。
+ /// MQTT别名数据传输对象。
public async Task GetMqttAliasByIdAsync(int id)
{
var mqttAlias = await _repoManager.VariableMqttAliases.GetByIdAsync(id);
return _mapper.Map(mqttAlias);
}
+ ///
+ /// 异步获取所有MQTT别名数据传输对象列表。
+ ///
+ /// MQTT别名数据传输对象列表。
public async Task> GetAllMqttAliasesAsync()
{
var mqttAliases = await _repoManager.VariableMqttAliases.GetAllAsync();
return _mapper.Map>(mqttAliases);
}
+ ///
+ /// 异步创建一个新MQTT别名(事务性操作)。
+ ///
+ /// 要创建的MQTT别名数据传输对象。
+ /// 新创建MQTT别名的ID。
+ /// 如果创建MQTT别名时发生错误。
public async Task CreateMqttAliasAsync(VariableMqttAliasDto mqttAliasDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var mqttAlias = _mapper.Map(mqttAliasDto);
await _repoManager.VariableMqttAliases.AddAsync(mqttAlias);
await _repoManager.CommitAsync();
@@ -49,11 +70,17 @@ public class MqttAliasAppService : IMqttAliasAppService
}
}
+ ///
+ /// 异步更新一个已存在的MQTT别名(事务性操作)。
+ ///
+ /// 要更新的MQTT别名数据传输对象。
+ /// 表示异步操作的任务。
+ /// 如果找不到MQTT别名或更新MQTT别名时发生错误。
public async Task UpdateMqttAliasAsync(VariableMqttAliasDto mqttAliasDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var mqttAlias = await _repoManager.VariableMqttAliases.GetByIdAsync(mqttAliasDto.Id);
if (mqttAlias == null)
{
@@ -70,11 +97,17 @@ public class MqttAliasAppService : IMqttAliasAppService
}
}
+ ///
+ /// 异步删除一个MQTT别名(事务性操作)。
+ ///
+ /// 要删除MQTT别名的ID。
+ /// 表示异步操作的任务。
+ /// 如果删除MQTT别名时发生错误。
public async Task DeleteMqttAliasAsync(int id)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
await _repoManager.VariableMqttAliases.DeleteByIdAsync(id);
await _repoManager.CommitAsync();
}
diff --git a/DMS.Application/Services/MqttAppService.cs b/DMS.Application/Services/MqttAppService.cs
index ba89aec..634027f 100644
--- a/DMS.Application/Services/MqttAppService.cs
+++ b/DMS.Application/Services/MqttAppService.cs
@@ -7,36 +7,57 @@ using DMS.Application.Interfaces;
namespace DMS.Application.Services;
///
-/// 实现MQTT服务器管理的应用服务。
+/// MQTT应用服务,负责处理MQTT服务器相关的业务逻辑。
+/// 实现 接口。
///
public class MqttAppService : IMqttAppService
{
private readonly IRepositoryManager _repoManager;
private readonly IMapper _mapper;
+ ///
+ /// 构造函数,通过依赖注入获取仓储管理器和AutoMapper实例。
+ ///
+ /// 仓储管理器实例。
+ /// AutoMapper 实例。
public MqttAppService(IRepositoryManager repoManager, IMapper mapper)
{
_repoManager = repoManager;
_mapper = mapper;
}
+ ///
+ /// 异步根据ID获取MQTT服务器数据传输对象。
+ ///
+ /// MQTT服务器ID。
+ /// MQTT服务器数据传输对象。
public async Task GetMqttServerByIdAsync(int id)
{
var mqttServer = await _repoManager.MqttServers.GetByIdAsync(id);
return _mapper.Map(mqttServer);
}
+ ///
+ /// 异步获取所有MQTT服务器数据传输对象列表。
+ ///
+ /// MQTT服务器数据传输对象列表。
public async Task> GetAllMqttServersAsync()
{
var mqttServers = await _repoManager.MqttServers.GetAllAsync();
return _mapper.Map>(mqttServers);
}
+ ///
+ /// 异步创建一个新MQTT服务器(事务性操作)。
+ ///
+ /// 要创建的MQTT服务器数据传输对象。
+ /// 新创建MQTT服务器的ID。
+ /// 如果创建MQTT服务器时发生错误。
public async Task CreateMqttServerAsync(MqttServerDto mqttServerDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var mqttServer = _mapper.Map(mqttServerDto);
await _repoManager.MqttServers.AddAsync(mqttServer);
await _repoManager.CommitAsync();
@@ -49,11 +70,17 @@ public class MqttAppService : IMqttAppService
}
}
+ ///
+ /// 异步更新一个已存在的MQTT服务器(事务性操作)。
+ ///
+ /// 要更新的MQTT服务器数据传输对象。
+ /// 表示异步操作的任务。
+ /// 如果找不到MQTT服务器或更新MQTT服务器时发生错误。
public async Task UpdateMqttServerAsync(MqttServerDto mqttServerDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var mqttServer = await _repoManager.MqttServers.GetByIdAsync(mqttServerDto.Id);
if (mqttServer == null)
{
@@ -70,11 +97,17 @@ public class MqttAppService : IMqttAppService
}
}
+ ///
+ /// 异步删除一个MQTT服务器(事务性操作)。
+ ///
+ /// 要删除MQTT服务器的ID。
+ /// 表示异步操作的任务。
+ /// 如果删除MQTT服务器时发生错误。
public async Task DeleteMqttServerAsync(int id)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
await _repoManager.MqttServers.DeleteByIdAsync(id);
await _repoManager.CommitAsync();
}
diff --git a/DMS.Application/Services/VariableAppService.cs b/DMS.Application/Services/VariableAppService.cs
index dc9be4e..6a7f7e9 100644
--- a/DMS.Application/Services/VariableAppService.cs
+++ b/DMS.Application/Services/VariableAppService.cs
@@ -7,36 +7,57 @@ using DMS.Application.Interfaces;
namespace DMS.Application.Services;
///
-/// 实现变量管理的应用服务。
+/// 变量应用服务,负责处理变量相关的业务逻辑。
+/// 实现 接口。
///
public class VariableAppService : IVariableAppService
{
private readonly IRepositoryManager _repoManager;
private readonly IMapper _mapper;
+ ///
+ /// 构造函数,通过依赖注入获取仓储管理器和AutoMapper实例。
+ ///
+ /// 仓储管理器实例。
+ /// AutoMapper 实例。
public VariableAppService(IRepositoryManager repoManager, IMapper mapper)
{
_repoManager = repoManager;
_mapper = mapper;
}
+ ///
+ /// 异步根据ID获取变量数据传输对象。
+ ///
+ /// 变量ID。
+ /// 变量数据传输对象。
public async Task GetVariableByIdAsync(int id)
{
var variable = await _repoManager.Variables.GetByIdAsync(id);
return _mapper.Map(variable);
}
+ ///
+ /// 异步获取所有变量数据传输对象列表。
+ ///
+ /// 变量数据传输对象列表。
public async Task> GetAllVariablesAsync()
{
var variables = await _repoManager.Variables.GetAllAsync();
return _mapper.Map>(variables);
}
+ ///
+ /// 异步创建一个新变量(事务性操作)。
+ ///
+ /// 要创建的变量数据传输对象。
+ /// 新创建变量的ID。
+ /// 如果创建变量时发生错误。
public async Task CreateVariableAsync(VariableDto variableDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var variable = _mapper.Map(variableDto);
await _repoManager.Variables.AddAsync(variable);
await _repoManager.CommitAsync();
@@ -49,11 +70,17 @@ public class VariableAppService : IVariableAppService
}
}
+ ///
+ /// 异步更新一个已存在的变量(事务性操作)。
+ ///
+ /// 要更新的变量数据传输对象。
+ /// 表示异步操作的任务。
+ /// 如果找不到变量或更新变量时发生错误。
public async Task UpdateVariableAsync(VariableDto variableDto)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
var variable = await _repoManager.Variables.GetByIdAsync(variableDto.Id);
if (variable == null)
{
@@ -70,11 +97,17 @@ public class VariableAppService : IVariableAppService
}
}
+ ///
+ /// 异步删除一个变量(事务性操作)。
+ ///
+ /// 要删除变量的ID。
+ /// 表示异步操作的任务。
+ /// 如果删除变量时发生错误。
public async Task DeleteVariableAsync(int id)
{
try
{
- _repoManager.BeginTranAsync();
+ await _repoManager.BeginTranAsync();
await _repoManager.Variables.DeleteByIdAsync(id);
await _repoManager.CommitAsync();
}
diff --git a/DMS.Application/Services/VariableTableAppService.cs b/DMS.Application/Services/VariableTableAppService.cs
index 97af599..a688efa 100644
--- a/DMS.Application/Services/VariableTableAppService.cs
+++ b/DMS.Application/Services/VariableTableAppService.cs
@@ -9,29 +9,53 @@ using DMS.Core.Enums;
namespace DMS.Application.Services
{
+ ///
+ /// 变量表应用服务,负责处理变量表相关的业务逻辑。
+ /// 实现 接口。
+ ///
public class VariableTableAppService : IVariableTableAppService
{
private readonly IRepositoryManager _repositoryManager;
private readonly IMapper _mapper;
+ ///
+ /// 构造函数,注入仓储管理器和AutoMapper。
+ ///
+ /// 仓储管理器实例。
+ /// AutoMapper 实例。
public VariableTableAppService(IRepositoryManager repositoryManager, IMapper mapper)
{
_repositoryManager = repositoryManager;
_mapper = mapper;
}
+ ///
+ /// 异步根据ID获取变量表。
+ ///
+ /// 变量表ID。
+ /// 变量表数据传输对象。
public async Task GetVariableTableByIdAsync(int id)
{
var variableTable = await _repositoryManager.VariableTables.GetByIdAsync(id);
return _mapper.Map(variableTable);
}
+ ///
+ /// 异步获取所有变量表。
+ ///
+ /// 变量表数据传输对象列表。
public async Task> GetAllVariableTablesAsync()
{
var variableTables = await _repositoryManager.VariableTables.GetAllAsync();
return _mapper.Map>(variableTables);
}
+ ///
+ /// 异步创建变量表,并可选择性地创建关联菜单。
+ ///
+ /// 包含变量表和菜单信息的创建数据传输对象。
+ /// 创建后的变量表数据传输对象。
+ /// 如果添加变量表失败或找不到设备菜单。
public async Task CreateVariableTableAsync(CreateVariableTableWithMenuDto createDto)
{
await _repositoryManager.BeginTranAsync();
@@ -48,6 +72,7 @@ namespace DMS.Application.Services
if (createDto.Menu!=null)
{
+ // 获取设备菜单,作为变量表菜单的父级
var deviceMenu
= await _repositoryManager.Menus.GetMenuByTargetIdAsync(
MenuType.DeviceMenu, createDto.DeviceId);
@@ -56,6 +81,7 @@ namespace DMS.Application.Services
throw new ApplicationException($"添加变量表菜单时,找不到设备ID:{createDto.DeviceId},请检查。");
}
+ // 映射菜单实体并设置关联信息
var menu = _mapper.Map(createDto.Menu);
menu.ParentId = deviceMenu.Id;
menu.TargetId = createdVariableTable.Id;
@@ -76,12 +102,22 @@ namespace DMS.Application.Services
}
}
+ ///
+ /// 异步更新变量表。
+ ///
+ /// 要更新的变量表数据传输对象。
+ /// 表示异步操作的任务。
public async Task UpdateVariableTableAsync(VariableTableDto variableTableDto)
{
var variableTable = _mapper.Map(variableTableDto);
await _repositoryManager.VariableTables.UpdateAsync(variableTable);
}
+ ///
+ /// 异步根据ID删除变量表。
+ ///
+ /// 要删除的变量表ID。
+ /// 表示异步操作的任务。
public async Task DeleteVariableTableAsync(int id)
{
await _repositoryManager.VariableTables.DeleteByIdAsync(id);