Bläddra i källkod

合并小视频不上传

lyhzzz 2 år sedan
förälder
incheckning
7c1912d5b6

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

@@ -91,22 +91,27 @@ public class CaseVideoServiceImpl extends ServiceImpl<ICaseVideoMapper, CaseVide
         Integer sort = 1;
         LinkedHashSet<String> filePathSet = new LinkedHashSet<>();
         for (MultipartFile file : files) {
-            String ossPath = uploadService.uploadFile(file, true, String.format(FilePath.VIDEO_OSS_PATH, videoFolder.getVideoFolderId()) + "/", filePathSet);
-            String suffixName = ossPath.substring(ossPath.lastIndexOf("."));
-
+            String localPath = uploadService.uploadFile(file, true);
+            if(StringUtils.isEmpty(localPath)){
+                throw new BusinessException(ResultCode.UPLOAD_ERROR);
+            }
+            filePathSet.add(localPath);
             CaseVideo caseVideo = new CaseVideo();
             caseVideo.setFolderId(videoFolder.getVideoFolderId());
-            caseVideo.setVideoPath(ossPath);
+            caseVideo.setVideoPath(localPath);
             caseVideo.setVideoName(file.getName());
-            caseVideo.setVideoCover(ossPath.replace(suffixName, ".jpg"));
             caseVideo.setSort(sort);
             videoList.add(caseVideo);
             sort++;
         }
-        runThread(videoList,filePathSet,videoFolder,this);
+        if (videoList.size() <= 0) {
+            return videoFolder;
+        }
+        this.saveBatch(videoList);
+        runThread(filePathSet,videoFolder,this);
         return videoFolder;
     }
-    public void runThread(List<CaseVideo> videoList, LinkedHashSet<String> filePathSet,CaseVideoFolder videoFolder,ICaseVideoService caseVideoService){
+    public void runThread(LinkedHashSet<String> filePathSet,CaseVideoFolder videoFolder,ICaseVideoService caseVideoService){
         new Thread(new Runnable() {
             @Override
             public void run() {
@@ -123,10 +128,6 @@ public class CaseVideoServiceImpl extends ServiceImpl<ICaseVideoMapper, CaseVide
                     }
                     caseVideoService.deleteByFolderId(videoFolder.getVideoFolderId());
                     redisUtil.set(RedisKeyUtil.mergerVideoKey + videoFolder.getVideoFolderId(), "10");
-                    caseVideoService.saveBatch(videoList);
-                    if (videoList.size() <= 0) {
-                        return;
-                    }
 
                     redisUtil.set(RedisKeyUtil.mergerVideoKey + videoFolder.getVideoFolderId(), "20");
                     if (StringUtils.isNotBlank(mergeVideoUrl)) {

+ 4 - 19
src/main/java/com/fdkankan/fusion/service/impl/UploadService.java

@@ -25,7 +25,7 @@ public class UploadService {
     @Value("${upload.query-path}")
     private String queryPath;
 
-    public String uploadFile(MultipartFile file, boolean newName, String filePathAdd, LinkedHashSet<String> filePathSet) {
+    public String uploadFile(MultipartFile file, boolean newName) {
         if(file.isEmpty()){
             throw new BusinessException(ResultCode.UPLOAD_FILE_NO_EXIST);
         }
@@ -50,30 +50,15 @@ public class UploadService {
             }
             localFile = File.createTempFile(fileName + suffixName,suffixName);
             file.transferTo(localFile);
-            String path = localFile.getPath();
-            if(filePathSet !=null){
-                filePathSet.add(path);
-            }
-            if(file.getOriginalFilename().toLowerCase().endsWith(".mp4")){
-                VideoUtil.ffmpegVideo(path,path.replace(suffixName,".jpg"),"200","200");
-                uploadToOssUtil.uploadOss(path.replace(suffixName,".jpg"),filePathAdd+ fileName + ".jpg");
-                if(!uploadToOssUtil.existKey(filePathAdd+ fileName + ".jpg")){
-                    throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
-                }
-            }
-            uploadToOssUtil.uploadOss(path,filePathAdd+ fileName + suffixName);
-            if(!uploadToOssUtil.existKey(filePathAdd + fileName + suffixName)){
-                throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
-            }
-            return queryPath +filePathAdd+ fileName + suffixName;
+            return localFile.getPath();
         }catch (Exception e){
-            throw new BusinessException(ResultCode.UPLOAD_ERROR.code,ResultCode.UPLOAD_ERROR.msg);
+           e.printStackTrace();
         }finally {
             if(localFile!=null){
                 localFile.deleteOnExit();   //退出删除,后续需要使用文件
             }
         }
-
+        return null;
     }
     public String uploadFile(MultipartFile file, boolean newName, String filePathAdd) {
         if(file.isEmpty()){