‘liusuyi’
2024-03-14 650b127a6a671a87034db5e027379e740aa56364
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
package com.ruoyi.device.camera.controller;
 
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.service.IArdCamerasService;
import com.ruoyi.device.camera.service.ICameraSdkService;
 
import com.ruoyi.device.noguidezone.domain.ArdCameraNoGuideZone;
import com.ruoyi.device.noguidezone.service.IArdCameraNoGuideZoneService;
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.utils.gis.Point;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @Description: 相机通用SDK接口
 * @ClassName: CameraSdkController
 * @Author: 刘苏义
 * @Date: 2023年10月14日17:02:56
 **/
 
@Api(tags = "相机通用SDK接口")
@Controller
@RequestMapping("/cameraSdk")
@Anonymous
public class CameraSdkController extends BaseController {
 
    @Resource
    private ICameraSdkService cameraSdkService;
    @Resource
    private IArdCamerasService ardCamerasService;
 
    @Autowired
    private IArdCameraNoGuideZoneService ardCameraNoGuideZoneService;
 
 
    @RequestMapping("/preview")
    private String preview() {
        return "preview";
    }
 
    @RequestMapping("/index")
    private String index() {
        return "test";
    }
 
    @GetMapping("/list")
    public @ResponseBody
    AjaxResult list(ArdCameras ardCamera) {
        List<ArdCameras> list = ardCamerasService.selectArdCamerasListNoDataScope(ardCamera);
        return AjaxResult.success("相机列表:", list);
    }
 
