guoshilong
2023-04-13 df42877cfd997c46fce3e76557ff2eedccb64224
Merge remote-tracking branch 'origin/jtdev' into jtdev
4 files modified
425 ■■■■ changed files
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/constant/HkConstant.java 13 ●●●●● patch | view | raw | blame | history
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/controller/HkController.java 50 ●●●●● patch | view | raw | blame | history
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/util/GetCameraPreviewURL.java 272 ●●●● patch | view | raw | blame | history
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/vo/HkVO.java 90 ●●●●● patch | view | raw | blame | history
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/constant/HkConstant.java
@@ -60,6 +60,19 @@
     */
    public static final String cameraSearchURLs = "/api/resource/v2/camera/search";
    /**
     * 云台控制url
     */
    public static final String controllingURLs = "/api/video/v1/ptzs/controlling";
    /**
     * 電子放大
     */
    public static final String selZoomURLs = "/api/video/v1/ptzs/selZoom";
    /**
     * 抓图
     */
    public static final String manualCaptureUrls = "/api/video/v1/manualCapture";
}
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/controller/HkController.java
@@ -15,8 +15,7 @@
import java.util.HashMap;
import java.util.Map;
import static cn.gistack.sm.hk.util.GetCameraPreviewURL.GetCameraPreviewURL;
import static cn.gistack.sm.hk.util.GetCameraPreviewURL.GetCameraResourcePage;
import static cn.gistack.sm.hk.util.GetCameraPreviewURL.*;
/**
 * @author zhongrj
@@ -54,7 +53,7 @@
    public R queryHkPreviewUrl(HkVO hk) {
        String url = "";
        // 获取海康播放url
        String result = GetCameraPreviewURL(HkConstant.previewURLs, hk.getCameraIndexCode(), ProtocolConstant.WS);
        String result = GetCameraPreviewURL(HkConstant.previewURLs, hk.getCameraIndexCode(), ProtocolConstant.HLS);
        if (null!=result) {
            JSONObject jsonObject = JSONObject.parseObject(result);
            Map map = (Map) jsonObject.get("data");
@@ -64,4 +63,49 @@
        return R.data(url);
    }
    /**
     * 海康摄像头云台的控制(摄像头左右旋转画面)
     * @param hk 查询参数
     * @return
     */
    @ApiOperation(value = "海康设备-海康摄像头云台的控制", notes = "海康设备-海康摄像头云台的控制")
    @GetMapping(value = "/handleCameraPosition")
    public R handleCameraPosition(HkVO hk) {
        // 获取海康播放url
        String result = controlling(HkConstant.controllingURLs,
            hk.getCameraIndexCode(),hk.getAction(),hk.getCommand(),hk.getSpeed(),null);
        // 返回
        return R.data(result);
    }
    /**
     * 海康摄像头电子放大
     * @param hk 查询参数
     * @return
     */
    @ApiOperation(value = "海康设备-海康摄像头电子放大", notes = "海康设备-海康摄像头电子放大")
    @GetMapping(value = "/selZoom")
    public R selZoom(HkVO hk) {
        // 获取海康播放url
        String result = selZoomURLs(HkConstant.selZoomURLs,
            hk.getCameraIndexCode(),hk.getStartX(),hk.getStartY(),hk.getEndX(),hk.getEndY());
        // 返回
        return R.data(result);
    }
    /**
     * 抓图
     * @param hk 查询参数
     * @return
     */
    @ApiOperation(value = "海康设备-抓图", notes = "海康设备-抓图")
    @GetMapping(value = "/manualCapture")
    public R manualCapture(HkVO hk) {
        // 获取海康播放url
        String result = manualCaptureUrls(HkConstant.manualCaptureUrls,
            hk.getCameraIndexCode());
        // 返回
        return R.data(result);
    }
}
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/util/GetCameraPreviewURL.java
@@ -18,14 +18,13 @@
public class GetCameraPreviewURL {
    /**
     * 获取视频预览数据
     * 公共方法
     *
     * @param url             视频预览url
     * @param cameraIndexCode 监控点唯一标识
     * @param url
     * @param body
     * @return
     */
    public static String GetCameraPreviewURL(String url, String cameraIndexCode, String protocol) {
    public static String common(String url, String body) {
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
@@ -53,19 +52,27 @@
         */
        String contentType = "application/json";
        /**
         * STEP5:组装请求参数
         * STEP6:调用接口
         * // post请求application/json类型参数
         */
//        JSONObject jsonBody = new JSONObject();
//        jsonBody.put("indexCode", cameraIndexCode);
//        jsonBody.put("streamType", 0);
//        jsonBody.put("netZoneCode", 0);
//        jsonBody.put("protocol", protocol);
//        jsonBody.put("transmode", 1);
//        jsonBody.put("expireTime", 300);
//        String body = jsonBody.toJSONString();
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);
        // 返回数据
        return result;
    }
    /**
     * 获取视频预览数据
     *
     * @param url             视频预览url
     * @param cameraIndexCode 监控点唯一标识
     * @return
     */
    public static String GetCameraPreviewURL(String url, String cameraIndexCode, String protocol) {
        /**
         * 组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", cameraIndexCode);
        jsonBody.put("streamType", 0);
@@ -73,13 +80,8 @@
        jsonBody.put("transmode", 1);
//        jsonBody.put("expand", "streamform=ps");
        String body = jsonBody.toJSONString();
        /**
         * STEP6:调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
        return result;
        // 调用公共方法
        return common(url,body);
    }
    /**
@@ -89,37 +91,12 @@
     * @param cameraCode 监控点唯一标识
     * @return
     */
    public static String QueryCameraPreviewURL(String url, String cameraCode, String resourceType, String key) {
    public static String QueryCameraPreviewURL(String url,
                                               String cameraCode,
                                               String resourceType,
                                               String key) {
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        // artemis网关服务器ip端口
        ArtemisConfig.host = HkConstant.HOST;
        // 秘钥appKey
        ArtemisConfig.appKey = HkConstant.AppKey;
        // 秘钥appSecret
        ArtemisConfig.appSecret = HkConstant.AppSecret;
        /**
         * STEP3:设置接口的URI地址
         */
        final String apiUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("https://", apiUrl);
            }
        };
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
        /**
         * STEP5:组装请求参数
         * 组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        List<JSONObject> list = new ArrayList<>();
@@ -136,11 +113,7 @@
        jsonBody.put("expressions", list);
        String body = jsonBody.toJSONString();
        System.out.println(jsonBody);
        /**
         * STEP6:调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
        return result;
        return common(url,body);
    }
@@ -152,36 +125,8 @@
     * @return
     */
    public static String GetTalkURLs(String url, String cameraIndexCode) {
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        // artemis网关服务器ip端口
        ArtemisConfig.host = HkConstant.HOST;
        // 秘钥appKey
        ArtemisConfig.appKey = HkConstant.AppKey;
        // 秘钥appSecret
        ArtemisConfig.appSecret = HkConstant.AppSecret;
        /**
         * STEP3:设置接口的URI地址
         */
        final String apiUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("https://", apiUrl);
            }
        };
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
        /**
         * STEP5:组装请求参数
         * 组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", cameraIndexCode);
@@ -193,11 +138,73 @@
        jsonBody.put("talkIndexCode", "ce744c4c67df464f92994185d825b6fa");
        jsonBody.put("protocol", "wss");
        String body = jsonBody.toJSONString();
        return common(url,body);
    }
    /**
     * 云台控制
     * action 0-开始  1-停止
     * 注:GOTO_PRESET命令下填任意值均可转到预置点,建议填0即可
     * @param url  云台控制url
     * @param cameraIndexCode 监控点唯一标识
     * @param command 命令
     * @return
     */
    public static String controlling(String url,
                                     String cameraIndexCode,
                                     Integer action,
                                     String command,
                                     Integer speed,
                                     Integer presetIndex
    ) {
        /**
         * STEP6:调用接口
         * 组装请求参数
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
        return result;
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", cameraIndexCode);
        jsonBody.put("action", action);
        jsonBody.put("command", command);
        jsonBody.put("speed", speed);
        jsonBody.put("presetIndex", presetIndex);
        String body = jsonBody.toJSONString();
        /**
         * 调用接口
         */
        return common(url,body);
    }
    /**
     * 云台控制
     *
     * @param url  云台控制url
     * @param cameraIndexCode 监控点唯一标识
     * @param startX 命令
     * @param startY 命令
     * @param endX 命令
     * @param endY 命令
     * @return
     */
    public static String selZoomURLs(String url,
                                     String cameraIndexCode,
                                     Integer startX,
                                     Integer startY,
                                     Integer endX,
                                     Integer endY
                                     ) {
        /**
         * 组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", cameraIndexCode);
        jsonBody.put("startX", startX);
        jsonBody.put("startY", startY);
        jsonBody.put("endX", endX);
        jsonBody.put("endY", endY);
        String body = jsonBody.toJSONString();
        /**
         * 调用接口
         */
        return common(url,body);
    }
@@ -208,35 +215,8 @@
     * @return
     */
    public static String GetCameraResourcePage(Integer pageNo, Integer pageSize, String url) {
        /**
         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
         */
        // artemis网关服务器ip端口
        ArtemisConfig.host = HkConstant.HOST;
        // 秘钥appKey
        ArtemisConfig.appKey = HkConstant.AppKey;
        // 秘钥appSecret
        ArtemisConfig.appSecret = HkConstant.AppSecret;
        /**
         * STEP3:设置接口的URI地址
         */
        final String apiUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("https://", apiUrl);
            }
        };
        /**
         * STEP4:设置参数提交方式
         */
        String contentType = "application/json";
        /**
         * STEP5:组装请求参数
         * 组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("pageNo", pageNo);
@@ -244,23 +224,67 @@
        String body = jsonBody.toJSONString();
        /**
         * STEP6:调用接口并返回数据
         * 调用接口并返回数据
         * post请求application/json类型参数;
         */
        return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);
        return common(url, body);
    }
    /**
     * 抓图
     *
     * @param url 监控资源url
     * @return
     */
    public static String manualCaptureUrls(String url,String cameraIndexCode) {
        /**
         * 组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("cameraIndexCode", cameraIndexCode);
        String body = jsonBody.toJSONString();
        /**
         * 调用接口并返回数据
         * post请求application/json类型参数;
         */
        return common(url, body);
    }
