13693261870
2025-07-02 6708810c4de34dfb9513061432d656f91d56ee3a
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.ruoyi.web.controller.manage;
 
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fuzhou.domain.CameraPTZ;
import com.ruoyi.fuzhou.domain.DpEquipment;
import com.ruoyi.fuzhou.domain.HikEvent;
import com.ruoyi.fuzhou.domain.HikEventObj;
import com.ruoyi.fuzhou.service.EquipmentService;
import com.ruoyi.fuzhou.service.HikService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.time.OffsetDateTime;
import java.util.Date;
 
@RestController
@RequestMapping("/dp/hik")
@Tag(name = "大屏--海康视频")
public class HikController extends BaseController {
    @Autowired
    private HikService hikService;
    @Autowired
    private EquipmentService dpEquipmentService;
 
    @GetMapping("/getCameraPreviewURL/{cameraName}")
    @Operation(summary = "根据name查询视频播放URL")
    public AjaxResult getCameraPreviewURL(@PathVariable("cameraName") String cameraName) throws Exception {
        return AjaxResult.success(hikService.getCameraPreviewURL(cameraName));
    }
 
    @GetMapping("/getCameraURL/{cameraIndexCode}")
    @Operation(summary = "根据indexcode查询视频播放URL")
    public AjaxResult getCameraURL(@PathVariable("cameraIndexCode") String cameraIndexCode) throws Exception {
        return AjaxResult.success(hikService.getCameraURL(cameraIndexCode));
    }
 
    @GetMapping("/getCameraOnline/{indexCodes}")
    @Operation(summary = "根据indexCodes数组查询监控状态")
    public AjaxResult getCameraOnline(@PathVariable("indexCodes") String[] indexCodes) throws Exception {
        return AjaxResult.success(hikService.getCameraOnline(indexCodes));
    }
 
    @Operation(summary = "云台操作")
    @PostMapping("/cameraCommand")
    public AjaxResult cameraCommand(@RequestBody CameraPTZ cameraPTZ) throws Exception{
        return AjaxResult.success(hikService.cameraCommand(cameraPTZ));
    }
 
    @Operation(summary = "根据事件类型订阅事件")
    @PostMapping("/subByEventTypes")
    public JSONObject subByEventTypes(@RequestBody HikEventObj hikEventObj) throws Exception{
        return hikService.subByEventTypes(hikEventObj);
    }
 
    @Operation(summary = "根据事件类型取消订阅事件")
    @PostMapping("/unSubByEventTypes")
    public JSONObject unSubByEventTypes(@RequestBody HikEventObj hikEventObj) throws Exception{
        return hikService.unSubByEventTypes(hikEventObj);
    }
 
    @Operation(summary = "查询订阅事件信息")
    @PostMapping("/eventView")
    public JSONObject eventView() throws Exception{
        return hikService.eventView();
    }
 
    @Operation(summary = "接收海康事件信息")
    @PostMapping("/eventRcv")
    public JSONObject eventRcv(@RequestBody JSONObject jsonObject) throws Exception{
        String method = null;
        JSONObject params = new JSONObject();
        JSONArray events = new JSONArray();
        JSONObject res = new JSONObject();
        String sendTime = null;
        if(jsonObject.containsKey("method")){
            method = jsonObject.getString("method");
        }
        if (jsonObject.containsKey("params")) {
            params = jsonObject.getJSONObject("params");
            if(params.containsKey("sendTime")){
                sendTime = params.getString("sendTime");
            }
            if (params.containsKey("events")) {
                events = params.getJSONArray("events");
                if(events.size()>0){
                    for (int i=0;i<events.size();i++){
                        JSONObject event = events.getJSONObject(i);
 
                        HikEvent hikEvent = new HikEvent();
                        hikEvent.setSendTime(convertTime(sendTime));
                        if(event.containsKey("srcIndex")){
                            String srcIndex = event.getString("srcIndex");
                            hikEvent.setSrcIndex(srcIndex);
                        }
                        if(event.containsKey("srcType")){
                            String srcType = event.getString("srcType");
                            hikEvent.setSrcType(srcType);
                        }
                        if(event.containsKey("srcName")){
                            String srcName = event.getString("srcName");
                            hikEvent.setSrcName(srcName);
                        }
                        if(event.containsKey("eventType")){
                            Integer eventType = event.getIntValue("eventType");
                            hikEvent.setEventType(eventType);
                        }
                        if(event.containsKey("happenTime")){
                            String happenTime = event.getString("happenTime");
                            hikEvent.setHappenTime(convertTime(happenTime));
                        }
                        boolean reaIns = hikService.saveInsert(hikEvent);
                        if(reaIns){
                            res.put("code","0");
                            res.put("msg","success");
                        }
 
                        if(event.containsKey("data")){
                            JSONObject data = event.getJSONObject("data");
                            if(data.containsKey("regionEntrance")){
                                JSONArray regionEntrance = data.getJSONArray("regionEntrance");
                                if(regionEntrance.size()>0){
                                    for (int k=0;k<regionEntrance.size();k++){
                                        JSONObject region = regionEntrance.getJSONObject(k);
                                        if(region.containsKey("targetAttrs")){
                                            JSONObject targetAttrs = region.getJSONObject("targetAttrs");
                                            if(targetAttrs.containsKey("cameraAddress")){
                                                String cameraAddress = targetAttrs.getString("cameraAddress");
                                            }
                                            if(targetAttrs.containsKey("cameraIndexCode")){
                                                String cameraIndexCode = targetAttrs.getString("cameraIndexCode");
                                            }
                                            if(targetAttrs.containsKey("deviceIndexCode")){
                                                String deviceIndexCode = targetAttrs.getString("deviceIndexCode");
                                            }
                                            if(targetAttrs.containsKey("imageServerCode")){
                                                String imageServerCode = targetAttrs.getString("imageServerCode");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return res;
    }
 
    /**
     * 查询海康事件列表
     */
    @PostMapping("/list")
    @Operation(summary = "查询海康事件列表(分页)")
    public TableDataInfo list(@RequestBody HikEvent hikEvent)
    {
        return hikService.getList(hikEvent);
    }
 
    /**
     * 查询所有海康事件列表
     */
    @GetMapping("/listAll")
    @Operation(summary = "查询所有海康事件列表")
    public AjaxResult listAll()
    {
        return AjaxResult.success(hikService.list());
    }
 
    /**
     * 获取港口信息详细信息
     */
    @GetMapping("/{id}")
    @Operation(summary = "获取海康事件信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(hikService.getById(id));
    }
 
    private Date convertTime(String time){
        OffsetDateTime offsetDateTime = OffsetDateTime.parse(time);
        Date date = Date.from(offsetDateTime.toInstant());
        return date;
    }
 
}