package com.fastbee.mq.redischannel.producer;

import com.fastbee.mqttclient.PubMqttCallBack;
import com.fastbee.mqttclient.PubMqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;

@Component
public class IssueInstructionsProducer {

    @Autowired
    private PubMqttClient pubMqttClient;

    @Autowired
    private PubMqttCallBack pubMqttCallBack;

    private final String issueInstructionsTopicTemplate = "hzlink/{0}/{1}/cmd/down";//平台给设备下发指令主题模板
    private final String receiveDataReportResponseTopicTemplate = "hzlink/{0}/{1}/info/reply";//平台回应收到设备上报数据主题模板

    /**
     * 平台给设备下发的指令
     */
    public void issueInstructions(String productId,String deviceNum, String message){

        String topic = MessageFormat.format(issueInstructionsTopicTemplate,productId,deviceNum);
        pubMqttClient.publish(1,true,topic, message);
    }

    /**
     * 平台回应接收到设备数据
     */
    public void receiveDataReportResponse(String productId,String deviceNum, String message){
        String topic = MessageFormat.format(receiveDataReportResponseTopicTemplate,productId,deviceNum);
        pubMqttClient.publish(1,true,topic, message);
    }

}
