2023-02-16 15:28:15 +08:00
|
|
|
package com.zhgd.xmgl.task;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.zhgd.xmgl.async.AsyncEnvironment;
|
|
|
|
|
import com.zhgd.xmgl.modules.project.entity.ProjectVideoConfig;
|
|
|
|
|
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;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @program: wisdomSite
|
|
|
|
|
* @description: 视频定时任务
|
|
|
|
|
* @author: Mr.Peng
|
|
|
|
|
* @create: 2021-11-11 18:48
|
|
|
|
|
**/
|
|
|
|
|
@Log4j
|
|
|
|
|
@Component
|
|
|
|
|
public class VideoTask {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ProjectVideoConfigMapper projectVideoConfigMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private VideoItemMapper videoItemMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private AsyncEnvironment asyncEnvironment;
|
|
|
|
|
@Value("${video-analysis-url}")
|
|
|
|
|
private String videoAnalysisUrl;
|
|
|
|
|
@Value("${serverUrl}")
|
|
|
|
|
private String serverUrl;
|
|
|
|
|
|
2023-04-01 10:46:58 +08:00
|
|
|
@SchedulerLock(name = "updateVideoState", lockAtMostFor = 1000*60*60, lockAtLeastFor = 1000*60*5)
|
|
|
|
|
@Scheduled(cron = "0 0 */3 * * ?")
|
2023-02-16 15:28:15 +08:00
|
|
|
// @Scheduled(cron = "*/50 * * * * ?")
|
|
|
|
|
public void updateVideoState(){
|
|
|
|
|
try{
|
|
|
|
|
QueryWrapper<ProjectVideoConfig> queryWrapper=new QueryWrapper<>();
|
|
|
|
|
queryWrapper.lambda().eq(ProjectVideoConfig::getIsEnable,1);
|
|
|
|
|
List<ProjectVideoConfig> list= projectVideoConfigMapper.selectList(queryWrapper);
|
|
|
|
|
if(list!=null&&list.size()>0){
|
|
|
|
|
for (ProjectVideoConfig videoConfig:list){
|
|
|
|
|
updateProjectVideo(videoConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
//e.printStackTrace();
|
|
|
|
|
log.info(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateProjectVideo(ProjectVideoConfig videoConfig){
|
|
|
|
|
try{
|
|
|
|
|
QueryWrapper<VideoItem> queryWrapper=new QueryWrapper<>();
|
|
|
|
|
queryWrapper.lambda().eq(VideoItem::getVideoId,videoConfig.getId());
|
|
|
|
|
List<VideoItem> list=videoItemMapper.selectList(queryWrapper);
|
|
|
|
|
if(list!=null&&list.size()>0){
|
|
|
|
|
if(videoConfig.getVideoType()==1){
|
|
|
|
|
String accessToken= YsVideoUtil.getToken(videoConfig.getAppId(),videoConfig.getAppSecret());
|
|
|
|
|
for(VideoItem videoItem:list){
|
|
|
|
|
Integer state=YsVideoUtil.getVideoStatus(videoConfig.getAppId(),videoConfig.getAppSecret(),videoItem.getSerialNumber(),accessToken);
|
|
|
|
|
videoItem.setDeviceState(state);
|
|
|
|
|
videoItemMapper.updateById(videoItem);
|
|
|
|
|
}
|
|
|
|
|
}else if(videoConfig.getVideoType()==2){
|
|
|
|
|
|
|
|
|
|
}else if(videoConfig.getVideoType()==3){
|
|
|
|
|
if(StringUtils.isNotEmpty(videoConfig.getAccount())&&StringUtils.isNotEmpty(videoConfig.getPassword())
|
|
|
|
|
&&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(),
|
|
|
|
|
videoConfig.getPassword(), videoConfig.getAppId(), videoConfig.getAppSecret());
|
|
|
|
|
if (StringUtils.isNotEmpty(url)) {
|
|
|
|
|
boolean status = PingUtil.pingUrl(url);
|
|
|
|
|
// boolean status= VideoUtils.getVideoOnlineSate(url);
|
|
|
|
|
if (status) {
|
|
|
|
|
videoItem.setDeviceState(1);
|
|
|
|
|
} else {
|
|
|
|
|
videoItem.setDeviceState(2);
|
|
|
|
|
}
|
|
|
|
|
videoItemMapper.updateById(videoItem);
|
|
|
|
|
}
|
|
|
|
|
//sendVideoData(videoItem,videoConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
QueryWrapper<VideoItem> qu=new QueryWrapper<>();
|
|
|
|
|
qu.lambda().eq(VideoItem::getVideoId,videoConfig.getId());
|
|
|
|
|
VideoItem item=new VideoItem();
|
|
|
|
|
item.setDeviceState(2);
|
|
|
|
|
item.setVideoId(videoConfig.getId());
|
|
|
|
|
videoItemMapper.update(item,qu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendVideoData(VideoItem videoItem,ProjectVideoConfig videoConfig){
|
|
|
|
|
List<Map<String,Object>> list=new ArrayList<>();
|
|
|
|
|
Map<String,Object> video=new HashMap<>();
|
|
|
|
|
video.put("appId",videoConfig.getAppId());
|
|
|
|
|
video.put("appSecret",videoConfig.getAppSecret());
|
|
|
|
|
video.put("ip",videoConfig.getAccount());
|
|
|
|
|
video.put("port",videoConfig.getPassword());
|
|
|
|
|
video.put("serialNumber",videoItem.getSerialNumber());
|
|
|
|
|
list.add(video);
|
|
|
|
|
List<Long> alarmIdList=new ArrayList<>();
|
|
|
|
|
alarmIdList.add(videoItem.getItemId());
|
|
|
|
|
Map<String,Object> object=new HashMap<>();
|
|
|
|
|
object.put("projectSn",videoConfig.getProjectSn());
|
|
|
|
|
object.put("videoList",list);
|
|
|
|
|
object.put("dataId",alarmIdList);
|
|
|
|
|
object.put("resultUrl",serverUrl+"/xmgl/api/saveVideoAnalysisResult");
|
|
|
|
|
object.put("type",2);
|
|
|
|
|
log.info(JSONUtil.toJsonStr(object));
|
|
|
|
|
if(StringUtils.isNotEmpty(videoAnalysisUrl)){
|
|
|
|
|
asyncEnvironment.sendVideoAnalysisData(videoAnalysisUrl,object);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*public static void main(String[] args) {
|
|
|
|
|
String Ip="182.101.141.23";
|
|
|
|
|
String port="18443";
|
|
|
|
|
String appkey="24017757";
|
|
|
|
|
String appSecret="VJz0FbzmE6drPQ7egsBi";
|
|
|
|
|
String url= HikVideoUtil.callPostApiGetPreviewURL("34ad8813a79d4cbaaebdbeaddaa53598", "rtmp",null,Ip,
|
|
|
|
|
port,appkey, appSecret);
|
|
|
|
|
log.info(url);
|
|
|
|
|
*//*boolean status= VideoUtils.getVideoOnlineSate(url);
|
|
|
|
|
log.info(status);*//*
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|