优化在线逻辑
This commit is contained in:
parent
076b755950
commit
9c830759b3
|
@ -294,20 +294,23 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
.filter(item -> Objects.equals(item.getMac(), device.getMac()))
|
||||
.findFirst().orElse(null);
|
||||
DeviceUtil.setIotInfo(device, iot);
|
||||
this.updateIot(device);
|
||||
}
|
||||
|
||||
// 异步发送命令,强制设备上报数据
|
||||
scheduledExecutorService.execute(() -> {
|
||||
for (DeviceVO device : deviceList) {
|
||||
try {
|
||||
if (onlineType != null) {
|
||||
iotService.getOnlineStatus(device, onlineType);
|
||||
if (onlineType != null) {
|
||||
scheduledExecutorService.execute(() -> {
|
||||
for (DeviceVO device : deviceList) {
|
||||
try {
|
||||
if (onlineType != null) {
|
||||
iotService.getOnlineStatus(device, onlineType);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("强制设备{}上报数据失败", device.getSn(), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("强制设备{}上报数据失败", device.getSn(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -319,6 +322,10 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
|||
if (info == null) {
|
||||
info = new DeviceCacheInfo();
|
||||
}
|
||||
// 若缓存时间大于设备时间,则不更新
|
||||
if (info.getLastTime() != null && device.getLastTime() != null && info.getLastTime().isAfter(device.getLastTime())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
info.setMac(device.getMac());
|
||||
if (device.getVoltage() != null) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.ruoyi.common.utils.MathUtils;
|
|||
import com.ruoyi.common.utils.map.GpsCoordinateUtils;
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
import com.ruoyi.iot.domain.IotDeviceSysInfo;
|
||||
import com.ruoyi.iot.service.impl.DeviceOnlineStatus;
|
||||
import com.ruoyi.iot.util.BatUtil;
|
||||
|
||||
public class DeviceUtil {
|
||||
|
@ -186,4 +187,19 @@ public class DeviceUtil {
|
|||
public static boolean isLowSatelliteSignal(DeviceVO device) {
|
||||
return device != null && device.getSatellites() != null && device.getSatellites() <= 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据推送设置设备信息
|
||||
*
|
||||
* @param device 设备
|
||||
* @param sys sys信息
|
||||
* @param at 时间
|
||||
* @param setNull 是否设置为空
|
||||
*/
|
||||
public static void setIotSysInfoByReceive(DeviceVO device, IotDeviceSysInfo sys, LocalDateTime at, boolean setNull) {
|
||||
setIotSysInfo(device, sys, at, setNull);
|
||||
|
||||
device.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
|
||||
device.setLastOnlineTime(at);
|
||||
}
|
||||
}
|
|
@ -102,11 +102,7 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
log.info("收到sys数据:{}", msg.getValue());
|
||||
IotDeviceSysInfo sys = IotUtil.toSysInfo(msg.getValue());
|
||||
LocalDateTime at = DateUtils.toLocalDateTime(msg.getAt());
|
||||
DeviceUtil.setIotSysInfo(device, sys, at, true);
|
||||
|
||||
// 更新设备信息
|
||||
device.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
|
||||
device.setLastOnlineTime(at);
|
||||
DeviceUtil.setIotSysInfoByReceive(device, sys, at, true);
|
||||
|
||||
// 更新设备信息
|
||||
deviceIotService.updateIot(device);
|
||||
|
|
Loading…
Reference in New Issue
Block a user