package com.njcn.csdevice.handler;


import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
import com.github.tocrhz.mqtt.annotation.Payload;
import com.njcn.common.pojo.dto.DeviceLogDTO;
import com.njcn.common.utils.PubUtils;
import com.njcn.cssystem.api.CsLogsFeignClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @author xuyang
 * @version 1.0.0
 * @date 2023年06月10日 09:41
 */
@Slf4j
@Component
@AllArgsConstructor
public class MqttMessageHandler {

    private final CsLogsFeignClient csLogsFeignClient;

    /**
     * 插入devicelog
     */
    @MqttSubscribe(value = "/deviceLog")
    public void responseRtData(String topic, MqttMessage message, @Payload String payload) {
        DeviceLogDTO deviceLogDTO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),DeviceLogDTO.class);
        csLogsFeignClient.addUserLog(deviceLogDTO);
    }


}
