| | |
| | | import org.springframework.context.event.EventListener; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | protected Validator validator; |
| | | |
| | | @Resource(name = "globalExecutor") |
| | | private ThreadPoolTaskExecutor executorService; |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) { |
| | |
| | | |
| | | public void initCamera() { |
| | | //清空相机缓存 |
| | | redisService.deleteObject(redisService.keys(getCacheKey("*"))); |
| | | redisService.deleteObject(CacheConstants.CAMERA_LIST); |
| | | //重新加载相机到缓存 |
| | | ardCameraMapper.selectArdCameraList(new ArdCamera()).forEach(ardCamera -> { |
| | | ardCameraMapper.resetCameraLoginId(ardCamera); |
| | | redisService.setCacheObject(getCacheKey(ardCamera.getId()), ardCamera); |
| | | cameraSDKService.login(ardCamera); |
| | | redisService.setCacheMapValue(CacheConstants.CAMERA_LIST, ardCamera.getId(), ardCamera); |
| | | // 提交到线程池异步执行 |
| | | executorService.submit(() -> { |
| | | cameraSDKService.login(ardCamera); |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 设置cache key |
| | | * |
| | | * @param configKey 参数键 |
| | | * @return 缓存键key |
| | | */ |
| | | private String getCacheKey(String configKey) { |
| | | return CacheConstants.CAMERA_LIST_KEY + configKey; |
| | | } |
| | | |
| | | |
| | |
| | | ardCamera.setUserId(SecurityUtils.getUserId()); |
| | | int res = ardCameraMapper.insertArdCamera(ardCamera); |
| | | if (res > 0) { |
| | | redisService.setCacheMapValue(CacheConstants.CAMERA_LIST, ardCamera.getId(), ardCamera); |
| | | cameraSDKService.login(ardCamera);//sdk登录获取通道信息 |
| | | } |
| | | return res; |
| | |
| | | ardCamera.setUpdateBy(SecurityUtils.getUsername()); |
| | | int res = ardCameraMapper.updateArdCamera(ardCamera); |
| | | if (res > 0) { |
| | | redisService.setCacheMapValue(CacheConstants.CAMERA_LIST, ardCamera.getId(), ardCamera); |
| | | cameraSDKService.logout(ardCamera);//sdk注销 |
| | | cameraSDKService.login(ardCamera);//sdk登录获取通道信息 |
| | | } |
| | |
| | | ArdCamera camera = ardCameraMapper.selectArdCameraById(id); |
| | | if (camera != null) { |
| | | //redis中删除 |
| | | redisService.deleteObject(getCacheKey(id)); |
| | | redisService.deleteCacheMapValue(CacheConstants.CAMERA_LIST, id); |
| | | //删除当前相机的所有通道 |
| | | ardChannelService.deleteArdChannelByDeviceId(id); |
| | | //sdk注销 |
| | |
| | | int i = ardCameraMapper.deleteArdCameraById(id); |
| | | if (i > 0) { |
| | | //redis中删除 |
| | | redisService.deleteObject(getCacheKey(id)); |
| | | redisService.deleteCacheMapValue(CacheConstants.CAMERA_LIST, id); |
| | | //删除当前相机的所有通道 |
| | | ardChannelService.deleteArdChannelByDeviceId(id); |
| | | //sdk注销 |
| | |
| | | @Override |
| | | public ArdCamera checkAirportHasCamera(ArdCamera camera) { |
| | | ArdCamera info = ardCameraMapper.checkAirportHasCamera(camera); |
| | | if (StringUtils.isNotNull(info)&& !info.getId().equals(camera.getId())) { |
| | | if (StringUtils.isNotNull(info) && !info.getId().equals(camera.getId())) { |
| | | return info; |
| | | } |
| | | return null; |
| | |
| | | public void LoginEventListener(LoginEvent loginEvent) { |
| | | ArdCamera camera = loginEvent.getCamera(); |
| | | ardCameraMapper.updateArdCamera(camera); |
| | | // SDK 登录成功后写入 Redis |
| | | redisService.setCacheObject(getCacheKey(camera.getId()), camera); |
| | | } |
| | | |
| | | /** |
| | |
| | | log.error("同步相机在线状态异常:{}", ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 同步相机通道 |
| | | */ |