feat: 菜单管理重构及MQTT服务器功能增强

This commit is contained in:
2025-10-05 17:07:17 +08:00
parent 80ea47e627
commit 6b55211dbf
23 changed files with 287 additions and 184 deletions

View File

@@ -19,18 +19,21 @@ public class MqttManagementService : IMqttManagementService
private readonly IEventService _eventService;
private readonly IMapper _mapper;
private readonly IDataProcessingService _dataProcessingService;
private readonly IMenuManagementService _menuManagementService;
public MqttManagementService(IMqttAppService mqttAppService,
IAppDataStorageService appDataStorageService,
IEventService eventService,
IMapper mapper,
IDataProcessingService dataProcessingService)
IDataProcessingService dataProcessingService,
IMenuManagementService menuManagementService)
{
_mqttAppService = mqttAppService;
_appDataStorageService = appDataStorageService;
_eventService = eventService;
_mapper = mapper;
_dataProcessingService = dataProcessingService;
_menuManagementService = menuManagementService;
}
/// <summary>
@@ -49,27 +52,6 @@ public class MqttManagementService : IMqttManagementService
return await _mqttAppService.GetAllMqttServersAsync();
}
/// <summary>
/// 异步创建一个新的MQTT服务器。
/// </summary>
public async Task<MqttServerDto> CreateMqttServerAsync(MqttServerDto mqttServerDto)
{
var result = await _mqttAppService.CreateMqttServerAsync(mqttServerDto);
// 创建成功后将MQTT服务器添加到内存中
if (result > 0)
{
mqttServerDto.Id = result; // 假设返回的ID是新创建的
if (_appDataStorageService.MqttServers.TryAdd(mqttServerDto.Id, mqttServerDto))
{
_eventService.RaiseMqttServerChanged(
this, new MqttServerChangedEventArgs(ActionChangeType.Added, mqttServerDto));
}
}
return mqttServerDto;
}
/// <summary>
/// 异步更新一个已存在的MQTT服务器。
/// </summary>
@@ -163,6 +145,32 @@ public class MqttManagementService : IMqttManagementService
return result;
}
/// <summary>
/// 异步创建MQTT服务器及其菜单项。
/// </summary>
public async Task<MqttServerDto> CreateMqttServerAsync(MqttServerDto mqttServerDto)
{
// 首先创建MQTT服务器
var mqttServerId = await _mqttAppService.CreateMqttServerAsync(mqttServerDto);
if (mqttServerId > 0)
{
mqttServerDto.Id = mqttServerId;
// 将MQTT服务器添加到内存中
if (_appDataStorageService.MqttServers.TryAdd(mqttServerDto.Id, mqttServerDto))
{
_eventService.RaiseMqttServerChanged(
this, new MqttServerChangedEventArgs(ActionChangeType.Added, mqttServerDto));
}
}
return mqttServerDto; // 返回null表示创建失败
}
/// <summary>
/// 获取发生变化的属性列表
/// </summary>