fix(智能媒体):发布任务完成监听器,如果任务状态为已完成则触发一键成片功能
This commit is contained in:
+21
-4
@@ -7,12 +7,10 @@ import com.central.order.enums.OrderStatus;
|
|||||||
import com.central.order.model.EditTask;
|
import com.central.order.model.EditTask;
|
||||||
import com.central.order.model.Order;
|
import com.central.order.model.Order;
|
||||||
import com.central.order.model.OrderFile;
|
import com.central.order.model.OrderFile;
|
||||||
|
import com.central.order.model.QrCode;
|
||||||
import com.central.order.model.dto.CallbackDTO;
|
import com.central.order.model.dto.CallbackDTO;
|
||||||
import com.central.order.model.params.EditTaskQueryParams;
|
import com.central.order.model.params.EditTaskQueryParams;
|
||||||
import com.central.order.service.IEditTaskService;
|
import com.central.order.service.*;
|
||||||
import com.central.order.service.IOrderFileService;
|
|
||||||
import com.central.order.service.IOrderService;
|
|
||||||
import com.central.order.service.IVideoEditService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -41,6 +39,8 @@ public class AutoCutVideoController {
|
|||||||
private IOrderFileService orderFileService;
|
private IOrderFileService orderFileService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IVideoEditService videoEditService;
|
private IVideoEditService videoEditService;
|
||||||
|
@Autowired
|
||||||
|
private IQrCodeService qrCodeService;
|
||||||
|
|
||||||
@Operation(summary = "根据订单号生成视频")
|
@Operation(summary = "根据订单号生成视频")
|
||||||
@PostMapping("/generate")
|
@PostMapping("/generate")
|
||||||
@@ -52,6 +52,14 @@ public class AutoCutVideoController {
|
|||||||
return Result.failed("订单状态不允许生成视频");
|
return Result.failed("订单状态不允许生成视频");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1. 检查是否开启一键成片
|
||||||
|
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||||
|
if (!isVideoEditEnabled(qrCode)) {
|
||||||
|
log.info("未开启一键成片功能: orderNo={}, codeId={}",
|
||||||
|
order.getOrderNo(), order.getCodeId());
|
||||||
|
return Result.failed("未开启一键成片功能");
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 检查是否存在进行中的任务
|
// 2. 检查是否存在进行中的任务
|
||||||
EditTask existingTask = editTaskService.getTaskByOrderSn(orderNo);
|
EditTask existingTask = editTaskService.getTaskByOrderSn(orderNo);
|
||||||
if (existingTask != null && EditTaskStatus.isProcessing(existingTask.getStatus())) {
|
if (existingTask != null && EditTaskStatus.isProcessing(existingTask.getStatus())) {
|
||||||
@@ -207,4 +215,13 @@ public class AutoCutVideoController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否开启一键成片功能
|
||||||
|
*/
|
||||||
|
private boolean isVideoEditEnabled(QrCode qrCode) {
|
||||||
|
return qrCode != null
|
||||||
|
&& qrCode.getEnableVideoEdit() != null
|
||||||
|
&& qrCode.getEnableVideoEdit() == 1
|
||||||
|
&& qrCode.getTemplateId() != null; // 确保有模板ID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-15
@@ -2,15 +2,11 @@ package com.central.order.listener;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.central.order.enums.MessageTemplateEnum;
|
import com.central.order.enums.MessageTemplateEnum;
|
||||||
|
import com.central.order.enums.OrderStatus;
|
||||||
import com.central.order.enums.OrderStatusChangeEnum;
|
import com.central.order.enums.OrderStatusChangeEnum;
|
||||||
import com.central.order.event.OrderStatusChangeEvent;
|
import com.central.order.event.OrderStatusChangeEvent;
|
||||||
import com.central.order.model.Message;
|
import com.central.order.model.*;
|
||||||
import com.central.order.model.Order;
|
import com.central.order.service.*;
|
||||||
import com.central.order.model.Tourism;
|
|
||||||
import com.central.order.service.IMessageService;
|
|
||||||
import com.central.order.service.IOrderService;
|
|
||||||
import com.central.order.service.ITourismService;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
@@ -20,6 +16,7 @@ import org.springframework.transaction.annotation.Propagation;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -30,7 +27,9 @@ public class OrderStatusChangeListener {
|
|||||||
private final IMessageService messageService;
|
private final IMessageService messageService;
|
||||||
private final ITourismService tourismService;
|
private final ITourismService tourismService;
|
||||||
private final IOrderService orderService;
|
private final IOrderService orderService;
|
||||||
private final ObjectMapper objectMapper;
|
private final IQrCodeService qrCodeService;
|
||||||
|
private final IVideoEditService videoEditService;
|
||||||
|
private final IOrderFileService orderFileService;
|
||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
@Async
|
@Async
|
||||||
@@ -109,19 +108,54 @@ public class OrderStatusChangeListener {
|
|||||||
|
|
||||||
log.info("站内信创建成功: userId={}", message.getUserId());
|
log.info("站内信创建成功: userId={}", message.getUserId());
|
||||||
|
|
||||||
|
// 订单完成时,检查是否需要触发一键成片
|
||||||
|
if (OrderStatus.COMPLETE.getId().equals(event.getNewStatus())) {
|
||||||
|
handleOrderComplete(order);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理订单状态变更事件失败", e);
|
log.error("处理订单状态变更事件失败", e);
|
||||||
throw new RuntimeException("处理订单状态变更事件失败", e);
|
throw new RuntimeException("处理订单状态变更事件失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer getMessageType(Integer orderStatus) {
|
/**
|
||||||
switch (orderStatus) {
|
* 处理订单完成逻辑
|
||||||
case 1: return 2; // 支付成功消息
|
*/
|
||||||
case 2: return 3; // 开始执行消息
|
private void handleOrderComplete(Order order) {
|
||||||
case 3: return 4; // 完成消息
|
try {
|
||||||
case 4: return 5; // 取消消息
|
// 1. 检查是否开启一键成片
|
||||||
default: return 1; // 其他消息
|
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
|
||||||
|
if (!isVideoEditEnabled(qrCode)) {
|
||||||
|
log.info("未开启一键成片功能: orderNo={}, codeId={}",
|
||||||
|
order.getOrderNo(), order.getCodeId());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. 获取订单视频文件
|
||||||
|
List<OrderFile> videoFiles = orderFileService.getOrderVideoFiles(order.getOrderNo());
|
||||||
|
if (videoFiles == null || videoFiles.isEmpty()) {
|
||||||
|
log.warn("未找到订单视频文件: orderNo={}", order.getOrderNo());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 提交视频编辑任务
|
||||||
|
String jobId = videoEditService.submitEditTask(order.getOrderNo(), videoFiles);
|
||||||
|
log.info("提交一键成片任务成功: orderNo={}, jobId={}", order.getOrderNo(), jobId);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 这里只记录错误,不抛出异常,避免影响订单状态变更的主流程
|
||||||
|
log.error("触发一键成片失败: orderNo={}", order.getOrderNo(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否开启一键成片功能
|
||||||
|
*/
|
||||||
|
private boolean isVideoEditEnabled(QrCode qrCode) {
|
||||||
|
return qrCode != null
|
||||||
|
&& qrCode.getEnableVideoEdit() != null
|
||||||
|
&& qrCode.getEnableVideoEdit() == 1
|
||||||
|
&& qrCode.getTemplateId() != null; // 确保有模板ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,4 @@ public class QrCode extends SuperEntity {
|
|||||||
@Schema(description = "是否开启一键成片")
|
@Schema(description = "是否开启一键成片")
|
||||||
private Integer enableVideoEdit;
|
private Integer enableVideoEdit;
|
||||||
|
|
||||||
/**
|
|
||||||
* 一键成片价格
|
|
||||||
*/
|
|
||||||
@Schema(description = "一键成片价格")
|
|
||||||
private BigDecimal videoEditPrice;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user