|
@@ -5,7 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.fdkankan.fusion.common.FilePath;
|
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
|
+import com.fdkankan.fusion.common.util.LocalToOssUtil;
|
|
|
+import com.fdkankan.fusion.common.util.ShellCmd;
|
|
|
import com.fdkankan.fusion.common.util.ShellUtil;
|
|
|
+import com.fdkankan.fusion.config.CacheUtil;
|
|
|
import com.fdkankan.fusion.entity.CaseImg;
|
|
|
import com.fdkankan.fusion.exception.BusinessException;
|
|
|
import com.fdkankan.fusion.mapper.ICaseImgMapper;
|
|
@@ -14,6 +17,7 @@ import com.fdkankan.fusion.service.ICaseImgService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -62,48 +66,53 @@ public class CaseImgServiceImpl extends ServiceImpl<ICaseImgMapper, CaseImg> imp
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Value("${upload.query-path}")
|
|
|
- private String queryPath;
|
|
|
+ @Autowired
|
|
|
+ LocalToOssUtil localToOssUtil;
|
|
|
@Override
|
|
|
public CaseImg ffmpegImage(MultipartFile[] files, Integer caseId) {
|
|
|
if(files == null || files.length <=0 || caseId == null){
|
|
|
throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
String filePath = FilePath.FFMPEG_IMG_PATH +"/"+ caseId+"/";
|
|
|
+ String ossPath = FilePath.OSS_FFMPEG_IMG_PATH +"/"+ caseId+"/";
|
|
|
try {
|
|
|
List<String> localList = new ArrayList<>();
|
|
|
+ List<String> localListOss = new ArrayList<>();
|
|
|
String outFileName = UUID.randomUUID().toString().replace("-","") ;
|
|
|
String outSuffixName = ".jpg";
|
|
|
String outLocalPath = filePath + outFileName +outSuffixName;
|
|
|
+ String outLocalPathOss = ossPath + outFileName +outSuffixName;
|
|
|
|
|
|
for (MultipartFile file : files) {
|
|
|
String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
//重新生成文件名
|
|
|
String fileName = UUID.randomUUID().toString().replace("-","") ;
|
|
|
String localFilePath = filePath + fileName + suffixName;
|
|
|
+ String localFilePathOSS = ossPath + fileName + suffixName;
|
|
|
File file1 = new File(localFilePath);
|
|
|
if(!file1.getParentFile().exists()){
|
|
|
file1.getParentFile().mkdirs();
|
|
|
}
|
|
|
file.transferTo(file1);
|
|
|
localList.add(localFilePath);
|
|
|
+ localListOss.add(localFilePathOSS);
|
|
|
}
|
|
|
- StringBuilder ffmpegCmd = new StringBuilder("ffmpeg ");
|
|
|
- if(files.length >1){
|
|
|
+ StringBuilder ffmpegCmd = new StringBuilder(ShellCmd.ffmpegCmd);
|
|
|
+ if(localList.size() >1){
|
|
|
for (String localPath : localList) {
|
|
|
ffmpegCmd.append(" -i ").append(localPath);
|
|
|
}
|
|
|
- ffmpegCmd.append(" -filter_complex hstack=inputs="+ files.length);
|
|
|
+ ffmpegCmd.append(" -filter_complex hstack=inputs="+ localList.size());
|
|
|
ffmpegCmd.append(" " +outLocalPath);
|
|
|
ShellUtil.execCmd(ffmpegCmd.toString());
|
|
|
}else {
|
|
|
outLocalPath = localList.get(0);
|
|
|
+ outLocalPathOss = localListOss.get(0);
|
|
|
}
|
|
|
-
|
|
|
if(!FileUtil.exist(outLocalPath)){
|
|
|
throw new BusinessException(ResultCode.UPLOAD_FILE_TYPE_ERROR);
|
|
|
}
|
|
|
- ShellUtil.yunUpload(outLocalPath,outLocalPath.replace("/mnt/",""));
|
|
|
+ localToOssUtil.uploadOss(outLocalPath,outLocalPathOss);
|
|
|
|
|
|
List<CaseImg> caseImgList = this.getByCaseId(caseId, 1);
|
|
|
CaseImg caseImg = null;
|
|
@@ -113,7 +122,7 @@ public class CaseImgServiceImpl extends ServiceImpl<ICaseImgMapper, CaseImg> imp
|
|
|
caseImg = caseImgList.get(0);
|
|
|
}
|
|
|
caseImg.setCaseId(caseId);
|
|
|
- caseImg.setImgUrl(queryPath + outLocalPath.replace("/mnt/",""));
|
|
|
+ caseImg.setImgUrl(CacheUtil.mapping +outLocalPathOss);
|
|
|
caseImg.setImgInfo("照片卷");
|
|
|
caseImg.setType(1);
|
|
|
this.saveOrUpdate(caseImg);
|
|
@@ -121,7 +130,12 @@ public class CaseImgServiceImpl extends ServiceImpl<ICaseImgMapper, CaseImg> imp
|
|
|
}catch (Exception e){
|
|
|
log.info("ffmpeg错误:{}",caseId,e);
|
|
|
}finally {
|
|
|
- FileUtil.del(filePath);
|
|
|
+ try {
|
|
|
+ Thread.sleep(2000L);
|
|
|
+ FileUtil.del(filePath);
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|