|
|
@@ -2,7 +2,6 @@ package com.zhiqiyun.open.core.video.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Maps;
|
|
|
-import com.zhiqiyun.open.core.models.hwVideo.DeviceList;
|
|
|
import com.zhiqiyun.open.core.video.VideoAnalysisService;
|
|
|
import com.zhiqiyun.open.exception.ServiceException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -10,21 +9,17 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.client.config.CookieSpecs;
|
|
|
import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-import org.apache.http.client.methods.HttpDelete;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.BoundValueOperations;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@@ -38,57 +33,21 @@ import static com.zhiqiyun.open.camera.config.CameraConfig.*;
|
|
|
@Service
|
|
|
public class VideoAnalysisServiceImpl implements VideoAnalysisService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ThreadPoolTaskExecutor taskExecutor;
|
|
|
-
|
|
|
- private final static int pageSize = 100;
|
|
|
-
|
|
|
@Resource
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
- private final static String LINE_CROSSING = "<run_extradata>" +
|
|
|
- " <![CDATA[<vcm_beh_alg_config>" +
|
|
|
- " <BEH_GLOBAL_ALARM>" +
|
|
|
- " <minSizeWidth>0.01</minSizeWidth>" +
|
|
|
- " <minSizeHeight>0.01</minSizeHeight>" +
|
|
|
- " <maxSizeWidth>0.9</maxSizeWidth>" +
|
|
|
- " <maxSizeHeight>0.9</maxSizeHeight>" +
|
|
|
- " <detSensitivity>1</detSensitivity>" +
|
|
|
- " <backgroundUpdateRate>1</backgroundUpdateRate>" +
|
|
|
- " <shadowRemove>0</shadowRemove>" +
|
|
|
- " </BEH_GLOBAL_ALARM>" +
|
|
|
- " <BEH_RULE>" +
|
|
|
- " <ruleId>0</ruleId>" +
|
|
|
- " <ruleType>4</ruleType>" +
|
|
|
- " <focusedPart>0</focusedPart>" +
|
|
|
- " <alarmThreshold>10</alarmThreshold>" +
|
|
|
- " <outCntInitValue>0</outCntInitValue>" +
|
|
|
- " <inCntInitValue>0</inCntInitValue>" +
|
|
|
- " <autoClearFlag>1</autoClearFlag>" +
|
|
|
- " <lineNum>1</lineNum>" +
|
|
|
- " <line>" +
|
|
|
- " <lineType>1</lineType>" +
|
|
|
- " <direct>1</direct>" +
|
|
|
- " <point>0.25208,0.15926</point>" +
|
|
|
- " <!-- 相对坐标系 -->" +
|
|
|
- " <point>0.00000,0.38056</point>" +
|
|
|
- " </line>" +
|
|
|
- " </BEH_RULE>" +
|
|
|
- " </vcm_beh_alg_config>]]>" +
|
|
|
- "</run_extradata>";
|
|
|
-
|
|
|
private final static String VCM_VIDEO_JSESSIONID_TOKEN = "VCM_VIDEO_JSESSIONID_TOKEN";
|
|
|
|
|
|
@Override
|
|
|
public String getValidToken() throws Exception {
|
|
|
BoundValueOperations<String, String> boundValueOperations = this.redisTemplate.boundValueOps(VCM_VIDEO_JSESSIONID_TOKEN);
|
|
|
- String token = null;
|
|
|
+ String token = boundValueOperations.get();
|
|
|
if (StringUtils.isBlank(token) || !token.contains("JSESSIONID")) {
|
|
|
Map<String, Object> paramValues = new HashMap<>(2);
|
|
|
- paramValues.put("account", "duijie01");
|
|
|
- paramValues.put("pwd", PASSWORD);
|
|
|
- CloseableHttpResponse response = httpPost("/sdk_service/rest/users/login/v1.1", paramValues, null);
|
|
|
- getApacheBodyXml(response);
|
|
|
+ paramValues.put("userName", "duijie01");
|
|
|
+ paramValues.put("password", PASSWORD);
|
|
|
+ CloseableHttpResponse response = httpPost("/loginInfo/login/v1.0", paramValues, null);
|
|
|
+ getApacheBody(response);
|
|
|
String setCookie = getApacheHeader(response, "Set-Cookie");
|
|
|
log.info("Set-Cookie JSESSIONID:{}", setCookie);
|
|
|
if (StringUtils.isBlank(setCookie)) {
|
|
|
@@ -120,108 +79,11 @@ public class VideoAnalysisServiceImpl implements VideoAnalysisService {
|
|
|
|
|
|
@Override
|
|
|
public void cameraList(Map<String, String> paramValues) throws Exception {
|
|
|
- CloseableHttpResponse response = httpGet("/device/deviceList/v1.0?deviceType=32", paramValues, getValidToken());
|
|
|
+ CloseableHttpResponse response = httpGet("/device/deviceList/v1.0?deviceType=1", paramValues, getValidToken());
|
|
|
JSONObject body = getApacheBody(response);
|
|
|
log.info("获取到的摄像机列表:{}", body.toJSONString());
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void startIntelligentAnalysis(String ids) throws Exception {
|
|
|
-// Map<String, String> params = Maps.newHashMap();
|
|
|
-// params.put("fromIndex", "1");
|
|
|
-// params.put("toIndex", "100");
|
|
|
-// JSONObject jsonObject = videoDockingService.loadDeviceList(params);
|
|
|
-// JSONObject cameraBriefExInfos = jsonObject.getJSONObject("cameraBriefExInfos");
|
|
|
-// JSONObject cameraBriefInfoExList = cameraBriefExInfos.getJSONObject("cameraBriefInfoExList");
|
|
|
-// List<DeviceList> cameraBriefInfoExes = cameraBriefInfoExList.getJSONArray("cameraBriefInfoExes").toJavaList(DeviceList.class);
|
|
|
- String builder = "<request>" +
|
|
|
- " <task_name>testPerson</task_name>" +
|
|
|
- " <type>0</type>" +
|
|
|
- " <camera_id>" + ids + "</camera_id>" +
|
|
|
- " <analyzeMode></analyzeMode>" +
|
|
|
- " <priority></priority>" +
|
|
|
- " <algorithms>" +
|
|
|
- " <algorithm></algorithm>" +
|
|
|
- " </algorithms>" +
|
|
|
- " <run_extradata>" +
|
|
|
- " <![CDATA[<vcm_beh_alg_config>" +
|
|
|
- " <BEH_GLOBAL_ALARM>" +
|
|
|
- " <minSizeWidth>0.01</minSizeWidth>" +
|
|
|
- " <minSizeHeight>0.01</minSizeHeight>" +
|
|
|
- " <maxSizeWidth>0.9</maxSizeWidth>" +
|
|
|
- " <maxSizeHeight>0.9</maxSizeHeight>" +
|
|
|
- " <detSensitivity>1</detSensitivity>" +
|
|
|
- " <backgroundUpdateRate>1</backgroundUpdateRate>" +
|
|
|
- " <shadowRemove>0</shadowRemove>" +
|
|
|
- " </BEH_GLOBAL_ALARM>" +
|
|
|
- " <BEH_RULE>" +
|
|
|
- " <ruleId>0</ruleId>" +
|
|
|
- " <ruleType>4</ruleType>" +
|
|
|
- " <focusedPart>0</focusedPart>" +
|
|
|
- " <alarmThreshold>10</alarmThreshold>" +
|
|
|
- " <outCntInitValue>0</outCntInitValue>" +
|
|
|
- " <inCntInitValue>0</inCntInitValue>" +
|
|
|
- " <autoClearFlag>1</autoClearFlag>" +
|
|
|
- " <lineNum>1</lineNum>" +
|
|
|
- " <line>" +
|
|
|
- " <lineType>1</lineType>" +
|
|
|
- " <direct>1</direct>" +
|
|
|
- " <point>0.25208,0.15926</point>" +
|
|
|
- " <point>0.00000,0.38056</point>" +
|
|
|
- " </line>" +
|
|
|
- " </BEH_RULE>" +
|
|
|
- "</vcm_beh_alg_config>]]>" +
|
|
|
- " </run_extradata>" +
|
|
|
- "</request>";
|
|
|
- CloseableHttpResponse response = httpPostXml("/sdk_service/rest/video-analysis/start-intelligent-analysis/v1.1", builder, getValidToken());
|
|
|
- Map<String, Object> body = getApacheBodyXml(response);
|
|
|
- log.info("获取到的摄像机列表:{}", JSONObject.toJSONString(body));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getIntelligentAnalysisList() throws Exception {
|
|
|
- String builder = "<request><page no=\"1\" pageSize=\"100\" pageSort=\"desc\" sortName=\"createDate\"/></request>";
|
|
|
- CloseableHttpResponse response = httpPostXml("/sdk_service/rest/video-analysis/get_intelligent_analysis_list/v1.1", builder, getValidToken());
|
|
|
- Map<String, Object> body = getApacheBodyXml(response);
|
|
|
- log.info("获取到的摄像机列表:{}", JSONObject.toJSONString(body));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void subscription() throws Exception {
|
|
|
- String builder = "<request><callbackUrl><master>http://171.104.234.207:9800/IntelligentData/DispositionNotifications</master>" +
|
|
|
- "<slave>http://192.168.0.108:9800/IntelligentData/SubscribeNotifications</slave><authMode>0</authMode></callbackUrl><taskId>62ecbd79d629f802a55395da,62ec985fd629f802a55395d5,62ec83cbd629f802a55395cd,62ebbbb2d629f802a5539551,62ebbbb2d629f802a5539550,62ebbbb2d629f802a553954f,62eb98e6d629f802a5539515</taskId><dataFormat>1</dataFormat></request>";
|
|
|
- CloseableHttpResponse response = httpPostXml("/sdk_service/rest/video-analysis/subscription", builder, getValidToken());
|
|
|
- Map<String, Object> body = getApacheBodyXml(response);
|
|
|
- log.info("获取到的摄像机列表:{}", JSONObject.toJSONString(body));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有设备信息
|
|
|
- *
|
|
|
- * @param fromIndex 页数
|
|
|
- * @param deviceLists 数据
|
|
|
- * @return List<DeviceList>
|
|
|
- * @throws Exception Exception
|
|
|
- */
|
|
|
- private List<DeviceList> loadAllDeviceList(int fromIndex, List<DeviceList> deviceLists) throws Exception {
|
|
|
-// Map<String, String> params = Maps.newHashMap();
|
|
|
-// params.put("fromIndex", String.valueOf((fromIndex - 1) * pageSize + 1));
|
|
|
-// params.put("toIndex", String.valueOf(fromIndex * pageSize));
|
|
|
-// JSONObject jsonObject = videoDockingService.loadDeviceList(params);
|
|
|
-// JSONObject cameraBriefExInfos = jsonObject.getJSONObject("cameraBriefExInfos");
|
|
|
-// JSONObject cameraBriefInfoExList = cameraBriefExInfos.getJSONObject("cameraBriefInfoExList");
|
|
|
-// List<DeviceList> cameraBriefInfoExes = cameraBriefInfoExList.getJSONArray("cameraBriefInfoExes").toJavaList(DeviceList.class);
|
|
|
-// if (cameraBriefInfoExes != null && cameraBriefInfoExes.size() > 0) {
|
|
|
-// deviceLists.addAll(cameraBriefInfoExes);
|
|
|
-// if (cameraBriefExInfos.size() == pageSize) {
|
|
|
-// return loadAllDeviceList(fromIndex + 1, deviceLists);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return deviceLists;
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 统一POST请求方法
|
|
|
*
|
|
|
@@ -234,14 +96,13 @@ public class VideoAnalysisServiceImpl implements VideoAnalysisService {
|
|
|
CloseableHttpClient httpClient = createSSLClientDefault();
|
|
|
String url = String.format("%s" + uri, VCM_URI);
|
|
|
log.info("REQUEST URI:{},cooke:{}", url, cookie);
|
|
|
-// url += "?" + URLEncoder.encode(postXForm(paramValues), "UTF-8");
|
|
|
-// log.info("REQUEST getRequestGetUri URI:{}", url);
|
|
|
RequestConfig defaultConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
|
|
|
+
|
|
|
// 2. 创建POST请求
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
- httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
|
|
|
+ httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
httpPost.setHeader("Connection", "keep-alive");
|
|
|
- httpPost.setHeader("Accept", "text/plain;charset=utf-8");
|
|
|
+ httpPost.setHeader("Accept", "application/json, text/plain, */*");
|
|
|
httpPost.setHeader("Accept-Encoding", "gzip, deflate, br");
|
|
|
httpPost.setHeader("Sec-Fetch-Site", "same-origin");
|
|
|
httpPost.setHeader("Sec-Fetch-Mode", "cors");
|
|
|
@@ -252,9 +113,8 @@ public class VideoAnalysisServiceImpl implements VideoAnalysisService {
|
|
|
}
|
|
|
httpPost.setConfig(defaultConfig);
|
|
|
if (paramValues != null && paramValues.size() > 0) {
|
|
|
- String body = postXForm(paramValues);
|
|
|
- log.info("http post body:{}", body);
|
|
|
- httpPost.setEntity(new StringEntity(body));
|
|
|
+ log.info("http post body:{}", paramValues);
|
|
|
+ httpPost.setEntity(new StringEntity(JSONObject.toJSONString(paramValues)));
|
|
|
}
|
|
|
return httpClient.execute(httpPost);
|
|
|
}
|
|
|
@@ -267,7 +127,6 @@ public class VideoAnalysisServiceImpl implements VideoAnalysisService {
|
|
|
* @return String
|
|
|
*/
|
|
|
private static CloseableHttpResponse httpGet(String uri, Map<String, String> paramValues, String cookie) throws IOException {
|
|
|
- // 1. 创建HttpClient
|
|
|
CloseableHttpClient httpClient = createSSLClientDefault();
|
|
|
String url = String.format("%s" + uri, VCM_URI);
|
|
|
log.info("REQUEST URI:{}", url);
|
|
|
@@ -275,7 +134,7 @@ public class VideoAnalysisServiceImpl implements VideoAnalysisService {
|
|
|
log.info("REQUEST getRequestGetUri URI:{}", url);
|
|
|
RequestConfig defaultConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
- httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
+ httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
httpGet.setHeader("Connection", "keep-alive");
|
|
|
httpGet.setHeader("Accept", "application/json, text/plain, */*");
|
|
|
httpGet.setHeader("Accept-Encoding", "gzip, deflate, br");
|
|
|
@@ -295,71 +154,4 @@ public class VideoAnalysisServiceImpl implements VideoAnalysisService {
|
|
|
httpGet.setConfig(defaultConfig);
|
|
|
return httpClient.execute(httpGet);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 统一POST请求方法
|
|
|
- *
|
|
|
- * @param uri uri
|
|
|
- * @param postXml postXml
|
|
|
- * @return String
|
|
|
- */
|
|
|
- public static CloseableHttpResponse httpPostXml(String uri, String postXml, String cookie) throws IOException {
|
|
|
- // 1. 创建HttpClient
|
|
|
- CloseableHttpClient httpClient = createSSLClientDefault();
|
|
|
- String url = String.format("%s" + uri, VCM_URI);
|
|
|
- log.info("REQUEST URI:{},cooke:{}", url, cookie);
|
|
|
- RequestConfig defaultConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
|
|
|
-
|
|
|
- // 2. 创建POST请求
|
|
|
- HttpPost httpPost = new HttpPost(url);
|
|
|
- httpPost.setHeader("Content-Type", "application/xml;charset=UTF-8");
|
|
|
- httpPost.setHeader("Connection", "keep-alive");
|
|
|
- httpPost.setHeader("Accept", "text/plain;charset=UTF-8");
|
|
|
- httpPost.setHeader("Accept-Encoding", "gzip, deflate, br");
|
|
|
- httpPost.setHeader("Sec-Fetch-Site", "same-origin");
|
|
|
- httpPost.setHeader("Sec-Fetch-Mode", "cors");
|
|
|
- httpPost.setHeader("Sec-Fetch-Dest", "empty");
|
|
|
- httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36");
|
|
|
- if (StringUtils.isNotBlank(cookie)) {
|
|
|
- httpPost.setHeader("Cookie", cookie);
|
|
|
- }
|
|
|
- httpPost.setConfig(defaultConfig);
|
|
|
- if (StringUtils.isNotBlank(postXml)) {
|
|
|
- log.info("http post body:{}", postXml);
|
|
|
- httpPost.setEntity(new StringEntity(postXml));
|
|
|
- }
|
|
|
- return httpClient.execute(httpPost);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 统一DELETE请求方法
|
|
|
- *
|
|
|
- * @param uri uri
|
|
|
- * @param paramValues paramValues
|
|
|
- * @return String
|
|
|
- */
|
|
|
- public static CloseableHttpResponse httpDelete(String uri, Map<String, String> paramValues, String cookie) throws IOException {
|
|
|
- // 1. 创建HttpClient
|
|
|
- CloseableHttpClient httpClient = createSSLClientDefault();
|
|
|
- String url = String.format("%s" + uri, VCM_URI);
|
|
|
- log.info("REQUEST URI:{},cooke:{}", url, cookie);
|
|
|
- url = getRequestGetUri(url, paramValues);
|
|
|
- RequestConfig defaultConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
|
|
|
-
|
|
|
- // 2. 创建POST请求
|
|
|
- HttpDelete httpDelete = new HttpDelete(url);
|
|
|
- httpDelete.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
- httpDelete.setHeader("Connection", "keep-alive");
|
|
|
- httpDelete.setHeader("Accept", "application/json, text/plain, */*");
|
|
|
- httpDelete.setHeader("Accept-Encoding", "gzip, deflate, br");
|
|
|
- httpDelete.setHeader("Sec-Fetch-Site", "same-origin");
|
|
|
- httpDelete.setHeader("Sec-Fetch-Mode", "cors");
|
|
|
- httpDelete.setHeader("Sec-Fetch-Dest", "empty");
|
|
|
- httpDelete.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36");
|
|
|
- if (StringUtils.isNotBlank(cookie)) {
|
|
|
- httpDelete.setHeader("Cookie", cookie);
|
|
|
- }
|
|
|
- httpDelete.setConfig(defaultConfig);
|
|
|
- return httpClient.execute(httpDelete);
|
|
|
- }
|
|
|
}
|