| | |
| | | redisService.setCacheObject(getCacheKey(camera.getId()), camera); |
| | | } |
| | | |
| | | /** |
| | | * 同步设备通道与本地通道库信息 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2024/8/22 14:37 |
| | | */ |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void syncChannel() { |
| | | try { |
| | | log.debug("定时执行同步通道任务"); |
| | | List<ArdCamera> ardCameraList = this.selectArdCameraList(new ArdCamera()); |
| | | if (!ardCameraList.isEmpty()) { |
| | | ardCameraList |
| | | .forEach(ardCamera -> { |
| | | //SDK获取实际通道 |
| | | List<ArdChannel> ardChannelListSDK = cameraSDKService.getChannels(ardCamera); |
| | | //数据库获取通道 |
| | | ArdChannel ardChannel = new ArdChannel(); |
| | | ardChannel.setDeviceId(ardCamera.getId()); |
| | | List<ArdChannel> ardChannelListDb = ardChannelService.selectArdChannelList(ardChannel); |
| | | //同步通道 |
| | | asyncChannel(ardChannelListDb, ardChannelListSDK); |
| | | }); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("定时执行同步通道任务异常:{}", ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 定时执行登录失败相机重新登录 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2024/8/22 14:37 |
| | | */ |
| | | @Scheduled(fixedDelay = 10000) |
| | | public void failedReconnect() { |
| | | try { |
| | | log.debug("定时执行失败相机重连任务"); |
| | | // 从数据库取全部设备 |
| | | List<ArdCamera> cameraList = selectArdCameraList(new ArdCamera()); |
| | | cameraList.stream() |
| | | // 只处理登录失败或离线的设备 |
| | | .filter(camera -> camera.getLoginId() == null || camera.getLoginId() < 0 || "0".equals(camera.getState())) |
| | | .forEach(camera -> { |
| | | log.info("尝试重新登录设备 {}:{}", camera.getIp(), camera.getPort()); |
| | | cameraSDKService.login(camera); |
| | | }); |
| | | |
| | | } catch (Exception ex) { |
| | | log.error("定时执行失败相机重连任务异常:{}", ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 同步相机在线状态 |
| | | * 刘苏义 |
| | | * 2023/10/8 14:54:41 |
| | | */ |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void cameraState() { |
| | | try { |
| | | log.debug("定时执行同步相机在线状态任务"); |
| | | //调用查询方法 |
| | | List<ArdCamera> ardCameraList = selectArdCameraList(new ArdCamera()); |
| | | ardCameraList |
| | | .forEach(camera -> { |
| | | boolean onLineNew = cameraSDKService.isOnLine(camera); |
| | | boolean onLineOld = "1".equals(camera.getState()); |
| | | if (onLineNew != onLineOld) { |
| | | if (onLineNew) { |
| | | camera.setState("1"); |
| | | } else { |
| | | camera.setState("0"); |
| | | } |
| | | camera.setUpdateTime(DateUtils.getNowDate()); |
| | | ardCameraMapper.updateArdCamera(camera); |
| | | } |
| | | }); |
| | | } catch (Exception ex) { |
| | | log.error("同步相机在线状态异常:{}", ex.getMessage()); |
| | | } |
| | | } |
| | | } |