    @ApiOperation("获取码流压缩参数")
    @PostMapping("/getVideoCompressionCfg")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    @Log(title = "获取码流压缩参数", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult getVideoCompressionCfg(@RequestBody CameraCmd cmd) {
        return AjaxResult.success(cameraSdkService.getVideoCompressionCfg(cmd));
    }
 
    @ApiOperation("在线状态")
    @PostMapping("/state")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId"})
    @Log(title = "在线状态", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult getOnlineState(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        boolean onLine = cameraSdkService.isOnLine(cmd);
        return AjaxResult.success(onLine);
    }
 
    @ApiOperation(value = "云台控制", notes = "Code:1-左上 2-上 3-右上 4-左 5-巡航 6-右 7-左下 8-下 9-右下 10-焦距变大 11-焦距变小\n" +
            "12-焦点前调 13-焦点后调 14-光圈扩大 15-光圈缩小 16-雨刷开启")
    @PostMapping("/PTZControlWithSpeed")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.speed", "cmd.enable", "cmd.code"})
    @Log(title = "云台控制", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult PTZControlWithSpeed(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.pTZControl(cmd);
    }
 
    @ApiOperation("调用预置点")
    @PostMapping("/gotoPreset")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.presetIndex"})
    @Log(title = "调用预置点", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult gotoPreset(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.gotoPreset(cmd);
    }
 
    @ApiOperation("设置预置点")
    @PostMapping("/setPreset")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.presetIndex"})
    @Log(title = "设置预置点", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult setPreset(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.setPreset(cmd);
    }
 
    @ApiOperation("获取聚焦值")
    @PostMapping("/getFocusPos")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    @Log(title = "获取聚焦值", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult getFocusPos(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.getFocusPos(cmd);
    }
 
    @ApiOperation("设置聚焦值")
    @PostMapping("/setFocusPos")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.dwFocusPos"})
    @Log(title = "设置聚焦值", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult setFocusPos(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.setFocusPos(cmd);
    }
 
    @ApiOperation("获取PTZ")
    @PostMapping("/getPTZ")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    @Log(title = "获取PTZ", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult getPTZ(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.getPtz(cmd);
    }
 
    @ApiOperation("获取PTZ范围")
    @PostMapping("/getPTZScope")
    @Log(title = "获取PTZ范围", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    public @ResponseBody
    AjaxResult getPTZScope(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.getPtzScope(cmd);
    }
 
    @ApiOperation("设置PTZ")
    @PostMapping("/setPTZ")
    @Log(title = "设置PTZ", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.ptzMap"})
    public @ResponseBody
    AjaxResult setPTZ(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.setPtz(cmd);
    }
 
    @ApiOperation("指向目标")
    @PostMapping("/setTargetPosition")
    @Log(title = "指向目标", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.targetPosition"})
    public @ResponseBody
    AjaxResult setTargetPosition(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        //拦截手动引导
        ArdCameraNoGuideZone ardCameraNoGuideZone = new ArdCameraNoGuideZone();
        ardCameraNoGuideZone.setCameraId(cmd.getCameraId());
        ardCameraNoGuideZone.setEnabled("1");
        //获取当前相机的禁引可视域列表
        List<ArdCameraNoGuideZone> ardCameraNoGuideZones = ardCameraNoGuideZoneService.selectArdCameraNoGuideZoneList(ardCameraNoGuideZone);
        if (ardCameraNoGuideZones.size() > 0) {
            //获取到当前相机的坐标集合
            for (ArdCameraNoGuideZone zone : ardCameraNoGuideZones) {
                String[] parts = zone.getPoi().split(",");
                List<Point> pointList = new ArrayList<>();
                for (int i = 0; i < parts.length; i += 3) {
                    Point point = new Point();
                    point.setLongitude(Double.valueOf(parts[i]));
                    point.setLatitude(Double.valueOf(parts[i + 1]));
                    pointList.add(point);
                }
                double lon = cmd.getTargetPosition()[0];
                double lat = cmd.getTargetPosition()[1];
                Point targetPoint = new Point(lon, lat);
                //判断引导目标是否在坐标集合组成的多边形内
                boolean inPolygon = GisUtil.isInPolygon(targetPoint, pointList);
                if (inPolygon) {
                    return AjaxResult.error("引导坐标位于禁引可视域内");
                }
            }
        }
        return cameraSdkService.guideTargetPosition(cmd);
    }
 
    @ApiOperation("指向目标井")
    @PostMapping("/setTargetWell")
    @Log(title = "指向目标井", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.wellId"})
    public @ResponseBody
    AjaxResult setTargetWell(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.guideTargetWell(cmd);
    }
 
    @ApiOperation("设置零方位角")
    @PostMapping("/setZeroPTZ")
    @Log(title = "设置零方位角", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    public @ResponseBody
    AjaxResult setZeroPTZ(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.setZeroPtz(cmd);
    }
 
    @ApiOperation("设置锁定")
    @PostMapping("/setPTZLock")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.expired"})
    @Log(title = "设置锁定", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult setPTZLock(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.controlLock(cmd);
    }
 
    @ApiOperation("设置解锁")
    @PostMapping("/setPTZUnLock")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId"})
    @Log(title = "设置解锁", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult setPTZUnLock(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.controlUnLock(cmd);
    }
 
    @ApiOperation("获取云台锁定信息")
    @PostMapping("/getPTZLockInfo")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    @Log(title = "获取云台锁定信息", businessType = BusinessType.CONTROL)
    public @ResponseBody
    AjaxResult getPTZLockInfo(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        AjaxResult ajaxResult = cameraSdkService.getPTZLockInfo(cmd);
        Integer byWorkMode = (Integer) ajaxResult.get("msg");
        if (byWorkMode == 0) {
            return AjaxResult.success("云台锁定状态:解锁");
        } else if (byWorkMode == 1) {
            return AjaxResult.success("云台锁定状态:锁定");
        } else {
            return AjaxResult.error("云台锁定状态:失败");
        }
    }
 
    @ApiOperation("透雾开关")
    @PostMapping("/defogcfg")
    @Log(title = "透雾开关", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.enable"})
    public @ResponseBody
    AjaxResult defogcfg(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.controlDefogcfg(cmd);
    }
 
    @ApiOperation("红外开关")
    @PostMapping("/infrarecfg")
    @Log(title = "红外开关", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.enable"})
    public @ResponseBody
    AjaxResult infrarecfg(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.controlInfrarecfg(cmd);
    }
 
    @ApiOperation(value = "手动/自动聚焦", notes = "true手动flase自动")
    @PostMapping("/focusMode")
    @Log(title = "手动/自动聚焦", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.enable"})
    public @ResponseBody
    AjaxResult enableFocusMode(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.controlFocusMode(cmd);
    }
 
    @ApiOperation(value = "获取聚焦模式", notes = "1手动2自动")
    @PostMapping("/getFocusMode")
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    public @ResponseBody
    AjaxResult getFocusMode(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.getFocusMode(cmd);
    }
 
    @ApiOperation("云台加热")
    @PostMapping("/heateRpwron")
    @Log(title = "云台加热", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.enable"})
    public @ResponseBody
    AjaxResult heateRpwron(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.controlPTHeateRpwron(cmd);
    }
 
 
    @ApiOperation("镜头加热")
    @PostMapping("/cameraDeicing")
    @Log(title = "镜头加热", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.enable"})
    public @ResponseBody
    AjaxResult cameraDeicing(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.controlCameraDeicing(cmd);
    }
 
    @ApiOperation("相机抓图")
    @PostMapping("/picCutCate")
    @Log(title = "相机抓图", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    public @ResponseBody
    AjaxResult picCutCate(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        String path = cameraSdkService.picCutCate(cmd);
        return toAjaxString(path, "相机抓图");
    }
 
    @ApiOperation("获取相机架设参数")
    @PostMapping("/getGisInfo")
    @Log(title = "获取相机架设参数", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    public @ResponseBody
    AjaxResult getGisInfo(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        return cameraSdkService.getGisInfo(cmd);
    }
 
    @ApiOperation("录像")
    @PostMapping("/record")
    @Log(title = "手动录像开始", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo", "cmd.enable"})
    public @ResponseBody
    AjaxResult record(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        String url = cameraSdkService.record(cmd);
        return AjaxResult.success(url);
    }
 
    @ApiOperation("手动录像开始")
    @PostMapping("/recordStart")
    @Log(title = "手动录像开始", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.chanNo"})
    public @ResponseBody
    AjaxResult recordStart(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        boolean b = cameraSdkService.recordStart(cmd);
        return toAjax(b);
    }
 
    @ApiOperation("手动录像停止")
    @PostMapping("/recordStop")
    @Log(title = "手动录像停止", businessType = BusinessType.CONTROL)
    @ApiOperationSupport(includeParameters = {"cmd.cameraId", "cmd.recordBucketName", "cmd.recordObjectName"})
    public @ResponseBody
    AjaxResult recordStop(@RequestBody CameraCmd cmd) {
        cmd.setOperator(SecurityUtils.getUserId());
        String url = cameraSdkService.recordStopToMinio(cmd);
        return AjaxResult.success(url);
    }
}