liusuyi
2024-10-10 38f29e38fcc668171dc05c53d40a36b895c86102
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/CameraSdkServiceImpl.java
@@ -25,12 +25,17 @@
import com.ruoyi.utils.sdk.common.GlobalVariable;
import com.ruoyi.utils.tools.ArdTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -41,7 +46,7 @@
 * @Date: 2023年10月16日15:21:01
 **/
@Service
@Slf4j(topic = "SDK")
@Slf4j(topic = "sdk")
public class CameraSdkServiceImpl implements ICameraSdkService, ApplicationRunner {
    @Resource
    private IArdCamerasService ardCamerasService;
@@ -64,10 +69,27 @@
    @Override
    public void run(ApplicationArguments args) {
        try {
            log.info("初始化登录相机开始");
            ardCamerasService.resetCameraLoginId();
            List<ArdCameras> ardCameras = ardCamerasService.selectArdCamerasListNoDataScope(new ArdCameras());
            for (ArdCameras camera : ardCameras) {
                asyncLogin(camera);
            }
            ardCameras.stream().forEach(ardCamera -> asyncLogin(ardCamera));
            //开启登录失败相机重连定时任务
            ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
            executor.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    try {
                        log.info("开始执行登录失败相机重连定时任务");
                        List<Object> ardCameras = redisCache.getListKey(CacheConstants.CAMERA_LIST_KEY);
                        ardCameras.stream()
                                .map(object -> (ArdCameras) object) // 将Object转换为ArdCameras
                                .filter(camera -> !GlobalVariable.loginMap.containsKey(camera.getId()))
                                .forEach(camera -> asyncLogin(camera));
                    } catch (Exception ex) {
                        log.error("重连相机异常:" + ex.getMessage());
                    }
                }
            }, 30, 30, TimeUnit.SECONDS);  // 任务延迟
        } catch (Exception ex) {
            log.error("初始化登录相机异常:" + ex.getMessage());
        }
@@ -586,17 +608,17 @@
                    case 1:
                        if (ardWellGuideCamera.getP1() != null) {
                            ptzMap = new HashMap<>();
                            ptzMap.put("p" , ardWellGuideCamera.getP1());
                            ptzMap.put("t" , ardWellGuideCamera.getT1());
                            ptzMap.put("z" , ardWellGuideCamera.getZ1());
                            ptzMap.put("p", ardWellGuideCamera.getP1());
                            ptzMap.put("t", ardWellGuideCamera.getT1());
                            ptzMap.put("z", ardWellGuideCamera.getZ1());
                        }
                        break;
                    case 2:
                        if (ardWellGuideCamera.getP2() != null) {
                            ptzMap = new HashMap<>();
                            ptzMap.put("p" , ardWellGuideCamera.getP2());
                            ptzMap.put("t" , ardWellGuideCamera.getT2());
                            ptzMap.put("z" , ardWellGuideCamera.getZ2());
                            ptzMap.put("p", ardWellGuideCamera.getP2());
                            ptzMap.put("t", ardWellGuideCamera.getT2());
                            ptzMap.put("z", ardWellGuideCamera.getZ2());
                        }
                        break;
@@ -624,9 +646,9 @@
        }
        //按井坐标开始引导
        if (!guideTargetPosition(cmd).get("code").equals(200)) {
            return AjaxResult.warn("井坐标引导失败" , "cameraId:" + cameraId);
            return AjaxResult.warn("井坐标引导失败", "cameraId:" + cameraId);
        }
        return AjaxResult.success("井坐标引导成功" , "cameraId:" + cameraId);
        return AjaxResult.success("井坐标引导成功", "cameraId:" + cameraId);
    }