浏览代码

添加转码

ct 2 天之前
父节点
当前提交
0b652bf02b

+ 30 - 23
fs-admin/src/main/java/com/fs/course/task/VideoTask.java

@@ -282,30 +282,37 @@ public class VideoTask {
                 Integer rewardType = config.getRewardType();
                 if (rewardType != null && rewardType == 2) {
                     List<FsCourseWatchLog> watchingLogs = courseWatchLogMapper.findWatchLogsIdExitAndFinish();
-                    //查询积分记录 是否存在
-                    for (FsCourseWatchLog watchingLog : watchingLogs) {
-                        FsUserIntegralLogs queryParam = new FsUserIntegralLogs();
-                        queryParam.setUserId(watchingLog.getUserId());
-                        queryParam.setBusinessId(watchingLog.getLogId().toString());
-                        queryParam.setLogType(FsUserIntegralLogTypeEnum.TYPE_17.getValue());
+                    if (watchingLogs != null && !watchingLogs.isEmpty()) {
                         //查询积分记录 是否存在
-                        Long num = fsUserIntegralLogsMapper.selectFsUserIntegralLogsListCOUNT(queryParam);
-                        if (num == null || num == 0){
-                            FsCourseSendRewardUParam param = new FsCourseSendRewardUParam();
-                            param.setIsAuto(1);
-                            param.setVideoId(watchingLog.getVideoId());
-                            param.setQwUserId(watchingLog.getQwUserId().toString());
-                            param.setCompanyUserId(watchingLog.getCompanyUserId());
-                            param.setCompanyId(watchingLog.getCompanyId());
-                            param.setCourseId(watchingLog.getCourseId());
-                            param.setQwExternalId(watchingLog.getQwExternalContactId());
-                            param.setSource(watchingLog.getWatchType() == 2?2:1);
-                            param.setSendType(watchingLog.getSendType());
-                            param.setPeriodId(watchingLog.getPeriodId());
-                            param.setUserId(watchingLog.getUserId());
-                            param.setAppId("");
-                            courseVideoService.sendRewardByFsUser(param);
-                            log.info("补发积分 userId:{},watchLogsId:{}",watchingLog.getUserId(),watchingLog.getLogId());
+                        for (FsCourseWatchLog watchingLog : watchingLogs) {
+                            FsUserIntegralLogs queryParam = new FsUserIntegralLogs();
+                            queryParam.setUserId(watchingLog.getUserId());
+                            queryParam.setBusinessId(watchingLog.getLogId().toString());
+                            queryParam.setLogType(FsUserIntegralLogTypeEnum.TYPE_17.getValue());
+                            //查询积分记录 是否存在
+                            Long num = fsUserIntegralLogsMapper.selectFsUserIntegralLogsListCOUNT(queryParam);
+                            if (num == null || num == 0){
+                                try {
+                                    FsCourseSendRewardUParam param = new FsCourseSendRewardUParam();
+                                    param.setIsAuto(1);
+                                    param.setVideoId(watchingLog.getVideoId());
+                                    param.setQwUserId(watchingLog.getQwUserId().toString());
+                                    param.setCompanyUserId(watchingLog.getCompanyUserId());
+                                    param.setCompanyId(watchingLog.getCompanyId());
+                                    param.setCourseId(watchingLog.getCourseId());
+                                    param.setQwExternalId(watchingLog.getQwExternalContactId());
+                                    param.setSource(watchingLog.getWatchType() == 2?2:1);
+                                    param.setSendType(watchingLog.getSendType());
+                                    param.setPeriodId(watchingLog.getPeriodId());
+                                    param.setUserId(watchingLog.getUserId());
+                                    param.setAppId("");
+                                    courseVideoService.sendRewardByFsUser(param);
+                                    log.info("补发积分 userId:{},watchLogsId:{}",watchingLog.getUserId(),watchingLog.getLogId());
+                                } catch (Exception e) {
+                                    log.error("补发积分失败 userId:{},watchLogsId:{}",watchingLog.getUserId(),watchingLog.getLogId());
+                                    continue;
+                                }
+                            }
                         }
                     }
                 }

+ 38 - 0
fs-company-app/src/main/java/com/fs/app/controller/CommonController.java

@@ -1,6 +1,7 @@
 package com.fs.app.controller;
 
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.jiguang.common.resp.APIConnectionException;
 import cn.jiguang.common.resp.APIRequestException;
 import com.fs.app.annotation.Login;
@@ -19,6 +20,7 @@ import com.fs.company.service.ICompanySmsLogsService;
 import com.fs.company.service.ICompanyUserService;
 import com.fs.company.service.ICompanyVoiceLogsService;
 import com.fs.core.config.ServerConfig;
+import com.fs.course.service.ITencentCloudCosService;
 import com.fs.crm.service.*;
 import com.fs.his.domain.FsCity;
 import com.fs.his.service.IFsAppVersionService;
@@ -103,6 +105,9 @@ public class CommonController extends AppBaseController {
 	@Autowired
 	private ICrmCustomerContactsService crmCustomerContactsService;
 
+	@Autowired
+	private ITencentCloudCosService tencentCloudCosService;
+
 	public static final Logger LOGGER = LoggerFactory.getLogger(CommonController.class);
 
 
@@ -239,5 +244,38 @@ public class CommonController extends AppBaseController {
 		return R.ok();
 	}
 
+	/**
+	 * 手动转码
+	 *
+	 * @param videoId
+	 * @return
+	 */
+	@GetMapping("/videoTranscodeByVideoId")
+	public R videoTranscode(Long videoId)
+	{
+		if (ObjectUtil.isNull(videoId)){
+			return R.error("videoId 不能为空");
+		}
+		return R.ok(tencentCloudCosService.videoTranscode(videoId));
+	}
+
+	/**
+	 * 手动更改转码成功数据
+	 * @param videoId
+	 * @param taskId
+	 * @return
+	 */
+	@GetMapping("/updateUrlByVideo")
+	public R updateUrl(Long videoId, String taskId)
+	{
+		if (ObjectUtil.isNull(videoId)){
+			return R.error("videoId 不能为空");
+		}
+		if (ObjectUtil.isNull(taskId)){
+			return R.error("taskId 不能为空");
+		}
+		return R.ok(tencentCloudCosService.updateUrl(videoId, taskId));
+	}
+
 
 }

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

@@ -10,10 +10,12 @@ public interface ITencentCloudCosService {
 
     R getKeyAndCredentials();
 
-//    byte[] getQcloudByte();
+    //    byte[] getQcloudByte();
     R updateUrl();
+    R updateUrl(Long videoId, String taskId);
 
     R videoTranscode();
+    R videoTranscode(Long videoId);
 
 
 }

+ 110 - 2
fs-service/src/main/java/com/fs/course/service/impl/TencentCloudCosService.java

@@ -19,6 +19,7 @@ import com.tencent.cloud.Response;
 import com.tencent.cloud.Statement;
 import com.tencent.cloud.cos.util.Jackson;
 import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
 import com.tencentcloudapi.common.profile.ClientProfile;
 import com.tencentcloudapi.common.profile.HttpProfile;
 import com.tencentcloudapi.mps.v20190612.MpsClient;
@@ -205,7 +206,7 @@ public class TencentCloudCosService implements ITencentCloudCosService {
     // 为每个视频更新使用独立事务
     @Transactional(propagation = Propagation.REQUIRES_NEW)
     public void updateSingleVideo(FsVideoResource video) {
-        String newUrl = replaceCourse(video.getLine1());
+        String newUrl = replaceCourse(video.getVideoUrl());
 
         FsVideoResource videoMap = new FsVideoResource();
         videoMap.setId(video.getId());
@@ -290,7 +291,7 @@ public class TencentCloudCosService implements ITencentCloudCosService {
         return input.replace("course", "course_transcode_100301");
     }
 
-    public void submitTranscodeJob(String inputPath,String outputPath) {
+    public String submitTranscodeJob(String inputPath,String outputPath) {
         try {
             // 输入文件配置(COS路径)
             MpsClient client = createMpsClient();
@@ -332,8 +333,115 @@ public class TencentCloudCosService implements ITencentCloudCosService {
             // 提交任务
             ProcessMediaResponse resp = client.ProcessMedia(req);
             System.out.println("任务提交成功,JobId: " + resp.getTaskId());
+            return resp.getTaskId();
         } catch (Exception e) {
             e.printStackTrace();
         }
+        return null;
     }
+
+
+    @Override
+    public R videoTranscode(Long videoId) {
+        FsUserCourseVideo fsUserCourseVideo = courseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
+        //查出未转码的视频
+        FsVideoResource video =  videoResourceMapper.selectByFileKey(fsUserCourseVideo.getFileKey());
+        String inputPath = "/"+video.getFileKey();
+        String outputPath = "/"+replaceCourse(video.getFileKey());
+        String taskId = submitTranscodeJob(inputPath,outputPath);
+        FsVideoResource videoMap = new FsVideoResource();
+        videoMap.setId(video.getId());
+        videoMap.setIsTranscode(1);
+        videoResourceMapper.updateById(videoMap);
+
+        return R.ok(taskId);
+    }
+    /**
+     * 简单查询任务状态(基于你提供的JSON结构)
+     */
+    public static boolean queryTaskSimple(MpsClient client, String taskId) throws TencentCloudSDKException {
+        DescribeTaskDetailRequest req = new DescribeTaskDetailRequest();
+        req.setTaskId(taskId);
+
+        DescribeTaskDetailResponse resp = client.DescribeTaskDetail(req);
+
+        System.out.println("任务查询结果:");
+        System.out.println("任务ID: " + taskId);
+        System.out.println("主状态: " + resp.getStatus());
+        System.out.println("任务类型: " + resp.getTaskType());
+        System.out.println("创建时间: " + resp.getCreateTime());
+
+        if (resp.getFinishTime() != null && !resp.getFinishTime().isEmpty()) {
+            System.out.println("完成时间: " + resp.getFinishTime());
+        }
+
+        String status = resp.getStatus();
+
+        // 判断任务状态
+        switch (status) {
+            case "PROCESSING":
+                System.out.println("任务处理中...");
+                return true;
+
+            case "FINISH":
+                // 检查工作流任务详情
+                WorkflowTask workflowTask = resp.getWorkflowTask();
+                if (workflowTask == null) {
+                    return false;
+                }
+
+                System.out.println("工作流状态: " + workflowTask.getStatus());
+                System.out.println("工作流消息: " + workflowTask.getMessage());
+
+                // 如果工作流状态不是FINISH,说明可能没真正完成
+                if (!"FINISH".equals(workflowTask.getStatus())) {
+                    return true;
+                }
+
+                // 检查错误码
+                if (workflowTask.getErrCode() != null && workflowTask.getErrCode() != 0) {
+                    return false;
+                }
+
+                System.out.println("任务已完成");
+                return false;
+
+            case "FAIL":
+                System.out.println("任务失败");
+                // 打印失败详情
+                printFailureDetails(resp);
+                return false;
+
+            default:
+                System.out.println("未知状态: " + status);
+                return true;
+        }
+    }
+
+    private static void printFailureDetails(DescribeTaskDetailResponse resp) {
+        WorkflowTask workflowTask = resp.getWorkflowTask();
+        if (workflowTask != null) {
+            System.out.println("工作流错误码: " + workflowTask.getErrCode());
+            System.out.println("工作流错误消息: " + workflowTask.getMessage());
+        }
+    }
+
+    @Override
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    public R updateUrl(Long videoId, String taskId) {
+        try {
+            MpsClient client = createMpsClient();
+            if (queryTaskSimple(client,taskId)){
+                return R.error("未完成请稍后在操作!");
+            }
+            FsUserCourseVideo fsUserCourseVideo = courseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
+            //查出未转码的视频
+            FsVideoResource video =  videoResourceMapper.selectByFileKey(fsUserCourseVideo.getFileKey());
+            updateSingleVideo(video);
+            return R.ok();
+        } catch (Exception e) {
+            return R.error(e.getMessage());
+        }
+    }
+
 }