设备上电审核基本信息上报接口,逻辑完善
This commit is contained in:
@ -0,0 +1,37 @@
|
||||
package com.fastbee.data.controller.gis.mqtt;
|
||||
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/mqtt")
|
||||
public class MqttTest {
|
||||
|
||||
@Autowired
|
||||
private PubMqttClient pubMqttClient;
|
||||
|
||||
@Autowired
|
||||
private PubMqttCallBack pubMqttCallBack;
|
||||
|
||||
/**
|
||||
* 测试平台mqtt发布消息
|
||||
*/
|
||||
@GetMapping("/publish")
|
||||
public String test(){
|
||||
pubMqttClient.publish(1,true,"/topic/test","mqtt测试主题发布消息!");
|
||||
return "test";
|
||||
}
|
||||
/**
|
||||
* 测试创建mqtt客户端
|
||||
*/
|
||||
@GetMapping("/subscribe")
|
||||
public String test2(){
|
||||
// pubMqttClient
|
||||
return "test2";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.fastbee.data.controller.sse;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.AjaxResultPro;
|
||||
import com.fastbee.iot.domain.DeviceReportInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@RestController
|
||||
@RequestMapping("/sse")
|
||||
@Slf4j
|
||||
@CrossOrigin(origins = "*")
|
||||
public class DeviceReportSSEController extends BaseController {
|
||||
private final Map<String, SseEmitter> emitters = new ConcurrentHashMap<>();//用户消息推送集合
|
||||
|
||||
/**
|
||||
* 与客户端建立http长链接
|
||||
*/
|
||||
@PostMapping(value = "/device/init",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter getReport() throws IOException {
|
||||
SseEmitter emitter= new SseEmitter(0L);
|
||||
emitters.put("device-init",emitter);
|
||||
emitter.send(JSONUtil.toJsonStr(Message.builder().event(1).content("连接成功!").build()));
|
||||
return emitter;
|
||||
}
|
||||
|
||||
@PostMapping("/device/init/new")
|
||||
public AjaxResultPro sendMsg(@RequestBody DeviceReportInfo reportInfo) {
|
||||
try{
|
||||
SseEmitter emitter = emitters.get("device-init");
|
||||
if(emitter==null){
|
||||
return AjaxResultPro.error("审核员离线!请到管理后台打开设备初始化页面!");
|
||||
}
|
||||
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build()));
|
||||
return AjaxResultPro.success();
|
||||
}catch (Exception e){
|
||||
log.error("发送消息失败",e);
|
||||
return AjaxResultPro.error("系统错误!");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/device/init/new/remove")
|
||||
public AjaxResultPro removeMsg() {
|
||||
emitters.clear();
|
||||
return AjaxResultPro.success();
|
||||
}
|
||||
|
||||
@PostMapping("/device/init/new/text")
|
||||
public void sendMsgText(@RequestBody DeviceReportInfo reportInfo) throws IOException {
|
||||
SseEmitter emitter = emitters.get("device-init");
|
||||
DeviceReportInfo deviceReportInfo = new DeviceReportInfo();
|
||||
deviceReportInfo.setImei("10086");
|
||||
deviceReportInfo.setIccid("10086");
|
||||
deviceReportInfo.setMcuId("wqewqewq");
|
||||
deviceReportInfo.setBspType("iwqjriqw");
|
||||
deviceReportInfo.setLteType("rui");
|
||||
deviceReportInfo.setMcuType("mcu");
|
||||
deviceReportInfo.setMcuFw("1.0.0");
|
||||
deviceReportInfo.setLteFw("opodaojdao");
|
||||
deviceReportInfo.setLcdManufacturer(1L);
|
||||
deviceReportInfo.setVoiceManufacturer(1L);
|
||||
deviceReportInfo.setFramModel("BTOOO");
|
||||
deviceReportInfo.setReplaceManufacturer(1L);
|
||||
deviceReportInfo.setTestRecord("test");
|
||||
if(emitter!=null){
|
||||
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(deviceReportInfo).build()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.fastbee.data.controller.sse;
|
||||
|
||||
import com.fastbee.iot.domain.DeviceReportInfo;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author mijiupro
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class Message {
|
||||
private String content;
|
||||
private Integer event;
|
||||
private DeviceReportInfo data;
|
||||
}
|
Reference in New Issue
Block a user