Преглед изворни кода

update VideoPostService#updateVideoFile

reghao пре 3 недеља
родитељ
комит
e542105511

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

@@ -24,7 +24,7 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
     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 updateVideoDuration(@Param("videoId") String videoId, @Param("duration") int duration);
+    void updateVideoFile(@Param("videoId") String videoId, @Param("status") int status, @Param("duration") int duration);
     void updateVideoPublish(VideoPost videoPost);
     void updateVideoCached(@Param("videoId") String videoId, @Param("videoMeta") VideoMeta videoMeta);
     void deleteByVideoId(String videoId);

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

@@ -2,6 +2,7 @@ package cn.reghao.tnb.content.app.vod.db.repository;
 
 import cn.reghao.file.api.dto.VideoMeta;
 import cn.reghao.tnb.common.db.GroupCount;
+import cn.reghao.tnb.content.api.constant.VideoStatus;
 import cn.reghao.tnb.content.app.vod.db.mapper.*;
 import cn.reghao.tnb.content.app.vod.model.dto.VideoInfoUpdate;
 import cn.reghao.tnb.content.app.vod.model.po.VideoCategoryPost;
@@ -55,8 +56,9 @@ public class VideoRepository {
         videoFileMapper.save(videoFile);
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public void updateVideoFile(VideoFile videoFile) {
-        videoPostMapper.updateVideoDuration(videoFile.getVideoId(), videoFile.getDuration());
+        videoPostMapper.updateVideoFile(videoFile.getVideoId(), VideoStatus.censor.getCode(), videoFile.getDuration());
         videoFileMapper.update(videoFile);
     }
 

+ 2 - 11
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/VideoPostService.java

@@ -174,17 +174,8 @@ public class VideoPostService {
             }
 
             String coverUrl = objectMeta.getUrl();
-            videoRepository.updateVideoCover(videoId, coverUrl);
-            String currentCover = videoPost.getCoverUrl();
-            deleteCoverFile(currentCover);
-        } catch (Exception e) {
-            log.error("{}", e.getMessage());;
-        }
-    }
-
-    private void deleteCoverFile(String coverUrl) {
-        try {
             ossService.deleteByObjectUrl(coverUrl);
+            videoRepository.updateVideoCover(videoId, coverUrl);
         } catch (Exception e) {
             log.error("{}", e.getMessage());;
         }
@@ -233,7 +224,7 @@ public class VideoPostService {
         if (owner == UserContext.getUserId()) {
             // 删除 videoId 关联的所有数据, 包括观看记录, 用户收藏, 视频数据, 视频标签, 推荐数据等
             String coverUrl = videoPost.getCoverUrl();
-            deleteCoverFile(coverUrl);
+            ossService.deleteByObjectUrl(coverUrl);
             List<VideoUrlDto> list = videoRepository.getVideoUrls(videoId);
             for (VideoUrlDto videoUrlDto : list) {
                 String videoFileId = videoUrlDto.getObjectId();

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

@@ -29,9 +29,9 @@
         set update_time=now(),`status`=#{status}
         where video_id=#{videoId}
     </update>
-    <update id="updateVideoDuration">
+    <update id="updateVideoFile">
         update vod_video_post
-        set update_time=now(),`duration`=#{duration}
+        set update_time=now(),`status`=#{status},`duration`=#{duration}
         where video_id=#{videoId}
     </update>
     <update id="updateVideoPublish">