‘liusuyi’
2023-05-25 c6eb731b0a70946e5ba265d9e5d427b8bb4537a6
ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/hikClientServiceImpl.java
@@ -5,20 +5,17 @@
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.constant.sdkPriority;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
import com.ruoyi.device.hiksdk.common.global.globalVariable;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.service.IArdCamerasService;
import com.ruoyi.device.cameracalibration.domain.ArdCamerasCalibration;
import com.ruoyi.device.hiksdk.domain.recordInfo;
import com.ruoyi.device.cameracalibration.service.IArdCamerasCalibrationService;
import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil;
import com.ruoyi.device.hiksdk.util.hikSdkUtil.HCNetSDK;
import com.ruoyi.device.hiksdk.service.hikClientService;
import com.ruoyi.device.hiksdk.util.imageUtil.waterMarkUtil;
import com.ruoyi.device.hiksdk.util.minioUtil.MinioUtil;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
@@ -29,11 +26,8 @@
import sun.misc.BASE64Encoder;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
@@ -289,7 +283,6 @@
        }
        return bool;
    }
    /**
     * 设置聚焦值
@@ -595,6 +588,39 @@
        }
    }
    @Override
    public boolean setTargetPosition(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer channelNum = cmd.getChannelNum();
        if (!globalVariable.loginMap.containsKey(cameraId)) {
            return false;
        }
        Integer userId = globalVariable.loginMap.get(cameraId);
        HCNetSDK.NET_DVR_PTZPOS m_ptzPosCurrent = new HCNetSDK.NET_DVR_PTZPOS();
        m_ptzPosCurrent.wAction = 1;
        try {
            double[] cameraPositon = Arrays.stream(cmd.getCamPosition().split(",")).mapToDouble(Double::parseDouble).toArray();
            double[] targetPositions = Arrays.stream(cmd.getTargetPosition().split(",")).mapToDouble(Double::parseDouble).toArray();
            double[] cameraPTZ = GisUtil.getCameraPTZ(cameraPositon, targetPositions, 20, 150);
            String p = String.valueOf((int) ( cameraPTZ[0] * 10));
            String t = String.valueOf((int) ( cameraPTZ[1] * 10));
            String z = String.valueOf((int) (cameraPTZ[2]* 10));
            m_ptzPosCurrent.wPanPos = (short) (Integer.parseInt(p, 16));
            m_ptzPosCurrent.wTiltPos = (short) (Integer.parseInt(t, 16));
            m_ptzPosCurrent.wZoomPos = (short) (Integer.parseInt(z, 16));
            Pointer point = m_ptzPosCurrent.getPointer();
            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.info("设置ptz失败,请稍后重试" + code);
            }
            return bool;
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return false;
        }
    }
    /**
     * @描述 操控锁定
     * @参数 [userId, channelNum]
@@ -605,77 +631,66 @@
     */
    @Override
    public boolean controlLock(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer expired = cmd.getExpired();
        String cameraId = cmd.getCameraId();//申请锁的相机
        ArdCameras ardCameras = ardCamerasMapper.selectArdCamerasById(cameraId);
        if (StringUtils.isNull(ardCameras)) {
            return false;//找不到相机拒绝操控
        }
        String operatorId = ardCameras.getOperatorId();
        if (StringUtils.isEmpty(operatorId)) {
            //如果该相机无人锁定,直接锁定
            LoginUser loginUser = SecurityUtils.getLoginUser();
            if (StringUtils.isNull(loginUser)) {
                return false;//当前登录用户为空不可以控制
            }
            SysUser user = loginUser.getUser();
            if (StringUtils.isNull(user.getCameraPriority())) {
                return false;//未配置优先级的用户不可以控制
            }
        Integer expired = cmd.getExpired();//申请控制时长
        String operator=cmd.getOperator();//申请者
        String currentOperator = ardCameras.getOperatorId();//相机当前控制者
        Date currentExpired = ardCameras.getOperatorExpired();//相机当前过期时间
        if(currentExpired==null)
        {
            //设置当前操作用户ID
            ardCameras.setOperatorId(user.getUserId());
            ardCameras.setOperatorId(operator);
            //设置当前过期时间
            Date now = new Date();
            now.setTime(now.getTime() + expired * 1000);
            now.setTime(now.getTime() + expired * 1000*60);
            ardCameras.setOperatorExpired(now);
            ardCamerasMapper.updateArdCameras(ardCameras);
        } else {
            //如果该相机有人锁定,判断优先级
            SysUser operatorUser = sysUserMapper.selectUserById(operatorId);
            if (StringUtils.isNull(operatorUser)) {
                return false;
            }
            if (StringUtils.isEmpty(operatorUser.getCameraPriority())) {
                return false;
            }
            Integer operatorPriority = Integer.parseInt(operatorUser.getCameraPriority());//相机已操作用户优先级
            LoginUser loginUser = SecurityUtils.getLoginUser();
            if (StringUtils.isNull(loginUser)) {
                return false;//当前登录用户为空不可以控制
            }
            SysUser user = loginUser.getUser();
            if (StringUtils.isEmpty(user.getCameraPriority())) {
                return false;//未配置优先级的用户不可以控制
            }
            Integer loginUserCameraPriority = Integer.parseInt(user.getCameraPriority());//当前登录用户优先级
            if (user.getUserId().equals(operatorUser.getUserId())) {
                //如果当前用户已经操控,直接更新过期时间
        }
         else {
            //如果过期时间有值
            //如果是本人直接修改
            if(currentOperator.equals(operator))
            {
                //设置当前过期时间
                Date now = new Date();
                now.setTime(now.getTime() + expired * 60 * 1000);
                ardCameras.setOperatorExpired(now);//设置当前过期时间
                now.setTime(now.getTime() + expired * 1000*60);
                ardCameras.setOperatorExpired(now);
                ardCamerasMapper.updateArdCameras(ardCameras);
            } else {
                if (loginUserCameraPriority > operatorPriority) {
                    //如果登录用户优先级高于已操作用户,覆盖更新
                    ardCameras.setOperatorId(user.getUserId());//设置当前操作用户ID
            }
            else {
                //如果非本人比较优先级
                Integer currentLevel = 0;//当前操作者的优先级
                if (sdkPriority.priorityMap.containsKey(currentOperator)) {
                    /*当前控制者为系统报警用户*/
                    currentLevel = (Integer) sdkPriority.priorityMap.get(currentOperator);
                } else {
                    /*当前控制者为普通用户*/
                    SysUser sysUser = sysUserMapper.selectUserById(currentOperator);
                    currentLevel = sysUser.getCameraPriority();
                }
                Integer operatorLevel = 0;//获取申请者的优先级
                if (sdkPriority.priorityMap.containsKey(operator)) {
                    /*包含说明当前申请控制者为系统报警用户*/
                    operatorLevel = (Integer) sdkPriority.priorityMap.get(operator);
                } else {
                    /*否则申请控制者为当前登录用户*/
                    LoginUser loginUser = SecurityUtils.getLoginUser();
                    SysUser user = loginUser.getUser();//获取登录用户的信息
                    operatorLevel = user.getCameraPriority();
                }
                //判断优先级
                if (operatorLevel > currentLevel) {
                    Date now = new Date();
                    now.setTime(now.getTime() + expired * 60 * 1000);
                    ardCameras.setOperatorExpired(now);//设置当前过期时间
                    ardCameras.setOperatorId(operator);//设置当前用户
                    ardCamerasMapper.updateArdCameras(ardCameras);
                } else {
                    //如果登录用户优先级低于等于已操作用户,判断是否过期
                    Date now = new Date();
                    Date operatorExpired = ardCameras.getOperatorExpired();
                    if (now.after(operatorExpired)) {
                        //已过期
                        ardCameras.setOperatorId(user.getUserId());//设置当前操作用户ID
                        now.setTime(now.getTime() + expired * 60 * 1000);
                        ardCameras.setOperatorExpired(now);//设置当前过期时间
                        ardCamerasMapper.updateArdCameras(ardCameras);
                    } else {
                        return false;//未过期不可控
                    }
                    return false;//优先级低无法上锁
                }
            }
        }
@@ -921,7 +936,8 @@
        if (enable) {
            struFocusMode.byFocusMode = 1;//手动聚焦
        } else {
            struFocusMode.byFocusMode = 0;//自动聚焦
            struFocusMode.byAutoFocusMode=1;
            struFocusMode.byFocusMode = 2;//自动聚焦
        }
        struFocusMode.byFocusDefinitionDisplay = 1;
        struFocusMode.byFocusSpeedLevel = 3;