‘liusuyi’
2024-04-02 6a26b1d539576a556d0f8682af7ae4317de78c7a
ard-work/src/main/java/com/ruoyi/utils/sdk/hiksdk/service/impl/HikvisionSDK.java
@@ -4,6 +4,7 @@
import com.ruoyi.alarm.global.domain.GuideTask;
import com.ruoyi.alarm.global.service.impl.QueueHandler;
import com.ruoyi.common.annotation.SdkOperate;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
@@ -19,6 +20,7 @@
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.utils.minio.MinioUtil;
import com.ruoyi.utils.sdk.common.GlobalVariable;
import com.ruoyi.utils.sdk.common.SdkErrorCodeEnum;
import com.ruoyi.utils.sdk.hiksdk.lib.ExceptionCallBack;
import com.ruoyi.utils.sdk.hiksdk.lib.HCNetSDK;
import com.sun.jna.NativeLong;
@@ -71,7 +73,7 @@
     * @修改人和其它信息
     */
    @Override
    public boolean login(ArdCameras camera) {
    public AjaxResult login(ArdCameras camera) {
        try {
            // 初始化
            if (!hCNetSDK.NET_DVR_Init()) {
@@ -111,14 +113,15 @@
            //同步登录
            int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
            if (lUserID < 0) {
                log.debug("Login Failed [ " + camera.getIp() + ":" + camera.getPort() + " ],错误码:" + hCNetSDK.NET_DVR_GetLastError());
                int errorCode = hCNetSDK.NET_DVR_GetLastError();
                camera.setChanNum(0);
                camera.setLoginId(-1);
                camera.setState("0");
                //删除管理通道
                ardChannelService.deleteArdChannelByDeviceId(camera.getId());
                ardCamerasService.updateArdCameras(camera);
                return false;
                log.error("设备[" + camera.getIp() + ":" + camera.getPort() + "]登录失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
                return AjaxResult.error("登录失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
            }
            log.debug("Login Success [ " + camera.getIp() + ":" + camera.getPort() + " ]");
@@ -127,7 +130,6 @@
                //设置异常回调函数(可在回调函数中获取设备上下线状态等)
                if (!hCNetSDK.NET_DVR_SetExceptionCallBack_V30(0, 0, fExceptionCallBack, null)) {
                    log.debug("Set fExceptionCallBack function fail");
                    return false;
                } else {
                    log.debug("Set fExceptionCallBack function successfully!");
                }
@@ -164,10 +166,11 @@
                GuidePriorityQueue.cameraQueueMap.put(camera.getId(), priorityQueue);
            }
            ardCamerasService.updateArdCameras(camera);
            return AjaxResult.success("设备登录成功");
        } catch (Exception ex) {
            log.error("注册设备异常", ex);
            return AjaxResult.error("注册设备异常" + ex.getMessage());
        }
        return true;
    }
    /**
@@ -180,11 +183,12 @@
     */
    @Override
    @Async("loginExecutor")
    public void asyncLogin(ArdCameras camera) {
    public AjaxResult asyncLogin(ArdCameras camera) {
        try {
            // 初始化
            if (!hCNetSDK.NET_DVR_Init()) {
                log.error("SDK初始化失败");
                return AjaxResult.error("SDK初始化失败");
            }
            //打印海康sdk日志
            if (Platform.isWindows()) {
@@ -220,16 +224,16 @@
            //同步登录
            int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
            if (lUserID < 0) {
                log.debug("Login Failed 【 " + camera.getIp() + ":" + camera.getPort() + " 】,Error Code:" + hCNetSDK.NET_DVR_GetLastError());
                int errorCode = hCNetSDK.NET_DVR_GetLastError();
                camera.setChanNum(0);
                camera.setLoginId(-1);
                camera.setState("0");
                //删除管理通道
                ardChannelService.deleteArdChannelByDeviceId(camera.getId());
                ardCamerasService.updateArdCameras(camera);
                return;
                log.error("设备[" + camera.getIp() + ":" + camera.getPort() + "]登录失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
                return AjaxResult.error("设备登录失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
            }
            log.debug("Login Success 【 " + camera.getIp() + ":" + camera.getPort() + " 】");
            synchronized (_lock) {
                if (fExceptionCallBack == null) {
@@ -237,7 +241,6 @@
                    //设置异常回调函数(可在回调函数中获取设备上下线状态等)
                    if (!hCNetSDK.NET_DVR_SetExceptionCallBack_V30(0, 0, fExceptionCallBack, null)) {
                        log.debug("Set fExceptionCallBack function fail");
                        return;
                    } else {
                        log.debug("Set fExceptionCallBack function successfully!");
                    }
@@ -272,8 +275,10 @@
            addVtdu(camera);
            //创建引导队列
            createGuideQueue(camera);
            return AjaxResult.success("设备登录成功");
        } catch (Exception ex) {
            log.error("注册设备异常", ex);
            return AjaxResult.error("注册设备异常" + ex.getMessage());
        }
    }
@@ -376,14 +381,14 @@
     */
    @Override
    @SdkOperate
    public boolean pTZControl(CameraCmd cmd) {
    public AjaxResult pTZControl(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChanNo();
        Integer speed = cmd.getSpeed();
        Integer code = cmd.getCode();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        int dwStop;
@@ -451,9 +456,10 @@
        boolean bool = hCNetSDK.NET_DVR_PTZControlWithSpeed_Other(userId, channelNum, dwPTZCommand, dwStop, speed);
        if (!bool) {
            int errorCode = hCNetSDK.NET_DVR_GetLastError();
            log.error("控制失败,请稍后重试" + errorCode);
            log.error("控制失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
            return AjaxResult.error("控制失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
        }
        return bool;
        return AjaxResult.success("控制成功");
    }
    /**
@@ -462,12 +468,12 @@
     * @param cmd 相机命令
     */
    @Override
    public boolean setFocusPos(CameraCmd cmd) {
    public AjaxResult setFocusPos(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        Integer dwFocusPos = cmd.getDwFocusPos();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        // 获取参数
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
@@ -485,10 +491,9 @@
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置GIS信息数据失败,请稍后重试" + code);
            return false;
        } else {
            return true;
            return AjaxResult.error("设置GIS信息数据失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        return AjaxResult.success("设置GIS信息数据成功");
    }
    /**
@@ -497,12 +502,11 @@
     * @param cmd 相机命令
     */
    @Override
    public int getFocusPos(CameraCmd cmd) {
        int result = 0;
    public AjaxResult getFocusPos(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return result;
            return AjaxResult.error("设备未登录");
        }
        // 获取参数
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
@@ -518,13 +522,12 @@
        boolean bool = hCNetSDK.NET_DVR_GetSTDConfig(userId, NET_DVR_GET_GISINFO, struStdCfg);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取GIS信息数据失败,请稍后重试" + code);
            return result;
        } else {
            struGisInfo.read();
            result = struGisInfo.struPtzPosEx.dwFocus;
            log.error("获取聚焦值失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取聚焦值失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        return result;
        struGisInfo.read();
        int result = struGisInfo.struPtzPosEx.dwFocus;
        return AjaxResult.success(result);
    }
    /**
@@ -533,20 +536,21 @@
     * @param cmd 相机命令
     */
    @Override
    public boolean setPreset(CameraCmd cmd) {
    public AjaxResult setPreset(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        Integer PresetIndex = cmd.getPresetIndex();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        boolean bool = hCNetSDK.NET_DVR_PTZPreset_Other(userId, channelNum, SET_PRESET, PresetIndex);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("预置点设置失败,请稍后重试" + code);
            log.error("预置点设置失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("预置点设置失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        return bool;
        return AjaxResult.success("预置点设置成功");
    }
    /**
@@ -555,20 +559,21 @@
     * @param cmd 相机命令
     */
    @Override
    public boolean gotoPreset(CameraCmd cmd) {
    public AjaxResult gotoPreset(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        Integer PresetIndex = cmd.getPresetIndex();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        boolean bool = hCNetSDK.NET_DVR_PTZPreset_Other(userId, channelNum, GOTO_PRESET, PresetIndex);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("预置点设置失败,请稍后重试" + code);
            log.error("调用预置点失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("调用预置点失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        return bool;
        return AjaxResult.success("调用预置点成功");
    }
    /**
@@ -891,11 +896,11 @@
     * @创建时间 2023/1/17 16:36
     * @修改人和其它信息
     */
    public Map<String, Object> getPtz1(CameraCmd cmd) {
    public AjaxResult getPtz(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return new HashMap<>();
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
@@ -904,31 +909,30 @@
        IntByReference ibrBytesReturned = new IntByReference(0);
        m_ptzPosCurrent.write();
        boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_PTZPOS, channelNum, pioint, m_ptzPosCurrent.size(), ibrBytesReturned);
        if (bool) {
            m_ptzPosCurrent.read();
            // DecimalFormat df = new DecimalFormat("0.0");//设置保留位数
            //16进制转Integer后除10,保留小数点1位
            //实际显示的PTZ值是获取到的十六进制值的十分之一,
            //如获取的水平参数P的值是0x1750,实际显示的P值为175度;
            //获取到的垂直参数T的值是0x0789,实际显示的T值为78.9度;
            //获取到的变倍参数Z的值是0x1100,实际显示的Z值为110倍。
            BigDecimal b = new BigDecimal((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wPanPos)) / 10);
            BigDecimal c = new BigDecimal((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wTiltPos)) / 10);
            BigDecimal d = new BigDecimal((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wZoomPos)) / 10);
            double p = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
            double t = c.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
            double z = d.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
            //log.debug("T垂直参数为: " + p + "P水平参数为: " + t + "Z变倍参数为: " + z);
            Map<String, Object> ptzMap = new HashMap<>();
            ptzMap.put("p", p);
            ptzMap.put("t", t);
            ptzMap.put("z", z);
            return ptzMap;
        } else {
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("控制失败,请稍后重试" + code);
            return new HashMap<>();
            log.error("获取ptz失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取ptz失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        m_ptzPosCurrent.read();
        // DecimalFormat df = new DecimalFormat("0.0");//设置保留位数
        //16进制转Integer后除10,保留小数点1位
        //实际显示的PTZ值是获取到的十六进制值的十分之一,
        //如获取的水平参数P的值是0x1750,实际显示的P值为175度;
        //获取到的垂直参数T的值是0x0789,实际显示的T值为78.9度;
        //获取到的变倍参数Z的值是0x1100,实际显示的Z值为110倍。
        BigDecimal b = new BigDecimal((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wPanPos)) / 10);
        BigDecimal c = new BigDecimal((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wTiltPos)) / 10);
        BigDecimal d = new BigDecimal((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wZoomPos)) / 10);
        double p = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
        double t = c.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
        double z = d.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
        //log.debug("T垂直参数为: " + p + "P水平参数为: " + t + "Z变倍参数为: " + z);
        Map<String, Object> ptzMap = new HashMap<>();
        ptzMap.put("p", p);
        ptzMap.put("t", t);
        ptzMap.put("z", z);
        return AjaxResult.success(ptzMap);
    }
    /**
@@ -940,13 +944,13 @@
     * @修改人和其它信息
     */
    @Override
    public Map<String, Object> getPtz(CameraCmd cmd) {
    public AjaxResult getPtzHigh(CameraCmd cmd) {
        Map<String, Object> ptzMap = new HashMap<>();
        try {
            String cameraId = cmd.getCameraId();
            Integer chanNo = cmd.getChanNo();
            if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                return new HashMap<>();
                return AjaxResult.error("设备未登录");
            }
            IntByReference pchannel = new IntByReference(chanNo);
            Pointer pChannelNum = pchannel.getPointer();
@@ -962,24 +966,26 @@
            lpConfigParam6696.write();
            boolean res = hCNetSDK.NET_DVR_GetSTDConfig(lUserID, HCNetSDK.NET_DVR_GET_PTZABSOLUTEEX, lpConfigParam6696);
            if (!res) {
                log.error("获取高精度PTZ绝对位置配置失败,错误号:" + hCNetSDK.NET_DVR_GetLastError());
            } else {
                lpPTZAbsoluteEX_cfg.read();
                //log.debug("P:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fPan + " T:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fTilt + " Z:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fZoom
                //        + " 聚焦参数:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.dwFocus + " 聚焦范围:" + lpPTZAbsoluteEX_cfg.dwFocalLen + " 水平转动速度:" + lpPTZAbsoluteEX_cfg.fHorizontalSpeed
                //        + " 垂直转动速度:" + lpPTZAbsoluteEX_cfg.fVerticalSpeed + " 镜头变倍配置类型:" + lpPTZAbsoluteEX_cfg.byZoomType);
                float p = lpPTZAbsoluteEX_cfg.struPTZCtrl.fPan;
                float fTilt = lpPTZAbsoluteEX_cfg.struPTZCtrl.fTilt;
                float t = fTilt < 0 ? fTilt + 360 : fTilt;
                float z = lpPTZAbsoluteEX_cfg.struPTZCtrl.fZoom;
                ptzMap.put("p", p);
                ptzMap.put("t", t);
                ptzMap.put("z", z);
                int code = hCNetSDK.NET_DVR_GetLastError();
                log.error("获取高精度PTZ绝对位置配置失败: errorCde" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
                return AjaxResult.error("获取高精度PTZ绝对位置配置失败: errorCde" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            }
            lpPTZAbsoluteEX_cfg.read();
            //log.debug("P:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fPan + " T:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fTilt + " Z:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.fZoom
            //        + " 聚焦参数:" + lpPTZAbsoluteEX_cfg.struPTZCtrl.dwFocus + " 聚焦范围:" + lpPTZAbsoluteEX_cfg.dwFocalLen + " 水平转动速度:" + lpPTZAbsoluteEX_cfg.fHorizontalSpeed
            //        + " 垂直转动速度:" + lpPTZAbsoluteEX_cfg.fVerticalSpeed + " 镜头变倍配置类型:" + lpPTZAbsoluteEX_cfg.byZoomType);
            float p = lpPTZAbsoluteEX_cfg.struPTZCtrl.fPan;
            float fTilt = lpPTZAbsoluteEX_cfg.struPTZCtrl.fTilt;
            float t = fTilt < 0 ? fTilt + 360 : fTilt;
            float z = lpPTZAbsoluteEX_cfg.struPTZCtrl.fZoom;
            ptzMap.put("p", p);
            ptzMap.put("t", t);
            ptzMap.put("z", z);
            return AjaxResult.success(ptzMap);
        } catch (Exception ex) {
            log.error("获取高精度PTZ绝对位置异常:" + ex.getMessage());
            return AjaxResult.error("获取高精度PTZ绝对位置异常:" + ex.getMessage());
        }
        return ptzMap;
    }
    /**
@@ -992,12 +998,12 @@
     */
    @Override
    @SdkOperate
    public boolean setPtz1(CameraCmd cmd) {
    public AjaxResult setPtz(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        Map<String, Double> ptz = cmd.getPtzMap();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS();
@@ -1013,13 +1019,14 @@
            m_ptzPosCurrent.write();
            boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_PTZPOS, channelNum, point, m_ptzPosCurrent.size());
            if (!bool) {
                int code = hCNetSDK.NET_DVR_GetLastError();
                log.error("设置PTZ参数失败,请稍后重试:" + code);
                int errorCode = hCNetSDK.NET_DVR_GetLastError();
                log.error("设置PTZ参数失败:" + errorCode);
                return AjaxResult.error("设置PTZ参数失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
            }
            return bool;
            return AjaxResult.success("设置PTZ参数成功");
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return false;
            return AjaxResult.error("设置PTZ参数异常:" + ex.getMessage());
        }
    }
@@ -1033,13 +1040,13 @@
     */
    @Override
    @SdkOperate
    public boolean setPtz(CameraCmd cmd) {
    public AjaxResult setPtzHigh(CameraCmd cmd) {
        try {
            String cameraId = cmd.getCameraId();
            Integer chanNo = cmd.getChanNo();
            Map<String, Double> ptz = cmd.getPtzMap();
            if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                return false;
                return AjaxResult.error("设备未登录");
            }
            Integer lUserID = (Integer) GlobalVariable.loginMap.get(cameraId);
            IntByReference pchannel = new IntByReference(chanNo);
@@ -1071,24 +1078,25 @@
            lpConfigParam6697.write();
            boolean bool = hCNetSDK.NET_DVR_SetSTDConfig(lUserID, NET_DVR_SET_PTZABSOLUTEEX, lpConfigParam6697);
            if (!bool) {
                int code = hCNetSDK.NET_DVR_GetLastError();
                log.error("设置高精度PTZ参数失败,请稍后重试:" + code);
                int errorCode = hCNetSDK.NET_DVR_GetLastError();
                log.error("设置高精度PTZ参数失败:" + errorCode);
                return AjaxResult.error("设置高精度PTZ参数失败: errorCode:" + errorCode + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(errorCode));
            }
            return bool;
            return AjaxResult.success("设置高精度PTZ参数成功");
        } catch (Exception ex) {
            log.error("设置高精度PTZ参数异常", ex);
            return false;
            return AjaxResult.error("设置高精度PTZ参数异常:" + ex);
        }
    }
    @Override
    @SdkOperate
    public boolean guideTargetPosition(CameraCmd cmd) {
    public AjaxResult guideTargetPosition(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer chanNo = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS();
@@ -1110,11 +1118,12 @@
            if (!bool) {
                int code = hCNetSDK.NET_DVR_GetLastError();
                log.error("设置ptz失败,请稍后重试" + code);
                return AjaxResult.error("设置ptz失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            }
            return bool;
            return AjaxResult.success("引导坐标成功");
        } catch (Exception ex) {
            log.error("引导异常:" + ex.getMessage());
            return false;
            log.error("引导坐标异常:" + ex.getMessage());
            return AjaxResult.error("引导坐标异常:" + ex.getMessage());
        }
    }
@@ -1127,11 +1136,11 @@
     * @创建时间 2023/1/17 16:36
     * @修改人和其它信息 0-解锁 1-锁定
     */
    public int getPTZLockInfo(CameraCmd cmd) {
    public AjaxResult getPTZLockInfo(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return -1;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_PTZ_LOCKCFG netDvrPtzLockcfg = new NET_DVR_PTZ_LOCKCFG();
@@ -1141,11 +1150,12 @@
        boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_PTZLOCKCFG, channelNum, point, netDvrPtzLockcfg.size(), ibrBytesReturned);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取ptz锁定信息失败,请稍后重试" + code);
            return -1;
            log.error("获取ptz锁定信息失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取ptz锁定信息失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        } else {
            netDvrPtzLockcfg.read();
            return netDvrPtzLockcfg.byWorkMode;
            int byWorkMode = netDvrPtzLockcfg.byWorkMode;
            return AjaxResult.success(byWorkMode);
        }
    }
@@ -1159,11 +1169,11 @@
     */
    @Override
    @SdkOperate
    public boolean setZeroPtz(CameraCmd cmd) {
    public AjaxResult setZeroPtz(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_INITIALPOSITIONCTRL initialpositionctrl = new NET_DVR_INITIALPOSITIONCTRL();
@@ -1176,10 +1186,11 @@
        initialpositionctrl.write();
        boolean bool = hCNetSDK.NET_DVR_RemoteControl(userId, NET_DVR_PTZ_INITIALPOSITIONCTRL, point, initialpositionctrl.size());
        if (!bool) {
            int i = hCNetSDK.NET_DVR_GetLastError();
            log.error("错误码:" + i);
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置零方位角失败:" + code);
            return AjaxResult.error("设置零方位角失败: errorCode:" + code + "errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        return bool;
        return AjaxResult.success();
    }
    /**
@@ -1191,11 +1202,11 @@
     * @修改人和其它信息
     */
    @Override
    public Map<String, Object> getPtzScope(CameraCmd cmd) {
    public AjaxResult getPtzScope(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return new HashMap<>();
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_PTZSCOPE m_ptzPosCurrent = new NET_DVR_PTZSCOPE();
@@ -1205,8 +1216,8 @@
        boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_PTZSCOPE, channelNum, point, m_ptzPosCurrent.size(), ibrBytesReturned);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置ptz失败,请稍后重试" + code);
            return new HashMap<>();
            log.error("获取ptz范围失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取ptz范围失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        } else {
            m_ptzPosCurrent.read();
            DecimalFormat df = new DecimalFormat("0.0");//设置保留位数
@@ -1224,13 +1235,12 @@
            ptzScopeMap.put("tMin", wTiltPosMin);
            ptzScopeMap.put("zMax", wZoomPosMax);
            ptzScopeMap.put("zMin", wZoomPosMin);
            return ptzScopeMap;
            return AjaxResult.success(ptzScopeMap);
        }
    }
    /**
     * @描述 透雾开关
     * @描述 切换透雾
     * @参数 [userId, channelNum, enable]
     * @返回值 boolean
     * @创建人 刘苏义
@@ -1238,12 +1248,12 @@
     * @修改人和其它信息
     */
    @Override
    public boolean controlDefogcfg(CameraCmd cmd) {
    public AjaxResult controlDefogcfg(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_CAMERAPARAMCFG_EX struCameraParam = new NET_DVR_CAMERAPARAMCFG_EX();
@@ -1251,7 +1261,9 @@
        IntByReference ibrBytesReturned = new IntByReference(0);
        boolean b_GetCameraParam = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_CCDPARAMCFG_EX, channelNum, point, struCameraParam.size(), ibrBytesReturned);
        if (!b_GetCameraParam) {
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        struCameraParam.read();
        log.debug("是否开启透雾:" + struCameraParam.struDefogCfg.byMode);
@@ -1268,14 +1280,15 @@
        boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_CCDPARAMCFG_EX, channelNum, point, struCameraParam.size());
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置透雾失败,请稍后重试" + code);
            log.error("切换透雾失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("切换透雾失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        log.debug("设置透雾成功");
        return bool;
        log.debug("切换透雾成功");
        return AjaxResult.success("切换透雾成功");
    }
    /**
     * @描述 红外开关
     * @描述 切换红外
     * @参数 [userId, channelNum, enable]
     * @返回值 boolean
     * @创建人 刘苏义
@@ -1283,20 +1296,22 @@
     * @修改人和其它信息
     */
    @Override
    public boolean controlInfrarecfg(CameraCmd cmd) {
    public AjaxResult controlInfrarecfg(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer chanNo = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_CAMERAPARAMCFG_EX struDayNigh = new NET_DVR_CAMERAPARAMCFG_EX();
        Pointer point = struDayNigh.getPointer();
        IntByReference ibrBytesReturned = new IntByReference(0);
        boolean b_GetCameraParam = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_CCDPARAMCFG_EX, chanNo, point, struDayNigh.size(), ibrBytesReturned);
        boolean b_GetCameraParam = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_CCDPARAMCFG, chanNo, point, struDayNigh.size(), ibrBytesReturned);
        if (!b_GetCameraParam) {
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取前端参数失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取前端参数失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        struDayNigh.read();
        String current = struDayNigh.struDayNight.byDayNightFilterType == 1 ? "开启" : "关闭";
@@ -1312,15 +1327,14 @@
        daynight.byDayNightFilterTime = 60;
        struDayNigh.struDayNight = daynight;
        struDayNigh.write();
        boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_CCDPARAMCFG_EX, chanNo, point, struDayNigh.size());
        boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_CCDPARAMCFG, chanNo, point, struDayNigh.size());
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置夜视失败,请稍后重试" + code);
        } else {
            log.debug("设置夜视成功");
            log.error("切换红外失败 ErrorCode:{},ErrorInfo:{}", code, SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("切换红外失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        return bool;
        log.debug("切换红外成功");
        return AjaxResult.success("切换红外成功");
    }
    /**
@@ -1332,12 +1346,12 @@
     * @修改人和其它信息
     */
    @Override
    public boolean controlFocusMode(CameraCmd cmd) {
    public AjaxResult controlFocusMode(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_FOCUSMODE_CFG struFocusMode = new NET_DVR_FOCUSMODE_CFG();
@@ -1345,7 +1359,9 @@
        IntByReference ibrBytesReturned = new IntByReference(0);
        boolean b_GetCameraParam = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, struFocusMode.size(), ibrBytesReturned);
        if (!b_GetCameraParam) {
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        struFocusMode.read();
        log.debug("当前聚焦模式:" + struFocusMode.byFocusMode);
@@ -1362,10 +1378,11 @@
        boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_FOCUSMODECFG, channelNum, point, struFocusMode.size());
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置聚焦模式失败,请稍后重试" + code);
            log.error("设置聚焦模式失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("设置聚焦模式失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        log.debug("设置聚焦模式成功");
        return bool;
        return AjaxResult.success("设置聚焦模式成功");
    }
    /**
@@ -1376,11 +1393,11 @@
     * @创建时间 2023/1/18 13:07
     * @修改人和其它信息
     */
    public String getFocusMode(CameraCmd cmd) {
    public AjaxResult getFocusMode(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return "";
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_FOCUSMODE_CFG struFocusMode = new NET_DVR_FOCUSMODE_CFG();
@@ -1388,11 +1405,13 @@
        IntByReference ibrBytesReturned = new IntByReference(0);
        boolean b_GetCameraParam = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, struFocusMode.size(), ibrBytesReturned);
        if (!b_GetCameraParam) {
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        struFocusMode.read();
        log.debug("当前聚焦模式:" + struFocusMode.byFocusMode);
        return String.valueOf(struFocusMode.byFocusMode);
        return AjaxResult.success(struFocusMode.byFocusMode);
    }
    /**
@@ -1404,12 +1423,12 @@
     * @修改人和其它信息
     */
    @Override
    public boolean controlPTHeateRpwron(CameraCmd cmd) {
    public AjaxResult controlPTHeateRpwron(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        int dwStop;
@@ -1421,10 +1440,11 @@
        boolean bool = hCNetSDK.NET_DVR_PTZControl_Other(userId, channelNum, HEATER_PWRON, dwStop);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置云台加热失败,请稍后重试" + code);
            log.error("设置云台加热失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("设置云台加热失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        log.debug("设置云台加热成功");
        return bool;
        return AjaxResult.success("设置云台加热成功");
    }
    /**
@@ -1436,12 +1456,12 @@
     * @修改人和其它信息
     */
    @Override
    public boolean controlCameraDeicing(CameraCmd cmd) {
    public AjaxResult controlCameraDeicing(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_DEVSERVER_CFG struDeicing = new NET_DVR_DEVSERVER_CFG();
@@ -1449,7 +1469,9 @@
        IntByReference ibrBytesReturned = new IntByReference(0);
        boolean b_GetCameraParam = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_DEVSERVER_CFG, channelNum, point, struDeicing.size(), ibrBytesReturned);
        if (!b_GetCameraParam) {
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取前端参数失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        struDeicing.read();
        log.debug("是否开启除冰:" + struDeicing.byEnableDeicing);
@@ -1463,10 +1485,11 @@
        boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_DEVSERVER_CFG, channelNum, point, struDeicing.size());
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("设置镜头除冰失败,请稍后重试" + code);
            log.error("设置镜头除冰失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("设置镜头除冰失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        log.debug("设置镜头除冰成功");
        return bool;
        return AjaxResult.success("设置镜头除冰成功");
    }
    /**
@@ -1474,17 +1497,18 @@
     *
     * @param cmd 相机命令
     */
    public String captureJPEGPicture(CameraCmd cmd) {
    public AjaxResult captureJPEGPicture(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return "";
            return AjaxResult.error("设备未登录");
        }
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
        NET_DVR_WORKSTATE_V30 devwork = new NET_DVR_WORKSTATE_V30();
        if (!hCNetSDK.NET_DVR_GetDVRWorkState_V30(userId, devwork)) {
            // 返回Boolean值,判断是否获取设备能力
            log.error("抓图失败,请稍后重试");
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取设备工作状态失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取设备工作状态失败: errorCode" + code + " errorInfo" + SdkErrorCodeEnum.getDescByCode(code));
        }
        //图片质量
        NET_DVR_JPEGPARA jpeg = new NET_DVR_JPEGPARA();
@@ -1504,7 +1528,7 @@
        String png_base64 = decoder.encodeToString(jpegBuffer.array());//转换成base64串
        png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n
        log.debug("-----------处理完成截图数据----------");
        return png_base64;
        return AjaxResult.success(png_base64);
    }
    /**
@@ -1870,11 +1894,11 @@
     * @修改人和其它信息 0-解锁 1-锁定
     */
    @Override
    public Map<String, Object> getGisInfo(CameraCmd cmd) {
    public AjaxResult getGisInfo(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return new HashMap<>();
            return AjaxResult.error("设备未登录");
        }
        // 获取参数
        Integer userId = (Integer) GlobalVariable.loginMap.get(cameraId);
@@ -1890,17 +1914,17 @@
        boolean bool = hCNetSDK.NET_DVR_GetSTDConfig(userId, NET_DVR_GET_GISINFO, struStdCfg);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.error("获取GIS信息数据失败,请稍后重试" + code);
            return new HashMap<>();
        } else {
            struGisInfo.read();
            Map<String, Object> map = new HashMap<>();
            map.put("p", struGisInfo.struPtzPos.fPanPos);
            map.put("t", struGisInfo.struPtzPos.fTiltPos < 0 ? struGisInfo.struPtzPos.fTiltPos + 360 : struGisInfo.struPtzPos.fTiltPos);
            map.put("z", struGisInfo.struPtzPos.fZoomPos);
            map.put("fHorFieldAngle", struGisInfo.fHorizontalValue);// 水平视场角
            map.put("fVerFieldAngle", struGisInfo.fVerticalValue);// 垂直视场角
            return map;
            log.error("获取GIS信息数据失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
            return AjaxResult.error("获取GIS信息数据失败: errorCode:" + code + " errorInfo:" + SdkErrorCodeEnum.getDescByCode(code));
        }
        struGisInfo.read();
        Map<String, Object> map = new HashMap<>();
        map.put("p", struGisInfo.struPtzPos.fPanPos);
        map.put("t", struGisInfo.struPtzPos.fTiltPos < 0 ? struGisInfo.struPtzPos.fTiltPos + 360 : struGisInfo.struPtzPos.fTiltPos);
        map.put("z", struGisInfo.struPtzPos.fZoomPos);
        map.put("fHorFieldAngle", struGisInfo.fHorizontalValue);// 水平视场角
        map.put("fVerFieldAngle", struGisInfo.fVerticalValue);// 垂直视场角
        return AjaxResult.success(map);
    }
}