package com.xueyi.system.emcs.service;

import com.xueyi.common.mqtt.service.MqttMessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yk
 * @description
 * @date 2023-05-10 19:08
 */
@Service
public class LogMqttMessageHandler implements MqttMessageHandler {

    private final static List<String> TOPICS = List.of("/digital_man/heart_beat", "/digital_man/log_upload_notification");

    @Autowired
    private HeartBeatMessageHandler heartBeatMessageHandler;

    @Autowired
    private LogUploadMessageHandler logUploadMessageHandler;

    @Override
    public void handleMessage(String topic, String message) throws Exception{
        // 处理消息的业务逻辑
        System.out.println("收到主题：" + topic + "，消息内：" + message);

        if (TOPICS.contains(topic)){
            if (topic.equalsIgnoreCase("/digital_man/log_upload_notification")){
                logUploadMessageHandler.handleMessage(topic, message);
            } else if (topic.equalsIgnoreCase("/digital_man/heart_beat")){
                heartBeatMessageHandler.handleMessage(topic, message);
            }
        }
    }
}
