|
@@ -0,0 +1,236 @@
|
|
|
+package com.miaxis.teachingDsp.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+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.teachingDsp.domain.TeachingDspInfo;
|
|
|
+import com.miaxis.teachingDsp.dto.TeachingDspInfoDto;
|
|
|
+import com.miaxis.teachingDsp.mapper.TeachingDspInfoMapper;
|
|
|
+import com.miaxis.teachingDsp.service.ITeachingDspInfoService;
|
|
|
+import com.miaxis.teachingDsp.vo.TeachingDspInfoVo;
|
|
|
+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.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 学车短视频Service业务层处理
|
|
|
+ *
|
|
|
+ * @author miaxis
|
|
|
+ * @date 2021-12-09
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class TeachingDspInfoServiceImpl extends ServiceImpl<TeachingDspInfoMapper, TeachingDspInfo> implements ITeachingDspInfoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TeachingDspInfoMapper teachingDspInfoMapper;
|
|
|
+
|
|
|
+ private final IFileInfoService fileInfoService;
|
|
|
+
|
|
|
+ private final VodClient vodClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询学车短视频列表
|
|
|
+ *
|
|
|
+ * @param teachingDspInfo 学车短视频
|
|
|
+ * @return 学车短视频
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TeachingDspInfoVo> selectTeachingDspInfoList(TeachingDspInfo teachingDspInfo){
|
|
|
+ return teachingDspInfoMapper.selectTeachingDspInfoList(teachingDspInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上架教学视频
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response removePutShelfByIds(Long[] ids) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ this.update(new UpdateWrapper<TeachingDspInfo>().set("shelf_status",0).eq("id",id));
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下架教学视频
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response removeOffShelfByIds(Long[] ids) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ this.update(new UpdateWrapper<TeachingDspInfo>().set("shelf_status",1).eq("id",id));
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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_DSP.getFileType());
|
|
|
+ cover.setFileUrl(coverUrl);
|
|
|
+ cover.setRemark("视频封面");
|
|
|
+ fileInfoService.save(cover);
|
|
|
+
|
|
|
+ return Response.success(cover);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("系统异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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("系统错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取教学视频详细信息
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response<TeachingDspInfoVo> getTeachingDspDetailsById(Long id) {
|
|
|
+ TeachingDspInfoVo info = teachingDspInfoMapper.getTeachingDspDetailsById(id);
|
|
|
+ return Response.success(info);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|