|
@@ -7,11 +7,13 @@ import com.zy.bms.model.*;
|
|
|
import com.zy.bms.redis.DeviceManager;
|
|
|
import com.zy.bms.service.*;
|
|
|
import com.zy.bms.utils.*;
|
|
|
+import com.zy.bms.utils.CodeGenerator;
|
|
|
+import com.zy.bms.utils.CoordTransformUtil;
|
|
|
+import com.zy.bms.utils.GaoDeApiUtil;
|
|
|
import com.zy.bms.websocket.WebSocketServer;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* MQTT 消息返回处理类
|
|
@@ -71,7 +73,7 @@ public class MqttCallbackHandler {
|
|
|
* 注册设备
|
|
|
*/
|
|
|
private void registerDevice(MqttMsgDto obj) {
|
|
|
- String num = obj.getData().get("regnum").toString();
|
|
|
+ String num = obj.getString("num");
|
|
|
//查询数据库中是否有此设备
|
|
|
Device device = deviceService.getByNum(num);
|
|
|
//没有该设备,保存至数据库
|
|
@@ -101,11 +103,11 @@ public class MqttCallbackHandler {
|
|
|
private void CallRecordsHandler(MqttMsgDto obj) {
|
|
|
CallRecords callRecords = new CallRecords();
|
|
|
callRecords.setDeviceId(obj.getR().split("/")[1]);
|
|
|
- callRecords.setCallType((int) obj.getData().get("type"));
|
|
|
- callRecords.setKeyNum((String) obj.getData().get("key"));
|
|
|
- callRecords.setPhoneNum((String) obj.getData().get("phnoenum"));
|
|
|
- callRecords.setTalkTime((int) obj.getData().get("talktime"));
|
|
|
- callRecords.setEndTime((String) obj.getData().get("endtime"));
|
|
|
+ callRecords.setCallType(obj.getInt("type"));
|
|
|
+ callRecords.setKeyNum(obj.getString("key"));
|
|
|
+ callRecords.setPhoneNum(obj.getString("phnoenum"));
|
|
|
+ callRecords.setTalkTime(obj.getInt("talktime"));
|
|
|
+ callRecords.setEndTime(obj.getString("endtime"));
|
|
|
callRecordsService.save(callRecords);
|
|
|
}
|
|
|
|
|
@@ -132,23 +134,21 @@ public class MqttCallbackHandler {
|
|
|
/**
|
|
|
* 解析信息转为位置对象
|
|
|
*/
|
|
|
- private DeviceLocation MqttMsgToLocation(MqttMsgDto msg) {
|
|
|
+ private DeviceLocation MqttMsgToLocation(MqttMsgDto obj) {
|
|
|
try {
|
|
|
DeviceLocation location = new DeviceLocation();
|
|
|
- Map<String, Object> dataMap = msg.getData();
|
|
|
- location.setDeviceId(msg.getR().split("/")[1]);
|
|
|
- location.setBatteryNum((int) dataMap.get("batterynum"));
|
|
|
- location.setSignalNum((int) dataMap.get("signalnum"));
|
|
|
- location.setMode((int) dataMap.get("mode"));
|
|
|
- location.setLon(dataMap.get("lon").toString());
|
|
|
- location.setLat(dataMap.get("lat").toString());
|
|
|
- location.setSpeed(dataMap.get("speed").toString());
|
|
|
- location.setNum((int) dataMap.get("num"));
|
|
|
- location.setUploadTime(DateTimeUtil.strToTime((String) dataMap.get("createtime")));
|
|
|
- Object cellInfo = dataMap.get("cellInfo");
|
|
|
- if (cellInfo != null) {
|
|
|
- location.setCellInfo(cellInfo.toString());
|
|
|
- }
|
|
|
+ location.setDeviceId(obj.getDeviceId());
|
|
|
+ location.setBatteryNum(obj.getInt("batterynum"));
|
|
|
+ location.setSignalNum(obj.getInt("signalnum"));
|
|
|
+ location.setMode(obj.getInt("mode"));
|
|
|
+ location.setLon(obj.getString("lon"));
|
|
|
+ location.setLon(obj.getString("lat"));
|
|
|
+ location.setSpeed(obj.getString("speed"));
|
|
|
+ location.setNum(obj.getInt("num"));
|
|
|
+ location.setUploadTime(obj.getDate("createtime"));
|
|
|
+ Object cellInfo = obj.getObject("cellInfo");
|
|
|
+ //该数据项可能为空
|
|
|
+ if (cellInfo != null) location.setCellInfo(cellInfo.toString());
|
|
|
//转换后的坐标
|
|
|
String[] gcj = CoordTransformUtil.wgs84toGcj02(location.getLon(), location.getLat());
|
|
|
location.setLonGcj(gcj[0]);
|