Bläddra i källkod

更新 content-service VideoPostServiceImpl 中编辑更新 VideoPost 的相关方法

reghao 1 månad sedan
förälder
incheckning
653fad2172

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

@@ -1,17 +1,20 @@
 package cn.reghao.tnb.content.api.dto;
 
 import lombok.AllArgsConstructor;
-import lombok.Getter;
+import lombok.Data;
 
 import jakarta.validation.constraints.NotBlank;
+import lombok.NoArgsConstructor;
+
 import java.io.Serializable;
 
 /**
  * @author reghao
  * @date 2023-08-25 11:03:33
  */
+@NoArgsConstructor
 @AllArgsConstructor
-@Getter
+@Data
 public class VideoFileUpdate implements Serializable {
     private static final long serialVersionUID = 1L;
 

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

@@ -27,7 +27,6 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
     void updateVideoScope(VideoScopeUpdate videoScopeUpdate);
     void updateVideoInfo(VideoInfoUpdate videoInfoUpdate);
     void updateVideoCover(@Param("videoId") String videoId, @Param("coverUrl") String coverUrl);
-    void updateVideoFile(@Param("videoId") String videoId, @Param("videoMeta") VideoMeta videoMeta);
     void updateVideoStatus(@Param("videoId") String videoId, @Param("status") int status);
     void updateVideoPublish(VideoPost videoPost);
     void updateVideoCached(@Param("videoId") String videoId,

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

@@ -42,6 +42,10 @@ public class VideoRepository {
         videoFileMapper.save(videoFile);
     }
 
+    public void saveVideoFile(VideoFile videoFile) {
+        videoFileMapper.save(videoFile);
+    }
+
     @Transactional(rollbackFor = Exception.class)
     public void updateVideoPublish(VideoPost videoPost) {
         videoPostMapper.updateVideoPublish(videoPost);

+ 31 - 30
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/VideoPostServiceImpl.java

@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author reghao
@@ -105,7 +106,6 @@ public class VideoPostServiceImpl implements VideoPostService {
             VideoFile videoFile = videoFileList.get(0);
             String videoFileId = videoFile.getObjectId();
 
-            int channelCode = videoFile.getChannelCode();
             int scope = videoPublishSbt.getScope();
             ossService.checkAndSetScope(videoFileId, scope);
 
@@ -156,19 +156,17 @@ public class VideoPostServiceImpl implements VideoPostService {
         String videoId = videoScopeUpdate.getVideoId();
         VideoPost videoPost = videoRepository.getVideoPost(videoId);
         if (videoPost == null) {
+            log.error("{} not exist video post", videoId);
             return;
         }
 
-        List<VideoUrlDto> list = videoRepository.getVideoUrls(videoId);
-        for (VideoUrlDto videoUrlDto : list) {
-            String videoFileId = videoUrlDto.getObjectId();
-            try {
-                int scope = videoScopeUpdate.getScope();
-                ossService.checkAndSetScope(videoFileId, scope);
-                videoPostMapper.updateVideoScope(videoScopeUpdate);
-            } catch (Exception e) {
-                log.error("{}", e.getMessage());
-            }
+        List<String> objectIds = videoRepository.getVideoFiles(videoId).stream()
+                .map(VideoFile::getObjectId)
+                .toList();
+        for (String objectId : objectIds) {
+            int scope = videoScopeUpdate.getScope();
+            ossService.checkAndSetScope(objectId, scope);
+            videoPostMapper.updateVideoScope(videoScopeUpdate);
         }
     }
 
@@ -220,27 +218,30 @@ public class VideoPostServiceImpl implements VideoPostService {
             return;
         }
 
-        List<VideoUrlDto> list = videoRepository.getVideoUrls(videoId);
-        for (VideoUrlDto videoUrlDto : list) {
-            String videoFileId = videoFileUpdate.getVideoFileId();
-            try {
-                int channelCode = 101;
-                VideoMeta videoMeta = ossService.getVideoMeta(videoFileId);
-                if (videoMeta == null) {
-                    log.error("{} not exist", videoFileId);
-                    return;
-                }
-
-                videoPostMapper.updateVideoFile(videoId, videoMeta);
-                int scope = videoPost.getScope();
-                if (scope != PostScope.PRIVATE.getCode()) {
-                    ossService.checkAndSetScope(videoId, scope);
-                }
+        String videoFileId = videoFileUpdate.getVideoFileId();
+        try {
+            VideoMeta videoMeta = ossService.getVideoMeta(videoFileId);
+            if (videoMeta == null) {
+                log.error("{} not exist", videoFileId);
+                return;
+            }
 
-                ossService.deleteByObjectId(videoFileId);
-            } catch (Exception e) {
-                log.error("{}", e.getMessage());;
+            int channelCode = 101;
+            VideoFile videoFile = new VideoFile(videoId, videoMeta, channelCode);
+            videoRepository.saveVideoFile(videoFile);
+            int scope = videoPost.getScope();
+            if (scope != PostScope.PRIVATE.getCode()) {
+                ossService.checkAndSetScope(videoId, scope);
             }
+
+            String objectId = videoFile.getObjectId();
+            List<String> objectIds = videoRepository.getVideoFiles(videoId).stream()
+                    .filter(videoFile1 -> !videoFile1.getObjectId().equals(objectId))
+                    .map(VideoFile::getObjectId)
+                    .toList();
+            //ossService.deleteByObjectId(videoFileId);
+        } catch (Exception e) {
+            log.error("{}", e.getMessage());;
         }
     }
 

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

@@ -24,11 +24,6 @@
         set update_time=now(),cover_url=#{coverUrl}
         where video_id=#{videoId}
     </update>
-    <update id="updateVideoFile">
-        update vod_video_post
-        set update_time=now(),duration=#{videoMeta.duration},quality=#{videoMeta.quality}
-        where video_id=#{videoId}
-    </update>
     <update id="updateVideoStatus">
         update vod_video_post
         set update_time=now(),`status`=#{status}