更新 MonitorService.java

pull/1/head
wangsiyuan 2023-12-09 14:12:07 +08:00
parent ae889a2447
commit 8772a041f3
1 changed files with 7 additions and 1 deletions

View File

@ -44,11 +44,17 @@ public class MonitorService {
continue;
}
long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis - device.getLastOnlineTime() > device.getTimeOutPeriod()) {
long timeDifferenceMillis = currentTimeMillis - device.getLastOnlineTime();
long timeDifferenceSeconds = timeDifferenceMillis / 1000;
if (timeDifferenceSeconds > device.getTimeOutPeriod()) {
logger.info("currentTimeMillis: {},device LastOnlineTime: {},时间差: {},设备超时时间: {}",currentTimeMillis,
device.getLastOnlineTime(),timeDifferenceSeconds,device.getTimeOutPeriod());
updateStatus(device, 0); // 设备离线
logger.info("Update the device status to offline.");
sendNotification(device);
} else {
updateStatus(device, 1); // 设备在线
logger.info("update the device status to online.");
}
} catch (Exception e) {
logger.error("Error processing device with SN " + device.getSN(), e);