|
|
|
|
@ -4,20 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.jcraft.jsch.ChannelSftp;
|
|
|
|
|
import com.jcraft.jsch.SftpATTRS;
|
|
|
|
|
import com.leaper.web.config.ConfigProperties;
|
|
|
|
|
import com.leaper.web.entity.Camera;
|
|
|
|
|
import com.leaper.web.entity.LightSource;
|
|
|
|
|
import com.leaper.web.entity.OrderLive;
|
|
|
|
|
import com.leaper.web.entity.PicData;
|
|
|
|
|
import com.leaper.web.entity.*;
|
|
|
|
|
import com.leaper.web.lib.CameraConnMap;
|
|
|
|
|
import com.leaper.web.lib.CameraControlModule;
|
|
|
|
|
import com.leaper.web.lib.hik.HikLoginModuleImpl;
|
|
|
|
|
import com.leaper.web.lib.joyware.JoywareLoginModuleImpl;
|
|
|
|
|
import com.leaper.web.mapper.CameraMapper;
|
|
|
|
|
import com.leaper.web.mapper.LightSourceMapper;
|
|
|
|
|
import com.leaper.web.mapper.OrderLiveMapper;
|
|
|
|
|
import com.leaper.web.mapper.PicDataMapper;
|
|
|
|
|
import com.leaper.web.mapper.*;
|
|
|
|
|
import com.leaper.web.service.damLightSource.JYDAMEquip;
|
|
|
|
|
import com.leaper.web.service.damLightSource.JYDamHelper;
|
|
|
|
|
import com.leaper.web.service.hikLightSource.HikControlSocket;
|
|
|
|
|
import com.leaper.web.task.S3Utils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import net.schmizz.sshj.sftp.SFTPClient;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
|
@ -32,10 +28,9 @@ import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.attribute.BasicFileAttributes;
|
|
|
|
|
import java.time.*;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
@ -100,6 +95,87 @@ public class CronTab {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归地清除指定目录下的所有文件和子目录。
|
|
|
|
|
*
|
|
|
|
|
* @param directory 要清除的目录路径
|
|
|
|
|
*/
|
|
|
|
|
@Scheduled(cron = "15 0 0 * * ?")
|
|
|
|
|
public void clearDirectoryRecursively() {
|
|
|
|
|
File directory = new File(configProperties.getS3Config().getUrlCache());
|
|
|
|
|
if (directory.exists() && directory.isDirectory()) {
|
|
|
|
|
File[] files = directory.listFiles();
|
|
|
|
|
if (files != null) {
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
|
// 递归调用此方法来清除子目录
|
|
|
|
|
clearDirectoryRecursively(file);
|
|
|
|
|
}
|
|
|
|
|
// 删除文件或空目录
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static void clearDirectoryRecursively(File directory) {
|
|
|
|
|
if (directory.exists() && directory.isDirectory()) {
|
|
|
|
|
File[] files = directory.listFiles();
|
|
|
|
|
if (files != null) {
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
|
// 递归调用此方法来清除子目录
|
|
|
|
|
clearDirectoryRecursively(file);
|
|
|
|
|
}
|
|
|
|
|
// 删除文件或空目录
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Resource
|
|
|
|
|
S3Utils s3Utils;
|
|
|
|
|
@Resource
|
|
|
|
|
CameraRecordDuojiMapper cameraRecordDuojiMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
CameraControlModule cameraControlModule;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 每分钟下载前两分钟的文件
|
|
|
|
|
*/
|
|
|
|
|
@Scheduled(cron = "5 0/1 * * * ? ")
|
|
|
|
|
//@Scheduled(cron = "0 0/1 * * * *")
|
|
|
|
|
public void s3DownloadFile() {
|
|
|
|
|
List<Camera> cameras = cameraMapper.selectList(new QueryWrapper<>());
|
|
|
|
|
LocalDate currentDate = LocalDate.now(); // 获取当前日期
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 设置日期格式
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
//结束时间
|
|
|
|
|
LocalDateTime currentMinuteStart = now.minusMinutes(2).withSecond(0).withNano(0);
|
|
|
|
|
//开始时间
|
|
|
|
|
LocalDateTime previousMinuteStart = now.minusMinutes(3).withSecond(0).withNano(0);
|
|
|
|
|
String formattedDate = currentDate.format(formatter);
|
|
|
|
|
for (Camera camera : cameras){
|
|
|
|
|
String url = formattedDate + "/" +UUID.randomUUID();
|
|
|
|
|
boolean ok =cameraControlModule.downloadMp4Stream(camera.getId(), "D:\\" + url, previousMinuteStart, currentMinuteStart, camera.getChannel());
|
|
|
|
|
if(ok) {
|
|
|
|
|
File file = new File("D:\\" + url);
|
|
|
|
|
s3Utils.uploadFile(configProperties.getS3Config().getBucketName(), url, file);
|
|
|
|
|
CameraRecordDuoji cameraRecordDuoji = new CameraRecordDuoji();
|
|
|
|
|
cameraRecordDuoji.setCameraId(camera.getId());
|
|
|
|
|
cameraRecordDuoji.setPath(configProperties.getS3Config().getBucketName()+ "/" +url);
|
|
|
|
|
cameraRecordDuoji.setStartTime(previousMinuteStart);
|
|
|
|
|
cameraRecordDuoji.setEndTime(currentMinuteStart);
|
|
|
|
|
cameraRecordDuoji.setPath(url);
|
|
|
|
|
cameraRecordDuojiMapper.insert(cameraRecordDuoji);
|
|
|
|
|
|
|
|
|
|
file.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 * * * * ?")
|
|
|
|
|
public void cameraConn() {
|
|
|
|
|
log.info("球机连接判断");
|
|
|
|
|
@ -144,12 +220,12 @@ public class CronTab {
|
|
|
|
|
if (ok) {
|
|
|
|
|
camera.setStatus("连接正常");
|
|
|
|
|
} else {
|
|
|
|
|
CameraConnMap.disConn(camera.getId());
|
|
|
|
|
//CameraConnMap.disConn(camera.getId());
|
|
|
|
|
camera.setStatus("未连接");
|
|
|
|
|
//cameraService.cameraLogin(camera);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
CameraConnMap.disConn(camera.getId());
|
|
|
|
|
//CameraConnMap.disConn(camera.getId());
|
|
|
|
|
camera.setStatus("未连接");
|
|
|
|
|
} finally {
|
|
|
|
|
latch.countDown();
|
|
|
|
|
|