|
|
@@ -9,22 +9,24 @@ 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;
|
|
|
import cn.reghao.tnb.content.api.dto.VideoFilePublish;
|
|
|
import cn.reghao.tnb.content.api.dto.VideoFileUpdate;
|
|
|
import cn.reghao.tnb.content.api.dto.VideoPublishSbt;
|
|
|
-import cn.reghao.tnb.content.app.vod.db.mapper.*;
|
|
|
+import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
|
|
|
import cn.reghao.tnb.content.app.vod.db.repository.VideoRepository;
|
|
|
import cn.reghao.tnb.content.app.vod.model.dto.VideoCoverUpdate;
|
|
|
import cn.reghao.tnb.content.app.vod.model.dto.VideoInfoUpdate;
|
|
|
import cn.reghao.tnb.content.app.vod.model.dto.VideoScopeUpdate;
|
|
|
-import cn.reghao.tnb.content.app.vod.model.po.*;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.po.VideoFile;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.po.VideoStatistic;
|
|
|
+import cn.reghao.tnb.content.app.vod.service.CategoryService;
|
|
|
+import cn.reghao.tnb.content.app.vod.service.TagService;
|
|
|
import cn.reghao.tnb.content.app.vod.service.VideoPostService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -40,28 +42,19 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
@DubboReference(check = false)
|
|
|
private JobService jobService;
|
|
|
|
|
|
- private int pageSize = 12;
|
|
|
- private final VideoPostMapper videoPostMapper;
|
|
|
- private final VideoStatisticMapper videoStatisticMapper;
|
|
|
- private final VideoTagMapper videoTagMapper;
|
|
|
- private final VideoPostTagMapper videoPostTagMapper;
|
|
|
- private final VideoFileMapper videoFileMapper;
|
|
|
private final IdGenerator idGenerator;
|
|
|
+ private final VideoPostMapper videoPostMapper;
|
|
|
private final VideoRepository videoRepository;
|
|
|
- private final VideoCategoryPostMapper videoCategoryPostMapper;
|
|
|
+ private final TagService tagService;
|
|
|
+ private final CategoryService categoryService;
|
|
|
|
|
|
- public VideoPostServiceImpl(VideoPostMapper videoPostMapper, VideoStatisticMapper videoStatisticMapper,
|
|
|
- VideoTagMapper videoTagMapper, VideoPostTagMapper videoPostTagMapper,
|
|
|
- VideoFileMapper videoFileMapper, VideoRepository videoRepository,
|
|
|
- VideoCategoryPostMapper videoCategoryPostMapper) {
|
|
|
- this.videoPostMapper = videoPostMapper;
|
|
|
- this.videoStatisticMapper = videoStatisticMapper;
|
|
|
- this.videoTagMapper = videoTagMapper;
|
|
|
- this.videoPostTagMapper = videoPostTagMapper;
|
|
|
- this.videoFileMapper = videoFileMapper;
|
|
|
+ public VideoPostServiceImpl(VideoPostMapper videoPostMapper, VideoRepository videoRepository,
|
|
|
+ TagService tagService, CategoryService categoryService) {
|
|
|
this.idGenerator = new IdGenerator("video-id");
|
|
|
+ this.videoPostMapper = videoPostMapper;
|
|
|
this.videoRepository = videoRepository;
|
|
|
- this.videoCategoryPostMapper = videoCategoryPostMapper;
|
|
|
+ this.tagService = tagService;
|
|
|
+ this.categoryService = categoryService;
|
|
|
}
|
|
|
|
|
|
public String publishVideoFile(VideoFilePublish videoFilePublish) throws Exception {
|
|
|
@@ -99,13 +92,13 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
String coverUrl = imageInfo.getUrl();
|
|
|
|
|
|
String videoId = videoPublishSbt.getVideoId();
|
|
|
- VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
|
|
|
+ VideoPost videoPost = videoRepository.getVideoPost(videoId);
|
|
|
if (videoPost == null) {
|
|
|
String errMsg = String.format("VideoId %s 不存在", videoId);
|
|
|
return Result.fail(errMsg);
|
|
|
}
|
|
|
|
|
|
- List<VideoFile> videoFileList = videoFileMapper.findByVideoId(videoId);
|
|
|
+ List<VideoFile> videoFileList = videoRepository.getVideoFiles(videoId);
|
|
|
if (videoFileList.isEmpty()) {
|
|
|
String errMsg = String.format("VideoId %s 关联的视频文件不存在", videoId);
|
|
|
return Result.fail(errMsg);
|
|
|
@@ -155,84 +148,30 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
public void saveVideo(VideoPost videoPost, String tags) {
|
|
|
String videoId = videoPost.getVideoId();
|
|
|
VideoStatistic videoStatistic = new VideoStatistic(videoId);
|
|
|
- setVideoCategoryPost(videoPost);
|
|
|
videoRepository.savePostVideo(videoPost, videoStatistic);
|
|
|
- setVideoTags(videoId, videoPost.getScope(), tags);
|
|
|
+
|
|
|
+ tagService.addVideoTags(videoId, videoPost.getScope(), tags);
|
|
|
+ categoryService.setVideoCategoryPost(videoPost);
|
|
|
}
|
|
|
|
|
|
- @Deprecated
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
+ @Deprecated
|
|
|
public void saveVideo(VideoPost videoPost, VideoStatistic videoStatistic, String tags) {
|
|
|
- int categoryId = videoPost.getCategoryId();
|
|
|
- long publishBy = videoPost.getPublishBy();
|
|
|
- VideoCategoryPost videoCategoryPost = videoCategoryPostMapper.findByCategoryIdAndUserId(categoryId, publishBy);
|
|
|
- if (videoCategoryPost == null) {
|
|
|
- videoCategoryPost = new VideoCategoryPost(videoPost);
|
|
|
- videoCategoryPostMapper.save(videoCategoryPost);
|
|
|
- } else {
|
|
|
- videoCategoryPost.setVideoId(videoPost.getVideoId());
|
|
|
- videoCategoryPost.setScope(videoPost.getScope());
|
|
|
- videoCategoryPost.setPublishAt(videoPost.getPublishAt());
|
|
|
- videoCategoryPostMapper.updateVideoCategoryPost(videoCategoryPost);
|
|
|
- }
|
|
|
+ videoRepository.savePostVideo(videoPost, videoStatistic);
|
|
|
|
|
|
String videoId = videoPost.getVideoId();
|
|
|
- videoPostMapper.save(videoPost);
|
|
|
- videoStatisticMapper.save(videoStatistic);
|
|
|
- setVideoTags(videoId, videoPost.getScope(), tags);
|
|
|
- }
|
|
|
-
|
|
|
- private void setVideoCategoryPost(VideoPost videoPost) {
|
|
|
- int categoryId = videoPost.getCategoryId();
|
|
|
- long publishBy = videoPost.getPublishBy();
|
|
|
- VideoCategoryPost videoCategoryPost = videoCategoryPostMapper.findByCategoryIdAndUserId(categoryId, publishBy);
|
|
|
- if (videoCategoryPost == null) {
|
|
|
- videoCategoryPost = new VideoCategoryPost(videoPost);
|
|
|
- videoCategoryPostMapper.save(videoCategoryPost);
|
|
|
- } else {
|
|
|
- videoCategoryPost.setVideoId(videoPost.getVideoId());
|
|
|
- videoCategoryPost.setScope(videoPost.getScope());
|
|
|
- videoCategoryPost.setPublishAt(videoPost.getPublishAt());
|
|
|
- videoCategoryPostMapper.updateVideoCategoryPost(videoCategoryPost);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void setVideoTags(String videoId, int scope, String tags) {
|
|
|
- if (tags.isBlank()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- List<VideoTag> list = new ArrayList<>();
|
|
|
- List<VideoPostTag> list1 = new ArrayList<>();
|
|
|
- for (String str : tags.split(",")) {
|
|
|
- String tag = StringUtils.trimAllWhitespace(str);
|
|
|
- VideoTag videoTag = videoTagMapper.findByName(tag);
|
|
|
- if (videoTag != null) {
|
|
|
- list1.add(new VideoPostTag(videoId, scope, videoTag.getTagId()));
|
|
|
- } else {
|
|
|
- String tagId = UUID.randomUUID().toString().replace("-", "");
|
|
|
- list.add(new VideoTag(tagId, tag));
|
|
|
- list1.add(new VideoPostTag(videoId, scope, tagId));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!list.isEmpty()) {
|
|
|
- videoTagMapper.saveAll(list);
|
|
|
- }
|
|
|
-
|
|
|
- if (!list1.isEmpty()) {
|
|
|
- videoPostTagMapper.saveAll(list1);
|
|
|
- }
|
|
|
+ tagService.addVideoTags(videoId, videoPost.getScope(), tags);
|
|
|
+ categoryService.setVideoCategoryPost(videoPost);
|
|
|
}
|
|
|
|
|
|
public void updateVideoScope(VideoScopeUpdate videoScopeUpdate) {
|
|
|
String videoId = videoScopeUpdate.getVideoId();
|
|
|
- VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
|
|
|
+ VideoPost videoPost = videoRepository.getVideoPost(videoId);
|
|
|
if (videoPost == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
|
|
|
+ List<VideoUrlDto> list = videoRepository.getVideoUrls(videoId);
|
|
|
for (VideoUrlDto videoUrlDto : list) {
|
|
|
String videoFileId = videoUrlDto.getObjectId();
|
|
|
try {
|
|
|
@@ -247,7 +186,8 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
}
|
|
|
|
|
|
public void updateVideoInfo(VideoInfoUpdate videoInfoUpdate) {
|
|
|
- VideoPost videoPost = videoPostMapper.findByVideoId(videoInfoUpdate.getVideoId());
|
|
|
+ String videoId = videoInfoUpdate.getVideoId();
|
|
|
+ VideoPost videoPost = videoRepository.getVideoPost(videoId);
|
|
|
if (videoPost == null) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -257,7 +197,7 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
|
|
|
public void updateVideoCover(VideoCoverUpdate videoCoverUpdate) {
|
|
|
String videoId = videoCoverUpdate.getVideoId();
|
|
|
- VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
|
|
|
+ VideoPost videoPost = videoRepository.getVideoPost(videoId);
|
|
|
if (videoPost == null) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -289,12 +229,12 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
|
|
|
public void updateVideoFile(VideoFileUpdate videoFileUpdate) {
|
|
|
String videoId = videoFileUpdate.getVideoId();
|
|
|
- VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
|
|
|
+ VideoPost videoPost = videoRepository.getVideoPost(videoId);
|
|
|
if (videoPost == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
|
|
|
+ List<VideoUrlDto> list = videoRepository.getVideoUrls(videoId);
|
|
|
for (VideoUrlDto videoUrlDto : list) {
|
|
|
String videoFileId = videoFileUpdate.getVideoFileId();
|
|
|
try {
|
|
|
@@ -319,7 +259,7 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
}
|
|
|
|
|
|
public void deleteVideo(String videoId) {
|
|
|
- VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
|
|
|
+ VideoPost videoPost = videoRepository.getVideoPost(videoId);
|
|
|
long owner = videoPost.getPublishBy();
|
|
|
if (owner == UserContext.getUserId()) {
|
|
|
// 删除 videoId 关联的所有数据, 包括观看记录, 用户收藏, 视频数据, 视频标签, 推荐数据等
|
|
|
@@ -327,7 +267,7 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
|
|
|
String coverUrl = videoPost.getCoverUrl();
|
|
|
deleteCoverFile(coverUrl);
|
|
|
- List<VideoUrlDto> list = videoFileMapper.findVideoUrls(videoId);
|
|
|
+ List<VideoUrlDto> list = videoRepository.getVideoUrls(videoId);
|
|
|
for (VideoUrlDto videoUrlDto : list) {
|
|
|
String videoFileId = videoUrlDto.getObjectId();
|
|
|
try {
|