From defe580b123e1b7c892b88619c05774157dc09b5 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Mon, 03 Nov 2025 15:39:32 +0800
Subject: [PATCH] 增加校验机场是否已关联相机

---
 ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java |   99 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java b/ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java
index 129ceca..b8f40d8 100644
--- a/ard-device/src/main/java/com/ard/device/camera/service/impl/ArdCameraServiceImpl.java
+++ b/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;
@@ -25,7 +27,9 @@
 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;
 import java.util.*;
@@ -54,6 +58,7 @@
 
     @Resource
     protected Validator validator;
+
 
     @Override
     public void run(ApplicationArguments args) {
@@ -291,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;
+    }
 
     /**
      * 同步通道
@@ -354,4 +373,84 @@
         redisService.setCacheObject(getCacheKey(camera.getId()), camera);
     }
 
+    /**
+     * 同步设备通道与本地通道库信息
+     *
+     * @author 刘苏义
+     * @date 2024/8/22 14:37
+     */
+    @Scheduled(cron = "0/10 * * * * ?")
+    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(cron = "0/30 * * * * ?")
+    public void failedReconnect() {
+        try {
+            log.debug("定时执行失败相机重连任务");
+            List<Object> ardCameras = redisService.getListKey(CacheConstants.CAMERA_LIST_KEY);
+            ardCameras.stream()
+                    .map(object -> (ArdCamera) object) // 将Object转换为ArdCameras
+                    .filter(camera -> !GlobalVariable.loginMap.containsKey(camera.getId()))
+                    .forEach(camera -> cameraSDKService.login(camera));
+        } catch (Exception ex) {
+            log.error("定时执行失败相机重连任务异常:{}", ex.getMessage());
+        }
+    }
+
+    /**
+     * 同步相机在线状态
+     * 刘苏义
+     * 2023/10/8 14:54:41
+     */
+    @Scheduled(cron = "0/10 * * * * ?")
+    public void cameraState() {
+        try {
+            log.debug("定时执行同步相机在线状态任务");
+            //调用查询方法
+            List<ArdCamera> ardCameraList = selectArdCameraList(new ArdCamera());
+            ardCameraList
+                    .forEach(camera -> {
+                        CameraCmd cmd = new CameraCmd();
+                        cmd.setCameraId(camera.getId());
+                        boolean onLineNew = cameraSDKService.isOnLine(cmd);
+                        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());
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3