|
@@ -23,14 +23,17 @@ import com.miaxis.teachingVideo.vo.TeachingVideoInfoVo;
|
|
|
import com.tencentcloudapi.vod.v20180717.VodClient;
|
|
|
import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosRequest;
|
|
|
import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosResponse;
|
|
|
+import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoRequest;
|
|
|
+import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoResponse;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -83,64 +86,37 @@ public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoM
|
|
|
public Response saveTeachingVideo(TeachingVideoInfoDto teachingVideoInfo) {
|
|
|
|
|
|
try{
|
|
|
- String mediaUrl="";//视频访问路径
|
|
|
- String coverUrl="";//视频封面访问路径
|
|
|
- String size="";//视频文件大小
|
|
|
- String duration="";//视屏时长
|
|
|
- Integer height=null;//视屏高度
|
|
|
- Integer width=null;//视屏宽度
|
|
|
+ //教学视频详细信息
|
|
|
+ TeachingVideoInfo videoInfo = new TeachingVideoInfo();
|
|
|
+ BeanUtils.copyProperties(teachingVideoInfo,videoInfo);
|
|
|
|
|
|
//根据fileId获取云点播视频信息
|
|
|
DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
|
- String[] fileId = {teachingVideoInfo.getVideoFileId(),teachingVideoInfo.getCoverFileId()};
|
|
|
+ String[] fileId = {teachingVideoInfo.getVideoFileId()};
|
|
|
String[] filter = {"basicInfo","metaData"};
|
|
|
req.setFileIds(fileId);
|
|
|
req.setFilters(filter);
|
|
|
DescribeMediaInfosResponse resp = vodClient.DescribeMediaInfos(req);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(DescribeMediaInfosResponse.toJsonString(resp));
|
|
|
JSONArray mediaInfoSetArr = (JSONArray)jsonObject.get("MediaInfoSet");
|
|
|
+ JSONObject mediaInfoSetObj = (JSONObject)mediaInfoSetArr.get(0);
|
|
|
+ JSONObject basicInfo = (JSONObject)mediaInfoSetObj.get("BasicInfo");
|
|
|
+ JSONObject metaData = (JSONObject)mediaInfoSetObj.get("MetaData");
|
|
|
|
|
|
- List<JSONObject> jsonObjects = mediaInfoSetArr.toJavaList(JSONObject.class);
|
|
|
- for (JSONObject object : jsonObjects) {
|
|
|
-
|
|
|
- //视频信息
|
|
|
- if (object.get("FileId").equals(teachingVideoInfo.getVideoFileId())){
|
|
|
- JSONObject videoBasicInfo = (JSONObject)object.get("BasicInfo");
|
|
|
- JSONObject videoMetaData = (JSONObject)object.get("MetaData");
|
|
|
-
|
|
|
- //获取视频基础信息
|
|
|
- mediaUrl = (String)videoBasicInfo.get("MediaUrl");
|
|
|
- size = String.valueOf(videoMetaData.get("Size"));
|
|
|
- duration = String.valueOf(videoMetaData.get("Duration"));
|
|
|
- height = (Integer)videoMetaData.get("Height");
|
|
|
- width = (Integer)videoMetaData.get("Width");
|
|
|
- }else{ //封面信息
|
|
|
- JSONObject coverBasicInfo = (JSONObject)object.get("BasicInfo");
|
|
|
- coverUrl = (String)coverBasicInfo.get("CoverUrl");
|
|
|
- }
|
|
|
- }
|
|
|
+ //获取视频、封面基础信息
|
|
|
+ String mediaUrl = (String)basicInfo.get("MediaUrl");//视频访问路径
|
|
|
+ String size = String.valueOf(metaData.get("Size"));//视频文件大小
|
|
|
+ String duration = String.valueOf(metaData.get("Duration"));//视屏时长
|
|
|
+ Integer height = (Integer)metaData.get("Height");//视屏高度
|
|
|
+ Integer width = (Integer)metaData.get("Width");//视屏宽度
|
|
|
|
|
|
- //保存视频、封面文件信息
|
|
|
FileInfo media = new FileInfo();
|
|
|
media.setFileType(FileUploadTypeEnum.STUDY_MOVIE.getFileType());
|
|
|
media.setFileUrl(mediaUrl);
|
|
|
media.setRemark(FileUploadTypeEnum.STUDY_MOVIE.getInfo());
|
|
|
-
|
|
|
- FileInfo cover = new FileInfo();
|
|
|
- cover.setFileType(FileUploadTypeEnum.STUDY_MOVIE.getFileType());
|
|
|
- cover.setFileUrl(coverUrl);
|
|
|
- cover.setRemark("视频封面");
|
|
|
-
|
|
|
fileInfoService.save(media);
|
|
|
- fileInfoService.save(cover);
|
|
|
|
|
|
- //保存教学视频详细信息
|
|
|
- TeachingVideoInfo videoInfo = new TeachingVideoInfo();
|
|
|
videoInfo.setFileId(media.getFileId());
|
|
|
- videoInfo.setCoverFileId(cover.getFileId());
|
|
|
- videoInfo.setTitle(teachingVideoInfo.getTitle());
|
|
|
- videoInfo.setVideoDescribe(teachingVideoInfo.getVideoDescribe());
|
|
|
- videoInfo.setTeachingVideoTypeId(teachingVideoInfo.getTeachingVideoTypeId());
|
|
|
videoInfo.setVideoDuration(duration);
|
|
|
BigDecimal decimalSize = BigDecimal.valueOf(Double.valueOf(size))
|
|
|
.divide(BigDecimal.valueOf(1024), 3, BigDecimal.ROUND_HALF_UP)
|
|
@@ -149,7 +125,6 @@ public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoM
|
|
|
videoInfo.setVideoHeight(height);
|
|
|
videoInfo.setVideoWidth(width);
|
|
|
videoInfo.setVodVideoFileId(teachingVideoInfo.getVideoFileId());
|
|
|
- videoInfo.setVodCoverFileId(teachingVideoInfo.getCoverFileId());
|
|
|
teachingVideoInfoMapper.insert(videoInfo);
|
|
|
|
|
|
return Response.success();
|
|
@@ -172,7 +147,7 @@ public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoM
|
|
|
TeachingVideoInfo info = new TeachingVideoInfo();
|
|
|
BeanUtils.copyProperties(teachingVideoInfo,info);
|
|
|
|
|
|
- //判断视频是否修改
|
|
|
+ //判断文件id是否修改
|
|
|
TeachingVideoInfo videoInfo = this.getById(teachingVideoInfo.getId());
|
|
|
if (!teachingVideoInfo.getVideoFileId().equals(videoInfo.getVodVideoFileId())){
|
|
|
DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
@@ -210,31 +185,6 @@ public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoM
|
|
|
info.setVideoHeight(height);
|
|
|
info.setVideoWidth(width);
|
|
|
info.setVodVideoFileId(teachingVideoInfo.getVideoFileId());
|
|
|
- info.setVodCoverFileId(teachingVideoInfo.getCoverFileId());
|
|
|
- }
|
|
|
-
|
|
|
- //判断封面是否修改
|
|
|
- if (!teachingVideoInfo.getCoverFileId().equals(videoInfo.getVodCoverFileId())){
|
|
|
- DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
|
- String[] fileId = {teachingVideoInfo.getCoverFileId()};
|
|
|
- String[] filter = {"basicInfo","metaData"};
|
|
|
- req.setFileIds(fileId);
|
|
|
- req.setFilters(filter);
|
|
|
- DescribeMediaInfosResponse resp = vodClient.DescribeMediaInfos(req);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(DescribeMediaInfosResponse.toJsonString(resp));
|
|
|
- JSONArray mediaInfoSetArr = (JSONArray)jsonObject.get("MediaInfoSet");
|
|
|
- JSONObject mediaInfoSetObj = (JSONObject)mediaInfoSetArr.get(0);
|
|
|
- JSONObject basicInfo = (JSONObject)mediaInfoSetObj.get("BasicInfo");
|
|
|
- String coverUrl = (String)basicInfo.get("CoverUrl");//封面访问路径
|
|
|
-
|
|
|
- //保存封面文件信息
|
|
|
- FileInfo cover = new FileInfo();
|
|
|
- cover.setFileType(FileUploadTypeEnum.STUDY_MOVIE.getFileType());
|
|
|
- cover.setFileUrl(coverUrl);
|
|
|
- cover.setRemark("视频封面");
|
|
|
- fileInfoService.save(cover);
|
|
|
-
|
|
|
- info.setCoverFileId(cover.getFileId());
|
|
|
}
|
|
|
|
|
|
teachingVideoInfoMapper.updateById(info);
|
|
@@ -327,5 +277,41 @@ public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoM
|
|
|
return Response.success(teachingVideoInfoMapper.searchTeachingVideoInfoByKeyword(keyword));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 封面上传
|
|
|
+ * @param fileId
|
|
|
+ * @param coverFile
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response coverUp(String fileId, MultipartFile coverFile) {
|
|
|
+ try{
|
|
|
+ byte[] refereeFileBase64Bytes = Base64.encodeBase64(coverFile.getBytes());
|
|
|
+ String UpFile = new String(refereeFileBase64Bytes, "UTF-8");
|
|
|
+ System.out.println(UpFile);
|
|
|
+
|
|
|
+ ModifyMediaInfoRequest req = new ModifyMediaInfoRequest();
|
|
|
+ req.setFileId(fileId);
|
|
|
+ req.setCoverData(UpFile);
|
|
|
+
|
|
|
+ ModifyMediaInfoResponse resp = vodClient.ModifyMediaInfo(req);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(DescribeMediaInfosResponse.toJsonString(resp));
|
|
|
+ String coverUrl = (String) jsonObject.get("CoverUrl");//封面访问路径
|
|
|
+
|
|
|
+ //保存封面文件信息
|
|
|
+ FileInfo cover = new FileInfo();
|
|
|
+ cover.setFileType(FileUploadTypeEnum.STUDY_MOVIE.getFileType());
|
|
|
+ cover.setFileUrl(coverUrl);
|
|
|
+ cover.setRemark("视频封面");
|
|
|
+ fileInfoService.save(cover);
|
|
|
+
|
|
|
+ return Response.success(cover);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|