视频监控
This commit is contained in:
parent
9d05c98216
commit
5e44f6ed44
17
pom.xml
17
pom.xml
@ -165,6 +165,23 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- 海康视频-->
|
||||
<dependency>
|
||||
<groupId>com.hikvision.ga</groupId>
|
||||
<artifactId>artemis-http-client</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--TTL-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
||||
81
src/main/java/com/zhgd/review/base/api/CameraPreview.java
Normal file
81
src/main/java/com/zhgd/review/base/api/CameraPreview.java
Normal file
@ -0,0 +1,81 @@
|
||||
package com.zhgd.review.base.api;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
||||
import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
||||
import com.zhgd.review.base.entity.VideoConfig;
|
||||
import com.zhgd.review.base.service.IVideoConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 视频监控外部接口
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CameraPreview {
|
||||
|
||||
@Autowired
|
||||
private IVideoConfigService videoConfigService;
|
||||
|
||||
public JSONObject GetCameraPreviewURL(String requestUrl, String body) {
|
||||
return GetCameraPreviewURL(requestUrl, body, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用
|
||||
* @param requestUrl 请求路径
|
||||
* @param body 请求参数体
|
||||
* @return
|
||||
*/
|
||||
public JSONObject GetCameraPreviewURL(String requestUrl, String body, Map<String, String> header) {
|
||||
/**
|
||||
* STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
||||
*/
|
||||
List<VideoConfig> list = videoConfigService.list();
|
||||
VideoConfig videoConfig = list.get(0);
|
||||
ArtemisConfig.host = videoConfig.getIp() + ":" + videoConfig.getPort();
|
||||
ArtemisConfig.appKey = videoConfig.getAppKey();
|
||||
ArtemisConfig.appSecret = videoConfig.getAppSecret();
|
||||
/**
|
||||
* STEP2:设置OpenAPI接口的上下文
|
||||
*/
|
||||
final String ARTEMIS_PATH = "/artemis";
|
||||
|
||||
/**
|
||||
* STEP3:设置接口的URI地址
|
||||
*/
|
||||
final String previewURLsApi = ARTEMIS_PATH + requestUrl;
|
||||
Map<String, String> path = new HashMap<String, String>(2) {
|
||||
{
|
||||
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* STEP4:设置参数提交方式
|
||||
*/
|
||||
String contentType = "application/json";
|
||||
|
||||
|
||||
/**
|
||||
* STEP6:调用接口
|
||||
*/
|
||||
String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null,
|
||||
contentType, header);// post请求application/json类型参数
|
||||
JSONObject jsonResult = JSONObject.parseObject(result);
|
||||
if (result != null) {
|
||||
String code = jsonResult.getString("code");
|
||||
if (!code.equals("0")) {
|
||||
log.error("调用海康开发平台接口出现错误,请求接口:" + requestUrl + "请求参数 :" + body + "返回错误码:" + code);
|
||||
jsonResult = null;
|
||||
}
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
}
|
||||
92
src/main/java/com/zhgd/review/base/api/MonitorApi.java
Normal file
92
src/main/java/com/zhgd/review/base/api/MonitorApi.java
Normal file
@ -0,0 +1,92 @@
|
||||
package com.zhgd.review.base.api;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 监控外部接口
|
||||
*/
|
||||
@Component
|
||||
public class MonitorApi {
|
||||
|
||||
@Autowired
|
||||
private CameraPreview cameraPreview;
|
||||
|
||||
/**
|
||||
* 根据监控点编号获取监控点状态
|
||||
* @return
|
||||
*/
|
||||
public JSONObject getMonitorOnline(List<String> monitorCode) {
|
||||
String path = "/api/nms/v1/online/camera/get";
|
||||
JSONObject jsonBody = new JSONObject();
|
||||
Object [] array = monitorCode.toArray();
|
||||
jsonBody.put("indexCodes", array);
|
||||
return cameraPreview.GetCameraPreviewURL(path, jsonBody.toJSONString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 监控点图片抓拍
|
||||
* @return
|
||||
*/
|
||||
public JSONObject manualCapture(String monitorCode) {
|
||||
String path = "/api/video/v1/manualCapture";
|
||||
JSONObject jsonBody = new JSONObject();
|
||||
jsonBody.put("cameraIndexCode", monitorCode);
|
||||
// Map<String, String> map = new HashMap<>();
|
||||
// map.put("userId", "admin");
|
||||
// map.put("domainId", "wan");
|
||||
return cameraPreview.GetCameraPreviewURL(path, jsonBody.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监控点预览取流
|
||||
* @return
|
||||
*/
|
||||
public String previewURLV1(Map<String, Object> map) {
|
||||
String path = "/api/video/v1/cameras/previewURLs";
|
||||
JSONObject jsonBody = JSONObject.parseObject(JSON.toJSONString(map));
|
||||
JSONObject jsonObject = cameraPreview.GetCameraPreviewURL(path, jsonBody.toJSONString());
|
||||
if (jsonObject == null) {
|
||||
return null;
|
||||
}
|
||||
return jsonObject.getJSONObject("data").get("url").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监控点预览取流
|
||||
* @return
|
||||
*/
|
||||
public String previewURL(Map<String, Object> map) {
|
||||
map.put("streamType", 1);
|
||||
String path = "/api/video/v2/cameras/previewURLs";
|
||||
JSONObject jsonBody = JSONObject.parseObject(JSON.toJSONString(map));
|
||||
JSONObject jsonObject = cameraPreview.GetCameraPreviewURL(path, jsonBody.toJSONString());
|
||||
if (jsonObject == null) {
|
||||
return null;
|
||||
}
|
||||
return jsonObject.getJSONObject("data").get("url").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 云台操作
|
||||
* @return
|
||||
*/
|
||||
public JSONObject controlling(Map<String, Object> map) {
|
||||
String path = "/api/video/v1/ptzs/controlling";
|
||||
JSONObject jsonBody = JSONObject.parseObject(JSON.toJSONString(map));
|
||||
Map<String, String> headMap = new HashMap<>();
|
||||
headMap.put("userId", "admin");
|
||||
JSONObject jsonObject = cameraPreview.GetCameraPreviewURL(path, jsonBody.toJSONString(), headMap);
|
||||
if (jsonObject == null) {
|
||||
return null;
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zhgd.review.annotation.OperLog;
|
||||
import com.zhgd.review.base.api.MonitorApi;
|
||||
import com.zhgd.review.base.query.QueryGenerator;
|
||||
import com.zhgd.review.base.util.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
@ -11,9 +12,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
@ -58,6 +57,9 @@ public class MonitorDevController {
|
||||
@Autowired
|
||||
private IMonitorDevService monitorDevService;
|
||||
|
||||
@Autowired
|
||||
private MonitorApi monitorApi;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
@ -202,9 +204,12 @@ public class MonitorDevController {
|
||||
if (monitorDev == null) {
|
||||
return Result.failed("未找到对应实体");
|
||||
} else {
|
||||
String url = monitorDev.getUrl();
|
||||
String result = HttpUtil.get(url);
|
||||
return Result.ok(JSONObject.parseObject(result));
|
||||
String cameraIndexCodes = monitorDev.getCode();
|
||||
Map<String, Object> apply = new HashMap<>();
|
||||
apply.put("cameraIndexCode", cameraIndexCodes);
|
||||
apply.put("protocol", "hls");
|
||||
String url = monitorApi.previewURL(apply);
|
||||
return Result.ok(url, "操作成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
55
src/main/java/com/zhgd/review/base/entity/VideoConfig.java
Normal file
55
src/main/java/com/zhgd/review/base/entity/VideoConfig.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.zhgd.review.base.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 视频配置
|
||||
* @author: pengj
|
||||
* @date: 2023-06-01
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("video_config")
|
||||
@ApiModel(value = "VideoConfig实体类", description = "VideoConfig")
|
||||
public class VideoConfig implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
@Excel(name = "ip地址", width = 15)
|
||||
@ApiModelProperty(value = "ip地址")
|
||||
private String ip;
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
@Excel(name = "端口号", width = 15)
|
||||
@ApiModelProperty(value = "端口号")
|
||||
private String port;
|
||||
/**
|
||||
* app_key
|
||||
*/
|
||||
@Excel(name = "app_key", width = 15)
|
||||
@ApiModelProperty(value = "app_key")
|
||||
private String appKey;
|
||||
/**
|
||||
* app_secret
|
||||
*/
|
||||
@Excel(name = "app_secret", width = 15)
|
||||
@ApiModelProperty(value = "app_secret")
|
||||
private String appSecret;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.zhgd.review.base.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zhgd.review.base.entity.VideoConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description: 视频配置
|
||||
* @author: pengj
|
||||
* @date: 2023-06-01
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface VideoConfigMapper extends BaseMapper<VideoConfig> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zhgd.review.base.mapper.VideoConfigMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,14 @@
|
||||
package com.zhgd.review.base.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zhgd.review.base.entity.VideoConfig;
|
||||
|
||||
/**
|
||||
* @Description: 视频配置
|
||||
* @author: pengj
|
||||
* @date: 2023-06-01
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface IVideoConfigService extends IService<VideoConfig> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.zhgd.review.base.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhgd.review.base.entity.VideoConfig;
|
||||
import com.zhgd.review.base.mapper.VideoConfigMapper;
|
||||
import com.zhgd.review.base.service.IVideoConfigService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: 视频配置
|
||||
* @author: pengj
|
||||
* @date: 2023-06-01
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class VideoConfigServiceImpl extends ServiceImpl<VideoConfigMapper, VideoConfig> implements IVideoConfigService {
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user