Browse Source

短视频新增修改

小么熊🐻 3 years ago
parent
commit
6e625fcb87

+ 15 - 9
zzjs-admin/src/main/java/com/miaxis/pc/controller/teachingDsp/TeachingDspInfoController.java

@@ -9,7 +9,9 @@ import com.miaxis.common.exception.CustomException;
 import com.miaxis.common.utils.StringUtils;
 import com.miaxis.common.utils.StringUtils;
 import com.miaxis.common.utils.poi.ExcelUtil;
 import com.miaxis.common.utils.poi.ExcelUtil;
 import com.miaxis.teachingDsp.domain.TeachingDspInfo;
 import com.miaxis.teachingDsp.domain.TeachingDspInfo;
+import com.miaxis.teachingDsp.dto.TeachingDspInfoDto;
 import com.miaxis.teachingDsp.service.ITeachingDspInfoService;
 import com.miaxis.teachingDsp.service.ITeachingDspInfoService;
+import com.miaxis.teachingVideo.dto.TeachingVideoInfoDto;
 import io.swagger.annotations.*;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -76,28 +78,32 @@ public class TeachingDspInfoController extends BaseController{
         return Response.success(teachingDspInfoService.getById(id));
         return Response.success(teachingDspInfoService.getById(id));
     }
     }
 
 
+
+
     /**
     /**
      * 新增学车短视频
      * 新增学车短视频
      */
      */
-    @PreAuthorize("@ss.hasPermi('teachingDsp:dsp:add')")
-    @Log(title = "学车短视频", businessType = BusinessTypeEnum.INSERT)
+    @PreAuthorize("@ss.hasPermi('teachingDsp:info:add')")
+    @Log(title = "新增学车短视频", businessType = BusinessTypeEnum.INSERT)
     @PostMapping
     @PostMapping
-    @ApiOperation("新增学车短视频")
-    public Response<Integer> add(@RequestBody TeachingDspInfo teachingDspInfo){
-        return toResponse(teachingDspInfoService.save(teachingDspInfo) ? 1 : 0);
+    @ApiOperation("新增学视频")
+    public Response add(@RequestBody TeachingDspInfoDto teachingDspInfoDto){
+        return teachingDspInfoService.saveTeachingDsp(teachingDspInfoDto);
     }
     }
 
 
+
     /**
     /**
      * 修改学车短视频
      * 修改学车短视频
      */
      */
-    @PreAuthorize("@ss.hasPermi('teachingDsp:dsp:edit')")
-    @Log(title = "学车短视频", businessType = BusinessTypeEnum.UPDATE)
+    @PreAuthorize("@ss.hasPermi('teachingDsp:info:edit')")
+    @Log(title = "修改学车短视频", businessType = BusinessTypeEnum.UPDATE)
     @PutMapping
     @PutMapping
     @ApiOperation("修改学车短视频")
     @ApiOperation("修改学车短视频")
-    public Response<Integer> edit(@RequestBody TeachingDspInfo teachingDspInfo){
-        return toResponse(teachingDspInfoService.updateById(teachingDspInfo) ? 1 : 0);
+    public Response edit(@RequestBody TeachingDspInfoDto teachingDspInfoDto){
+        return teachingDspInfoService.updateTeachingDspById(teachingDspInfoDto);
     }
     }
 
 
+
     /**
     /**
      * 删除学车短视频
      * 删除学车短视频
      */
      */

+ 2 - 106
zzjs-service/src/main/java/com/miaxis/teachingDsp/domain/TeachingDspInfo.java

@@ -70,13 +70,13 @@ public class TeachingDspInfo extends BaseBusinessEntity{
     @Excel(name = "视频高度")
     @Excel(name = "视频高度")
     @TableField("video_height")
     @TableField("video_height")
     @ApiModelProperty(value = "视频高度")
     @ApiModelProperty(value = "视频高度")
-    private Long videoHeight;
+    private Integer videoHeight;
 
 
     /** 视频宽度 */
     /** 视频宽度 */
     @Excel(name = "视频宽度")
     @Excel(name = "视频宽度")
     @TableField("video_width")
     @TableField("video_width")
     @ApiModelProperty(value = "视频宽度")
     @ApiModelProperty(value = "视频宽度")
-    private Long videoWidth;
+    private Integer videoWidth;
 
 
     /** 云点播视频fileId */
     /** 云点播视频fileId */
     @Excel(name = "云点播视频fileId")
     @Excel(name = "云点播视频fileId")
@@ -96,108 +96,4 @@ public class TeachingDspInfo extends BaseBusinessEntity{
     @ApiModelProperty(value = "状态  0:有效(默认)、1:失效 (伪删除)")
     @ApiModelProperty(value = "状态  0:有效(默认)、1:失效 (伪删除)")
     private String status;
     private String status;
 
 
-    public void setId(Long id){
-        this.id = id;
-    }
-
-    public Long getId(){
-        return id;
-    }
-    public void setFileId(Long fileId){
-        this.fileId = fileId;
-    }
-
-    public Long getFileId(){
-        return fileId;
-    }
-    public void setCoverFileId(Long coverFileId){
-        this.coverFileId = coverFileId;
-    }
-
-    public Long getCoverFileId(){
-        return coverFileId;
-    }
-    public void setTitle(String title){
-        this.title = title;
-    }
-
-    public String getTitle(){
-        return title;
-    }
-    public void setVideoDescribe(String videoDescribe){
-        this.videoDescribe = videoDescribe;
-    }
-
-    public String getVideoDescribe(){
-        return videoDescribe;
-    }
-    public void setVideoDuration(String videoDuration){
-        this.videoDuration = videoDuration;
-    }
-
-    public String getVideoDuration(){
-        return videoDuration;
-    }
-    public void setVideoSize(BigDecimal videoSize){
-        this.videoSize = videoSize;
-    }
-
-    public BigDecimal getVideoSize(){
-        return videoSize;
-    }
-    public void setVideoHeight(Long videoHeight){
-        this.videoHeight = videoHeight;
-    }
-
-    public Long getVideoHeight(){
-        return videoHeight;
-    }
-    public void setVideoWidth(Long videoWidth){
-        this.videoWidth = videoWidth;
-    }
-
-    public Long getVideoWidth(){
-        return videoWidth;
-    }
-    public void setVodVideoFileId(String vodVideoFileId){
-        this.vodVideoFileId = vodVideoFileId;
-    }
-
-    public String getVodVideoFileId(){
-        return vodVideoFileId;
-    }
-    public void setShelfStatus(Integer shelfStatus){
-        this.shelfStatus = shelfStatus;
-    }
-
-    public Integer getShelfStatus(){
-        return shelfStatus;
-    }
-    public void setStatus(String status){
-        this.status = status;
-    }
-
-    public String getStatus(){
-        return status;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("fileId", getFileId())
-            .append("coverFileId", getCoverFileId())
-            .append("title", getTitle())
-            .append("videoDescribe", getVideoDescribe())
-            .append("videoDuration", getVideoDuration())
-            .append("videoSize", getVideoSize())
-            .append("videoHeight", getVideoHeight())
-            .append("videoWidth", getVideoWidth())
-            .append("vodVideoFileId", getVodVideoFileId())
-            .append("shelfStatus", getShelfStatus())
-            .append("status", getStatus())
-            .append("createTime", getCreateTime())
-            .append("updateTime", getUpdateTime())
-            .toString();
-    }
 }
 }

+ 35 - 0
zzjs-service/src/main/java/com/miaxis/teachingDsp/dto/TeachingDspInfoDto.java

@@ -0,0 +1,35 @@
+package com.miaxis.teachingDsp.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 教学视频对象入参
+ * @author wwl
+ * @version 1.0
+ * @date 2021/7/2 14:25
+ */
+@Data
+@ApiModel(value = "TeachingDspInfoDto", description = "学车短视频对象入参")
+public class TeachingDspInfoDto implements Serializable {
+
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    @ApiModelProperty(value = "视频文件id")
+    private String videoFileId;
+
+    @ApiModelProperty(value = "封面图片id")
+    private Long coverFileId;
+
+    @ApiModelProperty(value = "视频标题")
+    private String title;
+
+    @ApiModelProperty(value = "视频描述")
+    private String videoDescribe;
+
+
+}

+ 15 - 0
zzjs-service/src/main/java/com/miaxis/teachingDsp/service/ITeachingDspInfoService.java

@@ -5,6 +5,7 @@ import java.util.List;
 import com.miaxis.common.core.domain.Response;
 import com.miaxis.common.core.domain.Response;
 import com.miaxis.teachingDsp.domain.TeachingDspInfo;
 import com.miaxis.teachingDsp.domain.TeachingDspInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.miaxis.teachingDsp.dto.TeachingDspInfoDto;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
 /**
 /**
@@ -45,4 +46,18 @@ public interface ITeachingDspInfoService extends IService<TeachingDspInfo>{
      * @return
      * @return
      */
      */
     Response coverUp(String fileId, MultipartFile coverFile);
     Response coverUp(String fileId, MultipartFile coverFile);
+
+    /**
+     * 新增学车短视频
+     * @param teachingDspInfoDto
+     * @return
+     */
+    Response saveTeachingDsp(TeachingDspInfoDto teachingDspInfoDto);
+
+    /**
+     * 修改学车短视频
+     * @param teachingDspInfoDto
+     * @return
+     */
+    Response updateTeachingDspById(TeachingDspInfoDto teachingDspInfoDto);
 }
 }

+ 112 - 0
zzjs-service/src/main/java/com/miaxis/teachingDsp/service/impl/TeachingDspInfoServiceImpl.java

@@ -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("系统错误");
+        }
+
+    }
+
 
 
 }
 }