Prechádzať zdrojové kódy

单挑视频转码定时任务

wjj 21 hodín pred
rodič
commit
9d350f4741

+ 10 - 0
fs-admin/src/main/java/com/fs/his/task/Task.java

@@ -656,11 +656,21 @@ public class Task {
         tencentCloudCosService.videoTranscode();
     }
 
+    public void videoTranscodeById(String videoId) throws Exception {
+
+        tencentCloudCosService.videoTranscodeById(Long.parseLong(videoId));
+    }
+
     public void updateUrl() throws Exception {
 
         tencentCloudCosService.updateUrl();
     }
 
+    public void updateUrlById(String videoId) throws Exception {
+
+        tencentCloudCosService.updateUrlByVideoId(Long.parseLong(videoId));
+    }
+
     public void addPrescribeImg() throws Exception {
         List<Long> ids = fsPrescribeService.selectFsPrescribeByPrescribeIdByOrderType();
         for (Long id : ids) {

+ 3 - 0
fs-service/src/main/java/com/fs/course/mapper/FsVideoResourceMapper.java

@@ -22,6 +22,9 @@ public interface FsVideoResourceMapper extends BaseMapper<FsVideoResource> {
     @Select("select * from fs_video_resource where line1 is not null and is_transcode = 0 and is_del = 0")
     List<FsVideoResource> selectVideoNotTranscode();
 
+    @Select("select * from fs_video_resource where video_url = #{videoUrl} and is_transcode = 0 and is_del = 0")
+    FsVideoResource selectVideoByVideoUrl(String videoUrl);
+
 
     @Select("select * from fs_video_resource where file_key = 'course/20251020/1760932918788.mp4'")
     List<FsVideoResource> selectVideoNotTranscodeTest();

+ 3 - 0
fs-service/src/main/java/com/fs/course/service/ITencentCloudCosService.java

@@ -12,8 +12,11 @@ public interface ITencentCloudCosService {
 
 //    byte[] getQcloudByte();
     R updateUrl();
+    R updateUrlByVideoId(Long videoId);
 
     R videoTranscode();
 
+    R videoTranscodeById(Long videoId);
+
 
 }

+ 36 - 0
fs-service/src/main/java/com/fs/course/service/impl/TencentCloudCosService.java

@@ -39,6 +39,7 @@ import java.util.*;
 public class TencentCloudCosService implements ITencentCloudCosService {
     private final COSClient cosClient;
     private final TencentProperties tencentProperties;
+    private final FsUserCourseVideoMapper fsUserCourseVideoMapper;
 
 
     @Override
@@ -202,6 +203,23 @@ public class TencentCloudCosService implements ITencentCloudCosService {
         }
     }
 
+    @Override
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    public R updateUrlByVideoId(Long videoId) {
+        try {
+            FsUserCourseVideo courseVideo = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
+            if (courseVideo != null) {
+                FsVideoResource video = videoResourceMapper.selectVideoByVideoUrl(courseVideo.getVideoUrl());
+                if (video != null) {
+                    updateSingleVideo(video); // 将单个视频更新逻辑提取到方法
+                }
+            }
+            return R.ok();
+        } catch (Exception e) {
+            return R.error(e.getMessage());
+        }
+    }
+
     // 为每个视频更新使用独立事务
     @Transactional(propagation = Propagation.REQUIRES_NEW)
     public void updateSingleVideo(FsVideoResource video) {
@@ -275,6 +293,24 @@ public class TencentCloudCosService implements ITencentCloudCosService {
         return R.ok();
     }
 
+    @Override
+    public R videoTranscodeById(Long videoId) {
+        FsUserCourseVideo courseVideo = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
+        if (courseVideo != null) {
+            FsVideoResource video = videoResourceMapper.selectVideoByVideoUrl(courseVideo.getVideoUrl());
+            if (video != null) {
+                String inputPath = "/"+video.getFileKey();
+                String outputPath = "/"+replaceCourse(video.getFileKey());
+                submitTranscodeJob(inputPath,outputPath);
+                FsVideoResource videoMap = new FsVideoResource();
+                videoMap.setId(video.getId());
+                videoMap.setIsTranscode(1);
+                videoResourceMapper.updateById(videoMap);
+            }
+        }
+        return R.ok();
+    }
+
     private MpsClient createMpsClient() {
         Credential cred = new Credential(tencentProperties.secretId, tencentProperties.secretKey);
         HttpProfile httpProfile = new HttpProfile();