|
@@ -2,29 +2,15 @@ package com.zy.bms.handler;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.zy.bms.common.Constant;
|
|
|
-import com.zy.bms.common.exception.ApiRuntimeException;
|
|
|
import com.zy.bms.entity.*;
|
|
|
-import com.zy.bms.entity.ubi.UbiNtrip;
|
|
|
-import com.zy.bms.entity.ubi.UbiInfoRecord;
|
|
|
-import com.zy.bms.entity.ubi.UbiInfoState;
|
|
|
-import com.zy.bms.entity.ubi.UbiTcp;
|
|
|
import com.zy.bms.pojo.dto.MqttDTO;
|
|
|
import com.zy.bms.service.*;
|
|
|
-import com.zy.bms.service.lp.ILpInfoStateService;
|
|
|
-import com.zy.bms.service.ubi.IUbiInfoRecordService;
|
|
|
-import com.zy.bms.service.ubi.IUbiInfoStateService;
|
|
|
-import com.zy.bms.service.ubi.IUbiNtripService;
|
|
|
-import com.zy.bms.service.ubi.IUbiTcpService;
|
|
|
-import com.zy.bms.utils.BeanUtil;
|
|
|
import com.zy.bms.utils.MD5Util;
|
|
|
import com.zy.bms.utils.RabbitMQApi;
|
|
|
-import com.zy.bms.utils.TransformEntity;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* MQTT 消息返回处理类
|
|
@@ -45,15 +31,7 @@ public class MqttCallbackHandler {
|
|
|
@Resource
|
|
|
private IDeviceBaseService deviceStaticService;
|
|
|
@Resource
|
|
|
- private IUbiInfoRecordService heartbeatRecordService;
|
|
|
- @Resource
|
|
|
- private IUbiInfoStateService deviceDynamicService;
|
|
|
- @Resource
|
|
|
- private IUbiNtripService ntripSetService;
|
|
|
- @Resource
|
|
|
- private IUbiTcpService tcpSetService;
|
|
|
- @Resource
|
|
|
- private ILpInfoStateService lpInfoStateService;
|
|
|
+ private UbiHandlers ubiHandlers;
|
|
|
|
|
|
/**
|
|
|
* 处理消息
|
|
@@ -83,12 +61,12 @@ public class MqttCallbackHandler {
|
|
|
}
|
|
|
// 心跳包
|
|
|
case Constant.M.UBI_HEARTBEAT: {
|
|
|
- heartbeatHandler(openNum, mqttDTO);
|
|
|
+ ubiHandlers.heartbeatHandler(openNum, mqttDTO);
|
|
|
break;
|
|
|
}
|
|
|
// 获取设备设置信息
|
|
|
case Constant.M.UBI_SET_INFO: {
|
|
|
- deviceSetHandler(openNum, mqttDTO);
|
|
|
+ ubiHandlers.deviceSetHandler(openNum, mqttDTO);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -121,100 +99,4 @@ public class MqttCallbackHandler {
|
|
|
// 返回处理结果
|
|
|
postMqttMsgService.handleRegister(device);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 心跳协议
|
|
|
- */
|
|
|
- private void heartbeatHandler(String openNum, MqttDTO mqttDTO) {
|
|
|
- try {
|
|
|
- UbiInfoRecord entity = TransformEntity.tsf2UbiInfoRecord(openNum, mqttDTO);
|
|
|
- //存储记录
|
|
|
- heartbeatRecordService.save(entity);
|
|
|
- //更新最新的记录
|
|
|
- UbiInfoState ubiInfoState = BeanUtil.cast(entity, UbiInfoState.class);
|
|
|
- //设置更新时间
|
|
|
- ubiInfoState.setUpdateTime(LocalDateTime.now());
|
|
|
- //设置在线状态
|
|
|
- ubiInfoState.setStatus(1);
|
|
|
- deviceDynamicService.saveOrUpdate(ubiInfoState,
|
|
|
- new QueryWrapper<UbiInfoState>().eq("open_num", ubiInfoState.getOpenNum()));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("解析设备心跳消息异常", e);
|
|
|
- throw new ApiRuntimeException("处理设备上传位置定位信息出错");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 普适性-设备设置信息
|
|
|
- */
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private void deviceSetHandler(String openNum, MqttDTO mqttDTO) {
|
|
|
- // ntrip数据链路设置
|
|
|
- UbiNtrip client = TransformEntity.tsf2UbiNtrip((Map<String, String>) mqttDTO.getObject("ntripclient"));
|
|
|
- UbiNtrip server = TransformEntity.tsf2UbiNtrip((Map<String, String>) mqttDTO.getObject("ntripserver"));
|
|
|
- ntripSetService.saveOrUpdateNtripSet(client, openNum, IUbiNtripService.CLIENT);
|
|
|
- ntripSetService.saveOrUpdateNtripSet(server, openNum, IUbiNtripService.SERVER);
|
|
|
- // tcp数据链路设置
|
|
|
- UbiTcp link1 = TransformEntity.tsf2UbiTcp((Map<String, String>) mqttDTO.getObject("tcplink1"));
|
|
|
- UbiTcp link2 = TransformEntity.tsf2UbiTcp((Map<String, String>) mqttDTO.getObject("tcplink2"));
|
|
|
- UbiTcp link3 = TransformEntity.tsf2UbiTcp((Map<String, String>) mqttDTO.getObject("tcplink3"));
|
|
|
- tcpSetService.saveOrUpdateTcpSet(link1, openNum, IUbiTcpService.LINK_1);
|
|
|
- tcpSetService.saveOrUpdateTcpSet(link2, openNum, IUbiTcpService.LINK_2);
|
|
|
- tcpSetService.saveOrUpdateTcpSet(link3, openNum, IUbiTcpService.LINK_3);
|
|
|
- }
|
|
|
-
|
|
|
-// /**
|
|
|
-// * 路牌-基本信息上传
|
|
|
-// */
|
|
|
-// private void LP_deviceInfoHandler(String topic, MqttDTO mqttDTO) {
|
|
|
-// try {
|
|
|
-// String openNum = Constant.splitOpenNum(topic);
|
|
|
-// LpInfoState dbDevice = lpInfoStateService.getByOpenNum(openNum);
|
|
|
-// if (dbDevice == null) {
|
|
|
-// log.error("设备需要手动添加至数据库:" + openNum);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// LpInfoState deviceLp = new LpInfoState();
|
|
|
-// Double wakeInt = mqttDTO.getDouble("sleept");
|
|
|
-// Integer thresh = mqttDTO.getInt("thresh");
|
|
|
-// //若数据库中没有设置唤醒时间和阈值则直接同步设备数据
|
|
|
-// if (dbDevice.getThresh() == null || dbDevice.getWakeInt() == null) {
|
|
|
-// deviceLp.setWakeInt(BigDecimal.valueOf(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);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
}
|