package com.yfd.platform.component.mqtt;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yfd.platform.modules.basedata.domain.Substation;
import com.yfd.platform.modules.basedata.domain.WeatherLog;
import com.yfd.platform.modules.basedata.service.ISubstationService;
import com.yfd.platform.modules.basedata.service.IWeatherLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.messaging.Message;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Set;

/**
 * MqttTopicHandle
 *
 * @date 2022/8/24
 */
@MqttService
public class MqttTopicHandle {

    public static MqttTopicHandle mqttTopicHandle;

    @Resource
    private ISubstationService substationService;



    @PostConstruct
    public void init() {
        mqttTopicHandle = this;
        mqttTopicHandle.substationService = this.substationService;

    }


    public static final Logger log = LoggerFactory.getLogger(MqttTopicHandle.class);


    // 更新数据库中气象实时数据
//    @MqttTopic("nodes/java/user/alert")
//    public void alert(Message<?> message) {
//        //更新数据库中气象数据
//        log.info("up=" + message.getPayload());
//
//    }

    @MqttTopic("nodes/java/user/heartbeat")
    public void heartbeat(Message<?> message) {
        log.info("收到心跳:"+message.toString());

    }


    // 这里就不自动订阅该主题了 (参考示例)
    @MqttTopic(value = "topic/1/2/down",autoSubscribe = false)
    public void down(Message<?> message){
        log.info("down="+message.getPayload());
    }

}

