|
@@ -1,5 +1,8 @@
|
|
|
package com.taais.biz.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -12,12 +15,16 @@ import com.taais.biz.domain.bo.Video2imageBo;
|
|
|
import com.taais.biz.domain.vo.Video2imageVo;
|
|
|
import com.taais.biz.mapper.Video2imageMapper;
|
|
|
import com.taais.biz.service.IVideo2imageService;
|
|
|
-import com.taais.biz.utils.VideoCapture;
|
|
|
import com.taais.common.core.utils.MapstructUtils;
|
|
|
import com.taais.common.orm.core.page.PageQuery;
|
|
|
import com.taais.common.core.core.page.PageResult;
|
|
|
import com.taais.common.orm.core.service.impl.BaseServiceImpl;
|
|
|
-import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.core.io.FileSystemResource;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -25,6 +32,9 @@ import static com.taais.biz.constant.BizConstant.VideoStatus.END;
|
|
|
import static com.taais.biz.constant.BizConstant.VideoStatus.RUNNING;
|
|
|
import static com.taais.biz.domain.table.Video2imageTableDef.VIDEO2IMAGE;
|
|
|
|
|
|
+import com.taais.biz.utils.VideoCapture;
|
|
|
+import com.taais.biz.utils.ZipUtils;
|
|
|
+
|
|
|
/**
|
|
|
* 视频转图片 Service业务层处理
|
|
|
*
|
|
@@ -32,9 +42,8 @@ import static com.taais.biz.domain.table.Video2imageTableDef.VIDEO2IMAGE;
|
|
|
* 2024-08-16
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class Video2imageServiceImpl extends BaseServiceImpl<Video2imageMapper, Video2image> implements IVideo2imageService {
|
|
|
- @Resource
|
|
|
- private Video2imageMapper video2imageMapper;
|
|
|
|
|
|
@Override
|
|
|
public QueryWrapper query() {
|
|
@@ -154,45 +163,85 @@ public class Video2imageServiceImpl extends BaseServiceImpl<Video2imageMapper, V
|
|
|
video2image.setCostSecond((video2image.getEndTime().getTime() - video2image.getStartTime().getTime()) / 1000);
|
|
|
this.updateById(video2image);
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public boolean startToImage(Long id) {
|
|
|
Video2image video2image = this.getById(id);
|
|
|
if (ObjectUtil.isNull(video2image)) {
|
|
|
- System.out.println("ObjectUtil.isNotNull(video2image)...");
|
|
|
+ log.info("ObjectUtil.isNotNull(video2image)...");
|
|
|
return false;
|
|
|
}
|
|
|
- System.out.println("开始截取图片...");
|
|
|
+ log.info("开始截取图片...");
|
|
|
|
|
|
String videoPath = video2image.getPath();
|
|
|
String outPath = video2image.getOutPath();
|
|
|
Long fps = video2image.getFps();
|
|
|
|
|
|
- System.out.println("videoPath: " + videoPath);
|
|
|
- System.out.println("outPath: " + outPath);
|
|
|
- System.out.println("fps: " + fps);
|
|
|
+ log.info("videoPath: " + videoPath);
|
|
|
+ log.info("outPath: " + outPath);
|
|
|
+ log.info("fps: " + fps);
|
|
|
+
|
|
|
+ File file = new File(videoPath);
|
|
|
+ if (!file.exists() || !file.isFile()) {
|
|
|
+ log.error("文件不存在...");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
video2image.setStatus(RUNNING);
|
|
|
video2image.setStartTime(new Date());
|
|
|
this.updateById(video2image);
|
|
|
|
|
|
- System.out.println("开始截取图片子线程...");
|
|
|
-
|
|
|
new Thread(() -> {
|
|
|
- String log = "开始截取图片...\n";
|
|
|
- System.out.println("开始截取图片...");
|
|
|
+ String log_str = "";
|
|
|
+ log.info("开始截取图片子线程...");
|
|
|
+ log.info("开始截取图片...");
|
|
|
+
|
|
|
+ log_str += "开始截取图片子线程...\n";
|
|
|
+ log_str += "开始截取图片...\n";
|
|
|
try {
|
|
|
VideoCapture.startCaputre(videoPath, outPath, fps);
|
|
|
- System.out.println("视频转图片结束...");
|
|
|
- log += "视频转图片结束...\n";
|
|
|
+ log.info("视频转图片结束...");
|
|
|
+ log_str += "视频转图片结束...\n";
|
|
|
+
|
|
|
+ log.info("开始压缩图片...");
|
|
|
+ log_str += "开始压缩图片...\n";
|
|
|
+ String zipFilePath = Paths.get(outPath).resolveSibling(video2image.getName() + ".zip").toString();
|
|
|
+ ZipUtils.zipFolderFiles(outPath, zipFilePath);
|
|
|
+
|
|
|
+ log_str += "压缩图片成功...\n";
|
|
|
+ log.info("压缩图片成功...");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log += "视频转图片出现位置错误...\n";
|
|
|
- log += e.getMessage();
|
|
|
+ log_str += "视频转图片出现位置错误...\n" + e.getMessage() + "\n";
|
|
|
+ log.error("视频转图片出现位置错误...", e);
|
|
|
}
|
|
|
- updateStatusToEnd(id, log);
|
|
|
- System.out.println("视频转图片子线程结束...");
|
|
|
+ updateStatusToEnd(id, log_str);
|
|
|
+ log.info("视频转图片子线程结束...");
|
|
|
}).start();
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseEntity<Resource> zipImages(Long id) {
|
|
|
+ Video2image video2image = this.getById(id);
|
|
|
+ if (ObjectUtil.isNull(video2image)) {
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ String sourceFolderPath = video2image.getOutPath();
|
|
|
+ String zipFilePath = Paths.get(sourceFolderPath).resolveSibling(video2image.getName() + ".zip").toString();
|
|
|
+
|
|
|
+ File file = new File(zipFilePath);
|
|
|
+
|
|
|
+ if (!file.exists() || !file.isFile()) {
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ org.springframework.core.io.Resource resource = new FileSystemResource(file);
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"")
|
|
|
+ .header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
|
|
|
+ .body(resource);
|
|
|
+ }
|
|
|
}
|