zhaowenyu
2026-02-10 8fe9faddf234f7087a516d7e1e068b558289e605
ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java
@@ -28,6 +28,7 @@
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;
@@ -59,6 +60,8 @@
    @Resource
    protected Validator validator;
    @Resource(name = "globalExecutor")
    private ThreadPoolTaskExecutor executorService;
    @Override
    public void run(ApplicationArguments args) {
@@ -67,23 +70,15 @@
    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);
            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;
        });
    }
@@ -146,6 +141,7 @@
        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;
@@ -163,6 +159,7 @@
        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登录获取通道信息
        }
@@ -182,7 +179,7 @@
            ArdCamera camera = ardCameraMapper.selectArdCameraById(id);
            if (camera != null) {
                //redis中删除
                redisService.deleteObject(getCacheKey(id));
                redisService.deleteCacheMapValue(CacheConstants.CAMERA_LIST, id);
                //删除当前相机的所有通道
                ardChannelService.deleteArdChannelByDeviceId(id);
                //sdk注销
@@ -203,7 +200,7 @@
        int i = ardCameraMapper.deleteArdCameraById(id);
        if (i > 0) {
            //redis中删除
            redisService.deleteObject(getCacheKey(id));
            redisService.deleteCacheMapValue(CacheConstants.CAMERA_LIST, id);
            //删除当前相机的所有通道
            ardChannelService.deleteArdChannelByDeviceId(id);
            //sdk注销
@@ -369,8 +366,6 @@
    public void LoginEventListener(LoginEvent loginEvent) {
        ArdCamera camera = loginEvent.getCamera();
        ardCameraMapper.updateArdCamera(camera);
        // SDK 登录成功后写入 Redis
        redisService.setCacheObject(getCacheKey(camera.getId()), camera);
    }
    /**
@@ -426,6 +421,7 @@
            log.error("同步相机在线状态异常:{}", ex.getMessage());
        }
    }
    /**
     * 同步相机通道
     */