liusuyi
2026-01-05 d2a65f0c13df21354ac83bf13b15f46937bd8ecb
ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java
@@ -13,10 +13,12 @@
import com.ard.common.utils.spring.SpringUtils;
import com.ard.common.utils.uuid.IdUtils;
import com.ard.device.camera.domain.ArdCamera;
import com.ard.device.camera.domain.CameraCmd;
import com.ard.device.camera.mapper.ArdCameraMapper;
import com.ard.device.camera.service.IArdCameraService;
import com.ard.device.channel.domain.ArdChannel;
import com.ard.device.channel.service.IArdChannelService;
import com.ard.device.component.sdk.common.GlobalVariable;
import com.ard.device.component.sdk.event.LoginEvent;
import com.ard.device.component.sdk.service.CameraSDKService;
import lombok.extern.slf4j.Slf4j;
@@ -27,6 +29,7 @@
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;
import java.util.*;
@@ -160,7 +163,7 @@
        ardCamera.setUpdateBy(SecurityUtils.getUsername());
        int res = ardCameraMapper.updateArdCamera(ardCamera);
        if (res > 0) {
            cameraSDKService.logout(ardCamera.getId());//sdk注销
            cameraSDKService.logout(ardCamera);//sdk注销
            cameraSDKService.login(ardCamera);//sdk登录获取通道信息
        }
        return res;
@@ -183,7 +186,7 @@
                //删除当前相机的所有通道
                ardChannelService.deleteArdChannelByDeviceId(id);
                //sdk注销
                cameraSDKService.logout(id);
                cameraSDKService.logout(camera);
            }
        }
        return ardCameraMapper.deleteArdCameraByIds(ids);
@@ -204,7 +207,7 @@
            //删除当前相机的所有通道
            ardChannelService.deleteArdChannelByDeviceId(id);
            //sdk注销
            cameraSDKService.logout(id);
            cameraSDKService.logout(ArdCamera.builder().id(id).build());
        }
        return i;
    }
@@ -293,6 +296,20 @@
        return DeviceConstants.UNIQUE;
    }
    /**
     * 校验机场是否已关联相机
     *
     * @param camera 相机
     * @return 结果
     */
    @Override
    public ArdCamera checkAirportHasCamera(ArdCamera camera) {
        ArdCamera info = ardCameraMapper.checkAirportHasCamera(camera);
        if (StringUtils.isNotNull(info)&& !info.getId().equals(camera.getId())) {
            return info;
        }
        return null;
    }
    /**
     * 同步通道
@@ -355,32 +372,5 @@
        // 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());
        }
    }
}