|
@@ -37,6 +37,7 @@ public class DeviceStatusReviewExecutor {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISmsbDeviceService smsbDeviceService;
|
|
private ISmsbDeviceService smsbDeviceService;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SmsbDeviceErrorRecordMapper smsbDeviceErrorRecordMapper;
|
|
private SmsbDeviceErrorRecordMapper smsbDeviceErrorRecordMapper;
|
|
|
|
|
|
|
@@ -52,33 +53,36 @@ public class DeviceStatusReviewExecutor {
|
|
|
redisKeys.forEach(key -> {
|
|
redisKeys.forEach(key -> {
|
|
|
Long lastHeartTime = RedisUtils.getCacheObject(key);
|
|
Long lastHeartTime = RedisUtils.getCacheObject(key);
|
|
|
String identifier = key.replace(DEVICE_LAST_HEART_PREFIX, "");
|
|
String identifier = key.replace(DEVICE_LAST_HEART_PREFIX, "");
|
|
|
- SmsbDeviceVo smsbDeviceVo = smsbDeviceService.getDeviceByIdentifier(identifier);
|
|
|
|
|
|
|
+
|
|
|
SmsbDeviceErrorRecord errorRecord = new SmsbDeviceErrorRecord();
|
|
SmsbDeviceErrorRecord errorRecord = new SmsbDeviceErrorRecord();
|
|
|
// 如果最后一次心跳已经超过60秒,设备离线 记录告警
|
|
// 如果最后一次心跳已经超过60秒,设备离线 记录告警
|
|
|
- if (nowTime - lastHeartTime > 60 * 1000 && smsbDeviceVo.getOnlineStatus() == DeviceConstants.DEVICE_STATUS_ONLINE.longValue()) {
|
|
|
|
|
- // 设备离线
|
|
|
|
|
- smsbDeviceVo.setOnlineStatus(DeviceConstants.DEVICE_STATUS_OFFLINE.longValue());
|
|
|
|
|
- smsbDeviceVo.setOfflineTime(new Date());
|
|
|
|
|
- smsbDeviceService.updateDeviceStatus(smsbDeviceVo);
|
|
|
|
|
- SnailJobLog.REMOTE.info("update device: " + smsbDeviceVo.getId() + " to offline success !");
|
|
|
|
|
- // 记录设备告警记录
|
|
|
|
|
- buildErrorRecord(errorRecord, smsbDeviceVo, DeviceConstants.DEVICE_ERROR_LEVEL_URGENT, DeviceConstants.DEVICE_ERROR_OFFLINE);
|
|
|
|
|
- smsbDeviceErrorRecordMapper.insert(errorRecord);
|
|
|
|
|
- }
|
|
|
|
|
- // 如果离线已经超时30分钟,且为第一次超时,记录超时告警
|
|
|
|
|
- if (nowTime - lastHeartTime > 30 * 60 * 1000) {
|
|
|
|
|
- // 判断最近一条告警是否为超时30分钟
|
|
|
|
|
- SmsbDeviceErrorRecord lastErrorRecord = smsbDeviceErrorRecordMapper.selectOne(new LambdaQueryWrapper<SmsbDeviceErrorRecord>()
|
|
|
|
|
- .eq(SmsbDeviceErrorRecord::getDeviceId, smsbDeviceVo.getId())
|
|
|
|
|
- .orderByDesc(SmsbDeviceErrorRecord::getCreateTime).last("limit 1"));
|
|
|
|
|
- if (lastErrorRecord == null || !lastErrorRecord.getErrorType().equals(DeviceConstants.DEVICE_ERROR_OFFLINE_THAN_30)) {
|
|
|
|
|
|
|
+ if (nowTime - lastHeartTime > 60 * 1000) {
|
|
|
|
|
+ SmsbDeviceVo smsbDeviceVo = smsbDeviceService.queryByIdentifier(identifier);
|
|
|
|
|
+ if (DeviceConstants.DEVICE_STATUS_ONLINE == Math.toIntExact(smsbDeviceVo.getOnlineStatus())) {
|
|
|
|
|
+ // 设备离线
|
|
|
|
|
+ smsbDeviceVo.setOnlineStatus(DeviceConstants.DEVICE_STATUS_OFFLINE.longValue());
|
|
|
|
|
+ smsbDeviceVo.setOfflineTime(new Date());
|
|
|
|
|
+ smsbDeviceService.updateDeviceStatus(smsbDeviceVo);
|
|
|
|
|
+ SnailJobLog.REMOTE.info("update device: " + smsbDeviceVo.getId() + " to offline success !");
|
|
|
// 记录设备告警记录
|
|
// 记录设备告警记录
|
|
|
- buildErrorRecord(errorRecord, smsbDeviceVo, DeviceConstants.DEVICE_ERROR_LEVEL_URGENT, DeviceConstants.DEVICE_ERROR_OFFLINE_THAN_30);
|
|
|
|
|
- errorRecord.setId(null);
|
|
|
|
|
|
|
+ buildErrorRecord(errorRecord, smsbDeviceVo, DeviceConstants.DEVICE_ERROR_LEVEL_URGENT, DeviceConstants.DEVICE_ERROR_OFFLINE);
|
|
|
smsbDeviceErrorRecordMapper.insert(errorRecord);
|
|
smsbDeviceErrorRecordMapper.insert(errorRecord);
|
|
|
- SnailJobLog.REMOTE.info("record device: " + smsbDeviceVo.getId() + " to offline than 30 min success !");
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ // 如果离线已经超时30分钟,且为第一次超时,记录超时告警
|
|
|
|
|
+ if (nowTime - lastHeartTime > 30 * 60 * 1000) {
|
|
|
|
|
+ // 判断最近一条告警是否为超时30分钟
|
|
|
|
|
+ SmsbDeviceErrorRecord lastErrorRecord = smsbDeviceErrorRecordMapper.selectOne(new LambdaQueryWrapper<SmsbDeviceErrorRecord>()
|
|
|
|
|
+ .eq(SmsbDeviceErrorRecord::getDeviceId, smsbDeviceVo.getId())
|
|
|
|
|
+ .orderByDesc(SmsbDeviceErrorRecord::getCreateTime).last("limit 1"));
|
|
|
|
|
+ if (lastErrorRecord == null || !lastErrorRecord.getErrorType().equals(DeviceConstants.DEVICE_ERROR_OFFLINE_THAN_30)) {
|
|
|
|
|
+ // 记录设备告警记录
|
|
|
|
|
+ buildErrorRecord(errorRecord, smsbDeviceVo, DeviceConstants.DEVICE_ERROR_LEVEL_URGENT, DeviceConstants.DEVICE_ERROR_OFFLINE_THAN_30);
|
|
|
|
|
+ errorRecord.setId(null);
|
|
|
|
|
+ smsbDeviceErrorRecordMapper.insert(errorRecord);
|
|
|
|
|
+ SnailJobLog.REMOTE.info("record device: " + smsbDeviceVo.getId() + " to offline than 30 min success !");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|