|
@@ -2,17 +2,16 @@ package com.zy.omp.config.mqtt;
|
|
|
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
/**
|
|
@@ -21,6 +20,7 @@ import java.time.LocalDateTime;
|
|
|
* @author yang xiao kun
|
|
|
* create on 2021/1/19
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
public class MqttCallbackHandler {
|
|
|
|
|
@@ -173,8 +173,7 @@ public class MqttCallbackHandler {
|
|
|
// 保存位置信息
|
|
|
deviceLocationService.saveLocation(location);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw new ApiRuntimeException("处理设备上传位置定位信息出错");
|
|
|
+ log.error("老人机上传位置信息异常", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -198,8 +197,7 @@ public class MqttCallbackHandler {
|
|
|
// 保存基本信息
|
|
|
deviceLpService.updateByNum(deviceLp, num);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw new ApiRuntimeException("处理路牌设备上传定位信息出错");
|
|
|
+ log.error("路牌上传位置信息异常", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -211,14 +209,24 @@ public class MqttCallbackHandler {
|
|
|
try {
|
|
|
String num = topic.split("IMEI")[1];
|
|
|
setService.getDeviceLocation_LP(num);
|
|
|
- //如果远程设备的信息与数据库的信息不一致,则发送消息更新远程信息
|
|
|
DeviceLp dbDevice = deviceLpService.getByNum(num);
|
|
|
- Double dbWakeInt = dbDevice.getWakeInt() == null ? null : dbDevice.getWakeInt().setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
|
|
|
- Double wakeInt = msg.getDouble("sleept") == null ? null : BigDecimal.valueOf(msg.getDouble("sleept")).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
|
|
|
- if (dbWakeInt == null || !dbWakeInt.equals(wakeInt) || !dbDevice.getThresh().equals(msg.getInt("thresh"))) {
|
|
|
- setService.updateDevice_LP(num, dbDevice.getWakeInt(), dbDevice.getThresh());
|
|
|
+ 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"));
|
|
@@ -233,8 +241,7 @@ public class MqttCallbackHandler {
|
|
|
// 保存基本信息
|
|
|
deviceLpService.updateByNum(deviceLp, num);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw new ApiRuntimeException("处理路牌设备上传基本信息出错");
|
|
|
+ log.error("路牌上传基本信息异常", e);
|
|
|
}
|
|
|
}
|
|
|
|