mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 16:36:03 +08:00
设备定位优化
This commit is contained in:
@@ -317,16 +317,22 @@ public class ToolController extends BaseController {
|
|||||||
if (model.getClientid().startsWith("server") || model.getClientid().startsWith("web") || model.getClientid().startsWith("phone")) {
|
if (model.getClientid().startsWith("server") || model.getClientid().startsWith("web") || model.getClientid().startsWith("phone")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String[] clientInfo = model.getClientid().split("&");
|
|
||||||
String deviceNum = clientInfo[1];
|
// 设备端认证:加密认证(E)和简单认证(S,配置的账号密码认证)
|
||||||
Device device = deviceService.selectShortDeviceBySerialNumber(deviceNum);
|
String[] clientArray = model.getClientid().split("&");
|
||||||
|
String authType = clientArray[0];
|
||||||
|
String deviceNumber = clientArray[1];
|
||||||
|
Long productId = Long.valueOf(clientArray[2]);
|
||||||
|
Long userId = Long.valueOf(clientArray[3]);
|
||||||
|
|
||||||
|
Device device = deviceService.selectShortDeviceBySerialNumber(deviceNumber);
|
||||||
// 设备状态(1-未激活,2-禁用,3-在线,4-离线)
|
// 设备状态(1-未激活,2-禁用,3-在线,4-离线)
|
||||||
if (model.getAction().equals("client_disconnected")) {
|
if (model.getAction().equals("client_disconnected")) {
|
||||||
device.setStatus(4);
|
device.setStatus(4);
|
||||||
deviceService.updateDeviceStatusAndLocation(device, "");
|
deviceService.updateDeviceStatusAndLocation(device, "");
|
||||||
// 发布设备状态
|
// 发布设备状态
|
||||||
emqxService.publishStatus(device.getProductId(), device.getSerialNumber(), 4, device.getIsShadow());
|
emqxService.publishStatus(device.getProductId(), device.getSerialNumber(), 4, device.getIsShadow());
|
||||||
// 清空保留消息,上线后发布新的属性功能保留消息 TODO 发布的时候取消保留消息
|
// 清空保留消息,上线后发布新的属性功能保留消息
|
||||||
emqxService.publishProperty(device.getProductId(), device.getSerialNumber(), null);
|
emqxService.publishProperty(device.getProductId(), device.getSerialNumber(), null);
|
||||||
emqxService.publishFunction(device.getProductId(), device.getSerialNumber(), null);
|
emqxService.publishFunction(device.getProductId(), device.getSerialNumber(), null);
|
||||||
} else if (model.getAction().equals("client_connected")) {
|
} else if (model.getAction().equals("client_connected")) {
|
||||||
|
|||||||
@@ -132,6 +132,11 @@ public class EmqxService {
|
|||||||
Device device = JSON.parseObject(message, Device.class);
|
Device device = JSON.parseObject(message, Device.class);
|
||||||
device.setProductId(productId);
|
device.setProductId(productId);
|
||||||
device.setSerialNumber(deviceNum);
|
device.setSerialNumber(deviceNum);
|
||||||
|
// 未采用设备定位则清空定位,定位方式(1=ip自动定位,2=设备定位,3=自定义)
|
||||||
|
if(device.getIsCustomLocation()!=2){
|
||||||
|
device.setLatitude(null);
|
||||||
|
device.setLongitude(null);
|
||||||
|
}
|
||||||
deviceService.reportDevice(device);
|
deviceService.reportDevice(device);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("接收设备信息,解析数据时异常 message={}", e.getMessage());
|
logger.error("接收设备信息,解析数据时异常 message={}", e.getMessage());
|
||||||
@@ -194,7 +199,6 @@ public class EmqxService {
|
|||||||
deviceLog.setIdentity(thingsModelValueRemarkItems.get(i).getId());
|
deviceLog.setIdentity(thingsModelValueRemarkItems.get(i).getId());
|
||||||
deviceLog.setLogType(3);
|
deviceLog.setLogType(3);
|
||||||
deviceLog.setIsMonitor(0);
|
deviceLog.setIsMonitor(0);
|
||||||
// deviceLogService.insertDeviceLog(deviceLog);
|
|
||||||
logService.saveDeviceLog(deviceLog);
|
logService.saveDeviceLog(deviceLog);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -566,12 +566,13 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public int updateDeviceStatusAndLocation(Device device,String ipAddress) {
|
public int updateDeviceStatusAndLocation(Device device,String ipAddress) {
|
||||||
// 设置定位和状态
|
// 设置自动定位和状态
|
||||||
if(ipAddress!="") {
|
if(ipAddress!="") {
|
||||||
if(device.getActiveTime()==null){
|
if(device.getActiveTime()==null){
|
||||||
device.setActiveTime(DateUtils.getNowDate());
|
device.setActiveTime(DateUtils.getNowDate());
|
||||||
}
|
}
|
||||||
if (device.getIsCustomLocation() == 0) {
|
// 定位方式(1=ip自动定位,2=设备定位,3=自定义)
|
||||||
|
if (device.getIsCustomLocation() == 1) {
|
||||||
device.setNetworkIp(ipAddress);
|
device.setNetworkIp(ipAddress);
|
||||||
setLocation(ipAddress, device);
|
setLocation(ipAddress, device);
|
||||||
}
|
}
|
||||||
@@ -596,7 +597,6 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
deviceLog.setLogType(6);
|
deviceLog.setLogType(6);
|
||||||
}
|
}
|
||||||
logService.saveDeviceLog(deviceLog);
|
logService.saveDeviceLog(deviceLog);
|
||||||
// deviceLogService.insertDeviceLog(deviceLog);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user