|
|
@@ -0,0 +1,101 @@
|
|
|
+package cn.reghao.tnb.content.app.vod.service;
|
|
|
+
|
|
|
+import cn.reghao.jutil.jdk.result.Result;
|
|
|
+import cn.reghao.tnb.common.auth.UserContext;
|
|
|
+import cn.reghao.tnb.content.api.constant.VideoErrorType;
|
|
|
+import cn.reghao.tnb.content.api.constant.VideoStatus;
|
|
|
+import cn.reghao.tnb.content.app.vod.db.mapper.VideoErrorMapper;
|
|
|
+import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
|
|
|
+import cn.reghao.tnb.content.app.vod.db.mapper.VipTagMapper;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.dto.VideoEdit;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.dto.VideoErrorReport;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.dto.VideoVipTags;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.po.VideoError;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.po.VipTag;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2025-08-02 20:12:44
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class VideoEditService {
|
|
|
+ private final VideoPostMapper videoPostMapper;
|
|
|
+ private final VipTagMapper vipTagMapper;
|
|
|
+ private final VideoErrorMapper videoErrorMapper;
|
|
|
+ private final Set<Long> adminUsers = Set.of(10001L, 10002L);
|
|
|
+
|
|
|
+ public VideoEditService(VideoPostMapper videoPostMapper, VipTagMapper vipTagMapper,
|
|
|
+ VideoErrorMapper videoErrorMapper) {
|
|
|
+ this.videoPostMapper = videoPostMapper;
|
|
|
+ this.vipTagMapper = vipTagMapper;
|
|
|
+ this.videoErrorMapper = videoErrorMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result errorReport(VideoErrorReport videoErrorReport) {
|
|
|
+ long loginUser = UserContext.getUser();
|
|
|
+ if (!adminUsers.contains(loginUser)) {
|
|
|
+ return Result.fail("no permission");
|
|
|
+ }
|
|
|
+
|
|
|
+ String videoId = videoErrorReport.getVideoId();
|
|
|
+ int errCode = videoErrorReport.getErrorCode();
|
|
|
+ VideoErrorType errorType = VideoErrorType.getDescByCode(errCode);
|
|
|
+ int videoStatus;
|
|
|
+ switch (errorType) {
|
|
|
+ case noCover:
|
|
|
+ case noAudio:
|
|
|
+ case noVideo:
|
|
|
+ videoStatus = VideoStatus.needRepair.getCode();
|
|
|
+ break;
|
|
|
+ case noResource:
|
|
|
+ videoStatus = VideoStatus.revoke.getCode();
|
|
|
+ break;
|
|
|
+ case hasAd:
|
|
|
+ videoStatus = VideoStatus.hasAd.getCode();
|
|
|
+ break;
|
|
|
+ case needRestore:
|
|
|
+ videoStatus = VideoStatus.needRestore.getCode();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return Result.fail("unknown errorType");
|
|
|
+ }
|
|
|
+
|
|
|
+ videoPostMapper.updateVideoStatus(videoId, videoStatus);
|
|
|
+ if (videoStatus != VideoStatus.revoke.getCode() || videoStatus != VideoStatus.needRestore.getCode()) {
|
|
|
+ VideoError videoError = new VideoError(videoErrorReport);
|
|
|
+ videoErrorMapper.save(videoError);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateVideoOwner(VideoEdit videoEdit) {
|
|
|
+ long newUserId = videoEdit.getNewUserId();
|
|
|
+ videoPostMapper.updateVideoUser(newUserId, videoEdit.getVideoIds());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<VipTag> getVipTags() {
|
|
|
+ List<VipTag> list = vipTagMapper.findAll();
|
|
|
+ Map<Integer, List<VipTag>> groupMap = list.stream().collect(Collectors.groupingBy(VipTag::getPid));
|
|
|
+ List<VipTag> parents = groupMap.get(0);
|
|
|
+ for (VipTag parent : parents) {
|
|
|
+ int id = parent.getId();
|
|
|
+ parent.setChildren(groupMap.get(id));
|
|
|
+ }
|
|
|
+ return parents;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addVipTags(VideoVipTags videoVipTags) {
|
|
|
+ String videoId = videoVipTags.getVideoId();
|
|
|
+ List<String> tags = videoVipTags.getTags();
|
|
|
+ log.info("{} -> {}", videoId, tags);
|
|
|
+ }
|
|
|
+}
|