ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
@@ -2,32 +2,36 @@
import com.ruoyi.common.annotation.SdkOperate;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.service.IArdCamerasService;
import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.hiksdk.common.GlobalVariable;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.hiksdk.config.MinioClientSingleton;
import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil;
import com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK;
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.device.hiksdk.sdk.HCNetSDK;
import com.ruoyi.device.hiksdk.service.IHikClientService;
import com.ruoyi.device.hiksdk.util.hikSdkUtil.LoginResultCallBack;
import com.ruoyi.device.hiksdk.util.minio.MinioUtils;
import com.ruoyi.device.hiksdk.sdk.LoginResultCallBack;
import com.ruoyi.utils.minio.MinioUtil;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Base64;
import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK.*;
import static com.ruoyi.device.hiksdk.sdk.HCNetSDK.*;
/**
 * @ClassName: hikClientServiceImpl
@@ -40,8 +44,10 @@
@Service
public class HikClientServiceImpl implements IHikClientService {
    @Value("${minio.endpoint}")
    private static String endpoint;
    @Resource
    IArdCamerasService ardCamerasService;
    private IArdCamerasService ardCamerasService;
    private static HCNetSDK hCNetSDK;
@@ -125,7 +131,7 @@
        GlobalVariable.loginMap.remove(camera.getId());
        GlobalVariable.loginMap.put(camera.getId(), lUserID);
        camera.setLoginId(lUserID);
        camera.setChannel((int) m_strDeviceInfo.byStartChan);
        camera.setStartDChan((int) m_strDeviceInfo.byStartChan);
        return camera;
    }
@@ -179,7 +185,7 @@
        int i = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
        if (i < 0) {
            int errorCode = hCNetSDK.NET_DVR_GetLastError();
            log.info("登录异常:" + errorCode);
            log.error("登录异常:" + errorCode);
        }
    }
@@ -256,7 +262,7 @@
    public boolean pTZControlWithSpeed(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        Integer speed = cmd.getSpeed();
        Integer code = cmd.getCode();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
@@ -328,7 +334,7 @@
        boolean bool = hCNetSDK.NET_DVR_PTZControlWithSpeed_Other(userId, channelNum, dwPTZCommand, dwStop, speed);
        if (!bool) {
            int errorCode = hCNetSDK.NET_DVR_GetLastError();
            log.info("控制失败,请稍后重试" + errorCode);
            log.error("控制失败,请稍后重试" + errorCode);
        }
        return bool;
    }
@@ -342,23 +348,31 @@
    @SdkOperate
    public boolean setFocusPos(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        Integer dwFocusPos = cmd.getDwFocusPos();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
        // 获取参数
        Integer userId = GlobalVariable.loginMap.get(cameraId);
        NET_DVR_FOCUSMODE_CFG focusmodeCfg = new NET_DVR_FOCUSMODE_CFG();
        Pointer point = focusmodeCfg.getPointer();
        IntByReference ibrBytesReturned = new IntByReference(0);
        focusmodeCfg.dwFocusPos = dwFocusPos;
        boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, focusmodeCfg.size(), ibrBytesReturned);
        HCNetSDK.NET_DVR_STD_CONFIG struStdCfg = new HCNetSDK.NET_DVR_STD_CONFIG();
        HCNetSDK.NET_DVR_GIS_INFO struGisInfo = new HCNetSDK.NET_DVR_GIS_INFO();
        struGisInfo.struPtzPosEx.dwFocus = dwFocusPos;
        struStdCfg.read();
        IntByReference lchannel = new IntByReference(channelNum);
        struStdCfg.lpInBuffer = struGisInfo.getPointer();
        struStdCfg.lpCondBuffer = lchannel.getPointer();
        struStdCfg.dwCondSize = 4;
        struStdCfg.dwInSize = struGisInfo.size();
        struStdCfg.write();//设置前之前要write()
        boolean bool = hCNetSDK.NET_DVR_SetSTDConfig(userId, NET_DVR_GET_GISINFO, struStdCfg);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("设置聚焦值失败,请稍后重试" + code);
            log.error("设置GIS信息数据失败,请稍后重试" + code);
            return false;
        } else {
            return true;
        }
        return bool;
    }
    /**
@@ -369,28 +383,31 @@
    @Override
    public Map<String, Object> getFocusPos(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return new HashMap<>();
        }
        // 获取参数
        Integer userId = GlobalVariable.loginMap.get(cameraId);
        NET_DVR_FOCUSMODE_CFG focusmodeCfg = new NET_DVR_FOCUSMODE_CFG();
        Pointer point = focusmodeCfg.getPointer();
        IntByReference ibrBytesReturned = new IntByReference(0);
        boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, NET_DVR_GET_FOCUSMODECFG, channelNum, point, focusmodeCfg.size(), ibrBytesReturned);
        if (bool) {
            focusmodeCfg.read();
            Map<String, Object> map = new HashMap<>();
            map.put("dwFocusPos", focusmodeCfg.dwFocusPos);
            map.put("byFocusDefinitionDisplay ", focusmodeCfg.byFocusDefinitionDisplay);
            map.put("dwRelativeFocusPos", focusmodeCfg.dwRelativeFocusPos);
            return map;
        } else {
        HCNetSDK.NET_DVR_STD_CONFIG struStdCfg = new HCNetSDK.NET_DVR_STD_CONFIG();
        HCNetSDK.NET_DVR_GIS_INFO struGisInfo = new HCNetSDK.NET_DVR_GIS_INFO();
        struStdCfg.read();
        IntByReference lchannel = new IntByReference(channelNum);
        struStdCfg.lpCondBuffer = lchannel.getPointer();
        struStdCfg.dwCondSize = 4;
        struStdCfg.lpOutBuffer = struGisInfo.getPointer();
        struStdCfg.dwOutSize = struGisInfo.size();
        struStdCfg.write();//设置前之前要write()
        boolean bool = hCNetSDK.NET_DVR_GetSTDConfig(userId, NET_DVR_GET_GISINFO, struStdCfg);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("获取聚焦值失败,请稍后重试" + code);
            log.error("获取GIS信息数据失败,请稍后重试" + code);
            return new HashMap<>();
        } else {
            struGisInfo.read();
            Map<String, Object> map = new HashMap<>();
            map.put("dwFocus", struGisInfo.struPtzPosEx.dwFocus);
            return map;
        }
    }
@@ -403,7 +420,7 @@
    @SdkOperate
    public boolean setPreset(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        Integer PresetIndex = cmd.getPresetIndex();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
@@ -412,7 +429,7 @@
        boolean bool = hCNetSDK.NET_DVR_PTZPreset_Other(userId, channelNum, SET_PRESET, PresetIndex);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("预置点设置失败,请稍后重试" + code);
            log.error("预置点设置失败,请稍后重试" + code);
        }
        return bool;
    }
@@ -426,7 +443,7 @@
    @SdkOperate
    public boolean gotoPreset(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        Integer PresetIndex = cmd.getPresetIndex();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
@@ -435,13 +452,13 @@
        boolean bool = hCNetSDK.NET_DVR_PTZPreset_Other(userId, channelNum, GOTO_PRESET, PresetIndex);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("预置点设置失败,请稍后重试" + code);
            log.error("预置点设置失败,请稍后重试" + code);
        }
        return bool;
    }
    /**
     * @描述 获取分辨率
     * @描述 获取通道压缩参数
     * @参数 [cameraId, channelNum]
     * @返回值 java.lang.String
     * @创建人 刘苏义
@@ -449,100 +466,158 @@
     * @修改人和其它信息
     */
    @Override
    public String getVideoResolution(CameraCmd cmd) {
    public Map<String,String> getVideoCompressionCfg(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer chanNo = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return " ";
            return null;
        }
        Integer userId = GlobalVariable.loginMap.get(cameraId);
        String ResResolution = "";
        NET_DVR_COMPRESSIONCFG_V30 resolution = new NET_DVR_COMPRESSIONCFG_V30();
        resolution.write();
        Pointer pioint = resolution.getPointer();
        Map<String,String> map=new HashMap<>();
        NET_DVR_COMPRESSIONCFG_V30 compressioncfg = new NET_DVR_COMPRESSIONCFG_V30();
        compressioncfg.write();
        Pointer pioint = compressioncfg.getPointer();
        IntByReference ibrBytesReturned = new IntByReference(0);
        try {
            boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_COMPRESSCFG_V30, channelNum, pioint, resolution.size(), ibrBytesReturned);
            boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_COMPRESSCFG_V30, chanNo, pioint, compressioncfg.size(), ibrBytesReturned);
            if (bool) {
                resolution.read();
                compressioncfg.read();
                //码流类型:0-视频流,1-复合流,0xfe- 自动(和源一致)
                String streamType="";
                switch(compressioncfg.struNormHighRecordPara.byStreamType)
                {
                    case 0: streamType="视频流";break;
                    case 1: streamType="复合流";break;
                    default:streamType="未知";break;
                }
                //视频编码类型:0-私有264,1-标准h264,2-标准mpeg4,7-M-JPEG,8-MPEG2,9-SVAC,10-标准h265,0xfe- 自动(和源一致),0xff-无效
                String videoEncType="";
                switch (compressioncfg.struNormHighRecordPara.byVideoEncType)
                {
                    case 0:videoEncType="私有264";break;
                    case 1:videoEncType="标准h264";break;
                    case 2:videoEncType="标准mpeg4";break;
                    case 7:videoEncType="M-JPEG";break;
                    case 8:videoEncType="MPEG2";break;
                    case 9:videoEncType="SVAC";break;
                    case 10:videoEncType="标准h265";break;
                    default: videoEncType="未知";break;
                }
                //视频码率
                String videoBitrate="";
                switch (compressioncfg.struNormHighRecordPara.dwVideoBitrate)
                {
                    case 0:videoBitrate="保留";break;
                    case 1:videoBitrate="16K(保留)";break;
                    case 2:videoBitrate="32K";break;
                    case 3:videoBitrate="48k";break;
                    case 4:videoBitrate="64k";break;
                    case 5:videoBitrate="80k";break;
                    case 6:videoBitrate="96k";break;
                    case 7:videoBitrate="128k";break;
                    case 8:videoBitrate="160k";break;
                    case 9:videoBitrate="192k";break;
                    case 10:videoBitrate="224k";break;
                    case 11:videoBitrate="256K";break;
                    case 12:videoBitrate="320K";break;
                    case 13:videoBitrate="384K";break;
                    case 14:videoBitrate="448K";break;
                    case 15:videoBitrate="512K";break;
                    case 16:videoBitrate="640K";break;
                    case 17:videoBitrate="768K";break;
                    case 18:videoBitrate="896K";break;
                    case 19:videoBitrate="1024K";break;
                    case 20:videoBitrate="1280K";break;
                    case 21:videoBitrate="1536K";break;
                    case 22:videoBitrate="1792K";break;
                    case 23:videoBitrate="2048K";break;
                    case 24:videoBitrate="3072K";break;
                    case 25:videoBitrate="4096K";break;
                    case 26:videoBitrate="8192K";break;
                    case 27:videoBitrate="16384K";break;
                    default:videoBitrate="其他";break;
                }
                //视频输出口分辨率:0- 1024x768,1- 1280x720,2-1280x1024,3- 1680x1050,4- 1920x1080,5- 3840*2160
//                byte byStreamType = resolution.struNormHighRecordPara.byStreamType;
//                int dwVideoBitrate = resolution.struNormHighRecordPara.dwVideoBitrate;
                int byResolution = resolution.struNormHighRecordPara.byResolution;
                switch (byResolution) {
                String resolution="";
                switch (compressioncfg.struNormHighRecordPara.byResolution) {
                    case 0:
                        ResResolution = "DCIF(528*384/528*320)";
                        resolution = "DCIF(528*384/528*320)";
                        break;
                    case 1:
                        ResResolution = "CIF(352*288/352*240)";
                        resolution = "CIF(352*288/352*240)";
                        break;
                    case 2:
                        ResResolution = "QCIF(176*144/176*120)";
                        resolution = "QCIF(176*144/176*120)";
                        break;
                    case 3:
                        ResResolution = "4CIF(704*576/704*480)";
                        resolution = "4CIF(704*576/704*480)";
                        break;
                    case 4:
                        ResResolution = "2CIF(704*288/704*240)";
                        resolution = "2CIF(704*288/704*240)";
                        break;
                    case 6:
                        ResResolution = "QVGA(320*240)";
                        resolution = "QVGA(320*240)";
                        break;
                    case 7:
                        ResResolution = "QQVGA(160*120)";
                        resolution = "QQVGA(160*120)";
                        break;
                    case 16:
                        ResResolution = "VGA(640*480)";
                        resolution = "VGA(640*480)";
                        break;
                    case 17:
                        ResResolution = "UXGA(1600*1200)";
                        resolution = "UXGA(1600*1200)";
                        break;
                    case 18:
                        ResResolution = "SVGA(800*600)";
                        resolution = "SVGA(800*600)";
                        break;
                    case 19:
                        ResResolution = "HD720P(1280*720)";
                        resolution = "HD720P(1280*720)";
                        break;
                    case 20:
                        ResResolution = "XVGA(1280*960)";
                        resolution = "XVGA(1280*960)";
                        break;
                    case 21:
                        ResResolution = "HD900P(1600*900)";
                        resolution = "HD900P(1600*900)";
                        break;
                    case 22:
                        ResResolution = "1360*1024";
                        resolution = "1360*1024";
                        break;
                    case 23:
                        ResResolution = "1536*1536";
                        resolution = "1536*1536";
                        break;
                    case 24:
                        ResResolution = "1920*1920";
                        resolution = "1920*1920";
                        break;
                    case 27:
                        ResResolution = "1920*1080p";
                        resolution = "1920*1080p";
                        break;
                    case 28:
                        ResResolution = "2560*1920";
                        resolution = "2560*1920";
                        break;
                    case 29:
                        ResResolution = "1600*304";
                        resolution = "1600*304";
                        break;
                    case 30:
                        ResResolution = "2048*1536";
                        resolution = "2048*1536";
                        break;
                    default:
                        ResResolution = "不在当前分辨率索引,请联系管理员添加";
                        resolution = "不在当前分辨率索引,请联系管理员添加";
                        break;
                }
                map.put("resolution",resolution);
                map.put("videoBitrate",videoBitrate);
                map.put("videoEncType",videoEncType);
                map.put("streamType",streamType);
            } else {
                int code = hCNetSDK.NET_DVR_GetLastError();
                System.out.println("控制失败,请稍后重试" + code);
                log.error("控制失败,请稍后重试" + code);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage());
        }
        return ResResolution;
        return map;
    }
    /**
@@ -556,7 +631,7 @@
    @Override
    public Map<String, Object> getPtz(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return null;
        }
@@ -589,7 +664,7 @@
            return ptzMap;
        } else {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("控制失败,请稍后重试" + code);
            log.error("控制失败,请稍后重试" + code);
            return new HashMap<>();
        }
@@ -607,7 +682,7 @@
    @SdkOperate
    public boolean setPtz(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        Map<String, Double> ptz = cmd.getPtzMap();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
@@ -627,7 +702,7 @@
            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.info("设置ptz失败,请稍后重试" + code);
                log.error("设置ptz失败,请稍后重试" + code);
            }
            return bool;
        } catch (Exception ex) {
@@ -640,7 +715,7 @@
    @SdkOperate
    public boolean guideTargetPosition(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
@@ -663,7 +738,7 @@
            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.info("设置ptz失败,请稍后重试" + code);
                log.error("设置ptz失败,请稍后重试" + code);
            }
            return bool;
        } catch (Exception ex) {
@@ -727,7 +802,7 @@
    @Override
    public int getPTZLockInfo(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return -1;
        }
@@ -739,7 +814,7 @@
        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.info("获取ptz锁定信息失败,请稍后重试" + code);
            log.error("获取ptz锁定信息失败,请稍后重试" + code);
            return -1;
        } else {
            netDvrPtzLockcfg.read();
@@ -759,7 +834,7 @@
    @SdkOperate
    public boolean setZeroPtz(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
@@ -791,7 +866,7 @@
    @Override
    public Map<String, Object> getPtzScope(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return new HashMap<>();
        }
@@ -803,7 +878,7 @@
        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.info("设置ptz失败,请稍后重试" + code);
            log.error("设置ptz失败,请稍后重试" + code);
            return new HashMap<>();
        } else {
            m_ptzPosCurrent.read();
@@ -840,7 +915,7 @@
    public boolean controlDefogcfg(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
@@ -853,7 +928,7 @@
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
        }
        struCameraParam.read();
        log.info("是否开启透雾:" + struCameraParam.struDefogCfg.byMode);
        log.debug("是否开启透雾:" + struCameraParam.struDefogCfg.byMode);
        NET_DVR_DEFOGCFG defogcfg = new NET_DVR_DEFOGCFG();
        if (enable) {
@@ -867,9 +942,9 @@
        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.info("设置透雾失败,请稍后重试" + code);
            log.error("设置透雾失败,请稍后重试" + code);
        }
        log.info("设置透雾成功");
        log.debug("设置透雾成功");
        return bool;
    }
@@ -886,7 +961,7 @@
    public boolean controlInfrarecfg(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
@@ -899,7 +974,7 @@
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
        }
        struDayNigh.read();
        log.info("是否开启夜视:" + struDayNigh.struDayNight.byDayNightFilterType);
        log.debug("是否开启夜视:" + struDayNigh.struDayNight.byDayNightFilterType);
        NET_DVR_DAYNIGHT daynight = new NET_DVR_DAYNIGHT();
        if (enable) {
@@ -915,9 +990,9 @@
        boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_CCDPARAMCFG_EX, channelNum, point, struDayNigh.size());
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("设置夜视失败,请稍后重试" + code);
            log.error("设置夜视失败,请稍后重试" + code);
        }
        log.info("设置夜视成功");
        log.debug("设置夜视成功");
        return bool;
    }
@@ -934,7 +1009,7 @@
    public boolean controlFocusMode(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
@@ -944,10 +1019,10 @@
        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) {
            System.out.println("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
        }
        struFocusMode.read();
        log.info("当前聚焦模式:" + struFocusMode.byFocusMode);
        log.debug("当前聚焦模式:" + struFocusMode.byFocusMode);
        if (enable) {
            struFocusMode.byFocusMode = 1;//手动聚焦
@@ -961,15 +1036,23 @@
        boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_FOCUSMODECFG, channelNum, point, struFocusMode.size());
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("设置聚焦模式失败,请稍后重试" + code);
            log.error("设置聚焦模式失败,请稍后重试" + code);
        }
        log.info("设置聚焦模式成功");
        log.debug("设置聚焦模式成功");
        return bool;
    }
    /**
     * @描述 获取聚焦模式
     * @参数 [userId, channelNum]
     * @返回值 boolean
     * @创建人 刘苏义
     * @创建时间 2023/1/18 13:07
     * @修改人和其它信息
     */
    public String getFocusMode(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return "";
        }
