|
@@ -21,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -57,6 +58,8 @@ public class MqttCallbackHandler {
|
|
* @param payload 消息内容
|
|
* @param payload 消息内容
|
|
*/
|
|
*/
|
|
public void handle(String topic, String payload) {
|
|
public void handle(String topic, String payload) {
|
|
|
|
+ //设备码
|
|
|
|
+ String openNum = Constant.splitOpenNum(topic);
|
|
MqttDTO mqttDTO;
|
|
MqttDTO mqttDTO;
|
|
try {
|
|
try {
|
|
//解析消息
|
|
//解析消息
|
|
@@ -76,12 +79,12 @@ public class MqttCallbackHandler {
|
|
}
|
|
}
|
|
// 心跳包
|
|
// 心跳包
|
|
case Constant.M.UBI_HEARTBEAT: {
|
|
case Constant.M.UBI_HEARTBEAT: {
|
|
- heartbeatHandler(mqttDTO);
|
|
|
|
|
|
+ heartbeatHandler(openNum, mqttDTO);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
// 获取设备设置信息
|
|
// 获取设备设置信息
|
|
case Constant.M.UBI_SET_INFO: {
|
|
case Constant.M.UBI_SET_INFO: {
|
|
- deviceSetHandler(topic, mqttDTO);
|
|
|
|
|
|
+ deviceSetHandler(openNum, mqttDTO);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -103,7 +106,7 @@ public class MqttCallbackHandler {
|
|
if (device == null) {
|
|
if (device == null) {
|
|
device = new DeviceBase();
|
|
device = new DeviceBase();
|
|
device.setOpenNum(openNum);
|
|
device.setOpenNum(openNum);
|
|
- device.setGroup(group);
|
|
|
|
|
|
+ device.setGroupId(group);
|
|
device.setUsername("IMEI" + openNum);
|
|
device.setUsername("IMEI" + openNum);
|
|
device.setPassword(MD5Util.encode(openNum));
|
|
device.setPassword(MD5Util.encode(openNum));
|
|
device.setSn("SN" + openNum);
|
|
device.setSn("SN" + openNum);
|
|
@@ -118,15 +121,16 @@ public class MqttCallbackHandler {
|
|
/**
|
|
/**
|
|
* 心跳协议
|
|
* 心跳协议
|
|
*/
|
|
*/
|
|
- private void heartbeatHandler(MqttDTO mqttDTO) {
|
|
|
|
|
|
+ private void heartbeatHandler(String openNum, MqttDTO mqttDTO) {
|
|
try {
|
|
try {
|
|
- UbiInfoRecord entity = TransformEntity.tsf2UbiInfoRecord(mqttDTO);
|
|
|
|
|
|
+ UbiInfoRecord entity = TransformEntity.tsf2UbiInfoRecord(openNum, mqttDTO);
|
|
//存储记录
|
|
//存储记录
|
|
heartbeatRecordService.save(entity);
|
|
heartbeatRecordService.save(entity);
|
|
//更新最新的记录
|
|
//更新最新的记录
|
|
UbiInfoState ubiInfoState = BeanUtil.cast(entity, UbiInfoState.class);
|
|
UbiInfoState ubiInfoState = BeanUtil.cast(entity, UbiInfoState.class);
|
|
- deviceDynamicService.saveOrUpdate(ubiInfoState, new QueryWrapper<UbiInfoState>()
|
|
|
|
- .eq("open_num", ubiInfoState.getOpenNum()));
|
|
|
|
|
|
+ ubiInfoState.setUpdateTime(LocalDateTime.now());
|
|
|
|
+ deviceDynamicService.saveOrUpdate(ubiInfoState,
|
|
|
|
+ new QueryWrapper<UbiInfoState>().eq("open_num", ubiInfoState.getOpenNum()));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("解析设备心跳消息异常", e);
|
|
log.error("解析设备心跳消息异常", e);
|
|
throw new ApiRuntimeException("处理设备上传位置定位信息出错");
|
|
throw new ApiRuntimeException("处理设备上传位置定位信息出错");
|
|
@@ -137,8 +141,7 @@ public class MqttCallbackHandler {
|
|
* 普适性-设备设置信息
|
|
* 普适性-设备设置信息
|
|
*/
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
- private void deviceSetHandler(String topic, MqttDTO mqttDTO) {
|
|
|
|
- String openNum = Constant.splitOpenNum(topic);
|
|
|
|
|
|
+ private void deviceSetHandler(String openNum, MqttDTO mqttDTO) {
|
|
// ntrip数据链路设置
|
|
// ntrip数据链路设置
|
|
UbiNtrip client = TransformEntity.tsf2UbiNtrip((Map<String, String>) mqttDTO.getData().get("ntripclient"));
|
|
UbiNtrip client = TransformEntity.tsf2UbiNtrip((Map<String, String>) mqttDTO.getData().get("ntripclient"));
|
|
UbiNtrip server = TransformEntity.tsf2UbiNtrip((Map<String, String>) mqttDTO.getData().get("ntripserver"));
|
|
UbiNtrip server = TransformEntity.tsf2UbiNtrip((Map<String, String>) mqttDTO.getData().get("ntripserver"));
|