监控在线状态
This commit is contained in:
parent
b787a52dbb
commit
26cf85ea3c
@ -8,8 +8,6 @@ import com.zhgd.xmgl.modules.project.mapper.ProjectVideoConfigMapper;
|
||||
import com.zhgd.xmgl.modules.video.entity.VideoItem;
|
||||
import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper;
|
||||
import com.zhgd.xmgl.util.HikVideoUtil;
|
||||
import com.zhgd.xmgl.util.PingUtil;
|
||||
import com.zhgd.xmgl.util.VideoUtils;
|
||||
import com.zhgd.xmgl.util.YsVideoUtil;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import net.javacrumbs.shedlock.core.SchedulerLock;
|
||||
@ -23,7 +21,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @program: wisdomSite
|
||||
@ -46,7 +43,7 @@ public class VideoTask {
|
||||
private String serverUrl;
|
||||
|
||||
@SchedulerLock(name = "updateVideoState", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
|
||||
@Scheduled(cron = "0 0 */3 * * ?")
|
||||
@Scheduled(cron = "0 0 */1 * * ?")
|
||||
// @Scheduled(cron = "*/50 * * * * ?")
|
||||
public void updateVideoState() {
|
||||
try {
|
||||
@ -84,12 +81,10 @@ public class VideoTask {
|
||||
&& StringUtils.isNotEmpty(videoConfig.getAppId()) && StringUtils.isNotEmpty(videoConfig.getAppSecret())) {
|
||||
for (VideoItem videoItem : list) {
|
||||
if (StringUtils.isNotEmpty(videoItem.getSerialNumber())) {
|
||||
String url = HikVideoUtil.callPostApiGetPreviewURL(videoItem.getSerialNumber(), "hls", null, videoConfig.getAccount(),
|
||||
Boolean online = HikVideoUtil.callPostApiOnlineStatus(videoItem.getSerialNumber(), videoConfig.getAccount(),
|
||||
videoConfig.getPassword(), videoConfig.getAppId(), videoConfig.getAppSecret());
|
||||
if (StringUtils.isNotEmpty(url)) {
|
||||
boolean status = PingUtil.pingUrl(url);
|
||||
// boolean status= VideoUtils.getVideoOnlineSate(url);
|
||||
if (status) {
|
||||
if (online != null) {
|
||||
if (online) {
|
||||
videoItem.setDeviceState(1);
|
||||
} else {
|
||||
videoItem.setDeviceState(2);
|
||||
@ -151,5 +146,4 @@ public class VideoTask {
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.zhgd.xmgl.util;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hikvision.artemis.sdk.Client;
|
||||
import com.hikvision.artemis.sdk.Request;
|
||||
@ -72,6 +73,48 @@ public class HikVideoUtil {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件获取监控点在线状态接口
|
||||
*/
|
||||
public static Boolean callPostApiOnlineStatus(String cameraIndexCode, String Ip, String port, String appke, String appSecret) {
|
||||
final String getCamsApi = ARTEMIS_PATH + "/api/nms/v1/online/camera/get";
|
||||
Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
|
||||
paramMap.put("indexCodes", Arrays.asList(cameraIndexCode));
|
||||
String body = JSON.toJSON(paramMap).toString();
|
||||
Map<String, String> path = new HashMap<String, String>(2) {
|
||||
{
|
||||
put("https://", getCamsApi);
|
||||
}
|
||||
};
|
||||
String host = Ip + ":" + port;
|
||||
String result = doPostStringArtemis(host, path, body, null, null, "application/json", appke, appSecret);
|
||||
log.info("callPostApiOnlineStatus:{}", result);
|
||||
if (result != null && result.length() > 0) {
|
||||
try {
|
||||
JSONObject json = JSONObject.parseObject(result);
|
||||
if ("0".equals((String) json.get("code"))) {
|
||||
JSONArray arr = (JSONArray) ((JSONObject) json.get("data")).get("list");
|
||||
if (arr.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
JSONObject one = (JSONObject) arr.get(0);
|
||||
Object online = one.get("online");
|
||||
if (online == null) {
|
||||
return null;
|
||||
}
|
||||
Integer o = Integer.valueOf(online.toString());
|
||||
return o.equals(1);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String setSubscriptionByEvent(String backUrl, String Ip, String port, String appke, String appSecret, Integer[] eventTypes) {
|
||||
String message = null;
|
||||
final String getCamsApi = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user