监控在线状态
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.entity.VideoItem;
|
||||||
import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper;
|
import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper;
|
||||||
import com.zhgd.xmgl.util.HikVideoUtil;
|
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 com.zhgd.xmgl.util.YsVideoUtil;
|
||||||
import lombok.extern.log4j.Log4j;
|
import lombok.extern.log4j.Log4j;
|
||||||
import net.javacrumbs.shedlock.core.SchedulerLock;
|
import net.javacrumbs.shedlock.core.SchedulerLock;
|
||||||
@ -23,7 +21,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @program: wisdomSite
|
* @program: wisdomSite
|
||||||
@ -45,51 +42,49 @@ public class VideoTask {
|
|||||||
@Value("${serverUrl}")
|
@Value("${serverUrl}")
|
||||||
private String serverUrl;
|
private String serverUrl;
|
||||||
|
|
||||||
@SchedulerLock(name = "updateVideoState", lockAtMostFor = 1000*60*60, lockAtLeastFor = 1000*60*5)
|
@SchedulerLock(name = "updateVideoState", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
|
||||||
@Scheduled(cron = "0 0 */3 * * ?")
|
@Scheduled(cron = "0 0 */1 * * ?")
|
||||||
// @Scheduled(cron = "*/50 * * * * ?")
|
// @Scheduled(cron = "*/50 * * * * ?")
|
||||||
public void updateVideoState(){
|
public void updateVideoState() {
|
||||||
try{
|
try {
|
||||||
QueryWrapper<ProjectVideoConfig> queryWrapper=new QueryWrapper<>();
|
QueryWrapper<ProjectVideoConfig> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.lambda().eq(ProjectVideoConfig::getIsEnable,1);
|
queryWrapper.lambda().eq(ProjectVideoConfig::getIsEnable, 1);
|
||||||
List<ProjectVideoConfig> list= projectVideoConfigMapper.selectList(queryWrapper);
|
List<ProjectVideoConfig> list = projectVideoConfigMapper.selectList(queryWrapper);
|
||||||
if(list!=null&&list.size()>0){
|
if (list != null && list.size() > 0) {
|
||||||
for (ProjectVideoConfig videoConfig:list){
|
for (ProjectVideoConfig videoConfig : list) {
|
||||||
updateProjectVideo(videoConfig);
|
updateProjectVideo(videoConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
//e.printStackTrace();
|
//e.printStackTrace();
|
||||||
log.info(e.getMessage());
|
log.info(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProjectVideo(ProjectVideoConfig videoConfig){
|
private void updateProjectVideo(ProjectVideoConfig videoConfig) {
|
||||||
try{
|
try {
|
||||||
QueryWrapper<VideoItem> queryWrapper=new QueryWrapper<>();
|
QueryWrapper<VideoItem> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.lambda().eq(VideoItem::getVideoId,videoConfig.getId());
|
queryWrapper.lambda().eq(VideoItem::getVideoId, videoConfig.getId());
|
||||||
List<VideoItem> list=videoItemMapper.selectList(queryWrapper);
|
List<VideoItem> list = videoItemMapper.selectList(queryWrapper);
|
||||||
if(list!=null&&list.size()>0){
|
if (list != null && list.size() > 0) {
|
||||||
if(videoConfig.getVideoType()==1){
|
if (videoConfig.getVideoType() == 1) {
|
||||||
String accessToken= YsVideoUtil.getToken(videoConfig.getAppId(),videoConfig.getAppSecret());
|
String accessToken = YsVideoUtil.getToken(videoConfig.getAppId(), videoConfig.getAppSecret());
|
||||||
for(VideoItem videoItem:list){
|
for (VideoItem videoItem : list) {
|
||||||
Integer state=YsVideoUtil.getVideoStatus(videoConfig.getAppId(),videoConfig.getAppSecret(),videoItem.getSerialNumber(),accessToken);
|
Integer state = YsVideoUtil.getVideoStatus(videoConfig.getAppId(), videoConfig.getAppSecret(), videoItem.getSerialNumber(), accessToken);
|
||||||
videoItem.setDeviceState(state);
|
videoItem.setDeviceState(state);
|
||||||
videoItemMapper.updateById(videoItem);
|
videoItemMapper.updateById(videoItem);
|
||||||
}
|
}
|
||||||
}else if(videoConfig.getVideoType()==2){
|
} else if (videoConfig.getVideoType() == 2) {
|
||||||
|
|
||||||
}else if(videoConfig.getVideoType()==3){
|
} else if (videoConfig.getVideoType() == 3) {
|
||||||
if(StringUtils.isNotEmpty(videoConfig.getAccount())&&StringUtils.isNotEmpty(videoConfig.getPassword())
|
if (StringUtils.isNotEmpty(videoConfig.getAccount()) && StringUtils.isNotEmpty(videoConfig.getPassword())
|
||||||
&&StringUtils.isNotEmpty(videoConfig.getAppId())&&StringUtils.isNotEmpty(videoConfig.getAppSecret())){
|
&& StringUtils.isNotEmpty(videoConfig.getAppId()) && StringUtils.isNotEmpty(videoConfig.getAppSecret())) {
|
||||||
for(VideoItem videoItem:list){
|
for (VideoItem videoItem : list) {
|
||||||
if(StringUtils.isNotEmpty(videoItem.getSerialNumber())) {
|
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());
|
videoConfig.getPassword(), videoConfig.getAppId(), videoConfig.getAppSecret());
|
||||||
if (StringUtils.isNotEmpty(url)) {
|
if (online != null) {
|
||||||
boolean status = PingUtil.pingUrl(url);
|
if (online) {
|
||||||
// boolean status= VideoUtils.getVideoOnlineSate(url);
|
|
||||||
if (status) {
|
|
||||||
videoItem.setDeviceState(1);
|
videoItem.setDeviceState(1);
|
||||||
} else {
|
} else {
|
||||||
videoItem.setDeviceState(2);
|
videoItem.setDeviceState(2);
|
||||||
@ -100,40 +95,40 @@ public class VideoTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
QueryWrapper<VideoItem> qu=new QueryWrapper<>();
|
QueryWrapper<VideoItem> qu = new QueryWrapper<>();
|
||||||
qu.lambda().eq(VideoItem::getVideoId,videoConfig.getId());
|
qu.lambda().eq(VideoItem::getVideoId, videoConfig.getId());
|
||||||
VideoItem item=new VideoItem();
|
VideoItem item = new VideoItem();
|
||||||
item.setDeviceState(2);
|
item.setDeviceState(2);
|
||||||
item.setVideoId(videoConfig.getId());
|
item.setVideoId(videoConfig.getId());
|
||||||
videoItemMapper.update(item,qu);
|
videoItemMapper.update(item, qu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendVideoData(VideoItem videoItem,ProjectVideoConfig videoConfig){
|
private void sendVideoData(VideoItem videoItem, ProjectVideoConfig videoConfig) {
|
||||||
List<Map<String,Object>> list=new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
Map<String,Object> video=new HashMap<>();
|
Map<String, Object> video = new HashMap<>();
|
||||||
video.put("appId",videoConfig.getAppId());
|
video.put("appId", videoConfig.getAppId());
|
||||||
video.put("appSecret",videoConfig.getAppSecret());
|
video.put("appSecret", videoConfig.getAppSecret());
|
||||||
video.put("ip",videoConfig.getAccount());
|
video.put("ip", videoConfig.getAccount());
|
||||||
video.put("port",videoConfig.getPassword());
|
video.put("port", videoConfig.getPassword());
|
||||||
video.put("serialNumber",videoItem.getSerialNumber());
|
video.put("serialNumber", videoItem.getSerialNumber());
|
||||||
list.add(video);
|
list.add(video);
|
||||||
List<Long> alarmIdList=new ArrayList<>();
|
List<Long> alarmIdList = new ArrayList<>();
|
||||||
alarmIdList.add(videoItem.getItemId());
|
alarmIdList.add(videoItem.getItemId());
|
||||||
Map<String,Object> object=new HashMap<>();
|
Map<String, Object> object = new HashMap<>();
|
||||||
object.put("projectSn",videoConfig.getProjectSn());
|
object.put("projectSn", videoConfig.getProjectSn());
|
||||||
object.put("videoList",list);
|
object.put("videoList", list);
|
||||||
object.put("dataId",alarmIdList);
|
object.put("dataId", alarmIdList);
|
||||||
object.put("resultUrl",serverUrl+"/xmgl/api/saveVideoAnalysisResult");
|
object.put("resultUrl", serverUrl + "/xmgl/api/saveVideoAnalysisResult");
|
||||||
object.put("type",2);
|
object.put("type", 2);
|
||||||
log.info(JSONUtil.toJsonStr(object));
|
log.info(JSONUtil.toJsonStr(object));
|
||||||
if(StringUtils.isNotEmpty(videoAnalysisUrl)){
|
if (StringUtils.isNotEmpty(videoAnalysisUrl)) {
|
||||||
asyncEnvironment.sendVideoAnalysisData(videoAnalysisUrl,object);
|
asyncEnvironment.sendVideoAnalysisData(videoAnalysisUrl, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,5 +146,4 @@ public class VideoTask {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.zhgd.xmgl.util;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.hikvision.artemis.sdk.Client;
|
import com.hikvision.artemis.sdk.Client;
|
||||||
import com.hikvision.artemis.sdk.Request;
|
import com.hikvision.artemis.sdk.Request;
|
||||||
@ -72,6 +73,48 @@ public class HikVideoUtil {
|
|||||||
return url;
|
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) {
|
public static String setSubscriptionByEvent(String backUrl, String Ip, String port, String appke, String appSecret, Integer[] eventTypes) {
|
||||||
String message = null;
|
String message = null;
|
||||||
final String getCamsApi = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
final String getCamsApi = ARTEMIS_PATH + "/api/eventService/v1/eventSubscriptionByEventTypes";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user