|
@@ -0,0 +1,325 @@
|
|
|
+package com.miaxis.teachingVideo.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+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.teachingVideo.domain.TeachingVideoInfo;
|
|
|
+import com.miaxis.teachingVideo.domain.TeachingVideoTypeInfo;
|
|
|
+import com.miaxis.teachingVideo.dto.TeachingVideoInfoDto;
|
|
|
+import com.miaxis.teachingVideo.mapper.TeachingVideoInfoMapper;
|
|
|
+import com.miaxis.teachingVideo.service.ITeachingVideoInfoService;
|
|
|
+import com.miaxis.teachingVideo.service.ITeachingVideoTypeInfoService;
|
|
|
+import com.miaxis.teachingVideo.vo.AppletTeachingVideoVo;
|
|
|
+import com.miaxis.teachingVideo.vo.TeachingVideoInfoAppletVo;
|
|
|
+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.cache.annotation.Cacheable;
|
|
|
+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.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 教学视频Service业务层处理
|
|
|
+ * @author wwl
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2021/7/1 14:48
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class TeachingVideoInfoServiceImpl extends ServiceImpl<TeachingVideoInfoMapper, TeachingVideoInfo> implements ITeachingVideoInfoService {
|
|
|
+
|
|
|
+ private final TeachingVideoInfoMapper teachingVideoInfoMapper;
|
|
|
+
|
|
|
+ private final IFileInfoService fileInfoService;
|
|
|
+
|
|
|
+ private final VodClient vodClient;
|
|
|
+
|
|
|
+ private final ITeachingVideoTypeInfoService videoTypeInfoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询教学视频列表
|
|
|
+ *
|
|
|
+ * @param teachingVideoInfo 教学视频
|
|
|
+ * @return 教学视频
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TeachingVideoInfoVo> selectTeachingVideoInfoList(TeachingVideoInfo teachingVideoInfo){
|
|
|
+ return teachingVideoInfoMapper.selectTeachingVideoInfoList(teachingVideoInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取教学视频详细信息
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response<TeachingVideoInfoVo> getTeachingVideoDetailsById(Long id) {
|
|
|
+ TeachingVideoInfoVo info = teachingVideoInfoMapper.getTeachingVideoDetailsById(id);
|
|
|
+ return Response.success(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增教学视频
|
|
|
+ * @param teachingVideoInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response saveTeachingVideo(TeachingVideoInfoDto teachingVideoInfo) {
|
|
|
+
|
|
|
+ try{
|
|
|
+ //教学视频详细信息
|
|
|
+ TeachingVideoInfo videoInfo = new TeachingVideoInfo();
|
|
|
+ BeanUtils.copyProperties(teachingVideoInfo,videoInfo);
|
|
|
+
|
|
|
+ //根据fileId获取云点播视频信息
|
|
|
+ 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);
|
|
|
+
|
|
|
+ videoInfo.setFileId(media.getFileId());
|
|
|
+ videoInfo.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);
|
|
|
+ videoInfo.setVideoSize(decimalSize);
|
|
|
+ videoInfo.setVideoHeight(height);
|
|
|
+ videoInfo.setVideoWidth(width);
|
|
|
+ videoInfo.setVodVideoFileId(teachingVideoInfo.getVideoFileId());
|
|
|
+ teachingVideoInfoMapper.insert(videoInfo);
|
|
|
+
|
|
|
+ return Response.success();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("系统错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改教学视频
|
|
|
+ * @param teachingVideoInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response updateTeachingVideoById(TeachingVideoInfoDto teachingVideoInfo) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ 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();
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ teachingVideoInfoMapper.updateById(info);
|
|
|
+
|
|
|
+ return Response.success();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("系统错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除教学视频(伪删除)
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response removeTeachingVideoByIds(Long[] ids) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ this.update(new UpdateWrapper<TeachingVideoInfo>().set("status",1).eq("id",id));
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上架教学视频
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Response removePutShelfByIds(Long[] ids) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ this.update(new UpdateWrapper<TeachingVideoInfo>().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<TeachingVideoInfo>().set("shelf_status",1).eq("id",id));
|
|
|
+ }
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * applet
|
|
|
+ * 查询教学视频列表
|
|
|
+ * @param pid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response queryTeachingVideoInfoList(String pid) {
|
|
|
+
|
|
|
+ ArrayList<AppletTeachingVideoVo> appletVideoVos = new ArrayList<>();
|
|
|
+
|
|
|
+ //获取pid下的二级分类id
|
|
|
+ List<TeachingVideoTypeInfo> typeInfos = videoTypeInfoService.list(new QueryWrapper<TeachingVideoTypeInfo>().eq("pid", pid).eq("status", 0).orderByAsc("type_sort"));
|
|
|
+ List<TeachingVideoInfoAppletVo> appletVos = teachingVideoInfoMapper.getTeachingVideoDetailsByTypeIds(pid);
|
|
|
+
|
|
|
+ for (TeachingVideoTypeInfo typeInfo : typeInfos) {
|
|
|
+ AppletTeachingVideoVo videoVo = new AppletTeachingVideoVo();
|
|
|
+ videoVo.setTypeName(typeInfo.getTypeName());
|
|
|
+ videoVo.setList(appletVos
|
|
|
+ .parallelStream()
|
|
|
+ .filter(f -> f.getTeachingVideoTypeId().toString().equals(typeInfo.getId().toString()))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ appletVideoVos.add(videoVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Response.success(appletVideoVos);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据关键字搜索教学视频
|
|
|
+ * @param keyword
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response searchTeachingVideoInfoByKeyword(String keyword) {
|
|
|
+
|
|
|
+ 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("系统异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Cacheable(cacheNames="video",key="'getTeachingVideoByTypeId'+#typeId")
|
|
|
+ public Response getTeachingVideoByTypeId(Long typeId) {
|
|
|
+ return Response.success(teachingVideoInfoMapper.getTeachingVideoByTypeId(typeId));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|