2025-09-04 13:40:07 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using DMS.Application.Interfaces;
|
|
|
|
|
|
using DMS.Application.Models;
|
|
|
|
|
|
using DMS.Core.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DMS.Application.Services.Processors;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 负责将变量数据发布到MQTT的处理器。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class MqttPublishProcessor : IVariableProcessor
|
|
|
|
|
|
{
|
2025-09-06 15:19:04 +08:00
|
|
|
|
// private readonly IMqttServiceManager _mqttServiceManager;
|
|
|
|
|
|
|
|
|
|
|
|
// public MqttPublishProcessor(IMqttServiceManager mqttServiceManager)
|
2025-09-04 13:40:07 +08:00
|
|
|
|
// {
|
2025-09-06 15:19:04 +08:00
|
|
|
|
// // _mqttServiceManager = mqttServiceManager;
|
2025-09-04 13:40:07 +08:00
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 处理单个变量上下文,如果有关联的MQTT配置,则将其推送到发送队列。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="context">包含变量及其元数据的上下文对象。</param>
|
|
|
|
|
|
public async Task ProcessAsync(VariableContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
// var variable = context.Data;
|
2025-09-06 15:19:04 +08:00
|
|
|
|
// if (variable?.MqttAliases == null || variable.MqttAliases.Count == 0)
|
2025-09-04 13:40:07 +08:00
|
|
|
|
// {
|
|
|
|
|
|
// return; // 没有关联的MQTT配置,直接返回
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 遍历所有关联的MQTT配置,并将其推入发送队列
|
2025-09-06 15:19:04 +08:00
|
|
|
|
// foreach (var variableMqttAlias in variable.MqttAliases)
|
2025-09-04 13:40:07 +08:00
|
|
|
|
// {
|
2025-09-06 15:19:04 +08:00
|
|
|
|
// // 创建VariableMqtt对象
|
|
|
|
|
|
// var variableMqtt = new VariableMqtt
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Variable = variable,
|
|
|
|
|
|
// Mqtt = variableMqttAlias.MqttServer,
|
|
|
|
|
|
// MqttId = variableMqttAlias.MqttServerId
|
|
|
|
|
|
// };
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 发布变量数据到MQTT服务器
|
|
|
|
|
|
// await _mqttServiceManager.PublishVariableDataAsync(variableMqtt);
|
2025-09-04 13:40:07 +08:00
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|