|
@@ -1,17 +1,22 @@
|
|
package com.miaxis.teachingDsp.service.impl;
|
|
package com.miaxis.teachingDsp.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.miaxis.common.core.domain.Response;
|
|
import com.miaxis.common.core.domain.Response;
|
|
import com.miaxis.common.enums.FileUploadTypeEnum;
|
|
import com.miaxis.common.enums.FileUploadTypeEnum;
|
|
import com.miaxis.common.exception.CustomException;
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
|
+import com.miaxis.common.utils.bean.BeanUtils;
|
|
import com.miaxis.file.domain.FileInfo;
|
|
import com.miaxis.file.domain.FileInfo;
|
|
import com.miaxis.file.service.IFileInfoService;
|
|
import com.miaxis.file.service.IFileInfoService;
|
|
import com.miaxis.teachingDsp.domain.TeachingDspInfo;
|
|
import com.miaxis.teachingDsp.domain.TeachingDspInfo;
|
|
|
|
+import com.miaxis.teachingDsp.dto.TeachingDspInfoDto;
|
|
import com.miaxis.teachingDsp.mapper.TeachingDspInfoMapper;
|
|
import com.miaxis.teachingDsp.mapper.TeachingDspInfoMapper;
|
|
import com.miaxis.teachingDsp.service.ITeachingDspInfoService;
|
|
import com.miaxis.teachingDsp.service.ITeachingDspInfoService;
|
|
|
|
+import com.miaxis.teachingVideo.domain.TeachingVideoInfo;
|
|
import com.tencentcloudapi.vod.v20180717.VodClient;
|
|
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.DescribeMediaInfosResponse;
|
|
import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoRequest;
|
|
import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoRequest;
|
|
import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoResponse;
|
|
import com.tencentcloudapi.vod.v20180717.models.ModifyMediaInfoResponse;
|
|
@@ -22,6 +27,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -109,5 +115,111 @@ public class TeachingDspInfoServiceImpl extends ServiceImpl<TeachingDspInfoMappe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Response saveTeachingDsp(TeachingDspInfoDto teachingDspInfoDto) {
|
|
|
|
+ try{
|
|
|
|
+ //教学视频详细信息
|
|
|
|
+ TeachingDspInfo dspInfo = new TeachingDspInfo();
|
|
|
|
+ BeanUtils.copyProperties(teachingDspInfoDto,dspInfo);
|
|
|
|
+
|
|
|
|
+ //根据fileId获取云点播视频信息
|
|
|
|
+ DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
|
|
+ String[] fileId = {teachingDspInfoDto.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_DSP.getFileType());
|
|
|
|
+ media.setFileUrl(mediaUrl);
|
|
|
|
+ media.setRemark(FileUploadTypeEnum.STUDY_DSP.getInfo());
|
|
|
|
+ fileInfoService.save(media);
|
|
|
|
+
|
|
|
|
+ dspInfo.setFileId(media.getFileId());
|
|
|
|
+ dspInfo.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);
|
|
|
|
+ dspInfo.setVideoSize(decimalSize);
|
|
|
|
+ dspInfo.setVideoHeight(height);
|
|
|
|
+ dspInfo.setVideoWidth(width);
|
|
|
|
+ dspInfo.setVodVideoFileId(teachingDspInfoDto.getVideoFileId());
|
|
|
|
+ teachingDspInfoMapper.insert(dspInfo);
|
|
|
|
+
|
|
|
|
+ return Response.success();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new CustomException("系统错误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Response updateTeachingDspById(TeachingDspInfoDto teachingDspInfoDto) {
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ TeachingDspInfo dspInfo = new TeachingDspInfo();
|
|
|
|
+ BeanUtils.copyProperties(teachingDspInfoDto,dspInfo);
|
|
|
|
+
|
|
|
|
+ //判断文件id是否修改
|
|
|
|
+ TeachingDspInfo dspInfoDb = this.getById(teachingDspInfoDto.getId());
|
|
|
|
+ if (!teachingDspInfoDto.getVideoFileId().equals(dspInfoDb.getVodVideoFileId())){
|
|
|
|
+ DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
|
|
+ String[] fileId = {teachingDspInfoDto.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);
|
|
|
|
+
|
|
|
|
+ dspInfo.setFileId(media.getFileId());
|
|
|
|
+ dspInfo.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);
|
|
|
|
+ dspInfo.setVideoSize(decimalSize);
|
|
|
|
+ dspInfo.setVideoHeight(height);
|
|
|
|
+ dspInfo.setVideoWidth(width);
|
|
|
|
+ dspInfo.setVodVideoFileId(teachingDspInfoDto.getVideoFileId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ teachingDspInfoMapper.updateById(dspInfo);
|
|
|
|
+
|
|
|
|
+ return Response.success();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new CustomException("系统错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|