|
@@ -1,14 +1,14 @@
|
|
|
-package com.zy.bms.config.mqtt;
|
|
|
+package com.zy.omp.config.mqtt;
|
|
|
|
|
|
-import com.zy.bms.common.Constant;
|
|
|
-import com.zy.bms.common.dto.MqttMsgDto;
|
|
|
-import com.zy.bms.common.exception.ApiRuntimeException;
|
|
|
-import com.zy.bms.model.*;
|
|
|
-import com.zy.bms.service.*;
|
|
|
-import com.zy.bms.utils.*;
|
|
|
-import com.zy.bms.utils.CoordTransformUtil;
|
|
|
-import com.zy.bms.utils.GaoDeApiUtil;
|
|
|
-import com.zy.bms.websocket.WebSocketServer;
|
|
|
+import com.zy.omp.common.Constant;
|
|
|
+import com.zy.omp.pojo.dto.MqttMsgDto;
|
|
|
+import com.zy.omp.common.exception.ApiRuntimeException;
|
|
|
+import com.zy.omp.model.*;
|
|
|
+import com.zy.omp.service.*;
|
|
|
+import com.zy.omp.utils.*;
|
|
|
+import com.zy.omp.utils.CoordTransformUtil;
|
|
|
+import com.zy.omp.utils.GaoDeApiUtil;
|
|
|
+import com.zy.omp.websocket.WebSocketServer;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -50,45 +50,98 @@ public class MqttCallbackHandler {
|
|
|
mqttLogService.saveLog(topic, payload, 0);
|
|
|
//消息返回JSON转Object
|
|
|
MqttMsgDto msgDto = MqttMsgDto.parse(payload);
|
|
|
- //根据报文标识代码 M 处理消息
|
|
|
- switch (msgDto.getM()) {
|
|
|
- //设备端注册报文
|
|
|
- case Constant.M_CODE_REGISTER: {
|
|
|
- registerDeviceHandler(msgDto);
|
|
|
- break;
|
|
|
+ //路牌项目
|
|
|
+ if (topic.startsWith("$regdtx2") || topic.startsWith("$dtxlp")) {
|
|
|
+ switch (msgDto.getM()) {
|
|
|
+ //设备端注册报文
|
|
|
+ case Constant.M_CODE_REGISTER: {
|
|
|
+ registerHandler_LP(msgDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 设备位置信息上报
|
|
|
+ case Constant.M_CODE_UPLOAD_LOCATION: {
|
|
|
+ uploadLocationHandler(msgDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //设备上传通话记录
|
|
|
+ case Constant.M_CODE_UPLOAD_CALL_RECORD: {
|
|
|
+ uploadCallRecordsHandler(msgDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- // 设备位置信息上报
|
|
|
- case Constant.M_CODE_UPLOAD_LOCATION: {
|
|
|
- uploadLocationHandler(msgDto);
|
|
|
- break;
|
|
|
+ }
|
|
|
+ //老人机项目
|
|
|
+ else {
|
|
|
+ switch (msgDto.getM()) {
|
|
|
+ //设备端注册报文
|
|
|
+ case Constant.M_CODE_REGISTER: {
|
|
|
+ registerHandler_OMP(msgDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 设备位置信息上报
|
|
|
+ case Constant.M_CODE_UPLOAD_LOCATION: {
|
|
|
+ uploadLocationHandler(msgDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //设备上传通话记录
|
|
|
+ case Constant.M_CODE_UPLOAD_CALL_RECORD: {
|
|
|
+ uploadCallRecordsHandler(msgDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- //设备上传通话记录
|
|
|
- case Constant.M_CODE_UPLOAD_CALL_RECORD: {
|
|
|
- uploadCallRecordsHandler(msgDto);
|
|
|
- break;
|
|
|
+ //转发消息至网页,忽略注册的报文
|
|
|
+ if (!topic.equals(Constant.TOPIC_REGISTER_SERVER)) {
|
|
|
+ webSocketServer.massMessage(msgDto.getDeviceId(), payload);
|
|
|
}
|
|
|
}
|
|
|
- //转发消息至网页,忽略注册的报文
|
|
|
- if (!topic.equals(Constant.TOPIC_REGISTER_SERVER)) {
|
|
|
- webSocketServer.massMessage(msgDto.getDeviceId(), payload);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注册设备
|
|
|
+ * 老人机
|
|
|
+ */
|
|
|
+ private void registerHandler_OMP(MqttMsgDto obj) {
|
|
|
+ String num = obj.getString("regnum");
|
|
|
+ //查询数据库中是否有此设备
|
|
|
+ Device device = deviceService.getByNum(num);
|
|
|
+ //没有该设备,保存至数据库
|
|
|
+ if (device == null) {
|
|
|
+ device = new Device();
|
|
|
+ device.setNum(num);
|
|
|
+ device.setClientId(Constant.OLD_PHONE_DEVICE_ID_PREFIX + num);
|
|
|
+ device.setPassword(MD5Util.MD5Encode(num));
|
|
|
+ deviceService.save(device);
|
|
|
+ SetBase setBase = new SetBase();
|
|
|
+ setBase.setDeviceId(device.getClientId());
|
|
|
+ setBaseService.save(setBase);
|
|
|
}
|
|
|
+ //mqtt服务器注册用户
|
|
|
+ rabbitMQApi.registerMqtt(device.getClientId(), device.getPassword());
|
|
|
+ //发送消息
|
|
|
+ setService.returnCode_OMP(device);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 注册设备
|
|
|
+ * 路牌
|
|
|
*/
|
|
|
- private void registerDeviceHandler(MqttMsgDto obj) {
|
|
|
+ private void registerHandler_LP(MqttMsgDto obj) {
|
|
|
String num = obj.getString("regnum");
|
|
|
//查询数据库中是否有此设备
|
|
|
Device device = deviceService.getByNum(num);
|
|
|
//没有该设备,保存至数据库
|
|
|
if (device == null) {
|
|
|
- device = createDevice(num);
|
|
|
+ device = new Device();
|
|
|
+ device.setNum(num);
|
|
|
+ device.setClientId(Constant.LP_DEVICE_ID_PREFIX + num);
|
|
|
+ device.setPassword(MD5Util.MD5Encode(num));
|
|
|
+ device.setGroup(obj.getString("group"));
|
|
|
+ deviceService.save(device);
|
|
|
}
|
|
|
//mqtt服务器注册用户
|
|
|
rabbitMQApi.registerMqtt(device.getClientId(), device.getPassword());
|
|
|
//发送消息
|
|
|
- setService.returnCodeToDevice(device);
|
|
|
+ setService.returnCode_LP(device);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -116,23 +169,6 @@ public class MqttCallbackHandler {
|
|
|
callRecordsService.save(callRecords);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 创建设备信息,保存设备基础信息以及设置信息
|
|
|
- *
|
|
|
- * @param num 设备随机码
|
|
|
- */
|
|
|
- private Device createDevice(String num) {
|
|
|
- Device device = new Device();
|
|
|
- device.setNum(num);
|
|
|
- String clientId = Constant.OLD_PHONE_DEVICE_ID_PREFIX + num;
|
|
|
- device.setClientId(clientId);
|
|
|
- device.setPassword(MD5Util.MD5Encode(clientId));
|
|
|
- deviceService.save(device);
|
|
|
- SetBase setBase = new SetBase();
|
|
|
- setBase.setDeviceId(device.getClientId());
|
|
|
- setBaseService.save(setBase);
|
|
|
- return device;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 解析信息转为位置对象
|