package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.mqtt;

import cn.estsh.i3plus.ext.mes.pcn.api.mqtt.MqttService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *
 */
@RestController
@Api(value = "MyMqttController", tags = {"MQTT相关操作接口"})
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mqtt")
@Slf4j
public class PcnMqttController {

    @Autowired(required = false)
    private MqttService mqttService;

    @GetMapping("/addTopic")
    @ApiOperation(value = "添加订阅主题接口")
    public void addTopic(String topic) {
        mqttService.addTopic(topic);
    }

    @GetMapping("/removeTopic")
    @ApiOperation(value = "取消订阅主题接口")
    public void removeTopic(String topic) {
        mqttService.removeTopic(topic);
    }

    @PostMapping("/public")
    @ApiOperation(value = "发布主题消息内容接口")
    public void publicTopic(String msgContent, String topic) {
        mqttService.publish(msgContent, topic);
    }


    @PostMapping("/unconnect")
    @ApiOperation(value = "退出连接接口")
    public void unconnect() {
        mqttService.unconnect();
    }

    @PostMapping("/connect")
    @ApiOperation(value = "手动连接接口")
    public void connect() {
        mqttService.connect();
    }


    @PostMapping("/testSend")
    @ApiOperation(value = "批量发送")
    public void testSend() {
        mqttService.testSend();
    }
    @PostMapping("/testSendList")
    @ApiOperation(value = "批量发送")
    public void testSendList() {
        mqttService.testSendList();
    }

}
