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;
|
}
|
|
}
|