| | |
| | | import org.springframework.boot.ApplicationRunner; |
| | | import org.springframework.context.event.EventListener; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | import javax.annotation.Resource; |
| | | import javax.validation.Validator; |
| | |
| | | |
| | | @Resource |
| | | protected Validator validator; |
| | | |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) { |
| | |
| | | // SDK 登录成功后写入 Redis |
| | | redisService.setCacheObject(getCacheKey(camera.getId()), camera); |
| | | } |
| | | |
| | | /** |
| | | * 同步设备通道与本地通道库信息 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2024/8/22 14:37 |
| | | */ |
| | | @Scheduled(cron = "0/10 * * * * ?") |
| | | public void syncChannel() { |
| | | try { |
| | | log.info("定时执行同步通道任务"); |
| | | 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()); |
| | | } |
| | | } |
| | | } |