Pu Zhibing
6 天以前 a91f50ce8ce976743c11de98f9e3ed574bb3f78e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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("获取海康实时视频预览地址失败");
        }
    }
 
}