Forráskód Böngészése

上传视频删除

lyhzzz 3 éve
szülő
commit
076323b8e6

+ 2 - 1
src/main/java/com/fdkankan/fusion/common/FilePath.java

@@ -10,7 +10,8 @@ public class FilePath {
 
     public final static String VIDEO_OSS_PATH = "fusion/video/%s";
 
-    public final static String VIDEO_LOCAL_PATH = "/home/fusion/video/merge";
+   // public final static String VIDEO_LOCAL_PATH = "D:\\video\\merge";
+   public final static String VIDEO_LOCAL_PATH = "/home/fusion/video/merge";
 
 
 }

+ 3 - 2
src/main/java/com/fdkankan/fusion/common/util/VideoUtil.java

@@ -24,7 +24,8 @@ public class VideoUtil {
         if(!tagFile.exists()){
             tagFile.mkdirs();
         }
-        output +="/"+ UUID.randomUUID().toString().replace("-","")+".mp4";
+        String fileName =  UUID.randomUUID().toString().replace("-","")+".mp4";
+        output +="/"+fileName;
 
         List<String> videoList = new ArrayList<>(videoAddrSet);
 
@@ -63,7 +64,7 @@ public class VideoUtil {
 
         recorder.close();
         grabber.close();
-        return output;
+        return fileName;
     }
 
 }

+ 1 - 1
src/main/java/com/fdkankan/fusion/controller/HotIconController.java

@@ -44,7 +44,7 @@ public class HotIconController {
 
     @PostMapping("/add")
     public ResultData add(@RequestParam(required = false) MultipartFile file, @RequestHeader String token) throws IOException {
-        String iconUrl = uploadService.uploadFile(file, true, "icon/",null);
+        String iconUrl = uploadService.uploadFile(file, true, "fusion/icon/",null);
 
         String username = JwtUtil.getUsername(token);
         HotIcon hotIcon = new HotIcon();

+ 1 - 1
src/main/java/com/fdkankan/fusion/controller/UploadController.java

@@ -30,6 +30,6 @@ public class UploadController {
     @PostMapping("/file")
     public ResultData file(@RequestParam(required = false) MultipartFile file) throws Exception {
 
-        return ResultData.ok( uploadService.uploadFile(file,true,"file/",null));
+        return ResultData.ok( uploadService.uploadFile(file,true,"fusion/file/",null));
     }
 }

+ 2 - 2
src/main/java/com/fdkankan/fusion/entity/CaseVideoFolder.java

@@ -46,12 +46,12 @@ public class CaseVideoFolder implements Serializable {
      * 封面图
      */
     @TableField("video_folder_cover")
-    private Integer videoFolderCover;
+    private String videoFolderCover;
     /**
      * 封面图
      */
     @TableField("video_merge_url")
-    private Integer videoMergeUrl;
+    private String videoMergeUrl;
 
     /**
      * 排序

+ 12 - 6
src/main/java/com/fdkankan/fusion/service/impl/CaseVideoServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fdkankan.fusion.service.impl;
 
+import cn.hutool.core.io.FileUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fdkankan.common.constant.ErrorCode;
@@ -84,9 +85,9 @@ public class CaseVideoServiceImpl extends ServiceImpl<ICaseVideoMapper, CaseVide
         this.deleteByFolderId(folderId);
         List<CaseVideo> videoList = new ArrayList<>();
         Integer sort = 1;
-        LinkedHashSet<String> filePath = new LinkedHashSet<>();
+        LinkedHashSet<String> filePathSet = new LinkedHashSet<>();
         for (MultipartFile file : files) {
-            String ossPath = uploadService.uploadFile(file, true, String.format(FilePath.VIDEO_OSS_PATH,videoFolder.getVideoFolderId()),filePath);
+            String ossPath = uploadService.uploadFile(file, true, String.format(FilePath.VIDEO_OSS_PATH,videoFolder.getVideoFolderId())+"/",filePathSet);
             CaseVideo caseVideo = new CaseVideo();
             caseVideo.setFolderId(videoFolder.getVideoFolderId());
             caseVideo.setVideoPath(ossPath);
@@ -96,10 +97,15 @@ public class CaseVideoServiceImpl extends ServiceImpl<ICaseVideoMapper, CaseVide
             sort ++;
         }
         this.saveBatch(videoList);
-        String mergeLocalPath = VideoUtil.videoMerge(filePath, FilePath.VIDEO_LOCAL_PATH);
-        uploadToOssUtil.upload(mergeLocalPath,String.format(FilePath.VIDEO_OSS_PATH,videoFolder.getVideoFolderId()));
-        File file = new File(mergeLocalPath);
-        file.deleteOnExit();
+
+        String mergeLocalName = VideoUtil.videoMerge(filePathSet, FilePath.VIDEO_LOCAL_PATH);
+        String mergeLocalPath =  FilePath.VIDEO_LOCAL_PATH +"/"+mergeLocalName;
+        String ossKey =  String.format(FilePath.VIDEO_OSS_PATH,videoFolder.getVideoFolderId()) +"/"+mergeLocalName;
+        uploadToOssUtil.upload(mergeLocalPath,ossKey);
+        videoFolder.setVideoMergeUrl(queryPath + ossKey);
+        videoFolder.setVideoFolderCover(null);
+        videoFolderService.updateById(videoFolder);
+        FileUtil.del(mergeLocalPath);
     }
 
 

+ 7 - 9
src/main/java/com/fdkankan/fusion/service/impl/UploadService.java

@@ -20,12 +20,10 @@ public class UploadService {
     @Resource
     private UploadToOssUtil uploadToOssUtil;
 
-    @Value("${upload.file-path}")
-    private String filePath;
     @Value("${upload.query-path}")
     private String queryPath;
 
-    public String uploadFile(MultipartFile file, boolean newName, String filePathAdd, LinkedHashSet<String> filePath) {
+    public String uploadFile(MultipartFile file, boolean newName, String filePathAdd, LinkedHashSet<String> filePathSet) {
         if(file.isEmpty()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
         }
@@ -44,21 +42,21 @@ public class UploadService {
             String suffixName = fileName.substring(fileName.lastIndexOf("."));
             //重新生成文件名
             if(newName){
-                fileName = UUID.randomUUID().toString().replace("-","") + suffixName;
+                fileName = UUID.randomUUID().toString().replace("-","") ;
             }else {
                 fileName= fileName.substring(0,fileName.lastIndexOf("."));
             }
             localFile = File.createTempFile(fileName,suffixName);
             file.transferTo(localFile);
             String path = localFile.getPath();
-            if(filePath !=null){
-                filePath.add(path);
+            if(filePathSet !=null){
+                filePathSet.add(path);
             }
-            uploadToOssUtil.upload(path,filePath +filePathAdd+ fileName + suffixName);
-            if(!uploadToOssUtil.existKey(filePath +filePathAdd + fileName + suffixName)){
+            uploadToOssUtil.upload(path,filePathAdd+ fileName + suffixName);
+            if(!uploadToOssUtil.existKey(filePathAdd + fileName + suffixName)){
                 throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
             }
-            return queryPath + filePath +filePathAdd+ fileName + suffixName;
+            return queryPath +filePathAdd+ fileName + suffixName;
         }catch (Exception e){
             throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
         }finally {