fix(智能媒体):一键成片功能完善
This commit is contained in:
@@ -86,4 +86,16 @@ public class QrCode extends SuperEntity {
|
||||
*/
|
||||
@Schema(description = "是否开启分润")
|
||||
private Integer enableProfit;
|
||||
|
||||
/**
|
||||
* 是否开启一键成片(0:否,1:是)
|
||||
*/
|
||||
@Schema(description = "是否开启一键成片")
|
||||
private Integer enableVideoEdit;
|
||||
|
||||
/**
|
||||
* 一键成片价格
|
||||
*/
|
||||
@Schema(description = "一键成片价格")
|
||||
private BigDecimal videoEditPrice;
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.central.order.scheduler;
|
||||
|
||||
import com.central.order.constants.EditTaskStatus;
|
||||
import com.central.order.model.EditTask;
|
||||
import com.central.order.service.IEditTaskService;
|
||||
import com.central.order.service.IVideoEditService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class VideoEditTaskChecker {
|
||||
|
||||
@Autowired
|
||||
private IEditTaskService editTaskService;
|
||||
@Autowired
|
||||
private IVideoEditService videoEditService;
|
||||
|
||||
// 每30秒检查一次任务状态
|
||||
@Scheduled(fixedRate = 30000)
|
||||
public void checkEditTasks() {
|
||||
try {
|
||||
// 获取所有处理中的任务
|
||||
List<EditTask> processingTasks = editTaskService.getProcessingTasks();
|
||||
|
||||
for (EditTask task : processingTasks) {
|
||||
try {
|
||||
// 检查任务是否超时
|
||||
if (isTaskTimeout(task)) {
|
||||
editTaskService.updateTaskStatus(task.getJobId(),
|
||||
EditTaskStatus.FAILED, "任务超时");
|
||||
continue;
|
||||
}
|
||||
|
||||
videoEditService.handleEditStatus(task.getJobId());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("检查任务状态失败: taskId={}", task.getJobId(), e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("执行任务状态检查失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTaskTimeout(EditTask task) {
|
||||
// 假设2小时超时
|
||||
return System.currentTimeMillis() - task.getCreateTime().getTime() > 7200000;
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -5,6 +5,8 @@ import com.central.common.model.PageResult;
|
||||
import com.central.order.model.EditTask;
|
||||
import com.central.order.model.params.EditTaskQueryParams;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 视频编辑任务服务接口
|
||||
*/
|
||||
@@ -58,4 +60,17 @@ public interface IEditTaskService extends IService<EditTask> {
|
||||
* 删除剪辑任务
|
||||
*/
|
||||
boolean deleteTask(Integer id);
|
||||
|
||||
/**
|
||||
* 获取处理中的任务列表
|
||||
* @return 处理中的任务列表
|
||||
*/
|
||||
List<EditTask> getProcessingTasks();
|
||||
|
||||
/**
|
||||
* 根据jobId获取编辑任务
|
||||
* @param jobId 任务ID
|
||||
* @return 编辑任务信息
|
||||
*/
|
||||
EditTask getByJobId(String jobId);
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,5 +24,5 @@ public interface IVideoEditService {
|
||||
* @param jobId 任务ID
|
||||
* @return 任务状态
|
||||
*/
|
||||
VideoEditStatus queryEditStatus(String jobId);
|
||||
VideoEditStatus handleEditStatus(String jobId);
|
||||
}
|
||||
|
||||
+35
@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 视频编辑任务服务实现类
|
||||
@@ -27,6 +28,8 @@ import java.util.Date;
|
||||
@RequiredArgsConstructor
|
||||
public class EditTaskServiceImpl extends ServiceImpl<EditTaskMapper, EditTask> implements IEditTaskService {
|
||||
|
||||
private final EditTaskMapper editTaskMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public EditTask createTask(String orderSn, Long userId) {
|
||||
@@ -162,6 +165,38 @@ public class EditTaskServiceImpl extends ServiceImpl<EditTaskMapper, EditTask> i
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EditTask> getProcessingTasks() {
|
||||
try {
|
||||
LambdaQueryWrapper<EditTask> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EditTask::getStatus, EditTaskStatus.PROCESSING)
|
||||
.orderByAsc(EditTask::getCreateTime);
|
||||
return editTaskMapper.selectList(wrapper);
|
||||
} catch (Exception e) {
|
||||
log.error("获取处理中的任务列表失败", e);
|
||||
throw new BusinessException("获取处理中的任务列表失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditTask getByJobId(String jobId) {
|
||||
try {
|
||||
LambdaQueryWrapper<EditTask> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EditTask::getJobId, jobId)
|
||||
.last("LIMIT 1"); // 确保只返回一条记录
|
||||
|
||||
EditTask task = editTaskMapper.selectOne(wrapper);
|
||||
if (task == null) {
|
||||
log.warn("未找到编辑任务: jobId={}", jobId);
|
||||
}
|
||||
return task;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("查询编辑任务失败: jobId={}", jobId, e);
|
||||
throw new BusinessException("查询编辑任务失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证任务参数
|
||||
*/
|
||||
|
||||
+151
-116
@@ -1,7 +1,6 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.aliyun.sdk.service.ice20201109.AsyncClient;
|
||||
import com.aliyun.sdk.service.ice20201109.models.GetMediaProducingJobRequest;
|
||||
import com.aliyun.sdk.service.ice20201109.models.GetMediaProducingJobResponse;
|
||||
@@ -17,6 +16,8 @@ import com.central.order.service.IMediaService;
|
||||
import com.central.order.service.IOrderFileService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -34,6 +35,10 @@ import java.util.concurrent.TimeoutException;
|
||||
@RequiredArgsConstructor
|
||||
public class MediaServiceImpl implements IMediaService {
|
||||
|
||||
private static final int TASK_SUBMIT_TIMEOUT = 30;
|
||||
private static final int TASK_QUERY_TIMEOUT = 10;
|
||||
private static final String OUTPUT_PATH_FORMAT = "output/%s_%s.mp4";
|
||||
|
||||
@Autowired
|
||||
private AsyncClient imsClient;
|
||||
@Autowired
|
||||
@@ -50,63 +55,20 @@ public class MediaServiceImpl implements IMediaService {
|
||||
@Override
|
||||
public String submitEditTask(String orderNo, List<OrderFile> orderFiles) {
|
||||
try {
|
||||
// 1. 获取订单信息
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
// 1. 验证并获取必要数据
|
||||
TaskSubmitData taskData = validateAndGetTaskData(orderNo, orderFiles);
|
||||
|
||||
// 2. 获取二维码信息
|
||||
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||
if (qrCode == null || qrCode.getTemplateId() == null) {
|
||||
throw new BusinessException("未配置视频模板ID");
|
||||
}
|
||||
// 2. 构建请求参数
|
||||
SubmitMediaProducingJobRequest request = buildSubmitRequest(taskData);
|
||||
|
||||
// 3. 获取订单视频文件
|
||||
List<OrderFile> videoFiles = orderFileService.getOrderVideoFiles(orderNo);
|
||||
if (videoFiles == null || videoFiles.size() < 2) {
|
||||
throw new BusinessException("订单视频文件数量不足,至少需要2个视频文件");
|
||||
}
|
||||
// 3. 提交任务
|
||||
return submitTask(request, taskData);
|
||||
|
||||
// 构建并验证参数
|
||||
String clipsParam = buildClipsParam(orderNo, videoFiles);
|
||||
String outputConfig = buildOutputConfig(orderNo);
|
||||
String userData = buildUserData(order, qrCode);
|
||||
|
||||
// 打印完整的请求参数用于调试
|
||||
log.info("提交任务参数: orderNo={}, templateId={}", orderNo, qrCode.getTemplateId());
|
||||
log.info("clips参数: {}", clipsParam);
|
||||
log.info("输出配置: {}", outputConfig);
|
||||
log.info("用户数据: {}", userData);
|
||||
|
||||
// 构建请求
|
||||
SubmitMediaProducingJobRequest request = SubmitMediaProducingJobRequest.builder()
|
||||
.templateId(qrCode.getTemplateId())
|
||||
.clipsParam(clipsParam)
|
||||
.outputMediaConfig(outputConfig)
|
||||
.userData(userData)
|
||||
.build();
|
||||
|
||||
// 提交任务
|
||||
CompletableFuture<SubmitMediaProducingJobResponse> future =
|
||||
imsClient.submitMediaProducingJob(request);
|
||||
SubmitMediaProducingJobResponse response = future.get(30, TimeUnit.SECONDS);
|
||||
|
||||
// 6. 处理响应
|
||||
if (response != null && response.getBody() != null) {
|
||||
String jobId = response.getBody().getJobId();
|
||||
log.info("提交智能一键成片任务成功: orderNo={}, jobId={}, templateId={}",
|
||||
orderNo, jobId, qrCode.getTemplateId());
|
||||
return jobId;
|
||||
} else {
|
||||
throw new BusinessException("提交任务失败: 响应为空");
|
||||
}
|
||||
|
||||
} catch (TimeoutException e) {
|
||||
log.error("提交任务超时: orderNo={}", orderNo, e);
|
||||
throw new BusinessException("提交任务超时");
|
||||
} catch (BusinessException e) {
|
||||
log.error("提交编辑任务失败: orderNo={}, error={}", orderNo, e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("提交智能一键成片任务失败: orderNo={}, error={}", orderNo, e.getMessage(), e);
|
||||
log.error("提交编辑任务异常: orderNo={}", orderNo, e);
|
||||
throw new BusinessException("提交任务失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -118,15 +80,10 @@ public class MediaServiceImpl implements IMediaService {
|
||||
.jobId(jobId)
|
||||
.build();
|
||||
|
||||
CompletableFuture<GetMediaProducingJobResponse> future =
|
||||
imsClient.getMediaProducingJob(request);
|
||||
GetMediaProducingJobResponse response = future.get(10, TimeUnit.SECONDS);
|
||||
CompletableFuture<GetMediaProducingJobResponse> future = imsClient.getMediaProducingJob(request);
|
||||
GetMediaProducingJobResponse response = future.get(TASK_QUERY_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
||||
if (response != null && response.getBody() != null
|
||||
&& response.getBody().getMediaProducingJob() != null) {
|
||||
return response.getBody().getMediaProducingJob().getStatus();
|
||||
}
|
||||
return "UNKNOWN";
|
||||
return extractTaskStatus(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("查询任务状态失败: jobId={}", jobId, e);
|
||||
@@ -137,16 +94,19 @@ public class MediaServiceImpl implements IMediaService {
|
||||
@Override
|
||||
public String getTaskResult(String jobId) {
|
||||
try {
|
||||
GetMediaProducingJobRequest getMediaProducingJobRequest =
|
||||
GetMediaProducingJobRequest
|
||||
.builder()
|
||||
.jobId(jobId)
|
||||
.build();
|
||||
CompletableFuture<GetMediaProducingJobResponse> response =
|
||||
imsClient.getMediaProducingJob(getMediaProducingJobRequest);
|
||||
GetMediaProducingJobResponse resp = response.get();
|
||||
return new Gson().toJson(resp);
|
||||
GetMediaProducingJobRequest request = GetMediaProducingJobRequest.builder()
|
||||
.jobId(jobId)
|
||||
.build();
|
||||
|
||||
CompletableFuture<GetMediaProducingJobResponse> future = imsClient.getMediaProducingJob(request);
|
||||
GetMediaProducingJobResponse response = future.get(TASK_QUERY_TIMEOUT, TimeUnit.SECONDS);
|
||||
log.info("查询剪辑任务RESPONSE: {}", response.toString());
|
||||
if (response != null && response.getBody() != null
|
||||
&& response.getBody().getMediaProducingJob() != null) {
|
||||
// 返回输出URL
|
||||
return response.getBody().getMediaProducingJob().getMediaURL();
|
||||
}
|
||||
throw new BusinessException("获取任务结果失败: 响应为空");
|
||||
} catch (Exception e) {
|
||||
log.error("获取任务结果失败: jobId={}", jobId, e);
|
||||
throw new BusinessException("获取任务结果失败: " + e.getMessage());
|
||||
@@ -154,49 +114,84 @@ public class MediaServiceImpl implements IMediaService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建用户数据
|
||||
* 验证并获取任务数据
|
||||
*/
|
||||
private String buildUserData(Order order, QrCode qrCode) {
|
||||
try {
|
||||
Map<String, Object> userData = new HashMap<>();
|
||||
// 订单信息
|
||||
userData.put("orderNo", order.getOrderNo());
|
||||
userData.put("orderId", order.getId());
|
||||
// 二维码信息
|
||||
userData.put("codeId", order.getCodeId());
|
||||
userData.put("templateId", qrCode.getTemplateId());
|
||||
// 其他信息
|
||||
userData.put("timestamp", System.currentTimeMillis());
|
||||
userData.put("source", "order_center");
|
||||
private TaskSubmitData validateAndGetTaskData(String orderNo, List<OrderFile> orderFiles) {
|
||||
// 1. 获取订单信息
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
String userDataJson = JSON.toJSONString(userData);
|
||||
log.debug("用户数据: {}", userDataJson);
|
||||
return userDataJson;
|
||||
// 2. 获取二维码信息
|
||||
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||
if (qrCode == null || qrCode.getTemplateId() == null) {
|
||||
throw new BusinessException("未配置视频模板ID");
|
||||
}
|
||||
|
||||
// 3. 获取视频文件
|
||||
List<OrderFile> videoFiles = orderFileService.getOrderVideoFiles(orderNo);
|
||||
if (videoFiles == null || videoFiles.size() < 2) {
|
||||
throw new BusinessException("订单视频文件数量不足,至少需要2个视频文件");
|
||||
}
|
||||
|
||||
return new TaskSubmitData(order, qrCode, videoFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建提交请求
|
||||
*/
|
||||
private SubmitMediaProducingJobRequest buildSubmitRequest(TaskSubmitData taskData) {
|
||||
String clipsParam = buildClipsParam(taskData);
|
||||
String outputConfig = buildOutputConfig(taskData.getOrder().getOrderNo());
|
||||
String userData = buildUserData(taskData);
|
||||
|
||||
// 打印请求参数
|
||||
logRequestParams(taskData, clipsParam, outputConfig, userData);
|
||||
|
||||
return SubmitMediaProducingJobRequest.builder()
|
||||
.templateId(taskData.getQrCode().getTemplateId())
|
||||
.clipsParam(clipsParam)
|
||||
.outputMediaConfig(outputConfig)
|
||||
.userData(userData)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交任务
|
||||
*/
|
||||
private String submitTask(SubmitMediaProducingJobRequest request, TaskSubmitData taskData) {
|
||||
try {
|
||||
CompletableFuture<SubmitMediaProducingJobResponse> future = imsClient.submitMediaProducingJob(request);
|
||||
SubmitMediaProducingJobResponse response = future.get(TASK_SUBMIT_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
||||
if (response != null && response.getBody() != null) {
|
||||
String jobId = response.getBody().getJobId();
|
||||
log.info("提交智能一键成片任务成功: orderNo={}, jobId={}, templateId={}",
|
||||
taskData.getOrder().getOrderNo(), jobId, taskData.getQrCode().getTemplateId());
|
||||
return jobId;
|
||||
}
|
||||
throw new BusinessException("提交任务失败: 响应为空");
|
||||
} catch (TimeoutException e) {
|
||||
throw new BusinessException("提交任务超时");
|
||||
} catch (Exception e) {
|
||||
log.error("构建用户数据失败: orderNo={}", order.getOrderNo(), e);
|
||||
throw new BusinessException("构建用户数据失败: " + e.getMessage());
|
||||
throw new BusinessException("提交任务失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建剪辑参数
|
||||
*/
|
||||
private String buildClipsParam(String orderNo, List<OrderFile> videoFiles) {
|
||||
private String buildClipsParam(TaskSubmitData taskData) {
|
||||
try {
|
||||
Map<String, String> clips = new HashMap<>();
|
||||
List<OrderFile> videoFiles = taskData.getVideoFiles();
|
||||
|
||||
// 使用完整的OSS URL
|
||||
String firstUrl = fileCenterService.getViewUrlByPath(videoFiles.get(0).getFilePath());
|
||||
clips.put("1", firstUrl);
|
||||
clips.put("1", fileCenterService.getViewUrlByPath(videoFiles.get(0).getFilePath()));
|
||||
clips.put("2", fileCenterService.getViewUrlByPath(videoFiles.get(1).getFilePath()));
|
||||
|
||||
String secondUrl = fileCenterService.getViewUrlByPath(videoFiles.get(1).getFilePath());
|
||||
clips.put("2", secondUrl);
|
||||
|
||||
String clipsJson = JSON.toJSONString(clips);
|
||||
log.info("剪辑参数: orderNo={}, clips={}", orderNo, clipsJson);
|
||||
return clipsJson;
|
||||
return JSON.toJSONString(clips);
|
||||
} catch (Exception e) {
|
||||
log.error("构建剪辑参数失败: orderNo={}", orderNo, e);
|
||||
throw new BusinessException("构建剪辑参数失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -207,33 +202,73 @@ public class MediaServiceImpl implements IMediaService {
|
||||
private String buildOutputConfig(String orderNo) {
|
||||
try {
|
||||
Map<String, String> config = new HashMap<>();
|
||||
// 使用正确的OSS路径格式
|
||||
config.put("MediaURL", String.format("https://"+imsConfig.getBucket()+"."+imsConfig.getOssEndpoint()+"/output/%s_%s.mp4",
|
||||
String outputUrl = String.format("https://%s.%s/" + OUTPUT_PATH_FORMAT,
|
||||
imsConfig.getBucket(),
|
||||
imsConfig.getOssEndpoint(),
|
||||
orderNo,
|
||||
System.currentTimeMillis()
|
||||
));
|
||||
|
||||
String configJson = JSON.toJSONString(config);
|
||||
log.info("输出配置: {}", configJson);
|
||||
return configJson;
|
||||
);
|
||||
config.put("MediaURL", outputUrl);
|
||||
return JSON.toJSONString(config);
|
||||
} catch (Exception e) {
|
||||
log.error("构建输出配置失败: orderNo={}", orderNo, e);
|
||||
throw new BusinessException("构建输出配置失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取媒体URL
|
||||
* 构建用户数据
|
||||
*/
|
||||
private String getMediaUrl(String filePath) {
|
||||
private String buildUserData(TaskSubmitData taskData) {
|
||||
try {
|
||||
return String.format("https://goflyapp.%s/picture/%s",
|
||||
imsConfig.getOssEndpoint(),
|
||||
filePath
|
||||
);
|
||||
Map<String, Object> userData = new HashMap<>();
|
||||
Order order = taskData.getOrder();
|
||||
QrCode qrCode = taskData.getQrCode();
|
||||
|
||||
userData.put("orderNo", order.getOrderNo());
|
||||
userData.put("orderId", order.getId());
|
||||
userData.put("codeId", order.getCodeId());
|
||||
userData.put("templateId", qrCode.getTemplateId());
|
||||
userData.put("timestamp", System.currentTimeMillis());
|
||||
userData.put("source", "order_center");
|
||||
|
||||
return JSON.toJSONString(userData);
|
||||
} catch (Exception e) {
|
||||
log.error("生成媒体URL失败: filePath={}", filePath, e);
|
||||
throw new BusinessException("生成媒体URL失败: " + e.getMessage());
|
||||
throw new BusinessException("构建用户数据失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取任务状态
|
||||
*/
|
||||
private String extractTaskStatus(GetMediaProducingJobResponse response) {
|
||||
if (response != null && response.getBody() != null
|
||||
&& response.getBody().getMediaProducingJob() != null) {
|
||||
return response.getBody().getMediaProducingJob().getStatus();
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录请求参数
|
||||
*/
|
||||
private void logRequestParams(TaskSubmitData taskData, String clipsParam,
|
||||
String outputConfig, String userData) {
|
||||
log.info("提交任务参数: orderNo={}, templateId={}",
|
||||
taskData.getOrder().getOrderNo(), taskData.getQrCode().getTemplateId());
|
||||
log.info("clips参数: {}", clipsParam);
|
||||
log.info("输出配置: {}", outputConfig);
|
||||
log.info("用户数据: {}", userData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 任务提交数据封装类
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
private static class TaskSubmitData {
|
||||
private Order order;
|
||||
private QrCode qrCode;
|
||||
private List<OrderFile> videoFiles;
|
||||
}
|
||||
}
|
||||
|
||||
+119
-8
@@ -1,17 +1,21 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.central.common.exception.BusinessException;
|
||||
import com.central.common.model.FileInfo;
|
||||
import com.central.order.constants.EditTaskStatus;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.model.EditTask;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.order.model.OrderFile;
|
||||
import com.central.order.model.dto.VideoEditStatus;
|
||||
import com.central.order.service.IEditTaskService;
|
||||
import com.central.order.service.IMediaService;
|
||||
import com.central.order.service.IVideoEditService;
|
||||
import com.central.order.service.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -21,9 +25,16 @@ import java.util.List;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VideoEditServiceImpl implements IVideoEditService {
|
||||
|
||||
private final IMediaService mediaService;
|
||||
private final IEditTaskService editTaskService;
|
||||
@Autowired
|
||||
private IMediaService mediaService;
|
||||
@Autowired
|
||||
private IEditTaskService editTaskService;
|
||||
@Autowired
|
||||
private IOrderFileService orderFileService;
|
||||
@Autowired
|
||||
private FileCenterService fileCenterService;
|
||||
@Autowired
|
||||
private IOrderService orderService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -43,13 +54,113 @@ public class VideoEditServiceImpl implements IVideoEditService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoEditStatus queryEditStatus(String jobId) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public VideoEditStatus handleEditStatus(String jobId) {
|
||||
try {
|
||||
// 1. 获取任务信息
|
||||
EditTask task = editTaskService.getByJobId(jobId);
|
||||
if (task == null) {
|
||||
throw new BusinessException("任务不存在");
|
||||
}
|
||||
|
||||
// 2. 获取任务状态
|
||||
String status = mediaService.getTaskStatus(jobId);
|
||||
return VideoEditStatus.fromCode(status);
|
||||
VideoEditStatus editStatus = VideoEditStatus.fromCode(status);
|
||||
|
||||
// 3. 处理不同状态
|
||||
switch (editStatus) {
|
||||
case SUCCESS:
|
||||
handleTaskSuccess(jobId, task);
|
||||
break;
|
||||
case FAIL:
|
||||
handleTaskFailed(jobId, task);
|
||||
break;
|
||||
case RUNNING:
|
||||
// 继续处理中,不需要更新
|
||||
break;
|
||||
default:
|
||||
log.warn("未知的任务状态: jobId={}, status={}", jobId, status);
|
||||
}
|
||||
|
||||
return editStatus;
|
||||
} catch (Exception e) {
|
||||
log.error("查询任务状态失败: jobId={}", jobId, e);
|
||||
throw new BusinessException("查询任务状态失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理任务成功
|
||||
*/
|
||||
private void handleTaskSuccess(String jobId, EditTask task) {
|
||||
try {
|
||||
// 1. 获取输出URL
|
||||
String outputUrl = mediaService.getTaskResult(jobId);
|
||||
if (outputUrl == null || outputUrl.isEmpty()) {
|
||||
throw new BusinessException("获取输出URL失败");
|
||||
}
|
||||
|
||||
// 2. 保存视频文件记录
|
||||
saveOutputVideo(task.getOrderSn(), outputUrl);
|
||||
|
||||
// 3. 更新任务状态
|
||||
editTaskService.updateTaskStatus(jobId, EditTaskStatus.COMPLETED, null);
|
||||
|
||||
log.info("视频编辑任务处理完成: jobId={}, orderNo={}, outputUrl={}",
|
||||
jobId, task.getOrderSn(), outputUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("处理任务成功状态失败: jobId={}", jobId, e);
|
||||
throw new BusinessException("处理任务成功状态失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理任务失败
|
||||
*/
|
||||
private void handleTaskFailed(String jobId, EditTask task) {
|
||||
try {
|
||||
editTaskService.updateTaskStatus(jobId, EditTaskStatus.FAILED, "任务处理失败");
|
||||
log.warn("视频编辑任务失败: jobId={}, orderNo={}", jobId, task.getOrderSn());
|
||||
} catch (Exception e) {
|
||||
log.error("处理任务失败状态失败: jobId={}", jobId, e);
|
||||
throw new BusinessException("处理任务失败状态失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存输出视频信息
|
||||
*/
|
||||
private void saveOutputVideo(String orderNo, String outputUrl) {
|
||||
try {
|
||||
FileInfo fileInfo = fileCenterService.creatFileInfo(outputUrl);
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
|
||||
OrderFile orderFile = new OrderFile();
|
||||
orderFile.setFileId(fileInfo.getId());
|
||||
orderFile.setOrderNo(orderNo);
|
||||
orderFile.setFileType("video/mp4");
|
||||
orderFile.setFilePath(extractFilePath(outputUrl));
|
||||
orderFile.setUserId(order.getUserId());
|
||||
orderFile.setTourismId(order.getTourismId());
|
||||
orderFileService.save(orderFile);
|
||||
} catch (Exception e) {
|
||||
log.error("保存输出视频信息失败: orderNo={}, outputUrl={}", orderNo, outputUrl, e);
|
||||
throw new BusinessException("保存视频信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从URL提取文件路径
|
||||
*/
|
||||
private String extractFilePath(String outputUrl) {
|
||||
try {
|
||||
// 假设URL格式为: https://bucket.endpoint/output/xxx.mp4
|
||||
String[] parts = outputUrl.split("/");
|
||||
return String.join("/", Arrays.copyOfRange(parts, 3, parts.length));
|
||||
} catch (Exception e) {
|
||||
log.error("提取文件路径失败: outputUrl={}", outputUrl, e);
|
||||
throw new BusinessException("提取文件路径失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-1
@@ -7,7 +7,7 @@ import {
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Form } from 'antd';
|
||||
import { ENABLE_PROFIT_OPTIONS, PAYEE_TYPE_OPTIONS } from '../index';
|
||||
import { ENABLE_PROFIT_OPTIONS, PAYEE_TYPE_OPTIONS, ENABLE_VIDEO_EDIT_OPTIONS } from '../index';
|
||||
|
||||
interface CreateFormProps {
|
||||
visible: boolean;
|
||||
@@ -163,6 +163,17 @@ const CreateForm: React.FC<CreateFormProps> = ({
|
||||
disabled={enableProfit === 0}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="enableVideoEdit"
|
||||
label="是否开启一键成片"
|
||||
options={ENABLE_VIDEO_EDIT_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否开启一键成片' }]}
|
||||
initialValue={0}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
+11
-1
@@ -6,7 +6,7 @@ import {
|
||||
ProFormText,
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
import { STATUS_OPTIONS, PAYEE_TYPE_OPTIONS, ENABLE_PROFIT_OPTIONS } from '../index';
|
||||
import { STATUS_OPTIONS, PAYEE_TYPE_OPTIONS, ENABLE_PROFIT_OPTIONS, ENABLE_VIDEO_EDIT_OPTIONS } from '../index';
|
||||
import { Form, Space } from 'antd';
|
||||
import styles from './index.less';
|
||||
|
||||
@@ -165,6 +165,16 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
disabled={enableProfit === 0}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="enableVideoEdit"
|
||||
label="是否开启一键成片"
|
||||
options={ENABLE_VIDEO_EDIT_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择是否开启一键成片' }]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -49,6 +49,12 @@ export const ENABLE_PROFIT_OPTIONS = [
|
||||
{ label: '是', value: 1 },
|
||||
] as const;
|
||||
|
||||
// 添加一键成片状态常量
|
||||
export const ENABLE_VIDEO_EDIT_OPTIONS = [
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
] as const;
|
||||
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
@@ -384,6 +390,20 @@ const TableList: React.FC = () => {
|
||||
'PERSONAL_OPENID': { text: '个人openid' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '是否开启一键成片',
|
||||
dataIndex: 'enableVideoEdit',
|
||||
width: 140,
|
||||
render: (_, record) => {
|
||||
const status = record.enableVideoEdit === 1 ? '是' : '否';
|
||||
const color = record.enableVideoEdit === 1 ? 'green' : 'default';
|
||||
return <Tag color={color}>{status}</Tag>;
|
||||
},
|
||||
valueEnum: {
|
||||
0: { text: '否' },
|
||||
1: { text: '是' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
|
||||
Reference in New Issue
Block a user