forked from I3-YF/i3plus-mes-pcn-yfai
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSortShippingCheckService.javatags/yfai-pcn-ext-v1.0
commit
9795b07de1
@ -0,0 +1,38 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.api.mqtt;
|
||||||
|
|
||||||
|
public interface MqttService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加订阅主题
|
||||||
|
*
|
||||||
|
* @param topic 主题名称
|
||||||
|
*/
|
||||||
|
void addTopic(String topic);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消订阅主题
|
||||||
|
*
|
||||||
|
* @param topic 主题名称
|
||||||
|
*/
|
||||||
|
void removeTopic(String topic);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布主题消息内容
|
||||||
|
*
|
||||||
|
* @param msgContent
|
||||||
|
* @param topic
|
||||||
|
*/
|
||||||
|
void publish(String msgContent, String topic);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布主题消息内容
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void unconnect();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布主题消息内容
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void connect();
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@Api(value = "MyMqttController", tags = {"MQTT相关操作接口"})
|
||||||
|
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mqtt")
|
||||||
|
@Slf4j
|
||||||
|
public class PcnMqttController {
|
||||||
|
@Autowired
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.mqtt;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.api.mqtt.MqttService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.mqtt.PcnMqttClient;
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MqttServiceImpl implements MqttService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PcnMqttClient myMqttClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTopic(String topic) {
|
||||||
|
myMqttClient.subscribe(topic);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeTopic(String topic) {
|
||||||
|
myMqttClient.cleanTopic(topic);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(String msgContent, String topic) {
|
||||||
|
/*try {
|
||||||
|
myMqttClient.unconnect();
|
||||||
|
} catch (MqttException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}*/
|
||||||
|
/* //MyXxxMqttMsg 转Json
|
||||||
|
EquipLogMqttMsg myXxxMqttMsg = new EquipLogMqttMsg();
|
||||||
|
myXxxMqttMsg.setContent(msgContent);
|
||||||
|
myXxxMqttMsg.setTimestamp(System.currentTimeMillis());
|
||||||
|
// TODO Md5值
|
||||||
|
myXxxMqttMsg.setMd5(UUID.randomUUID().toString());
|
||||||
|
String msgJson = JSON.toJSONString(myXxxMqttMsg);
|
||||||
|
|
||||||
|
//发布消息
|
||||||
|
myMqttClient.publish(msgJson, topic);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unconnect() {
|
||||||
|
try {
|
||||||
|
myMqttClient.unconnect();
|
||||||
|
} catch (MqttException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void connect() {
|
||||||
|
try {
|
||||||
|
myMqttClient.connect();
|
||||||
|
} catch (MqttException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.pojo.mqtt;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EquipLogMqttMsg implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8303548938481407659L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备id
|
||||||
|
*/
|
||||||
|
private String PTCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点位地址
|
||||||
|
*/
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点位地址
|
||||||
|
*/
|
||||||
|
private String tagAddress;
|
||||||
|
/**
|
||||||
|
* 值
|
||||||
|
*/
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间戳
|
||||||
|
*/
|
||||||
|
private String time;
|
||||||
|
}
|
Loading…
Reference in New Issue