|
@@ -2,21 +2,28 @@ package com.ozs.web.core.util;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.ozs.common.config.BaseConfig;
|
|
import com.ozs.common.config.BaseConfig;
|
|
import com.ozs.common.constant.Constants;
|
|
import com.ozs.common.constant.Constants;
|
|
import com.ozs.common.core.domain.entity.SysDictData;
|
|
import com.ozs.common.core.domain.entity.SysDictData;
|
|
import com.ozs.common.exception.base.BaseException;
|
|
import com.ozs.common.exception.base.BaseException;
|
|
import com.ozs.common.utils.DateUtils;
|
|
import com.ozs.common.utils.DateUtils;
|
|
import com.ozs.common.utils.http.HttpUtils;
|
|
import com.ozs.common.utils.http.HttpUtils;
|
|
|
|
+import com.ozs.service.entity.BaseCameraManagement;
|
|
|
|
+import com.ozs.service.service.BaseCameraManagementService;
|
|
import com.ozs.system.mapper.SysDictDataMapper;
|
|
import com.ozs.system.mapper.SysDictDataMapper;
|
|
import com.ozs.web.core.config.CaneraConfig;
|
|
import com.ozs.web.core.config.CaneraConfig;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
|
|
+import javax.annotation.Resource;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
@@ -28,7 +35,8 @@ import java.util.stream.Collectors;
|
|
/**
|
|
/**
|
|
* 相机工具
|
|
* 相机工具
|
|
*/
|
|
*/
|
|
-@Component
|
|
|
|
|
|
+
|
|
|
|
+@Configuration
|
|
@Slf4j
|
|
@Slf4j
|
|
public class CameraUtil {
|
|
public class CameraUtil {
|
|
|
|
|
|
@@ -43,6 +51,8 @@ public class CameraUtil {
|
|
private CaneraConfig caneraConfig;
|
|
private CaneraConfig caneraConfig;
|
|
@Autowired
|
|
@Autowired
|
|
private SysDictDataMapper dictDataMapper;
|
|
private SysDictDataMapper dictDataMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ BaseCameraManagementService baseCameraManagementService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -299,28 +309,6 @@ public class CameraUtil {
|
|
log.info("返回结果:{}", rspList);
|
|
log.info("返回结果:{}", rspList);
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
|
-
|
|
|
|
-// List<String> fromVideoFileList = new ArrayList();
|
|
|
|
-// String p = "C:\\Users\\Administrator.DESKTOP-0NUUTMM\\Desktop\\work\\106\\流媒体\\";
|
|
|
|
-// String newfilePath = p + "hb.flv";
|
|
|
|
-// fromVideoFileList.add(p + "20230303_174931_175031-d6d56396-b9a8-11ed-aeb9-00163e06a5f3.flv");
|
|
|
|
-// fromVideoFileList.add(p + "20230303_175032_175132-fb32b9fe-b9a8-11ed-aeb9-00163e06a5f3.flv");
|
|
|
|
-// fromVideoFileList.add(p + "20230303_175133_175233-1f97af04-b9a9-11ed-aeb9-00163e06a5f3.flv");
|
|
|
|
-// fromVideoFileList.add(p + "20230303_175234_175334-43f4daf1-b9a9-11ed-aeb9-00163e06a5f3.flv");
|
|
|
|
-// fromVideoFileList.add(p + "m.flv");
|
|
|
|
-// fromVideoFileList.add(p + "m33.flv");
|
|
|
|
-// fromVideoFileList.add(p + "mv.flv");
|
|
|
|
-// fromVideoFileList.add(p + "mvido.flv");
|
|
|
|
-// convetor(fromVideoFileList, newfilePath);
|
|
|
|
-
|
|
|
|
- String channel = "34020000001320000002";
|
|
|
|
- String startTime = "2023-03-09";
|
|
|
|
- String endTime = "2023-03-09";
|
|
|
|
- String param = "channel=" + channel + "&startTime=" + startTime + "&endTime=" + endTime;
|
|
|
|
- String s = HttpUtils.sendGet("http://47.106.159.135/streams" + "/api/record/flv/list", param);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
public void init() {
|
|
public void init() {
|
|
@@ -440,5 +428,84 @@ public class CameraUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 定时任务:关闭录制视频
|
|
|
|
+ *
|
|
|
|
+ * @throws IOException
|
|
|
|
+ * @throws InterruptedException
|
|
|
|
+ */
|
|
|
|
+ public void closeRecording() throws IOException, InterruptedException, ParseException {
|
|
|
|
+ LambdaQueryWrapper<BaseCameraManagement> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(BaseCameraManagement::getStartRecording, 1);
|
|
|
|
+ wrapper.isNotNull(BaseCameraManagement::getTaskId);
|
|
|
|
+ List<BaseCameraManagement> list = baseCameraManagementService.list(wrapper);
|
|
|
|
+ log.info("list======================================" + list);
|
|
|
|
+ List<String> collect = list.stream().map(BaseCameraManagement::getCameraCode).collect(Collectors.toList());
|
|
|
|
+// List<String> collect=new ArrayList<>();
|
|
|
|
+// collect.add("42010001541320001116");
|
|
|
|
+ //遍历每个进行视频录制的摄像头
|
|
|
|
+ File file = new File("D://file");
|
|
|
|
+ log.info("closeRecording-file.Name()======================================" + file.getName());
|
|
|
|
+ log.info("closeRecording-file.exists()======================================" + file.exists());
|
|
|
|
+ if (file.exists() && file.isDirectory()) {
|
|
|
|
+ //获取文件夹中所有的子文件夹和文件
|
|
|
|
+ File[] files = file.listFiles();
|
|
|
|
+ if (!ObjectUtils.isEmpty(files) && files.length > 0) {
|
|
|
|
+ for (File file1 : files) {
|
|
|
|
+ log.info("closeRecording-file1---------------" + file1);
|
|
|
|
+ log.info("closeRecording-cameraCode---------------" + collect);
|
|
|
|
+ String substring = file1.toString().substring(file1.toString().lastIndexOf("\\") + 1);
|
|
|
|
+ if (collect.contains(substring)) {
|
|
|
|
+ File[] files1 = file1.listFiles();
|
|
|
|
+ if (!ObjectUtils.isEmpty(files1) && files1.length > 0) {
|
|
|
|
+ int length = files1.length;
|
|
|
|
+ File file2 = files1[length - 1];
|
|
|
|
+ log.info("closeRecording-file2---------------" + file2);
|
|
|
|
+ String time = file2.toString().substring(file2.toString().lastIndexOf("\\") + 1);
|
|
|
|
+ String substring1 = time.substring(0, 15);
|
|
|
|
+ String substring2 = substring1.substring(0, 4);
|
|
|
|
+ String substring3 = substring1.substring(4, 6);
|
|
|
|
+ String substring4 = substring1.substring(6, 8);
|
|
|
|
+ String substring5 = substring1.substring(9, 11);
|
|
|
|
+ String substring6 = substring1.substring(11, 13);
|
|
|
|
+ String substring7 = substring1.substring(13, 15);
|
|
|
|
+ String date = substring2 + "-" + substring3 + "-" + substring4 + " " + substring5 + ":" + substring6 + ":" + substring7;
|
|
|
|
+ System.out.println(date);
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ Date parse = sdf.parse(date);
|
|
|
|
+ //当前时间戳
|
|
|
|
+ long dades = System.currentTimeMillis();
|
|
|
|
+ //文件的时间戳
|
|
|
|
+ long time1 = parse.getTime();
|
|
|
|
+ //当前时间10分钟之前的时间戳
|
|
|
|
+ long time2 = dades - 600000L;
|
|
|
|
+ if (time2 <= time1 && time1 < dades) {
|
|
|
|
+ } else {
|
|
|
|
+ LambdaQueryWrapper<BaseCameraManagement> lw = new LambdaQueryWrapper<BaseCameraManagement>();
|
|
|
|
+ lw.eq(BaseCameraManagement::getCameraCode, substring);
|
|
|
|
+ BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(lw);
|
|
|
|
+ log.info("closeRecording-endRecording------------" + baseCameraManagement.getTaskId());
|
|
|
|
+ String start = HttpUtils.sendGet(CameraUtil.endRecording(baseCameraManagement.getTaskId()));
|
|
|
|
+ log.info("closeRecording-endRecording------------" + start);
|
|
|
|
+ if ("success".equals(start)) {
|
|
|
|
+ baseCameraManagement.setStartRecording(2);
|
|
|
|
+ baseCameraManagement.setTaskId("");
|
|
|
|
+ } else {
|
|
|
|
+ baseCameraManagement.setStartRecording(2);
|
|
|
|
+ baseCameraManagement.setTaskId("");
|
|
|
|
+ log.error("关闭视频录制异常日志如下:" + start);
|
|
|
|
+ }
|
|
|
|
+ baseCameraManagementService.updateById(baseCameraManagement);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public static void main(String[] args) throws InterruptedException, ParseException, IOException {
|
|
|
|
+ CameraUtil cameraUtil = new CameraUtil();
|
|
|
|
+ cameraUtil.closeRecording();
|
|
|
|
+ }
|
|
}
|
|
}
|