@@ -979,10 +1062,10 @@
        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) {
            System.out.println("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
        }
        struFocusMode.read();
        log.info("当前聚焦模式:" + struFocusMode.byFocusMode);
        log.debug("当前聚焦模式:" + struFocusMode.byFocusMode);
        return String.valueOf(struFocusMode.byFocusMode);
    }
@@ -999,7 +1082,7 @@
    public boolean controlPTHeateRpwron(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
@@ -1013,9 +1096,9 @@
        boolean bool = hCNetSDK.NET_DVR_PTZControl_Other(userId, channelNum, HEATER_PWRON, dwStop);
        if (!bool) {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("设置云台加热失败,请稍后重试" + code);
            log.error("设置云台加热失败,请稍后重试" + code);
        }
        log.info("设置云台加热成功");
        log.debug("设置云台加热成功");
        return bool;
    }
@@ -1032,7 +1115,7 @@
    public boolean controlCameraDeicing(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        boolean enable = cmd.isEnable();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
@@ -1045,7 +1128,7 @@
            log.error("获取前端参数失败,错误码:" + hCNetSDK.NET_DVR_GetLastError());
        }
        struDeicing.read();
        log.info("是否开启除冰:" + struDeicing.byEnableDeicing);
        log.debug("是否开启除冰:" + struDeicing.byEnableDeicing);
        if (enable) {
            struDeicing.byEnableDeicing = 1;//开启
@@ -1056,9 +1139,9 @@
        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.info("设置镜头除冰失败,请稍后重试" + code);
            log.error("设置镜头除冰失败,请稍后重试" + code);
        }
        log.info("设置镜头除冰成功");
        log.debug("设置镜头除冰成功");
        return bool;
    }
