|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.enums.FileUploadTypeEnum;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
+import com.miaxis.common.utils.bean.BeanUtils;
|
|
|
import com.miaxis.file.domain.FileInfo;
|
|
|
import com.miaxis.file.service.IFileInfoService;
|
|
|
import com.miaxis.teachingVideo.domain.TeachingVideoInfo;
|
|
@@ -21,6 +22,7 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -71,40 +73,56 @@ 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;//视屏宽度
|
|
|
+
|
|
|
//根据fileId获取云点播视频信息
|
|
|
DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
|
- String[] fileId = {teachingVideoInfo.getFileId()};
|
|
|
+ String[] fileId = {teachingVideoInfo.getVideoFileId(),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");
|
|
|
- JSONObject metaData = (JSONObject)mediaInfoSetObj.get("MetaData");
|
|
|
-
|
|
|
- //获取视频、封面基础信息
|
|
|
- String coverUrl = (String)basicInfo.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 cover = new FileInfo();
|
|
|
- cover.setFileType(FileUploadTypeEnum.STUDY_MOVIE.getFileType());
|
|
|
- cover.setFileUrl(coverUrl);
|
|
|
- cover.setRemark("视频封面");
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //保存视频、封面文件信息
|
|
|
FileInfo media = new FileInfo();
|
|
|
media.setFileType(FileUploadTypeEnum.STUDY_MOVIE.getFileType());
|
|
|
media.setFileUrl(mediaUrl);
|
|
|
media.setRemark(FileUploadTypeEnum.STUDY_MOVIE.getInfo());
|
|
|
|
|
|
- fileInfoService.save(cover);
|
|
|
+ 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();
|
|
@@ -114,9 +132,14 @@ public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoM
|
|
|
videoInfo.setVideoDescribe(teachingVideoInfo.getVideoDescribe());
|
|
|
videoInfo.setTeachingVideoTypeId(teachingVideoInfo.getTeachingVideoTypeId());
|
|
|
videoInfo.setVideoDuration(duration);
|
|
|
- videoInfo.setVideoSize(String.valueOf((Integer.valueOf(size) / 1024) / 1024));
|
|
|
+ BigDecimal decimalSize = BigDecimal.valueOf(Double.valueOf(size))
|
|
|
+ .divide(BigDecimal.valueOf(1024), 3, BigDecimal.ROUND_HALF_UP)
|
|
|
+ .divide(BigDecimal.valueOf(1024), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ videoInfo.setVideoSize(decimalSize);
|
|
|
videoInfo.setVideoHeight(height);
|
|
|
videoInfo.setVideoWidth(width);
|
|
|
+ videoInfo.setVodVideoFileId(teachingVideoInfo.getVideoFileId());
|
|
|
+ videoInfo.setVodCoverFileId(teachingVideoInfo.getCoverFileId());
|
|
|
teachingVideoInfoMapper.insert(videoInfo);
|
|
|
|
|
|
return Response.success();
|
|
@@ -126,6 +149,92 @@ public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoM
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改教学视频
|
|
|
+ * @param teachingVideoInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response updateTeachingVideoById(TeachingVideoInfoDto teachingVideoInfo) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ TeachingVideoInfo info = new TeachingVideoInfo();
|
|
|
+ BeanUtils.copyProperties(teachingVideoInfo,info);
|
|
|
+
|
|
|
+ //判断视频是否修改
|
|
|
+ TeachingVideoInfo videoInfo = this.getById(teachingVideoInfo.getId());
|
|
|
+ if (!teachingVideoInfo.getVideoFileId().equals(videoInfo.getVodVideoFileId())){
|
|
|
+ DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
|
+ 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");
|
|
|
+
|
|
|
+ //获取视频、封面基础信息
|
|
|
+ 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());
|
|
|
+ fileInfoService.save(media);
|
|
|
+
|
|
|
+ info.setFileId(media.getFileId());
|
|
|
+ info.setVideoDuration(duration);
|
|
|
+ BigDecimal decimalSize = BigDecimal.valueOf(Double.valueOf(size))
|
|
|
+ .divide(BigDecimal.valueOf(1024), 3, BigDecimal.ROUND_HALF_UP)
|
|
|
+ .divide(BigDecimal.valueOf(1024), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ info.setVideoSize(decimalSize);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ return Response.success();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("系统错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 删除教学视频(伪删除)
|