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