Pu Zhibing
4 天以前 a91f50ce8ce976743c11de98f9e3ed574bb3f78e
添加海康威视实时监控对接功能
3个文件已修改
7个文件已添加
390 ■■■■■ 已修改文件
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/controller/HaiKangContent.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/model/UPWarnMsgAdptInfo.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java 122 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/ExactCondition.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/ExactCondition1.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/FindCameraPageRequest.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/FindVehicleByLicensePlateRequest.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/FindVehiclePageRequest.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/PreviewURLsRequest.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/mqtt/MqttInit.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/controller/HaiKangContent.java
New file
@@ -0,0 +1,93 @@
package com.ruoyi.dataInterchange.controller;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.dataInterchange.util.haikang.Artemis;
import com.ruoyi.dataInterchange.util.haikang.model.ExactCondition1;
import com.ruoyi.dataInterchange.util.haikang.model.FindCameraPageRequest;
import com.ruoyi.dataInterchange.util.haikang.model.FindVehicleByLicensePlateRequest;
import com.ruoyi.dataInterchange.util.haikang.model.PreviewURLsRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
/**
 * @author zhibing.pu
 * @Date 2025/5/28 18:35
 */
@RestController
@RequestMapping(value = "/haikang")
public class HaiKangContent {
    /**
     * 根据车牌号获取海康实时视频预览地址
     * @param vehicleLicensePlate
     * @return
     */
    @PostMapping("/getCarPreviewURLs")
    public R<String> getCarPreviewURLs(@RequestParam("vehicleLicensePlate") String vehicleLicensePlate){
        try {
            FindVehicleByLicensePlateRequest findVehicleByLicensePlateRequest = new FindVehicleByLicensePlateRequest();
            findVehicleByLicensePlateRequest.setVehicleLicensePlate(vehicleLicensePlate);
            String vehicleByLicensePlate = Artemis.findVehicleByLicensePlate(findVehicleByLicensePlateRequest);
            JSONObject jsonObject = JSONObject.parseObject(vehicleByLicensePlate);
            String code = jsonObject.getString("code");
            if(!"0".equals(code)){
                return R.fail("获取海康实时视频预览地址失败");
            }
            JSONObject data = jsonObject.getJSONObject("data");
            //车辆编号
            String indexCode = data.getString("indexCode");
            //主设备编号
            String primaryDeviceIndexCode = data.getString("primaryDeviceIndexCode");
            //根据车辆编号和设备编号获取监控点信息列表
            FindCameraPageRequest findCameraPageRequest = new FindCameraPageRequest();
            findCameraPageRequest.setPageNo(1);
            findCameraPageRequest.setPageSize(1000);
            ExactCondition1 exactCondition = new ExactCondition1();
            exactCondition.setDeviceIndexCodes(new ArrayList<String>(){{
                add(primaryDeviceIndexCode);
            }});
            exactCondition.setVehicleIndexCodes(new ArrayList<String>(){{
                add(indexCode);
            }});
            findCameraPageRequest.setExactCondition(exactCondition);
            String cameraPage = Artemis.findCameraPage(findCameraPageRequest);
            jsonObject = JSONObject.parseObject(cameraPage);
            code = jsonObject.getString("code");
            if(!"0".equals(code)){
                return R.fail("获取海康实时视频预览地址失败");
            }
            data = jsonObject.getJSONObject("data");
            JSONArray list = data.getJSONArray("list");
            //监控点编号
            String indexCode1 = "";
            for (int i = 0; i < list.size(); i++) {
                com.alibaba.fastjson2.JSONObject jsonObject1 = list.getJSONObject(i);
                String cameraName = jsonObject1.getString("cameraName");
                if("驾驶位".equals(cameraName)){
                    indexCode1 = jsonObject1.getString("indexCode");
                }
            }
            //根据监控点编号获取监控预览url
            PreviewURLsRequest previewURLsRequest = new PreviewURLsRequest();
            previewURLsRequest.setCameraIndexCode(indexCode1);
            String s = Artemis.previewURLs(previewURLsRequest);
            jsonObject = JSONObject.parseObject(s);
            code = jsonObject.getString("code");
            if(!"0".equals(code)){
                return R.fail("获取海康实时视频预览地址失败");
            }
            data = jsonObject.getJSONObject("data");
            String url = data.getString("url");
            return R.ok(url);
        }catch (Exception e){
            return R.fail("获取海康实时视频预览地址失败");
        }
    }
}
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/model/UPWarnMsgAdptInfo.java
@@ -237,17 +237,17 @@
            //纬度
            this.latitude = byteBuf.readInt();
            //海拔高度
            this.altitude = byteBuf.readUnsignedShort();
            this.altitude = byteBuf.readShort();
            //行车速度
            this.speed = byteBuf.readUnsignedShort();
            this.speed = byteBuf.readShort();
            //行驶记录速度
            this.vec2 = byteBuf.readUnsignedShort();
            this.vec2 = byteBuf.readShort();
            //报警状态
            this.status = byteBuf.readByte();
            //方向
            this.direction = byteBuf.readUnsignedShort();
            this.direction = byteBuf.readShort();
            //报警数据长度
            this.infoLength = byteBuf.readUnsignedShort();
            this.infoLength = byteBuf.readShort();
            //报警信息内容
            this.infoContent = Jtt809Util.readGBKString(byteBuf,this.infoLength);
        }catch (Exception e){
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java
@@ -2,12 +2,10 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSONArray;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.ruoyi.dataInterchange.util.haikang.model.EventSubscriptionByEventTypesRequest;
import com.ruoyi.dataInterchange.util.haikang.model.EventSubscriptionViewRequest;
import com.ruoyi.dataInterchange.util.haikang.model.EventUnSubscriptionByEventTypesRequest;
import com.ruoyi.dataInterchange.util.haikang.model.GetTopicInfoRequest;
import com.ruoyi.dataInterchange.util.haikang.model.*;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
@@ -33,7 +31,7 @@
     * appKey : 请填入appKey
     * appSecret : 请填入appSecret
     */
    private static ArtemisConfig artemisConfig = new ArtemisConfig("https://112.18.106.230:443", "27273246", "vjvZA7X4hHUc0SbONht9");
    private static ArtemisConfig artemisConfig = new ArtemisConfig("112.18.106.230:443", "27273246", "vjvZA7X4hHUc0SbONht9");
    
    //按事件类型取消订阅
    public static String eventUnSubscriptionByEventTypes(EventUnSubscriptionByEventTypesRequest eventUnSubscriptionByEventTypesRequest) throws Exception {
@@ -75,7 +73,117 @@
    }
    
    public static void main(String[] args) {
        Artemis.run();
        try {
            FindVehicleByLicensePlateRequest findVehicleByLicensePlateRequest = new FindVehicleByLicensePlateRequest();
            findVehicleByLicensePlateRequest.setVehicleLicensePlate("川J52303");
            String vehicleByLicensePlate = Artemis.findVehicleByLicensePlate(findVehicleByLicensePlateRequest);
            com.alibaba.fastjson2.JSONObject jsonObject = com.alibaba.fastjson2.JSONObject.parseObject(vehicleByLicensePlate);
            String code = jsonObject.getString("code");
            if(!"0".equals(code)){
                return ;
            }
            com.alibaba.fastjson2.JSONObject data = jsonObject.getJSONObject("data");
            //车辆编号
            String indexCode = data.getString("indexCode");
            //主设备编号
            String primaryDeviceIndexCode = data.getString("primaryDeviceIndexCode");
            //根据车辆编号和设备编号获取监控点信息列表
            FindCameraPageRequest findCameraPageRequest = new FindCameraPageRequest();
            findCameraPageRequest.setPageNo(1);
            findCameraPageRequest.setPageSize(1000);
            ExactCondition1 exactCondition = new ExactCondition1();
            exactCondition.setDeviceIndexCodes(new ArrayList<String>(){{
                add(primaryDeviceIndexCode);
            }});
            exactCondition.setVehicleIndexCodes(new ArrayList<String>(){{
                add(indexCode);
            }});
            findCameraPageRequest.setExactCondition(exactCondition);
            String cameraPage = Artemis.findCameraPage(findCameraPageRequest);
            jsonObject = com.alibaba.fastjson2.JSONObject.parseObject(cameraPage);
            code = jsonObject.getString("code");
            if(!"0".equals(code)){
                return;
            }
            data = jsonObject.getJSONObject("data");
            JSONArray list = data.getJSONArray("list");
            //监控点编号
            String indexCode1 = "";
            for (int i = 0; i < list.size(); i++) {
                com.alibaba.fastjson2.JSONObject jsonObject1 = list.getJSONObject(i);
                String cameraName = jsonObject1.getString("cameraName");
                if("驾驶位".equals(cameraName)){
                    indexCode1 = jsonObject1.getString("indexCode");
                }
            }
            //根据监控点编号获取监控预览url
            PreviewURLsRequest previewURLsRequest = new PreviewURLsRequest();
            previewURLsRequest.setCameraIndexCode(indexCode1);
            String s = Artemis.previewURLs(previewURLsRequest);
            jsonObject = com.alibaba.fastjson2.JSONObject.parseObject(s);
            code = jsonObject.getString("code");
            if(!"0".equals(code)){
                return ;
            }
            data = jsonObject.getJSONObject("data");
            String url = data.getString("url");
            System.out.println(url);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    //根据车牌号码获取车辆信息(含设备)
    public static String findVehicleByLicensePlate(FindVehicleByLicensePlateRequest findVehicleByLicensePlateRequest)throws Exception{
        String findVehicleByLicensePlateDataApi = ARTEMIS_PATH +"/api/rtsm/v1/resource/findVehicleByLicensePlate";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",findVehicleByLicensePlateDataApi);
            }
        };
        String body=JSON.toJSONString(findVehicleByLicensePlateRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
    //根据车辆编号与设备编号获取监控点信息列表
    public static String findCameraPage(FindCameraPageRequest findCameraPageRequest)throws Exception{
        String findCameraPageDataApi = ARTEMIS_PATH +"/api/rtsm/v1/vehicle/findCameraPage";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",findCameraPageDataApi);
            }
        };
        String body=JSON.toJSONString(findCameraPageRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
    //获取监控点预览取流URL
    public static String previewURLs(PreviewURLsRequest previewURLsRequest)throws Exception{
        String previewURLsDataApi = ARTEMIS_PATH +"/api/video/v1/cameras/previewURLs";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",previewURLsDataApi);
            }
        };
        String body=JSON.toJSONString(previewURLsRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
    //分页查询车辆信息
    public static String findVehiclePage(FindVehiclePageRequest findVehiclePageRequest)throws Exception{
        String findVehiclePageDataApi = ARTEMIS_PATH +"/api/rtsm/v1/resource/findVehiclePage";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",findVehiclePageDataApi);
            }
        };
        String body=JSON.toJSONString(findVehiclePageRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json");
        return result;
    }
    
    public static void run() {
@@ -92,7 +200,7 @@
            e.printStackTrace();
        }
    }
    //按事件类型获取事件订阅信息
    public static String getTopicInfo(GetTopicInfoRequest getTopicInfoRequest)throws Exception {
        String getTopicInfoDataApi = ARTEMIS_PATH +"/api/common/v1/event/getTopicInfo";
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/ExactCondition.java
New file
@@ -0,0 +1,15 @@
package com.ruoyi.dataInterchange.util.haikang.model;
import java.util.ArrayList;
public class ExactCondition {
    private ArrayList<String> orgIndexCodes;
    public ArrayList<String> getOrgIndexCodes() {
        return orgIndexCodes;
    }
    public void setOrgIndexCodes(ArrayList<String> orgIndexCodes) {
        this.orgIndexCodes = orgIndexCodes;
    }
}
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/ExactCondition1.java
New file
@@ -0,0 +1,24 @@
package com.ruoyi.dataInterchange.util.haikang.model;
import java.util.ArrayList;
public class ExactCondition1 {
    private ArrayList<String> deviceIndexCodes;
    private ArrayList<String> vehicleIndexCodes;
    public ArrayList<String> getDeviceIndexCodes() {
        return deviceIndexCodes;
    }
    public void setDeviceIndexCodes(ArrayList<String> deviceIndexCodes) {
        this.deviceIndexCodes = deviceIndexCodes;
    }
    public ArrayList<String> getVehicleIndexCodes() {
        return vehicleIndexCodes;
    }
    public void setVehicleIndexCodes(ArrayList<String> vehicleIndexCodes) {
        this.vehicleIndexCodes = vehicleIndexCodes;
    }
}
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/FindCameraPageRequest.java
New file
@@ -0,0 +1,31 @@
package com.ruoyi.dataInterchange.util.haikang.model;
public class FindCameraPageRequest {
    private Integer pageNo;
    private Integer pageSize;
    private ExactCondition1 exactCondition;
    public Integer getPageNo() {
        return pageNo;
    }
    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }
    public Integer getPageSize() {
        return pageSize;
    }
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
    public ExactCondition1 getExactCondition() {
        return exactCondition;
    }
    public void setExactCondition(ExactCondition1 exactCondition) {
        this.exactCondition = exactCondition;
    }
}
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/FindVehicleByLicensePlateRequest.java
New file
@@ -0,0 +1,13 @@
package com.ruoyi.dataInterchange.util.haikang.model;
public class FindVehicleByLicensePlateRequest {
    private String vehicleLicensePlate;
    public String getVehicleLicensePlate() {
        return vehicleLicensePlate;
    }
    public void setVehicleLicensePlate(String vehicleLicensePlate) {
        this.vehicleLicensePlate = vehicleLicensePlate;
    }
}
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/FindVehiclePageRequest.java
New file
@@ -0,0 +1,31 @@
package com.ruoyi.dataInterchange.util.haikang.model;
public class FindVehiclePageRequest {
    private Integer pageNo;
    private Integer pageSize;
    private ExactCondition exactCondition;
    public Integer getPageNo() {
        return pageNo;
    }
    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }
    public Integer getPageSize() {
        return pageSize;
    }
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
    public ExactCondition getExactCondition() {
        return exactCondition;
    }
    public void setExactCondition(ExactCondition exactCondition) {
        this.exactCondition = exactCondition;
    }
}
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/PreviewURLsRequest.java
New file
@@ -0,0 +1,49 @@
package com.ruoyi.dataInterchange.util.haikang.model;
public class PreviewURLsRequest {
    private String cameraIndexCode;
    private Integer streamType;
    private String protocol;
    private Integer transmode;
    private String expand;
    public String getCameraIndexCode() {
        return cameraIndexCode;
    }
    public void setCameraIndexCode(String cameraIndexCode) {
        this.cameraIndexCode = cameraIndexCode;
    }
    public Integer getStreamType() {
        return streamType;
    }
    public void setStreamType(Integer streamType) {
        this.streamType = streamType;
    }
    public String getProtocol() {
        return protocol;
    }
    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }
    public Integer getTransmode() {
        return transmode;
    }
    public void setTransmode(Integer transmode) {
        this.transmode = transmode;
    }
    public String getExpand() {
        return expand;
    }
    public void setExpand(String expand) {
        this.expand = expand;
    }
}
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/mqtt/MqttInit.java
@@ -25,6 +25,6 @@
    public void subscribeAllTopics() {
        messageDrivenChannelAdapter.addTopic("artemis/event_msa_alarm/5201154049/admin");
        messageDrivenChannelAdapter.addTopic("artemis/event_msa_alarm/5201154049/admin", "artemis/event_msa_pic/5201301505/admin");
    }
}