package com.fastbee.data.controller.gis.mqtt;

import cn.hutool.json.JSONUtil;
import com.fastbee.mqttclient.PubMqttCallBack;
import com.fastbee.mqttclient.PubMqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/mqtt")
public class MqttTest {

    @Autowired
    private PubMqttClient pubMqttClient;

    @Autowired
    private PubMqttCallBack pubMqttCallBack;

    /**
     * 测试平台mqtt下发指令
     */
    @GetMapping("/publish")
    public String test(){
        Map<String,Object> param = new HashMap<>();
        param.put("cmd",700);
        Map<String,Object> data = new HashMap<>();
        data.put("status",0);
        param.put("data",data);
        pubMqttClient.publish(1,true,"/10086/155/cmd/down", JSONUtil.toJsonStr(param));
        return "ok";
    }

    /**
     * 测试创建mqtt客户端
     */
    @GetMapping("/subscribe")
    public String test2(){
//        pubMqttClient
        return "test2";
    }

}
