|
|
@@ -45,16 +45,18 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
private final VideoPostTagMapper videoPostTagMapper;
|
|
|
private final IdGenerator idGenerator;
|
|
|
private final VideoRepository videoRepository;
|
|
|
+ private final VideoCategoryPostMapper videoCategoryPostMapper;
|
|
|
|
|
|
public VideoPostServiceImpl(VideoPostMapper videoPostMapper, VideoStatisticMapper videoStatisticMapper,
|
|
|
VideoTagMapper videoTagMapper, VideoPostTagMapper videoPostTagMapper,
|
|
|
- VideoRepository videoRepository) {
|
|
|
+ VideoRepository videoRepository, VideoCategoryPostMapper videoCategoryPostMapper) {
|
|
|
this.videoPostMapper = videoPostMapper;
|
|
|
this.videoStatisticMapper = videoStatisticMapper;
|
|
|
this.videoTagMapper = videoTagMapper;
|
|
|
this.videoPostTagMapper = videoPostTagMapper;
|
|
|
this.idGenerator = new IdGenerator("video-id");
|
|
|
this.videoRepository = videoRepository;
|
|
|
+ this.videoCategoryPostMapper = videoCategoryPostMapper;
|
|
|
}
|
|
|
|
|
|
public Result publishVideo(VideoPublishSbt videoPublishSbt) {
|
|
|
@@ -141,6 +143,7 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
public void saveVideo(VideoFile videoFile, VideoPost videoPost, String tags) {
|
|
|
String videoId = videoPost.getVideoId();
|
|
|
VideoStatistic videoStatistic = new VideoStatistic(videoId);
|
|
|
+ setVideoCategoryPost(videoPost);
|
|
|
videoRepository.savePostVideo(videoFile, videoPost, videoStatistic);
|
|
|
setVideoTags(videoId, tags);
|
|
|
}
|
|
|
@@ -148,12 +151,40 @@ public class VideoPostServiceImpl implements VideoPostService {
|
|
|
@Deprecated
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
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);
|
|
|
+ }
|
|
|
+
|
|
|
String videoId = videoPost.getVideoId();
|
|
|
videoPostMapper.save(videoPost);
|
|
|
videoStatisticMapper.save(videoStatistic);
|
|
|
setVideoTags(videoId, 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, String tags) {
|
|
|
if (tags.isBlank()) {
|
|
|
return;
|