@@ -1069,7 +1152,7 @@
     */
    public String captureJPEGPicture(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return "";
        }
@@ -1090,13 +1173,13 @@
        ByteBuffer jpegBuffer = ByteBuffer.allocate(1024 * 1024);
        // 抓图到内存,单帧数据捕获并保存成JPEG存放在指定的内存空间中
        boolean is = hCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(userId, channelNum, jpeg, jpegBuffer, 1024 * 1024, a);
        log.info("-----------这里开始图片存入内存----------" + is);
        log.debug("-----------这里开始图片存入内存----------" + is);
        Base64.Encoder decoder = Base64.getEncoder();
      //  BASE64Encoder encoder = new BASE64Encoder();
        //  BASE64Encoder encoder = new BASE64Encoder();
        String png_base64 = decoder.encodeToString(jpegBuffer.array());//转换成base64串
        png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n
        log.info("-----------处理完成截图数据----------");
        log.debug("-----------处理完成截图数据----------");
        return png_base64;
    }
@@ -1112,7 +1195,7 @@
    @SdkOperate
    public String picCutCate(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return "";
        }
@@ -1134,25 +1217,22 @@
        //设置图片大小
        ByteBuffer jpegBuffer = ByteBuffer.allocate(1024 * 1024);
        // 抓图到内存,单帧数据捕获并保存成JPEG存放在指定的内存空间中
        log.info("-----------这里开始封装 NET_DVR_CaptureJPEGPicture_NEW---------");
        log.debug("-----------这里开始封装 NET_DVR_CaptureJPEGPicture_NEW---------");
        boolean is = hCNetSDK.NET_DVR_CaptureJPEGPicture_NEW(userId, channelNum, jpeg, jpegBuffer, 1024 * 1024, a);
        log.info("-----------这里开始图片存入内存----------" + is);
        log.debug("-----------这里开始图片存入内存----------" + is);
        if (is) {
            log.info("hksdk(抓图)-结果状态值(0表示成功):" + hCNetSDK.NET_DVR_GetLastError());
            log.debug("hksdk(抓图)-结果状态值(0表示成功):" + hCNetSDK.NET_DVR_GetLastError());
            byte[] array = jpegBuffer.array();
            //存储到minio
            String BucketName = "pic";
            String uuid = UUID.randomUUID().toString().replace("-", "");
            String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
            String ObjectName = time + "/" + uuid + ".jpeg";
            String ContentType = "image/JPEG";
            String ObjectName = "capture/" + IdUtils.simpleUUID() + ".jpeg";
            InputStream input = new ByteArrayInputStream(array);
            String url = "";
            try {
                boolean b = MinioUtils.uploadObject(BucketName, ObjectName, input, input.available(), ContentType);
                boolean b = MinioUtil.uploadObject(BucketName, ObjectName, input, input.available(), MimeTypeUtils.IMAGE_JPEG);
                if (b) {
                    url = MinioUtils.getBucketObjectUrl(BucketName, ObjectName);
                    log.info("上传文件成功!" + url);
                    url = MinioUtil.getBucketObjectUrl(BucketName, ObjectName);
                    log.debug("上传文件成功!" + url);
                }
            } catch (IOException ex) {
                log.error("上传文件异常:" + ex.getMessage());
@@ -1160,7 +1240,7 @@
            return url;
        } else {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("抓图失败,请稍后重试" + code);
            log.error("抓图失败,请稍后重试" + code);
            return "";
        }
    }
