2024-04-02 18:26:22 +08:00
|
|
|
|
package com.zhgd.xmgl.task;
|
|
|
|
|
|
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import com.zhgd.jeecg.common.mybatis.EntityMap;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import com.zhgd.xmgl.async.AsyncHikvision;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import com.zhgd.xmgl.call.HikvisionVideoCall;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.project.entity.Project;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.project.entity.ProjectVideoConfig;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.project.mapper.ProjectVideoConfigMapper;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.project.service.IProjectService;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.project.service.IProjectVideoConfigService;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.project.service.ProgressTaskService;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.video.entity.ProjectVideoHkVqd;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.video.entity.VideoItem;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.video.mapper.ProjectVideoHkVqdMapper;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.video.service.impl.VideoItemServiceImpl;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.xz.entity.XzHikvisionVideoFull;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.xz.entity.XzHikvisionVideoOnline;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionVideoFullMapper;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.xz.mapper.XzHikvisionVideoOnlineMapper;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import com.zhgd.xmgl.util.*;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import net.javacrumbs.shedlock.core.SchedulerLock;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import org.apache.commons.collections4.MapUtils;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
|
2024-10-29 09:41:50 +08:00
|
|
|
|
import java.io.File;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
import java.util.*;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 视频设备(监控点)定时任务
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
2024-10-29 09:41:50 +08:00
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/xmgl/task/")
|
2024-04-02 18:26:22 +08:00
|
|
|
|
public class VideoItemTask {
|
2024-05-21 20:43:59 +08:00
|
|
|
|
@Lazy
|
2024-04-02 18:26:22 +08:00
|
|
|
|
@Autowired
|
2024-05-21 20:43:59 +08:00
|
|
|
|
HikvisionVideoCall hikvisionVideoCall;
|
|
|
|
|
|
@Lazy
|
2024-04-02 18:26:22 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
AsyncHikvision asyncHikvision;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
@Lazy
|
2024-04-02 18:26:22 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
ProgressTaskService progressTaskService;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
@Lazy
|
2024-04-02 18:26:22 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
VideoItemMapper videoItemMapper;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
@Lazy
|
2024-04-02 18:26:22 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
ProjectVideoConfigMapper projectVideoConfigMapper;
|
2024-05-21 20:43:59 +08:00
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
XzHikvisionVideoOnlineMapper xzHikvisionVideoOnlineMapper;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
ProjectMapper projectMapper;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
ProjectVideoHkVqdMapper projectVideoHkVqdMapper;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
XzHikvisionVideoFullMapper xzHikvisionVideoFullMapper;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
VideoItemServiceImpl videoItemService;
|
2024-10-29 09:41:50 +08:00
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private IProjectService projectService;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private IProjectVideoConfigService projectVideoConfigService;
|
2024-04-02 18:26:22 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 定时获取录像完整性结果
|
|
|
|
|
|
*/
|
2024-05-21 20:43:59 +08:00
|
|
|
|
@SchedulerLock(name = "saveXzHikvisionVideoFull", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5)
|
2024-04-02 18:26:22 +08:00
|
|
|
|
@Scheduled(cron = "0 0 0/1 * * ?")
|
2024-05-21 20:43:59 +08:00
|
|
|
|
public void saveXzHikvisionVideoFull() throws Exception {
|
2024-04-02 18:26:22 +08:00
|
|
|
|
log.info("定时获取录像完整性结果任务开始");
|
2024-07-05 19:07:36 +08:00
|
|
|
|
doSaveXzHikvisionVideoFull(new HashMap<String, Object>(16));
|
2024-05-21 20:43:59 +08:00
|
|
|
|
}
|
2024-04-02 18:26:22 +08:00
|
|
|
|
|
2024-05-21 20:43:59 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 定时获取录像完整性结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void doSaveXzHikvisionVideoFull(Map<String, Object> param) throws Exception {
|
|
|
|
|
|
param.putIfAbsent("beginTime", new Date());
|
|
|
|
|
|
param.putIfAbsent("endTime", new Date());
|
|
|
|
|
|
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getSyncHikvision, 1));
|
|
|
|
|
|
for (Project project : projects) {
|
|
|
|
|
|
List<EntityMap> videoItems = videoItemMapper.selectProjectVideoList(new MapBuilder<String, Object>().put("projectSn", project.getProjectSn()).build());
|
|
|
|
|
|
if (CollUtil.isEmpty(videoItems)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
JSONObject jo = new JSONObject();
|
|
|
|
|
|
jo.put("pageNo", 1);
|
|
|
|
|
|
jo.put("pageSize", 1000);
|
|
|
|
|
|
jo.put("beginTime", DateUtils.getISO8601StrWithMs(DateUtil.beginOfDay(DateUtil.parse(MapUtils.getString(param, "beginTime")))));
|
|
|
|
|
|
jo.put("endTime", DateUtils.getISO8601StrWithMs(DateUtil.endOfDay(DateUtil.parse(MapUtils.getString(param, "endTime")))));
|
|
|
|
|
|
jo.put("indexCodes", videoItems.stream().map(entityMap -> entityMap.get("serialNumber")).filter(Objects::nonNull).collect(Collectors.toList()));
|
|
|
|
|
|
JSONObject rsJo = hikvisionVideoCall.getNmsRecordForHikvisionForHttp(project, jo);
|
|
|
|
|
|
if (HikvisionUtil.isSuccess(rsJo)) {
|
2024-07-01 09:51:07 +08:00
|
|
|
|
JSONObject dataJo = HikvisionUtil.getJsonObjectData(rsJo);
|
2024-05-21 20:43:59 +08:00
|
|
|
|
JSONArray listJa = dataJo.getJSONArray("list");
|
|
|
|
|
|
for (int i = 0; i < listJa.size(); i++) {
|
|
|
|
|
|
JSONObject oneJo = listJa.getJSONObject(i);
|
|
|
|
|
|
String indexCode = oneJo.getString("indexCode");
|
|
|
|
|
|
Integer result = oneJo.getInteger("result");
|
|
|
|
|
|
String date = oneJo.getString("date");
|
2024-05-21 21:40:25 +08:00
|
|
|
|
JSONArray videoClipstimeSegmentJa = oneJo.getJSONArray("videoClipstimeSegment");
|
|
|
|
|
|
for (int j = 0; j < videoClipstimeSegmentJa.size(); j++) {
|
|
|
|
|
|
XzHikvisionVideoFull entity = new XzHikvisionVideoFull();
|
|
|
|
|
|
entity.setProjectSn(project.getProjectSn());
|
|
|
|
|
|
entity.setSerialNumber(indexCode);
|
|
|
|
|
|
entity.setType(result);
|
|
|
|
|
|
entity.setDate(date);
|
|
|
|
|
|
JSONObject jo1 = videoClipstimeSegmentJa.getJSONObject(j);
|
|
|
|
|
|
Integer from = jo1.getInteger("from");
|
|
|
|
|
|
entity.setFrom(from);
|
|
|
|
|
|
Integer to = jo1.getInteger("to");
|
|
|
|
|
|
entity.setTo(to);
|
|
|
|
|
|
Integer count = xzHikvisionVideoFullMapper.selectCount(new LambdaQueryWrapper<XzHikvisionVideoFull>()
|
|
|
|
|
|
.eq(XzHikvisionVideoFull::getSerialNumber, entity.getSerialNumber())
|
|
|
|
|
|
.eq(XzHikvisionVideoFull::getDate, entity.getDate())
|
|
|
|
|
|
.eq(XzHikvisionVideoFull::getFrom, entity.getFrom())
|
|
|
|
|
|
);
|
|
|
|
|
|
if (count != 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
xzHikvisionVideoFullMapper.insert(entity);
|
2024-05-21 20:43:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-02 18:26:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 定时获取视频质量诊断结果
|
|
|
|
|
|
*/
|
2024-05-21 20:43:59 +08:00
|
|
|
|
@SchedulerLock(name = "addVqdForHikvision", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60)
|
2024-04-02 18:26:22 +08:00
|
|
|
|
@Scheduled(cron = "0 0 0/1 * * ?")
|
2024-05-21 20:43:59 +08:00
|
|
|
|
public void addVqdForHikvision() throws Exception {
|
2024-04-02 18:26:22 +08:00
|
|
|
|
log.info("定时获取视频质量诊断结果任务开始");
|
2024-05-21 20:43:59 +08:00
|
|
|
|
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getSyncHikvision, 1));
|
|
|
|
|
|
for (Project project : projects) {
|
|
|
|
|
|
List<EntityMap> videoItems = videoItemMapper.selectProjectVideoList(new MapBuilder<String, Object>().put("projectSn", project.getProjectSn()).build());
|
|
|
|
|
|
if (CollUtil.isEmpty(videoItems)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
JSONObject jo = new JSONObject();
|
|
|
|
|
|
jo.put("pageNo", 1);
|
|
|
|
|
|
jo.put("pageSize", 1000);
|
|
|
|
|
|
jo.put("indexCodes", videoItems.stream().map(entityMap -> entityMap.get("serialNumber")).filter(Objects::nonNull).collect(Collectors.toList()));
|
|
|
|
|
|
JSONObject rsJo = hikvisionVideoCall.getVqdForHikvisionForHttp(project, jo);
|
|
|
|
|
|
if (HikvisionUtil.isSuccess(rsJo)) {
|
2024-07-01 09:51:07 +08:00
|
|
|
|
JSONObject dataJo = HikvisionUtil.getJsonObjectData(rsJo);
|
2024-05-21 20:43:59 +08:00
|
|
|
|
JSONArray listJa = dataJo.getJSONArray("list");
|
|
|
|
|
|
for (int i = 0; i < listJa.size(); i++) {
|
|
|
|
|
|
JSONObject oneJo = listJa.getJSONObject(i);
|
|
|
|
|
|
ProjectVideoHkVqd entity = new ProjectVideoHkVqd();
|
|
|
|
|
|
BeanUtil.copyProperties(oneJo, entity);
|
|
|
|
|
|
entity.setProjectSn(project.getProjectSn());
|
|
|
|
|
|
entity.setSerialNumber(oneJo.getString("indexCode"));
|
|
|
|
|
|
projectVideoHkVqdMapper.insert(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-02 18:26:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-21 20:43:59 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 3分钟保存一次监控在线状态
|
|
|
|
|
|
*/
|
|
|
|
|
|
@SchedulerLock(name = "saveDeviceState", lockAtMostFor = 1000 * 60, lockAtLeastFor = 1000 * 60)
|
|
|
|
|
|
@Scheduled(cron = "0 */3 * * * ?")
|
|
|
|
|
|
public void saveDeviceState() throws Exception {
|
|
|
|
|
|
log.info("3分钟保存一次监控在线状态");
|
|
|
|
|
|
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getSyncHikvision, 1));
|
|
|
|
|
|
for (Project project : projects) {
|
|
|
|
|
|
List<EntityMap> videoItems = videoItemMapper.selectProjectVideoList(new MapBuilder<String, Object>().put("projectSn", project.getProjectSn()).build());
|
|
|
|
|
|
if (CollUtil.isEmpty(videoItems)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
JSONObject jo = new JSONObject();
|
|
|
|
|
|
jo.put("pageNo", 1);
|
|
|
|
|
|
jo.put("pageSize", 1000);
|
|
|
|
|
|
jo.put("indexCodes", videoItems.stream().map(entityMap -> entityMap.get("serialNumber")).filter(Objects::nonNull).collect(Collectors.toList()));
|
|
|
|
|
|
JSONObject rsJo = hikvisionVideoCall.getCameraOnlineForHttp(project, jo);
|
|
|
|
|
|
if (HikvisionUtil.isSuccess(rsJo)) {
|
2024-07-01 09:51:07 +08:00
|
|
|
|
JSONObject dataJo = HikvisionUtil.getJsonObjectData(rsJo);
|
2024-05-21 20:43:59 +08:00
|
|
|
|
JSONArray listJa = dataJo.getJSONArray("list");
|
|
|
|
|
|
for (int i = 0; i < listJa.size(); i++) {
|
|
|
|
|
|
JSONObject oneJo = listJa.getJSONObject(i);
|
|
|
|
|
|
XzHikvisionVideoOnline entity = new XzHikvisionVideoOnline();
|
|
|
|
|
|
entity.setProjectSn(project.getProjectSn());
|
|
|
|
|
|
entity.setSerialNumber(oneJo.getString("indexCode"));
|
|
|
|
|
|
entity.setDeviceState(Optional.ofNullable(oneJo.getInteger("online")).map(integer -> integer == 0 ? 1 : 2).orElse(3));
|
|
|
|
|
|
xzHikvisionVideoOnlineMapper.insert(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-11-06 16:47:07 +08:00
|
|
|
|
//
|
|
|
|
|
|
// /**
|
|
|
|
|
|
// * 每2个小时更新一下监控封面
|
|
|
|
|
|
// *
|
|
|
|
|
|
// * @throws Exception
|
|
|
|
|
|
// */
|
|
|
|
|
|
// @RequestMapping("saveVideoItemCover")
|
|
|
|
|
|
// @SchedulerLock(name = "saveVideoItemCover", lockAtMostFor = 1000 * 60, lockAtLeastFor = 1000 * 60)
|
|
|
|
|
|
// @Scheduled(cron = "0 0 */2 * * ?")
|
|
|
|
|
|
// public void saveVideoItemCover() throws Exception {
|
|
|
|
|
|
// List<ProjectVideoConfig> configList = projectVideoConfigService.list(new LambdaQueryWrapper<ProjectVideoConfig>()
|
|
|
|
|
|
// .eq(ProjectVideoConfig::getIsEnable, 1));
|
|
|
|
|
|
// List<VideoItem> itemList = videoItemService.list();
|
|
|
|
|
|
// String basePath = "videoItemCover";
|
|
|
|
|
|
// for (ProjectVideoConfig projectVideoConfig : configList) {
|
|
|
|
|
|
// if (Objects.equals(projectVideoConfig.getVideoType(), 3)) {
|
|
|
|
|
|
// List<VideoItem> items = itemList.stream().filter(o -> Objects.equals(o.getVideoId(), projectVideoConfig.getId())).collect(Collectors.toList());
|
|
|
|
|
|
// for (VideoItem item : items) {
|
|
|
|
|
|
// saveVideoItemCoverAsync(basePath, projectVideoConfig, item);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// @Async("saveVideoItemCover")
|
|
|
|
|
|
// public void saveVideoItemCoverAsync(String basePath, ProjectVideoConfig projectVideoConfig, VideoItem item) throws Exception {
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// String url = HikVideoUtil.callPostApiGetPreviewURL(item.getSerialNumber(), "rtsp",
|
|
|
|
|
|
// 2, projectVideoConfig.getAccount(),
|
|
|
|
|
|
// projectVideoConfig.getPassword(), projectVideoConfig.getAppId(), projectVideoConfig.getAppSecret());
|
|
|
|
|
|
// if (url != null) {
|
|
|
|
|
|
// String uuidPic = IdUtil.fastUUID() + ".jpg";
|
|
|
|
|
|
// String picPath = PathUtil.getBasePath() + "/" + basePath + "/" + uuidPic;
|
|
|
|
|
|
// new File(picPath).getParentFile().mkdirs();
|
|
|
|
|
|
// RtspUtils.getVideoImagePathByRSTP(url, picPath);
|
|
|
|
|
|
// item.setCoverUrl(PathUtil.getServerUrl() + "/image/" + basePath + "/" + uuidPic);
|
|
|
|
|
|
// videoItemService.updateById(item);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2024-04-02 18:26:22 +08:00
|
|
|
|
}
|