|
@@ -1,11 +1,18 @@
|
|
|
package com.taais.biz.controller;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import com.taais.biz.domain.bo.Video2imageBo;
|
|
|
import com.taais.biz.domain.vo.Video2imageVo;
|
|
|
import com.taais.biz.service.IVideo2imageService;
|
|
|
import com.taais.common.core.core.page.PageResult;
|
|
|
+import com.taais.common.core.utils.StringUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
@@ -18,6 +25,11 @@ import com.taais.common.log.enums.BusinessType;
|
|
|
import com.taais.common.web.annotation.RepeatSubmit;
|
|
|
import com.taais.common.web.core.BaseController;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+
|
|
|
+import static com.taais.biz.constant.BizConstant.UPLOAD_DIR;
|
|
|
+import static com.taais.biz.constant.BizConstant.VideoStatus.NOT_START;
|
|
|
|
|
|
/**
|
|
|
* 视频转图片Controller
|
|
@@ -30,6 +42,7 @@ import jakarta.annotation.Resource;
|
|
|
@RestController
|
|
|
@RequestMapping("/demo/video2image")
|
|
|
public class Video2imageController extends BaseController {
|
|
|
+
|
|
|
@Resource
|
|
|
private IVideo2imageService video2imageService;
|
|
|
|
|
@@ -70,7 +83,20 @@ public class Video2imageController extends BaseController {
|
|
|
@RepeatSubmit()
|
|
|
@PostMapping
|
|
|
public CommonResult<Void> add(@Validated @RequestBody Video2imageBo video2imageBo) {
|
|
|
- boolean inserted = video2imageService.insert(video2imageBo);
|
|
|
+ Video2imageBo newVideo2imageBo = new Video2imageBo();
|
|
|
+ if (StringUtils.isEmpty(video2imageBo.getFileId())) {
|
|
|
+ return CommonResult.fail("请上传视频文件!");
|
|
|
+ }
|
|
|
+ newVideo2imageBo.setName(video2imageBo.getName());
|
|
|
+ newVideo2imageBo.setFileId(video2imageBo.getFileId());
|
|
|
+ newVideo2imageBo.setFps(video2imageBo.getFps());
|
|
|
+ newVideo2imageBo.setStartTime(new Date());
|
|
|
+ newVideo2imageBo.setStatus(NOT_START);
|
|
|
+ newVideo2imageBo.setPath(Paths.get(UPLOAD_DIR, video2imageBo.getFileId()).toString());
|
|
|
+ newVideo2imageBo.setOutPath(Paths.get(UPLOAD_DIR, video2imageBo.getName(), "images").toString());
|
|
|
+ newVideo2imageBo.setRemarks(video2imageBo.getRemarks());
|
|
|
+
|
|
|
+ boolean inserted = video2imageService.insert(newVideo2imageBo);
|
|
|
if (!inserted) {
|
|
|
return CommonResult.fail("新增视频转图片记录失败!");
|
|
|
}
|
|
@@ -105,4 +131,34 @@ public class Video2imageController extends BaseController {
|
|
|
}
|
|
|
return CommonResult.success();
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/upload")
|
|
|
+ public CommonResult uploadFile(@RequestParam("file") MultipartFile file) {
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ return CommonResult.success("文件不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 创建上传目录(如果不存在)
|
|
|
+ Path uploadPath = Paths.get(UPLOAD_DIR);
|
|
|
+ if (!Files.exists(uploadPath)) {
|
|
|
+ Files.createDirectories(uploadPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ UUID uuid = UUID.randomUUID();
|
|
|
+ String uuidString = uuid.toString();
|
|
|
+
|
|
|
+ // 获取文件名并构建目标路径
|
|
|
+ String fileName = uuidString + "_" + file.getOriginalFilename();
|
|
|
+ Path targetPath = uploadPath.resolve(fileName);
|
|
|
+
|
|
|
+ // 保存文件到目标路径
|
|
|
+ Files.copy(file.getInputStream(), targetPath);
|
|
|
+
|
|
|
+ return CommonResult.success(fileName, "上传成功");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return CommonResult.success("上传失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|