|
@@ -1,23 +1,26 @@
|
|
|
package kankan.daikan.core.controller;
|
|
|
|
|
|
import fdage.back.sdk.base.entity.Result;
|
|
|
+import fdage.back.sdk.base.enums.ResultCodeEnum;
|
|
|
+import fdage.back.sdk.base.exception.CommonBaseException;
|
|
|
import fdage.back.sdk.core.alibabaUtils.AlibabaOssHelper;
|
|
|
import fdage.back.sdk.core.alibabaUtils.AlibabaSmsService;
|
|
|
+import fdage.back.sdk.utils.FileUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import kankan.daikan.base.utils.DataUtils;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.apache.velocity.shaded.commons.io.FilenameUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
@Api(tags = "公共操作相关接口")
|
|
|
@RestController
|
|
@@ -38,6 +41,13 @@ public class CommonController extends BaseController{
|
|
|
@Value("${oss.query.url}")
|
|
|
private String ossQueryUrl;
|
|
|
|
|
|
+ @Value("${oss.video.file.path}")
|
|
|
+ private String ossVideoPath;
|
|
|
+
|
|
|
+ @Value("${video-file-path}")
|
|
|
+ private String videoLocalBackupPath;
|
|
|
+
|
|
|
+
|
|
|
@ApiOperation("上传照片(只支持JPG或者PNG格式)")
|
|
|
@PostMapping(value = "/uploadImage")
|
|
|
public Result<Object> uploadImage(@RequestParam("file") MultipartFile file) throws Exception {
|
|
@@ -92,5 +102,56 @@ public class CommonController extends BaseController{
|
|
|
return Result.success(mp);
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "上传视频")
|
|
|
+ @PostMapping("/upLoadVideo")
|
|
|
+ @ResponseBody
|
|
|
+ @RequiresPermissions("sys:oss:all")
|
|
|
+ public Result uploadIntroduceVideo(@RequestParam("file") MultipartFile file) {
|
|
|
+ if (null == file) {
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D3001);
|
|
|
+ }
|
|
|
+ log.info("当前视频大小为:{} bytes" , file.getSize());
|
|
|
+ if(file.getSize() > 1024000000){
|
|
|
+ return Result.failure("视频不能超过1G");
|
|
|
+ }
|
|
|
+ String downLoanVideoPath = FileUtils.parseFile(file, videoLocalBackupPath);
|
|
|
+ log.info("视频文件已经下载到本地:{}", downLoanVideoPath);
|
|
|
+ //视频文件名一般为:xxx.mp4这种格式
|
|
|
+ String videoFilePureName = file.getOriginalFilename();
|
|
|
+ log.info("视频文件名为:{}", videoFilePureName);
|
|
|
+ //去掉格式,只获取纯名字
|
|
|
+ int index = videoFilePureName.indexOf(".");
|
|
|
+ //获取纯名字
|
|
|
+ if (index != -1) {
|
|
|
+ videoFilePureName = videoFilePureName.substring(0, index);
|
|
|
+ } else {
|
|
|
+ Random random = new Random();
|
|
|
+ videoFilePureName = "default_imag_" + random.nextInt(10000);
|
|
|
+ log.info("采用默认的图片名字:{}", videoFilePureName);
|
|
|
+ }
|
|
|
+ //这里默认第一帧图片是jpg格式
|
|
|
+ String imageFormatter = "jpg";
|
|
|
+ //视频在oss中的object name
|
|
|
+ String imageOssObjectName = ossVideoPath + videoFilePureName + "." + imageFormatter;
|
|
|
+ //截取视频第一帧图片
|
|
|
+ boolean cutFirstImageResult = DataUtils.executeCodecs(downLoanVideoPath, videoLocalBackupPath,
|
|
|
+ videoFilePureName, imageFormatter);
|
|
|
+
|
|
|
+ if (cutFirstImageResult) {
|
|
|
+ log.info("成功截取第一帧图片,将上传到oss上");
|
|
|
+ String imageLocalPath = videoLocalBackupPath + videoFilePureName + "." + imageFormatter;
|
|
|
+ alibabaOssHelper.doUploadThenDelete(imageLocalPath, imageOssObjectName);
|
|
|
+ log.info("上传第一帧图片到oss完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ String videoObjectName = ossVideoPath + file.getOriginalFilename();
|
|
|
+ alibabaOssHelper.doUploadThenDelete(downLoanVideoPath, videoObjectName);
|
|
|
+
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("image", ossQueryUrl + imageOssObjectName);
|
|
|
+ resultMap.put("video", ossQueryUrl + videoObjectName);
|
|
|
+ return Result.success("视频文件上传oss结束", resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|