Explorar o código

更新 content 中的 VideoPost 和 VideoFile 的部分字段

reghao hai 10 meses
pai
achega
9094079d2f

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

@@ -16,7 +16,7 @@ import java.util.List;
 public interface VideoFileMapper extends BaseMapper<VideoFile> {
     void deleteByVideoFileId(String videoFileId);
 
-    List<VideoUrlDto> findVideoUrls(String videoFileId);
-    List<VideoFile> findByVideoFileId(String videoFileId);
+    List<VideoUrlDto> findVideoUrls(String videoId);
+    VideoFile findByVideoFileId(String videoFileId);
     List<VideoInfo> findVideoInfo(String videoFileId);
 }

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

@@ -48,7 +48,6 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
     List<VideoPostCard> findByNextVideos(VideoQuery videoQuery, LocalDateTime publishAt);
 
     VideoPost findByVideoId(String videoId);
-    VideoPost findByVideoFileId(String videoFileId);
     VideoDetail findVideoPostDetail(VideoQuery videoQuery);
 
     List<VideoPostCard> findVideoCardByVideoIds(List<String> videoIds);

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

@@ -12,6 +12,7 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -46,7 +47,7 @@ public class VideoRepository {
 
     @Transactional(rollbackFor = Exception.class)
     public void updateBiliVideoFile(String videoId, VideoInfo videoInfo, int channelId) {
-        VideoFile videoFile = new VideoFile(videoInfo);
+        VideoFile videoFile = new VideoFile(videoId, videoInfo, channelId);
         videoFileMapper.save(videoFile);
         videoPostMapper.updateVideoCached(videoId, videoInfo, channelId);
     }
@@ -62,11 +63,7 @@ public class VideoRepository {
     }
 
     public List<String> deleteVideoFile(String videoFileId) {
-        List<String> objectIds = videoFileMapper.findByVideoFileId(videoFileId).stream()
-                .map(VideoFile::getObjectId)
-                .collect(Collectors.toList());
-        deleteVideoFile0(videoFileId);
-        return objectIds;
+        return Collections.emptyList();
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -78,18 +75,8 @@ public class VideoRepository {
         return videoFileMapper.findVideoInfo(videoFileId);
     }
 
-    public VideoFile getOriginalVideoFile(String videoFileId) {
-        List<VideoFile> list = videoFileMapper.findByVideoFileId(videoFileId);
-        return list.isEmpty() ? null : list.get(0);
-    }
-
-    public List<VideoFile> getVideoFiles(String videoFileId) {
-        List<VideoFile> list = videoFileMapper.findByVideoFileId(videoFileId);
-        return list;
-    }
-
-    public List<VideoUrlDto> findVideoUrls(String videoFileId) {
-        return videoFileMapper.findVideoUrls(videoFileId);
+    public List<VideoUrlDto> findVideoUrls(String videoId) {
+        return videoFileMapper.findVideoUrls(videoId);
     }
 
     //@Cacheable(cacheNames = "tnb:content:publishBy", key = "publishBy", unless = "#result == null")
@@ -117,6 +104,12 @@ public class VideoRepository {
     }
 
     public VideoPost getVideoPostByFileId(String videoFileId) {
-        return videoPostMapper.findByVideoFileId(videoFileId);
+        VideoFile videoFile = videoFileMapper.findByVideoFileId(videoFileId);
+        if (videoFile != null) {
+            String videoId = videoFile.getVideoId();
+            return videoPostMapper.findByVideoId(videoId);
+        }
+
+        return null;
     }
 }

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

@@ -16,9 +16,11 @@ import lombok.Setter;
 @Setter
 @Getter
 public class VideoFile extends BaseObject<Integer> {
+    private String videoId;
     // 原始文件的 objectId
     private String videoFileId;
     private String objectId;
+    private Integer channelCode;
     private String videoCodec;
     private Long vbitRate;
     private String audioCodec;
@@ -33,9 +35,11 @@ public class VideoFile extends BaseObject<Integer> {
     // 单位秒
     private Integer duration;
 
-    public VideoFile(VideoInfo videoInfo) {
+    public VideoFile(String videoId, VideoInfo videoInfo, int channelCode) {
+        this.videoId = videoId;
         this.videoFileId = videoInfo.getVideoFileId();
         this.objectId = videoInfo.getObjectId();
+        this.channelCode = channelCode;
         this.videoCodec = videoInfo.getVideoCodec();
         this.vbitRate = videoInfo.getVbitRate();
         this.audioCodec = videoInfo.getAudioCodec();
@@ -50,9 +54,11 @@ public class VideoFile extends BaseObject<Integer> {
         this.duration = videoInfo.getDuration();
     }
 
-    public VideoFile(String videoFileId, VideoInfo videoInfo) {
+    public VideoFile(String videoId, String videoFileId, int channelCode, VideoInfo videoInfo) {
+        this.videoId = videoId;
         this.videoFileId = videoFileId;
         this.objectId = videoInfo.getObjectId();
+        this.channelCode = channelCode;
         this.videoCodec = videoInfo.getVideoCodec();
         this.vbitRate = videoInfo.getVbitRate();
         this.audioCodec = videoInfo.getAudioCodec();

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

@@ -24,17 +24,17 @@ import java.time.LocalDateTime;
 @Data
 public class VideoPost extends BaseObject<Integer> {
     private String videoId;
-    private String videoFileId;
-    private Integer channelId;
+    //private String videoFileId;
+    //private Integer channelId;
     private String title;
     private String description;
     private Integer categoryPid;
     private Integer categoryId;
     private int duration;
-    @Deprecated
-    private String quality;
-    @Deprecated
-    private String codec;
+    //@Deprecated
+    //private String quality;
+    //@Deprecated
+    //private String codec;
     private Boolean horizontal;
     private String coverUrl;
     private int scope;
@@ -45,15 +45,15 @@ public class VideoPost extends BaseObject<Integer> {
     public VideoPost(String videoId, VideoPublishSbt video, String coverUrl,
                      VideoFile videoInfo, int status, long publishAt) {
         this.videoId = videoId;
-        this.videoFileId = video.getVideoFileId();
-        this.channelId = video.getChannelCode();
+        //this.videoFileId = video.getVideoFileId();
+        //this.channelId = video.getChannelCode();
         this.title = video.getTitle();
         this.description = video.getDescription();
         this.categoryPid = video.getCategoryPid();
         this.categoryId = video.getCategoryId();
         this.duration = videoInfo.getDuration();
-        this.quality = videoInfo.getQuality();
-        this.codec = codec;
+//        this.quality = videoInfo.getQuality();
+//        this.codec = codec;
         this.horizontal = videoInfo.getHorizontal();
         this.coverUrl = coverUrl;
         this.scope = video.getScope();
@@ -65,7 +65,7 @@ public class VideoPost extends BaseObject<Integer> {
     @Deprecated
     public VideoPost(CrawledVideo video, int categoryPid, int categoryId) {
         this.videoId = video.getVideoId();
-        this.videoFileId = video.getVideoId();
+        //this.videoFileId = video.getVideoId();
         this.title = video.getTitle();
         this.description = video.getDescription();
         this.categoryPid = categoryPid;

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

@@ -44,7 +44,7 @@ public class VideoDetail implements Serializable {
 
     public VideoDetail(VideoPost videoPost, VideoStatistic videoStatistic, String publishBy) {
         this.videoId = videoPost.getVideoId();
-        this.videoFileId = videoPost.getVideoFileId();
+        this.videoFileId = null;
         this.title = videoPost.getTitle();
         this.description = videoPost.getDescription();
         this.coverUrl = videoPost.getCoverUrl();

+ 8 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/rpc/AdminVideoServiceImpl.java

@@ -121,8 +121,11 @@ public class AdminVideoServiceImpl implements AdminVideoService {
     public VideoUrls getVideoUrl(String videoId) {
         double currentTime = 0.0;
         VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
-        String videoFileId = videoPost.getVideoFileId();
-        List<VideoUrlDto> list = videoRepository.findVideoUrls(videoFileId);
+        if (videoPost == null) {
+            return new VideoUrls();
+        }
+
+        List<VideoUrlDto> list = videoRepository.findVideoUrls(videoId);
         if (list.isEmpty()) {
             return new VideoUrls();
         }
@@ -130,12 +133,12 @@ public class AdminVideoServiceImpl implements AdminVideoService {
         String urlType = list.get(0).getType();
         int scope = videoPost.getScope();
         if (scope != PostScope.PUBLIC.getCode()) {
-            int channelId = videoPost.getChannelId();
             try {
                 List<VideoUrl> urls = list.stream().map(videoUrlDto -> {
                     try {
+                        int channelId = videoUrlDto.getChannelCode();
                         String quality = videoUrlDto.getQuality();
-                        String signedUrl = ossService.getSignedUrl(channelId, videoFileId);
+                        String signedUrl = ossService.getSignedUrl(channelId, videoUrlDto.getObjectId());
                         return new VideoUrl(quality, signedUrl);
                     } catch (Exception e) {
                         e.printStackTrace();
@@ -181,8 +184,8 @@ public class AdminVideoServiceImpl implements AdminVideoService {
                 ossService.setObjectScope(channelCode, uploadId, scope);
             }
 
-            VideoFile videoFile = new VideoFile(videoFileId, videoInfo);
             String videoId = videoPost.getVideoId();
+            VideoFile videoFile = new VideoFile(videoId, videoFileId, channelCode, videoInfo);
             videoRepository.updateVideoPublish(videoId, videoFile);
         } catch (Exception e) {
             e.printStackTrace();

+ 18 - 8
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/VideoService.java

@@ -2,6 +2,8 @@ package cn.reghao.tnb.content.app.vod.service;
 
 import cn.reghao.file.api.iface.OssService;
 import cn.reghao.jutil.jdk.result.Result;
+import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
+import cn.reghao.oss.sdk.model.dto.media.VideoUrlDto;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.api.constant.VideoErrorType;
 import cn.reghao.tnb.content.api.constant.VideoStatus;
@@ -13,6 +15,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.stereotype.Service;
 
+import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -26,11 +30,13 @@ public class VideoService {
     private OssService ossService;
 
     private final VideoPostMapper videoPostMapper;
+    private final VideoFileMapper videoFileMapper;
     private final VideoErrorMapper videoErrorMapper;
     private final Set<Long> adminUsers;
 
-    public VideoService(VideoPostMapper videoPostMapper, VideoErrorMapper videoErrorMapper) {
+    public VideoService(VideoPostMapper videoPostMapper, VideoFileMapper videoFileMapper, VideoErrorMapper videoErrorMapper) {
         this.videoPostMapper = videoPostMapper;
+        this.videoFileMapper = videoFileMapper;
         this.videoErrorMapper = videoErrorMapper;
         this.adminUsers = Set.of(10001L, 10002L);
     }
@@ -84,14 +90,18 @@ public class VideoService {
             return null;
         }
 
-        try {
-            int channelId = videoPost.getChannelId();
-            String videoFileId = videoPost.getVideoFileId();
-            String signedUrl = ossService.getSignedUrl(channelId, videoFileId);
-            return new DownloadUrl(signedUrl, "");
-        } catch (Exception e) {
-            e.printStackTrace();
+        List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
+        for (VideoUrlDto videoUrlDto : list) {
+            try {
+                int channelId = videoUrlDto.getChannelCode();
+                String videoFileId = videoUrlDto.getObjectId();
+                String signedUrl = ossService.getSignedUrl(channelId, videoFileId);
+                return new DownloadUrl(signedUrl, "");
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
+
         return null;
     }
 }

+ 3 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/VideoPlayServiceImpl.java

@@ -68,8 +68,7 @@ public class VideoPlayServiceImpl implements VideoPlayService {
         }
 
         VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
-        String videoFileId = videoPost.getVideoFileId();
-        List<VideoUrlDto> list = videoRepository.findVideoUrls(videoFileId);
+        List<VideoUrlDto> list = videoRepository.findVideoUrls(videoId);
         if (list.isEmpty()) {
             return new VideoUrls();
         }
@@ -83,10 +82,11 @@ public class VideoPlayServiceImpl implements VideoPlayService {
         }
 
         if (scope != PostScope.PUBLIC.getCode()) {
-            int channelId = videoPost.getChannelId();
             try {
                 List<VideoUrl> urls = list.stream().map(videoUrlDto -> {
                     try {
+                        int channelId = videoUrlDto.getChannelCode();
+                        String videoFileId = videoUrlDto.getObjectId();
                         String quality = videoUrlDto.getQuality();
                         String signedUrl = ossService.getSignedUrl(channelId, videoFileId);
                         return new VideoUrl(quality, signedUrl);

+ 19 - 9
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/VideoPostQueryImpl.java

@@ -6,6 +6,7 @@ import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
+import cn.reghao.oss.sdk.model.dto.media.VideoUrlDto;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.common.util.StringUtil;
 import cn.reghao.tnb.content.api.constant.PostScope;
@@ -48,6 +49,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
 
     private final int pageSize = 12;
     private final VideoPostMapper videoPostMapper;
+    private final VideoFileMapper videoFileMapper;
     private final VideoStatisticMapper videoStatisticMapper;
     private final VideoCategoryPostMapper videoCategoryPostMapper;
     private final VideoTagMapper videoTagMapper;
@@ -58,11 +60,12 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     private final Random random = new SecureRandom();
     private final IDObfuscation userIdObfuscation;
 
-    public VideoPostQueryImpl(VideoPostMapper videoPostMapper, VideoTagMapper videoTagMapper,
+    public VideoPostQueryImpl(VideoPostMapper videoPostMapper, VideoFileMapper videoFileMapper, VideoTagMapper videoTagMapper,
                               VideoStatisticMapper videoStatisticMapper, VideoCategoryPostMapper videoCategoryPostMapper,
                               ContentPermission contentPermission, CategoryService categoryService,
                               VideoRepository videoRepository, VideoPostTagMapper videoPostTagMapper) {
         this.videoPostMapper = videoPostMapper;
+        this.videoFileMapper = videoFileMapper;
         this.videoTagMapper = videoTagMapper;
         this.videoStatisticMapper = videoStatisticMapper;
         this.videoCategoryPostMapper = videoCategoryPostMapper;
@@ -268,9 +271,9 @@ public class VideoPostQueryImpl implements VideoPostQuery {
         int scope = videoPost.getScope();
         int status = videoPost.getStatus();
         int duration = videoPost.getDuration();
-        String quality = videoPost.getQuality();
+        String quality = "";
         String direction = videoPost.getHorizontal() ? "横屏" : "竖屏";
-        String codec = videoPost.getCodec();
+        String codec = "";
         return new UserVideoPost(videoId, title, description, coverUrl, pubDate, scope, status, duration, quality, direction, codec);
     }
 
@@ -290,13 +293,20 @@ public class VideoPostQueryImpl implements VideoPostQuery {
 
     public List<VideoInfo> getVideoResource(String videoId) {
         VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
+        if (videoPost == null) {
+            return Collections.emptyList();
+        }
+
         int channelId = 105;
-        String videoFileId = videoPost.getVideoFileId();
-        try {
-            VideoInfo videoInfo = ossService.getVideoInfo(channelId, videoFileId);
-            return videoInfo != null ? List.of(videoInfo) : Collections.emptyList();
-        } catch (Exception e) {
-            e.printStackTrace();
+        List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
+        for (VideoUrlDto videoUrlDto : list) {
+            String videoFileId = videoUrlDto.getObjectId();
+            try {
+                VideoInfo videoInfo = ossService.getVideoInfo(channelId, videoFileId);
+                return videoInfo != null ? List.of(videoInfo) : Collections.emptyList();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
 
         return Collections.emptyList();

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

@@ -6,6 +6,7 @@ import cn.reghao.jutil.jdk.result.Result;
 import cn.reghao.jutil.tool.id.IdGenerator;
 import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
 import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
+import cn.reghao.oss.sdk.model.dto.media.VideoUrlDto;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.api.constant.PostScope;
 import cn.reghao.tnb.content.api.constant.VideoStatus;
@@ -33,7 +34,7 @@ import java.util.*;
 @Slf4j
 @Service
 public class VideoPostServiceImpl implements VideoPostService {
-    @DubboReference(check = false)
+    @DubboReference(check = false, timeout = 60_000)
     private OssService ossService;
     @DubboReference(check = false)
     private JobService jobService;
@@ -43,17 +44,20 @@ public class VideoPostServiceImpl implements VideoPostService {
     private final VideoStatisticMapper videoStatisticMapper;
     private final VideoTagMapper videoTagMapper;
     private final VideoPostTagMapper videoPostTagMapper;
+    private final VideoFileMapper videoFileMapper;
     private final IdGenerator idGenerator;
     private final VideoRepository videoRepository;
     private final VideoCategoryPostMapper videoCategoryPostMapper;
 
     public VideoPostServiceImpl(VideoPostMapper videoPostMapper, VideoStatisticMapper videoStatisticMapper,
                                 VideoTagMapper videoTagMapper, VideoPostTagMapper videoPostTagMapper,
-                                VideoRepository videoRepository, VideoCategoryPostMapper videoCategoryPostMapper) {
+                                VideoFileMapper videoFileMapper, VideoRepository videoRepository,
+                                VideoCategoryPostMapper videoCategoryPostMapper) {
         this.videoPostMapper = videoPostMapper;
         this.videoStatisticMapper = videoStatisticMapper;
         this.videoTagMapper = videoTagMapper;
         this.videoPostTagMapper = videoPostTagMapper;
+        this.videoFileMapper = videoFileMapper;
         this.idGenerator = new IdGenerator("video-id");
         this.videoRepository = videoRepository;
         this.videoCategoryPostMapper = videoCategoryPostMapper;
@@ -79,7 +83,8 @@ public class VideoPostServiceImpl implements VideoPostService {
                 return Result.fail(errMsg);
             }
 
-            VideoFile videoFile = new VideoFile(videoInfo);
+            String videoId = idGenerator.getUuid();
+            VideoFile videoFile = new VideoFile(videoId, videoInfo, channelCode);
             String videoCodec = videoInfo.getVideoCodec();
             String audioCodec = videoInfo.getAudioCodec();
             if (audioCodec == null) {
@@ -98,7 +103,6 @@ public class VideoPostServiceImpl implements VideoPostService {
                 ossService.setObjectScope(channelCode, videoFileId, scope);
             }
 
-            String videoId = idGenerator.getUuid();
             Set<String> tags = videoPublishSbt.getTags();
             String tags1 = tags.toString().replace("[", "").replace("]", "");
 
@@ -223,19 +227,23 @@ public class VideoPostServiceImpl implements VideoPostService {
     }
 
     public void updateVideoScope(VideoScopeUpdate videoScopeUpdate) {
-        VideoPost videoPost = videoPostMapper.findByVideoId(videoScopeUpdate.getVideoId());
+        String videoId = videoScopeUpdate.getVideoId();
+        VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
         if (videoPost == null) {
             return;
         }
 
-        String videoFileId = videoPost.getVideoFileId();
-        try {
-            int channelId = videoPost.getChannelId();
-            int scope = videoScopeUpdate.getScope();
-            ossService.setObjectScope(channelId, videoFileId, scope);
-            videoPostMapper.updateVideoScope(videoScopeUpdate);
-        } catch (Exception e) {
-            e.printStackTrace();
+        List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
+        for (VideoUrlDto videoUrlDto : list) {
+            String videoFileId = videoUrlDto.getObjectId();
+            try {
+                int channelId = videoUrlDto.getChannelCode();
+                int scope = videoScopeUpdate.getScope();
+                ossService.setObjectScope(channelId, videoFileId, scope);
+                videoPostMapper.updateVideoScope(videoScopeUpdate);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 
@@ -287,25 +295,27 @@ public class VideoPostServiceImpl implements VideoPostService {
             return;
         }
 
-        String videoFileId = videoFileUpdate.getVideoFileId();
-        try {
-            int channelId = 101;
-            VideoInfo videoInfo = ossService.getVideoInfo(channelId, videoFileId);
-            if (videoInfo == null) {
-                log.error("{} not exist", videoFileId);
-                return;
-            }
+        List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
+        for (VideoUrlDto videoUrlDto : list) {
+            String videoFileId = videoFileUpdate.getVideoFileId();
+            try {
+                int channelId = 101;
+                VideoInfo videoInfo = ossService.getVideoInfo(channelId, videoFileId);
+                if (videoInfo == null) {
+                    log.error("{} not exist", videoFileId);
+                    return;
+                }
 
-            videoPostMapper.updateVideoFile(videoId, videoInfo);
-            int scope = videoPost.getScope();
-            if (scope != PostScope.PRIVATE.getCode()) {
-                ossService.setObjectScope(channelId, videoId, scope);
-            }
+                videoPostMapper.updateVideoFile(videoId, videoInfo);
+                int scope = videoPost.getScope();
+                if (scope != PostScope.PRIVATE.getCode()) {
+                    ossService.setObjectScope(channelId, videoId, scope);
+                }
 
-            String currentVideoFileId = videoPost.getVideoFileId();
-            ossService.deleteByObjectId(channelId, currentVideoFileId);
-        } catch (Exception e) {
-            e.printStackTrace();
+                ossService.deleteByObjectId(channelId, videoFileId);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 
@@ -318,12 +328,15 @@ public class VideoPostServiceImpl implements VideoPostService {
 
             String coverUrl = videoPost.getCoverUrl();
             deleteCoverFile(coverUrl);
-            String videoFileId = videoPost.getVideoFileId();
-            try {
-                int channelId = videoPost.getChannelId();
-                ossService.deleteByObjectId(channelId, videoFileId);
-            } catch (Exception e) {
-                e.printStackTrace();
+            List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
+            for (VideoUrlDto videoUrlDto : list) {
+                String videoFileId = videoUrlDto.getObjectId();
+                try {
+                    int channelId = videoUrlDto.getChannelCode();
+                    ossService.deleteByObjectId(channelId, videoFileId);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
             }
         }
     }

+ 10 - 8
content/content-service/src/main/resources/mapper/vod/VideoFileMapper.xml

@@ -4,16 +4,16 @@
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoFileMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into vod_video_file
-        (`video_file_id`,`object_id`,`video_codec`,`vbit_rate`,`audio_codec`,`abit_rate`,`format_name`,`url_type`,`url`,`quality`,`width`,`height`,`horizontal`,`duration`)
-        values 
-        (#{videoFileId},#{objectId},#{videoCodec},#{vbitRate},#{audioCodec},#{abitRate},#{formatName},#{urlType},#{url},#{quality},#{width},#{height},#{horizontal},#{duration})
+        (`video_id`,`video_file_id`,`object_id`,`channel_code`,`video_codec`,`vbit_rate`,`audio_codec`,`abit_rate`,`format_name`,`url_type`,`url`,`quality`,`width`,`height`,`horizontal`,`duration`)
+        values
+        (#{videoId},#{videoFileId},#{objectId},#{channelCode},#{videoCodec},#{vbitRate},#{audioCodec},#{abitRate},#{formatName},#{urlType},#{url},#{quality},#{width},#{height},#{horizontal},#{duration})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
         insert into vod_video_file
-        (`video_file_id`,`object_id`,`video_codec`,`vbit_rate`,`audio_codec`,`abit_rate`,`format_name`,`url_type`,`url`,`quality`,`width`,`height`,`horizontal`,`duration`)
+        (`video_id`,`video_file_id`,`object_id`,`channel_code`,`video_codec`,`vbit_rate`,`audio_codec`,`abit_rate`,`format_name`,`url_type`,`url`,`quality`,`width`,`height`,`horizontal`,`duration`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.videoFileId},#{item.objectId},#{item.videoCodec},#{item.vbitRate},#{item.audioCodec},#{item.abitRate},#{item.formatName},#{item.urlType},#{item.url},#{item.quality},#{item.width},#{item.height},#{item.horizontal},#{item.duration})
+            (#{item.videoId},#{item.videoFileId},#{item.objectId},#{item.channelCode},#{item.videoCodec},#{item.vbitRate},#{item.audioCodec},#{item.abitRate},#{item.formatName},#{item.urlType},#{item.url},#{item.quality},#{item.width},#{item.height},#{item.horizontal},#{item.duration})
         </foreach>
     </insert>
 
@@ -32,12 +32,14 @@
         where video_file_id=#{videoFileId}
     </select>
     <select id="findByVideoFileId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoFile">
-        select * from vod_video_file
+        select *
+        from vod_video_file
         where video_file_id=#{videoFileId}
     </select>
     <select id="findVideoUrls" resultType="cn.reghao.oss.sdk.model.dto.media.VideoUrlDto">
-        select url_type as type,url,width,height,quality
+        select video_file_id as object_id,channel_code,url_type as type,url,width,height,quality
         from vod_video_file
-        where video_file_id=#{videoFileId}
+        where video_id=#{videoId}
+        order by id desc
     </select>
 </mapper>

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

@@ -4,9 +4,9 @@
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into vod_video_post
-        (`video_id`,`video_file_id`,`channel_id`,`title`,`description`,`category_pid`,`category_id`,`cover_url`,`scope`,`status`,`horizontal`,`duration`,`quality`,`codec`,`publish_at`,`publish_by`)
+        (`video_id`,`title`,`description`,`category_pid`,`category_id`,`cover_url`,`scope`,`status`,`horizontal`,`duration`,`publish_at`,`publish_by`)
         values
-        (#{videoId},#{videoFileId},#{channelId},#{title},#{description},#{categoryPid},#{categoryId},#{coverUrl},#{scope},#{status},#{horizontal},#{duration},#{quality},#{codec},#{publishAt},#{publishBy})
+        (#{videoId},#{title},#{description},#{categoryPid},#{categoryId},#{coverUrl},#{scope},#{status},#{horizontal},#{duration},#{publishAt},#{publishBy})
     </insert>
 
     <update id="updateVideoScope">
@@ -26,7 +26,7 @@
     </update>
     <update id="updateVideoFile">
         update vod_video_post
-        set update_time=now(),video_file_id=#{videoInfo.videoFileId},duration=#{videoInfo.duration},quality=#{videoInfo.quality}
+        set update_time=now(),duration=#{videoInfo.duration},quality=#{videoInfo.quality}
         where video_id=#{videoId}
     </update>
     <update id="updateVideoStatus">
@@ -41,7 +41,7 @@
     </update>
     <update id="updateVideoCached">
         update vod_video_post
-        set update_time=now(),video_file_id=#{videoInfo.videoFileId},duration=#{videoInfo.duration},quality=#{videoInfo.quality},channel_id=#{channelId},`status`=2
+        set update_time=now(),duration=#{videoInfo.duration},`status`=2
         where video_id=#{videoId}
     </update>
 
@@ -334,7 +334,6 @@
 
     <resultMap id="videoDetail" type="cn.reghao.tnb.content.app.vod.model.vo.VideoDetail">
         <id column="video_id" property="videoId"/>
-        <id column="video_file_id" property="videoFileId"/>
         <result column="title" property="title"/>
         <result column="description" property="description"/>
         <result column="cover_url" property="coverUrl"/>
@@ -352,7 +351,7 @@
         <collection column="tag_name" property="tags" ofType="java.lang.String" select="findVideoTags"/>
     </resultMap>
     <select id="findVideoPostDetail" resultMap="videoDetail">
-        select post.publish_by,post.video_id,post.video_file_id,post.title,post.description,post.cover_url,post.duration,post.publish_at,post.scope,post.status,
+        select post.publish_by,post.video_id,post.title,post.description,post.cover_url,post.duration,post.publish_at,post.scope,post.status,
         statistic.view,statistic.danmaku,statistic.comment,statistic.thumb_up,
         statistic.favorite,statistic.share
         from vod_video_post post
@@ -462,11 +461,6 @@
         from vod_video_post
         where deleted=0 and video_id=#{videoId}
     </select>
-    <select id="findByVideoFileId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
-        select *
-        from vod_video_post
-        where deleted=0 and video_file_id=#{videoFileId}
-    </select>
     <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
         select *
         from vod_video_post