diff --git a/DMS.Application/Services/DataLoaderService.cs b/DMS.Application/Services/DataLoaderService.cs index 464e25b..890f61c 100644 --- a/DMS.Application/Services/DataLoaderService.cs +++ b/DMS.Application/Services/DataLoaderService.cs @@ -4,6 +4,7 @@ using DMS.Application.Interfaces; using DMS.Core.Interfaces; using System.Collections.Concurrent; using DMS.Application.DTOs.Events; +using DMS.Core.Models; namespace DMS.Application.Services; @@ -85,6 +86,20 @@ public class DataLoaderService : IDataLoaderService foreach (var variableMqttAliasDto in variableMqttAliasDtos) { _appDataStorageService.VariableMqttAliases.TryAdd(variableMqttAliasDto.Id, variableMqttAliasDto); + if (_appDataStorageService.Variables.TryGetValue(variableMqttAliasDto.VariableId, out var variable)) + { + variableMqttAliasDto.Variable = _mapper.Map(variable); + variable.MqttAliases?.Add(variableMqttAliasDto); + } + + if (_appDataStorageService.MqttServers.TryGetValue(variableMqttAliasDto.MqttServerId, out var mqttServer)) + { + variableMqttAliasDto.MqttServer = _mapper.Map(mqttServer); + variableMqttAliasDto.MqttServerName = variableMqttAliasDto.MqttServer.ServerName; + mqttServer.VariableAliases?.Add(variableMqttAliasDto); + } + + } } diff --git a/DMS.Infrastructure/Services/MqttServiceManager.cs b/DMS.Infrastructure/Services/MqttServiceManager.cs index d4ad501..8cdea04 100644 --- a/DMS.Infrastructure/Services/MqttServiceManager.cs +++ b/DMS.Infrastructure/Services/MqttServiceManager.cs @@ -238,9 +238,10 @@ namespace DMS.Infrastructure.Services try { var topic = context.MqttServer.PublishTopic; - var payload = variableMqtt.Variable.DataValue?.ToString() ?? string.Empty; - await context.MqttService.PublishAsync(topic, payload); + var sendMsg = $"{variableMqtt.Variable.Name}:{variableMqtt.Variable.DataValue}"; + + await context.MqttService.PublishAsync(topic, sendMsg); _logger.LogDebug("成功向MQTT服务器 {ServerName} 发布变量 {VariableName} 的数据", context.MqttServer.ServerName, variableMqtt.Variable.Name); } diff --git a/DMS.WPF/Profiles/MappingProfile.cs b/DMS.WPF/Profiles/MappingProfile.cs index 24ab14a..274b24c 100644 --- a/DMS.WPF/Profiles/MappingProfile.cs +++ b/DMS.WPF/Profiles/MappingProfile.cs @@ -24,6 +24,7 @@ namespace DMS.WPF.Profiles .ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap();