Ver Fonte

update VideoPostService

reghao há 2 semanas atrás
pai
commit
bc52420927

+ 3 - 3
content/content-api/src/main/java/cn/reghao/tnb/content/api/constant/VideoStatus.java

@@ -20,10 +20,10 @@ public enum VideoStatus {
     private final Integer code;
     private final String desc;
 
-    private static Map<Integer, String> descMap = new HashMap<>();
+    private static Map<Integer, VideoStatus> descMap = new HashMap<>();
     static {
         for (VideoStatus status : VideoStatus.values()) {
-            descMap.put(status.code, status.desc);
+            descMap.put(status.code, status);
         }
     }
 
@@ -41,7 +41,7 @@ public enum VideoStatus {
     }
 
     // TODO 第一次调用时会初始化 descMap
-    public static String getDescByCode(int code) {
+    public static VideoStatus getByCode(int code) {
         return descMap.get(code);
     }
 }

+ 2 - 2
content/content-api/src/main/java/cn/reghao/tnb/content/api/dto/VideoPublishSbt.java

@@ -24,8 +24,8 @@ public class VideoPublishSbt implements Serializable {
 
     @NotBlank
     private String videoId;
-    @NotBlank
-    private String coverFileId;
+    /*@NotBlank
+    private String coverFileId;*/
     @NotBlank
     private String title;
     private String description;

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/VideoPostMapper.java

@@ -24,10 +24,10 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
 
     void updateVideoScope(@Param("videoId") String videoId, @Param("scope") int scope);
     void updateVideoInfo(VideoInfoUpdate videoInfoUpdate);
-    void updateVideoCover(@Param("videoId") String videoId, @Param("coverUrl") String coverUrl);
-    void updateVideoStatus(@Param("videoId") String videoId, @Param("status") int status);
+    void updateVideoCover(@Param("videoId") String videoId, @Param("status") int status, @Param("coverUrl") String coverUrl);
     void updateVideoFile(@Param("videoId") String videoId, @Param("status") int status, @Param("duration") int duration);
     void updateVideoPublish(VideoPost videoPost);
+    void updateVideoStatus(@Param("videoId") String videoId, @Param("status") int status);
 
     /* 根据条件分页获取 */
     int countByCriteria(VideoQuery videoQuery);

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/repository/VideoRepository.java

@@ -62,8 +62,8 @@ public class VideoRepository {
         videoFileMapper.update(videoFile);
     }
 
-    public void updateVideoCover(String videoId, String coverUrl) {
-        videoPostMapper.updateVideoCover(videoId, coverUrl);
+    public void updateVideoCover(String videoId, VideoStatus videoStatus, String coverUrl) {
+        videoPostMapper.updateVideoCover(videoId, videoStatus.getCode(), coverUrl);
     }
 
     public void updateVideoInfo(VideoInfoUpdate videoInfoUpdate) {

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/VideoError.java

@@ -30,7 +30,7 @@ public class VideoError extends BaseObject<Integer> {
     public VideoError(VideoErrorReport videoErrorReport) {
         this.videoId = videoErrorReport.getVideoId();
         this.errorCode = videoErrorReport.getErrorCode();
-        this.errorInfo = VideoStatus.getDescByCode(videoErrorReport.getErrorCode());
+        this.errorInfo = VideoStatus.getByCode(videoErrorReport.getErrorCode()).getDesc();
         this.solved = false;
     }
 }

+ 1 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/VideoPost.java

@@ -84,12 +84,11 @@ public class VideoPost extends BaseObject<Integer> {
         this.publishBy = publishBy;
     }
 
-    public void update(VideoPublishSbt video, String coverUrl, long publishAt) {
+    public void update(VideoPublishSbt video, long publishAt, VideoStatus videoStatus) {
         this.title = video.getTitle();
         this.description = video.getDescription() != null ? video.getDescription() : "";
         this.categoryPid = video.getCategoryPid();
         this.categoryId = video.getCategoryId();
-        this.coverUrl = coverUrl;
         this.scope = video.getScope();
         this.status = VideoStatus.PENDING_REVIEW.getCode();
         this.publishAt = DateTimeConverter.localDateTime(publishAt);

+ 17 - 15
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/VideoPostService.java

@@ -10,6 +10,7 @@ import cn.reghao.jutil.jdk.web.result.Result;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.common.util.IdService;
 import cn.reghao.tnb.content.api.constant.PostScope;
+import cn.reghao.tnb.content.api.constant.VideoStatus;
 import cn.reghao.tnb.content.api.dto.VideoFilePublish;
 import cn.reghao.tnb.content.api.dto.VideoPublishSbt;
 import cn.reghao.tnb.content.api.dto.VideoFileUpdate;
@@ -57,10 +58,6 @@ public class VideoPostService {
         String title = videoFilePublish.getFilename();
         String videoFileId = videoFilePublish.getVideoFileId();
         VideoMeta videoMeta = ossService.getVideoMeta(videoFileId);
-        if (!videoMeta.getFormatName().contains("mov,mp4")) {
-            log.error("视频格式 {} 不支持 web 播放", videoMeta.getFormatName());
-        }
-
         String videoId = idGenerator.getUuid();
         VideoFile videoFile = new VideoFile(videoId, videoMeta);
         VideoPost videoPost = new VideoPost(videoId, title, videoFile);
@@ -71,14 +68,6 @@ public class VideoPostService {
     public Result publishVideoPost(VideoPublishSbt videoPublishSbt) {
         Result result;
         try {
-            String coverFileId = videoPublishSbt.getCoverFileId();
-            ObjectMeta objectMeta = ossService.getObjectMeta(coverFileId);
-            if (objectMeta == null) {
-                String errMsg = String.format("封面文件 %s 在 oss 中不存在", coverFileId);
-                return Result.fail(errMsg);
-            }
-            String coverUrl = objectMeta.getUrl();
-
             String videoId = videoPublishSbt.getVideoId();
             VideoPost videoPost = videoRepository.getVideoPost(videoId);
             if (videoPost == null) {
@@ -97,16 +86,22 @@ public class VideoPostService {
             int scope = videoPublishSbt.getScope();
             ossService.checkAndSetScope(videoFileId, scope);
 
+            VideoStatus videoStatus = VideoStatus.DRAFT;
+            String coverUrl = videoPost.getCoverUrl();
+            if (coverUrl != null && !coverUrl.isBlank()) {
+                videoStatus = VideoStatus.PENDING_REVIEW;
+            }
+
             Long scheduledTime = videoPublishSbt.getScheduledTime();
             if (scheduledTime == null) {
                 long publishAt = System.currentTimeMillis();
-                videoPost.update(videoPublishSbt, coverUrl, publishAt);
+                videoPost.update(videoPublishSbt, publishAt, videoStatus);
             } else {
                 /*long duration = publishAt-System.currentTimeMillis();
                 if (duration < 600_000) {
                     return Result.fail("定时发布的时间至少应在 10 分钟后");
                 }*/
-                videoPost.update(videoPublishSbt, coverUrl, scheduledTime);
+                videoPost.update(videoPublishSbt, scheduledTime, videoStatus);
                 long jobId = jobService.addPublishVideoJob(videoId, videoPublishSbt.getScheduledTime());
             }
 
@@ -163,9 +158,16 @@ public class VideoPostService {
         String videoId = videoCoverUpdate.getVideoId();
         VideoPost videoPost = videoRepository.getVideoPost(videoId);
         if (videoPost == null) {
+            log.error("VideoPost with videoId {} not exist", videoId);
             return;
         }
 
+        VideoStatus videoStatus = VideoStatus.getByCode(videoPost.getStatus());
+        int categoryPid = videoPost.getCategoryPid();
+        if (categoryPid != 0) {
+            videoStatus = VideoStatus.PENDING_REVIEW;
+        }
+
         String coverFileId = videoCoverUpdate.getCoverFileId();
         try {
             ObjectMeta objectMeta = ossService.getObjectMeta(coverFileId);
@@ -176,7 +178,7 @@ public class VideoPostService {
 
             String currentCover = videoPost.getCoverUrl();
             String coverUrl = objectMeta.getUrl();
-            videoRepository.updateVideoCover(videoId, coverUrl);
+            videoRepository.updateVideoCover(videoId, videoStatus, coverUrl);
             if (currentCover != null && !currentCover.isBlank()) {
                 ossService.deleteByObjectUrl(currentCover);
             }

+ 6 - 6
content/content-service/src/main/resources/mapper/vod/VideoPostMapper.xml

@@ -26,12 +26,7 @@
     </update>
     <update id="updateVideoCover">
         update vod_video_post
-        set update_time=now(),cover_url=#{coverUrl}
-        where video_id=#{videoId}
-    </update>
-    <update id="updateVideoStatus">
-        update vod_video_post
-        set update_time=now(),`status`=#{status}
+        set update_time=now(),`status`=#{status},cover_url=#{coverUrl}
         where video_id=#{videoId}
     </update>
     <update id="updateVideoFile">
@@ -44,6 +39,11 @@
         set update_time=now(),`title`=#{title},`description`=#{description},`category_pid`=#{categoryPid},`category_id`=#{categoryId},`cover_url`=#{coverUrl},`scope`=#{scope},`status`=#{status},`publish_at`=#{publishAt}
         where video_id=#{videoId}
     </update>
+    <update id="updateVideoStatus">
+        update vod_video_post
+        set update_time=now(),`status`=#{status}
+        where video_id=#{videoId}
+    </update>
 
     <select id="countByCriteria" resultType="java.lang.Integer">
         select count(*)