‘liusuyi’
2023-06-25 be6191688920d3927fff16ddb0709d205d784468
ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
@@ -6,13 +6,13 @@
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.constant.sdkPriority;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.constant.CamPriority;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
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.domain.recordInfo;
import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil;
import com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK;
import com.ruoyi.device.hiksdk.service.IHikClientService;
@@ -24,7 +24,6 @@
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Encoder;
@@ -36,7 +35,6 @@
import java.text.SimpleDateFormat;
import java.util.*;
import static com.ruoyi.device.hiksdk.common.GlobalVariable.threadMap;
import static com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK.*;
/**
@@ -598,7 +596,7 @@
            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);
//            log.debug("T垂直参数为: " + p + "P水平参数为: " + t + "Z变倍参数为: " + z);
            Map<String, Object> ptzMap = new HashMap<>();
            ptzMap.put("p", p);
            ptzMap.put("t", t);
@@ -607,7 +605,7 @@
        } else {
            int code = hCNetSDK.NET_DVR_GetLastError();
            log.info("控制失败,请稍后重试" + code);
            return null;
            return new HashMap<>();
        }
    }
@@ -655,7 +653,7 @@
    @Override
    @SdkOperate
    public boolean setTargetPosition(CameraCmd cmd) {
    public boolean guideTargetPosition(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
@@ -728,18 +726,18 @@
            } else {
                //如果非本人比较优先级
                Integer currentLevel = 0;//当前操作者的优先级
                if (sdkPriority.priorityMap.containsKey(currentOperator)) {
                if (CamPriority.priorityMap.containsKey(currentOperator)) {
                    /*当前控制者为系统报警用户*/
                    currentLevel = (Integer) sdkPriority.priorityMap.get(currentOperator);
                    currentLevel = (Integer) CamPriority.priorityMap.get(currentOperator);
                } else {
                    /*当前控制者为普通用户*/
                    SysUser sysUser = sysUserMapper.selectUserById(currentOperator);
                    currentLevel = sysUser.getCameraPriority();
                }
                Integer operatorLevel = 0;//获取申请者的优先级
                if (sdkPriority.priorityMap.containsKey(operator)) {
                if (CamPriority.priorityMap.containsKey(operator)) {
                    /*包含说明当前申请控制者为系统报警用户*/
                    operatorLevel = (Integer) sdkPriority.priorityMap.get(operator);
                    operatorLevel = (Integer) CamPriority.priorityMap.get(operator);
                } else {
                    /*否则申请控制者为当前登录用户*/
                    LoginUser loginUser = SecurityUtils.getLoginUser();
@@ -1016,6 +1014,25 @@
        return bool;
    }
    public String getFocusMode(CameraCmd cmd)
    {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        if (!GlobalVariable.loginMap.containsKey(cameraId)) {
            return "";
        }
        Integer userId = GlobalVariable.loginMap.get(cameraId);
        NET_DVR_FOCUSMODE_CFG struFocusMode = new NET_DVR_FOCUSMODE_CFG();
        Pointer point = struFocusMode.getPointer();
        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());
        }
        struFocusMode.read();
        log.info("当前聚焦模式:" + struFocusMode.byFocusMode);
        return String.valueOf(struFocusMode.byFocusMode);
    }
    /**
     * @描述 云台加热开关
     * @参数 [userId, channelNum, enable]
@@ -1307,14 +1324,14 @@
    }
    @Override
    public void recordToMinio(CameraCmd cmd) {
    public String recordToMinio(CameraCmd cmd) {
        try {
            String cameraId = cmd.getCameraId();
            Integer channelNum = cmd.getChannelNum();
            String path = FileUtils.createFile("D:/recordTemp/" + cameraId + ".mp4");
            boolean enable = cmd.isEnable();
            if (!GlobalVariable.loginMap.containsKey(cameraId)) {
                return;
                return "";
            }
            Integer userId = GlobalVariable.loginMap.get(cameraId);
            //强制I帧结构体对象
@@ -1342,40 +1359,47 @@
                    Integer lRealHandle = GlobalVariable.previewMap.get(cameraId);
                    hCNetSDK.NET_DVR_StopRealPlay(lRealHandle);
                    GlobalVariable.previewMap.remove(cameraId);
                    log.info("录像停止");
                    log.debug("停止当前录像");
                }
                int lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null);
                if (lRealHandle == -1) {
                    log.error("取流失败" + hCNetSDK.NET_DVR_GetLastError());
                    return;
                    return "";
                }
                log.info("取流成功");
                GlobalVariable.threadMap.put(cameraId,Thread.currentThread().getName());
                log.debug("取流成功");
                GlobalVariable.threadMap.put(cameraId, Thread.currentThread().getName());
                GlobalVariable.previewMap.put(cameraId, lRealHandle);
                if (!hCNetSDK.NET_DVR_SaveRealData_V30(GlobalVariable.previewMap.get(cameraId), 2, path)) {
                    log.error("保存视频文件到临时文件夹失败 错误码为:  " + hCNetSDK.NET_DVR_GetLastError());
                    return;
                    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("录像停止");
                //存入minio
                String BucketName = cmd.getRecordBucketName();
                String ObjectName = cmd.getRecordObjectName();
                String ContentType = "video/MP4";
                FileInputStream stream = new FileInputStream(path);
                boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType);
                String simpleUUID = IdUtils.simpleUUID();
                String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
                String recordName = cameraId + "/" + time + "/" + ObjectName +"_"+ simpleUUID + ".mp4";
                boolean b = MinioUtils.uploadObject(BucketName, recordName, stream, stream.available(), ContentType);
                if (b) {
                    log.info("上传文件成功!" + MinioClientSingleton.domainUrl + "/" + BucketName + "/" + ObjectName);
                    String url = MinioClientSingleton.domainUrl + "/" + BucketName + "/" + recordName;
                    log.debug("上传文件成功!" + url);
                    return url;
                }
            }
            return "";
        } catch (Exception ex) {
            log.error("录像异常" + ex.getMessage());
            return "";
        }
    }
}