|
@@ -27,8 +27,6 @@ public class MqttCallbackHandler {
|
|
|
@Resource
|
|
|
private DeviceService deviceService;
|
|
|
@Resource
|
|
|
- private DeviceLpService deviceLpService;
|
|
|
- @Resource
|
|
|
private SetBaseService setBaseService;
|
|
|
@Resource
|
|
|
private SetService setService;
|
|
@@ -54,50 +52,27 @@ public class MqttCallbackHandler {
|
|
|
mqttLogService.saveReceiveLog(topic, payload);
|
|
|
//消息返回JSON转Object
|
|
|
MqttMsgDto msgDto = MqttMsgDto.parse(payload);
|
|
|
- //路牌项目
|
|
|
- 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_INFO_LP: {
|
|
|
- uploadLocationInfoLPHandler(topic, msgDto);
|
|
|
- break;
|
|
|
- }
|
|
|
- // 设备上传基本信息
|
|
|
- case Constant.M_CODE_UPLOAD_INFO_LP: {
|
|
|
- uploadDeviceInfoLPHandler(topic, msgDto);
|
|
|
- break;
|
|
|
- }
|
|
|
+ switch (msgDto.getM()) {
|
|
|
+ //设备端注册报文
|
|
|
+ case Constant.M_CODE_REGISTER: {
|
|
|
+ registerHandler_OMP(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_LOCATION: {
|
|
|
+ uploadLocationHandler(msgDto);
|
|
|
+ break;
|
|
|
}
|
|
|
- //转发消息至网页,忽略注册的报文
|
|
|
- if (!topic.equals(Constant.TOPIC_REGISTER_SERVER)) {
|
|
|
- webSocketServer.massMessage(msgDto.getDeviceId(), payload);
|
|
|
+ //设备上传通话记录
|
|
|
+ case Constant.M_CODE_UPLOAD_CALL_RECORD: {
|
|
|
+ uploadCallRecordsHandler(msgDto);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ //转发消息至网页,忽略注册的报文
|
|
|
+ if (!topic.equals(Constant.TOPIC_REGISTER_SERVER)) {
|
|
|
+ webSocketServer.massMessage(msgDto.getDeviceId(), payload);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -125,29 +100,6 @@ public class MqttCallbackHandler {
|
|
|
setService.returnCode_OMP(device);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 注册设备
|
|
|
- * 路牌
|
|
|
- */
|
|
|
- private void registerHandler_LP(MqttMsgDto obj) {
|
|
|
- String num = obj.getString("regnum");
|
|
|
- //查询数据库中是否有此设备
|
|
|
- DeviceLp deviceLp = deviceLpService.getByNum(num);
|
|
|
- //没有该设备,保存至数据库
|
|
|
- if (deviceLp == null) {
|
|
|
- deviceLp = new DeviceLp();
|
|
|
- deviceLp.setNum(num);
|
|
|
- deviceLp.setClientId(Constant.LP_DEVICE_ID_PREFIX + num);
|
|
|
- deviceLp.setPassword(MD5Util.encodeCut(num));
|
|
|
- deviceLp.setGroup(obj.getString("group"));
|
|
|
- deviceLpService.save(deviceLp);
|
|
|
- }
|
|
|
- //mqtt服务器注册用户
|
|
|
- rabbitMQApi.registerMqtt(deviceLp.getClientId(), deviceLp.getPassword());
|
|
|
- //发送消息
|
|
|
- setService.returnCode_LP(deviceLp);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 处理上传位置
|
|
|
* 老人机
|
|
@@ -177,86 +129,6 @@ public class MqttCallbackHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 处理设备定位信息上传
|
|
|
- * 路牌
|
|
|
- */
|
|
|
- private void uploadLocationInfoLPHandler(String topic, MqttMsgDto msg) {
|
|
|
- try {
|
|
|
- String num = topic.split("IMEI")[1];
|
|
|
- DeviceLp deviceLp = new DeviceLp();
|
|
|
- deviceLp.setMode(msg.getInt("mode"));
|
|
|
- deviceLp.setLon(msg.getString("lon"));
|
|
|
- deviceLp.setLat(msg.getString("lat"));
|
|
|
- //转换后的坐标
|
|
|
- String[] gcj = CoordTransformUtil.wgs84toGcj02(deviceLp.getLon(), deviceLp.getLat());
|
|
|
- deviceLp.setLonGcj(gcj[0]);
|
|
|
- deviceLp.setLatGcj(gcj[1]);
|
|
|
- // 逆地理位置解析
|
|
|
- deviceLp.setSite(GaoDeApiUtil.regeo(deviceLp.getLonGcj(), deviceLp.getLatGcj()));
|
|
|
- // 保存基本信息
|
|
|
- deviceLpService.updateByNum(deviceLp, num);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("路牌上传位置信息异常", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理设备基本信息上传
|
|
|
- * 路牌
|
|
|
- */
|
|
|
- private void uploadDeviceInfoLPHandler(String topic, MqttMsgDto msg) {
|
|
|
- try {
|
|
|
- String num = topic.split("IMEI")[1];
|
|
|
- //setService.getDeviceLocation_LP(num);
|
|
|
- DeviceLp dbDevice = deviceLpService.getByNum(num);
|
|
|
- if (dbDevice == null) {
|
|
|
- log.warn("设备需要手动添加至数据库:" + num);
|
|
|
- return;
|
|
|
- }
|
|
|
- DeviceLp deviceLp = new DeviceLp();
|
|
|
- Double wakeInt = msg.getDouble("sleept");
|
|
|
- Integer thresh = msg.getInt("thresh");
|
|
|
- //若数据库中没有设置唤醒时间和阈值则直接同步设备数据
|
|
|
- if (dbDevice.getThresh() == null || dbDevice.getWakeInt() == null) {
|
|
|
- deviceLp.setWakeInt(wakeInt);
|
|
|
- deviceLp.setThresh(thresh);
|
|
|
- } else {
|
|
|
- //如果远程设备的(唤醒时间,阈值)与数据库的数据不一致,则发送消息更新设备的设置数据与数据库保持一致
|
|
|
- if (!dbDevice.getWakeInt().equals(wakeInt) || !dbDevice.getThresh().equals(thresh)) {
|
|
|
- setService.updateDevice_LP(num, dbDevice.getWakeInt(), dbDevice.getThresh());
|
|
|
- }
|
|
|
- }
|
|
|
- deviceLp.setDataType(msg.getString("datetype"));
|
|
|
- deviceLp.setBattery(msg.getString("batterynum"));
|
|
|
- deviceLp.setS4g(msg.getString("s4g"));
|
|
|
- deviceLp.setX(msg.getString("x"));
|
|
|
- deviceLp.setY(msg.getString("y"));
|
|
|
- deviceLp.setZ(msg.getString("z"));
|
|
|
- deviceLp.setAnglex(msg.getString("anglex"));
|
|
|
- deviceLp.setAngley(msg.getString("angley"));
|
|
|
- deviceLp.setAnglez(msg.getString("anglez"));
|
|
|
- deviceLp.setTemp(msg.getString("temp"));
|
|
|
- deviceLp.setUpdateTime(LocalDateTime.now());
|
|
|
- //临时解决方案
|
|
|
- if (msg.getString("lon")!=null){
|
|
|
- deviceLp.setMode(msg.getInt("mode"));
|
|
|
- deviceLp.setLon(msg.getString("lon"));
|
|
|
- deviceLp.setLat(msg.getString("lat"));
|
|
|
- //转换后的坐标
|
|
|
- String[] gcj = CoordTransformUtil.wgs84toGcj02(deviceLp.getLon(), deviceLp.getLat());
|
|
|
- deviceLp.setLonGcj(gcj[0]);
|
|
|
- deviceLp.setLatGcj(gcj[1]);
|
|
|
- // 逆地理位置解析
|
|
|
- deviceLp.setSite(GaoDeApiUtil.regeo(deviceLp.getLonGcj(), deviceLp.getLatGcj()));
|
|
|
- }
|
|
|
- // 保存基本信息
|
|
|
- deviceLpService.updateByNum(deviceLp, num);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("路牌上传基本信息异常", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 设备上传通话记录
|
|
|
*/
|