@@ -1177,7 +1257,7 @@
    public String record(CameraCmd cmd) {
        try {
            String cameraId = cmd.getCameraId();
            Integer channelNum = cmd.getChannelNum();
            Integer channelNum = cmd.getChanNo();
            String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4");
            boolean enable = cmd.isEnable();
            if (!GlobalVariable.loginMap.containsKey(cameraId)) {
@@ -1212,21 +1292,21 @@
                        log.error("取流失败" + hCNetSDK.NET_DVR_GetLastError());
                        return "";
                    }
                    log.info("取流成功");
                    log.debug("取流成功");
                    GlobalVariable.previewMap.put(cameraId, lRealHandle);
                }
                if (!hCNetSDK.NET_DVR_SaveRealData_V30(GlobalVariable.previewMap.get(cameraId), 2, path)) {
                    log.error("保存视频文件到临时文件夹失败 错误码为:  " + hCNetSDK.NET_DVR_GetLastError());
                    return "";
                }
                log.info("录像开始");
                log.debug("录像开始");
            } else {
                if (GlobalVariable.previewMap.containsKey(cameraId)) {
                    Integer lRealHandle = GlobalVariable.previewMap.get(cameraId);
                    hCNetSDK.NET_DVR_StopRealPlay(lRealHandle);
                    GlobalVariable.previewMap.remove(cameraId);
                }
                log.info("录像停止");
                log.debug("录像停止");
            }
            return url;
        } catch (Exception ex) {
@@ -1239,7 +1319,7 @@
    public void recordStart(CameraCmd cmd) {
        try {
            String cameraId = cmd.getCameraId();
            Integer channelNum = cmd.getChannelNum();
            Integer channelNum = cmd.getChanNo();
            String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4");
            if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                return;
@@ -1294,7 +1374,7 @@
        String url = "";
        try {
            String cameraId = cmd.getCameraId();
            Integer channelNum = cmd.getChannelNum();
            Integer channelNum = cmd.getChanNo();
            String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4");
            if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                return "";
@@ -1330,14 +1410,11 @@
            log.debug("录像停止");
            //存入minio
            String BucketName = cmd.getRecordBucketName();
            String ObjectName = cmd.getRecordObjectName();
            String ContentType = "video/MP4";
            String ObjectName = cmd.getRecordObjectName() + ".mp4";
            FileInputStream stream = new FileInputStream(path);
            String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
            String recordName = cameraId + "/" + time + "/" + ObjectName + ".mp4";
            boolean b = MinioUtils.uploadObject(BucketName, recordName, stream, stream.available(), ContentType);
            boolean b = MinioUtil.uploadObject(BucketName, ObjectName, stream, stream.available(), "video/MP4");
            if (b) {
                url = MinioClientSingleton.domainUrl + "/" + BucketName + "/" + recordName;
                url = MinioUtil.getBucketObjectUrl(BucketName, ObjectName);
                log.debug("上传文件成功!" + url);
            }
            return url;
@@ -1351,7 +1428,7 @@
    public void recordStopNotToMinio(CameraCmd cmd) {
        try {
            String cameraId = cmd.getCameraId();
            Integer channelNum = cmd.getChannelNum();
            Integer channelNum = cmd.getChanNo();
            if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                return;
            }
@@ -1386,4 +1463,84 @@
            log.error("录像停止异常" + ex.getMessage());
        }
    }
    //获取IP通道
    @Override
    public List<ArdChannel> getCameraChannelList(ArdCameras camera) {
        /*获取通道*/
        List<ArdChannel> channelList = new ArrayList<>();
        try {
            Integer chanNum = camera.getChanNum();
            Integer startDChan = camera.getStartDChan();
            if (chanNum > 0) {
                // 获取通道号
                for (int iChannum = 0; iChannum < chanNum; iChannum++) {
                    ArdChannel ardChannel = new ArdChannel();
                    int channum = iChannum + startDChan + 1;
                    HCNetSDK.NET_DVR_PICCFG_V40 strPicCfg = new HCNetSDK.NET_DVR_PICCFG_V40();
                    strPicCfg.dwSize = strPicCfg.size();
                    strPicCfg.write();
                    Pointer pStrPicCfg = strPicCfg.getPointer();
                    NativeLong lChannel = new NativeLong(channum);
                    IntByReference pInt = new IntByReference(0);
                    boolean b_GetPicCfg = hCNetSDK.NET_DVR_GetDVRConfig(camera.getLoginId(), HCNetSDK.NET_DVR_GET_PICCFG_V40, lChannel.intValue(),
                            pStrPicCfg, strPicCfg.size(), pInt);
                    if (b_GetPicCfg) {
                        strPicCfg.read();
                        String channelName = new String(strPicCfg.sChanName, "GBK").trim();
                        ardChannel.setName(channelName);
                    }
                    ardChannel.setDeviceId(camera.getId());
                    ardChannel.setChanNo(iChannum + 1);
                    channelList.add(ardChannel);
                }
            }
        } catch (Exception ex) {
            log.error("获取相机通道异常:" + ex.getMessage());
        }
        return channelList;
    }
    /**
     * @描述 获取GIS信息数据
     * @参数 [userId, channelNum]
     * @返回值 boolean
     * @创建人 刘苏义
     * @创建时间 2023/1/17 16:36
     * @修改人和其它信息 0-解锁 1-锁定
     */
    @Override
    public Map<String, Object> getGisInfo(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChanNo();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return new HashMap<>();
        }
        // 获取参数
        Integer userId = GlobalVariable.loginMap.get(cameraId);
        HCNetSDK.NET_DVR_STD_CONFIG struStdCfg = new HCNetSDK.NET_DVR_STD_CONFIG();
        HCNetSDK.NET_DVR_GIS_INFO struGisInfo = new HCNetSDK.NET_DVR_GIS_INFO();
        struStdCfg.read();
        IntByReference lchannel = new IntByReference(channelNum);
        struStdCfg.lpCondBuffer = lchannel.getPointer();
        struStdCfg.dwCondSize = 4;
        struStdCfg.lpOutBuffer = struGisInfo.getPointer();
        struStdCfg.dwOutSize = struGisInfo.size();
        struStdCfg.write();//设置前之前要write()
        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;
        }
    }
}