| | |
| | | String redisKey = CacheConstants.UAV_ONLINE_KEY + boxSn; |
| | | boolean currentOnline = remote.getOnLine() == 1; |
| | | |
| | | // 获取上次状态 |
| | | boolean lastOnline = redisCache.getCacheObject(redisKey) != null; |
| | | ArdDroneInfo local = localMap.get(boxSn); |
| | | boolean dbOnline = local != null && local.getOnLine() == 1; |
| | | boolean needUpdate = (dbOnline != currentOnline); |
| | | |
| | | // 如果状态变化才更新 |
| | | if (lastOnline != currentOnline) { |
| | | if (needUpdate){ |
| | | // 更新 Redis |
| | | if (currentOnline) { |
| | | redisCache.setCacheObject(redisKey, remote); |
| | |
| | | // 发布事件 |
| | | eventPublisher.publishEvent(new DeviceStatusEvent(boxSn, currentOnline)); |
| | | // 更新数据库 |
| | | ArdDroneInfo local = localMap.get(boxSn); |
| | | if (local != null) { |
| | | local.setOnLine(currentOnline ? 1 : 0); |
| | | updateArdDrone(local); |