//    public static void main(String[] args) {
//
//        String result = GetCameraResourcePage(1, 10, HkConstant.cameras);
//        //根据设备id获取设备编号
////        String result1 = QueryCameraPreviewURL(HkConstant.camerasID, "111111222", "encodeDevice", "deviceCode");
//
//        JSONObject jsonObject1 = JSONObject.parseObject(result);
//        JSONObject res1 = (JSONObject) jsonObject1.get("data");
//        JSONArray arr1 = JSON.parseArray(res1.getString("list"));
//        JSONObject data1 = (JSONObject) arr1.get(1);
//        String code1 = data1.get("cameraIndexCode").toString();
//
//        // 云台控制
////        String right = controlling(HkConstant.controllingURLs,
////            "ff1f050afd1c47829dec1ec14575c9e3",
////            0,
////            "ZOOM_OUT",
////            null,
////            null
////        );
////        System.out.println("right = " + right);
//
////        // 放大
////        String big = selZoomURLs(HkConstant.selZoomURLs,
////            "ff1f050afd1c47829dec1ec14575c9e3",
////            55,
////            58,
////            22,
////            23
////        );
////        System.out.println("big = " + big);
//
//        // 抓图
////        String manualCapture = manualCaptureUrls(HkConstant.manualCaptureUrls,
////            "ff1f050afd1c47829dec1ec14575c9e3");
////        System.out.println("manualCapture = " + manualCapture);
//
//        //根据设备编号获取子节点编号
////        String result2 = QueryCameraPreviewURL(HkConstant.camerasID, code1, "camera", "parentIndexCode");
@@ -274,16 +298,16 @@
//        //e2cb261e14144f53a300769839d54753
//        //根据子节点编号获取设备播放地址
//        String result3 = GetCameraPreviewURL(HkConstant.previewURLs,
//            "ff1f050afd1c47829dec1ec14575c9e3", ProtocolConstant.WS);
//            "ff1f050afd1c47829dec1ec14575c9e3", ProtocolConstant.HLS);
//        JSONObject jsonObject = JSONObject.parseObject(result3);
//        Map map = (Map) jsonObject.get("data");
//        //根据子节点编号获取音频对讲地址
////        String result4 = GetTalkURLs(HkConstant.talkURLs, code1);
//
//        System.out.println("result结果示例: " + result);
////        System.out.println("result结果示例: " + result);
////        System.out.println("result1 = " + result1);
////        System.out.println("result2 = " + result2);
//        System.out.println("result3 = " + result3);
////        System.out.println("result3 = " + result3);
//        System.out.println("url = " + map.get("url"));
////        System.out.println("result4 = " + result4);
//    }
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/hk/vo/HkVO.java
@@ -16,4 +16,94 @@
     * 监控设备code
     */
    private String cameraIndexCode;
    /**
     * 开始点 x
     */
    private Integer startX;
    /**
     * 开始点 y
     */
    private Integer startY;
    /**
     * 结束点 x
     */
    private Integer endX;
    /**
     * 结束点 y
     */
    private Integer endY;
    /**
     * 云台移动开启状态
     * 0-开始
     * 1-停止
     * 注:GOTO_PRESET命令下填任意值均可转到预置点,建议填0即可
     */
    private Integer action;
    /**
     * 云台移动命令
     * 不区分大小写
     * 说明:
     * LEFT 左转
     * RIGHT右转
     * UP 上转
     * DOWN 下转
     * ZOOM_IN 焦距变大
     * ZOOM_OUT 焦距变小
     * LEFT_UP 左上
     * LEFT_DOWN 左下
     * RIGHT_UP 右上
     * RIGHT_DOWN 右下 FOCUS_NEAR 焦点前移
     * FOCUS_FAR 焦点后移 IRIS_ENLARGE 光圈扩大
     * IRIS_REDUCE 光圈缩小
     * WIPER_SWITCH 接通雨刷开关
     * START_RECORD_TRACK开始记录轨迹
     * STOP_RECORD_TRACK 停止记录轨迹
     * START_TRACK 开始轨迹
     * STOP_TRACK 停止轨迹
     *
     * 以下命令presetIndex不可
     * 为空:
     * GOTO_PRESET到预置点
     */
    private String command;
    /**
     * 云台移动速度 取值范围为1-100,默认50,非必填
     */
    private Integer speed;
    /**
     * 预置点编号,整数,通常在300以内,非必填
     */
    private Integer presetIndex;
    /**
     * 码流类型,0:主码流
     * 1:子码流
     * 2:第三码流
     * 参数不填,默认为主码流
     */
    private Integer streamType;
    /**
     * 取流协议(应用层协议),“hik”:HIK私有协议,使用视频SDK进行播放时,传入此类型;“rtsp”:RTSP协议;“rtmp”:RTMP协议;“hls”:HLS协议(HLS协议只支持海康SDK协议、EHOME协议、ONVIF协议接入的设备;只支持H264视频编码和AAC音频编码)。参数不填,默认为HIK协议
     */
    private Integer protocol;
    /**
     * 传输协议(传输层协议),0:UDP
     * 1:TCP
     * 默认是TCP
     * 注:
     * GB28181 2011及以前版本只支持UDP传输
     */
    private Integer transmode;
}