|
@@ -7,7 +7,6 @@ import com.zy.bms.model.*;
|
|
import com.zy.bms.redis.DeviceManager;
|
|
import com.zy.bms.redis.DeviceManager;
|
|
import com.zy.bms.service.*;
|
|
import com.zy.bms.service.*;
|
|
import com.zy.bms.utils.*;
|
|
import com.zy.bms.utils.*;
|
|
-import com.zy.bms.utils.CodeGenerator;
|
|
|
|
import com.zy.bms.utils.CoordTransformUtil;
|
|
import com.zy.bms.utils.CoordTransformUtil;
|
|
import com.zy.bms.utils.GaoDeApiUtil;
|
|
import com.zy.bms.utils.GaoDeApiUtil;
|
|
import com.zy.bms.websocket.WebSocketServer;
|
|
import com.zy.bms.websocket.WebSocketServer;
|
|
@@ -33,8 +32,6 @@ public class MqttCallbackHandler {
|
|
@Resource
|
|
@Resource
|
|
private DeviceLocationService deviceLocationService;
|
|
private DeviceLocationService deviceLocationService;
|
|
@Resource
|
|
@Resource
|
|
- private GaoDeApiUtil gaoDeApiService;
|
|
|
|
- @Resource
|
|
|
|
private DeviceManager deviceRedisService;
|
|
private DeviceManager deviceRedisService;
|
|
@Resource
|
|
@Resource
|
|
private WebSocketServer webSocketServer;
|
|
private WebSocketServer webSocketServer;
|
|
@@ -58,13 +55,13 @@ public class MqttCallbackHandler {
|
|
//根据报文标识代码 M 处理消息
|
|
//根据报文标识代码 M 处理消息
|
|
switch (msgObject.getM()) {
|
|
switch (msgObject.getM()) {
|
|
case Constant.M_CODE_REGISTER://设备端注册报文
|
|
case Constant.M_CODE_REGISTER://设备端注册报文
|
|
- registerDevice(msgObject);
|
|
|
|
|
|
+ registerDeviceHandler(msgObject);
|
|
break;
|
|
break;
|
|
case Constant.M_CODE_UPLOAD_LOCATION:// 设备位置信息上报
|
|
case Constant.M_CODE_UPLOAD_LOCATION:// 设备位置信息上报
|
|
- LocationHandler(msgObject);
|
|
|
|
|
|
+ uploadLocationHandler(msgObject);
|
|
break;
|
|
break;
|
|
case Constant.M_CODE_UPLOAD_CALL_RECORD://设备上传通话记录
|
|
case Constant.M_CODE_UPLOAD_CALL_RECORD://设备上传通话记录
|
|
- CallRecordsHandler(msgObject);
|
|
|
|
|
|
+ uploadCallRecordsHandler(msgObject);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -72,7 +69,7 @@ public class MqttCallbackHandler {
|
|
/**
|
|
/**
|
|
* 注册设备
|
|
* 注册设备
|
|
*/
|
|
*/
|
|
- private void registerDevice(MqttMsgDto obj) {
|
|
|
|
|
|
+ private void registerDeviceHandler(MqttMsgDto obj) {
|
|
String num = obj.getString("num");
|
|
String num = obj.getString("num");
|
|
//查询数据库中是否有此设备
|
|
//查询数据库中是否有此设备
|
|
Device device = deviceService.getByNum(num);
|
|
Device device = deviceService.getByNum(num);
|
|
@@ -81,16 +78,16 @@ public class MqttCallbackHandler {
|
|
device = createDevice(num);
|
|
device = createDevice(num);
|
|
}
|
|
}
|
|
//发送消息
|
|
//发送消息
|
|
- setToDeviceService.returnCodeToDevice(device.getNum(), device.getClientId(), device.getPassword());
|
|
|
|
|
|
+ setToDeviceService.returnCodeToDevice(device);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 处理上传位置
|
|
* 处理上传位置
|
|
*/
|
|
*/
|
|
- private void LocationHandler(MqttMsgDto msg) {
|
|
|
|
|
|
+ private void uploadLocationHandler(MqttMsgDto msg) {
|
|
DeviceLocation location = MqttMsgToLocation(msg);
|
|
DeviceLocation location = MqttMsgToLocation(msg);
|
|
// 逆地理位置解析
|
|
// 逆地理位置解析
|
|
- location.setSite(gaoDeApiService.regeo(location.getLonGcj(), location.getLatGcj()));
|
|
|
|
|
|
+ location.setSite(GaoDeApiUtil.regeo(location.getLonGcj(), location.getLatGcj()));
|
|
// 保存位置信息--历史记录
|
|
// 保存位置信息--历史记录
|
|
deviceLocationService.save(location);
|
|
deviceLocationService.save(location);
|
|
// 将最新位置信息保存至redis中
|
|
// 将最新位置信息保存至redis中
|
|
@@ -100,7 +97,7 @@ public class MqttCallbackHandler {
|
|
/**
|
|
/**
|
|
* 设备上传通话记录
|
|
* 设备上传通话记录
|
|
*/
|
|
*/
|
|
- private void CallRecordsHandler(MqttMsgDto obj) {
|
|
|
|
|
|
+ private void uploadCallRecordsHandler(MqttMsgDto obj) {
|
|
CallRecords callRecords = new CallRecords();
|
|
CallRecords callRecords = new CallRecords();
|
|
callRecords.setDeviceId(obj.getR().split("/")[1]);
|
|
callRecords.setDeviceId(obj.getR().split("/")[1]);
|
|
callRecords.setCallType(obj.getInt("type"));
|
|
callRecords.setCallType(obj.getInt("type"));
|
|
@@ -119,12 +116,9 @@ public class MqttCallbackHandler {
|
|
private Device createDevice(String num) {
|
|
private Device createDevice(String num) {
|
|
Device device = new Device();
|
|
Device device = new Device();
|
|
device.setNum(num);
|
|
device.setNum(num);
|
|
- String md5 = MD5Util.MD5Encode(num);
|
|
|
|
- if (md5 == null) {
|
|
|
|
- md5 = CodeGenerator.generateUUID();
|
|
|
|
- }
|
|
|
|
- device.setClientId(md5);
|
|
|
|
- device.setPassword(md5.substring(10));
|
|
|
|
|
|
+ String clientId = MD5Util.MD5Encode(num);
|
|
|
|
+ device.setClientId(clientId);
|
|
|
|
+ device.setPassword(MD5Util.MD5Encode(clientId));
|
|
device.setGroupId(1);
|
|
device.setGroupId(1);
|
|
deviceService.save(device);
|
|
deviceService.save(device);
|
|
setBaseService.initSetBase(device.getClientId());
|
|
setBaseService.initSetBase(device.getClientId());
|