You've already forked FrameTour-BE
feat(task): 添加渲染预览任务创建功能
- 引入渲染相关DTO和服务类用于预览任务创建 - 移除未使用的消息生产者和通知认证工具依赖 - 在任务创建后异步触发渲染预览任务生成 - 实现虚拟线程异步处理渲染预览任务创建逻辑 - 添加素材映射转换支持视频和图片类型识别 - 实现异常捕获确保主流程不受渲染服务影响
This commit is contained in:
@@ -9,6 +9,10 @@ import com.ycwl.basic.integration.common.manager.DeviceConfigManager;
|
||||
import com.ycwl.basic.integration.common.manager.RenderWorkerConfigManager;
|
||||
import com.ycwl.basic.integration.common.manager.ScenicConfigManager;
|
||||
import com.ycwl.basic.integration.message.service.ZtMessageProducerService;
|
||||
import com.ycwl.basic.integration.render.dto.job.CreatePreviewRequest;
|
||||
import com.ycwl.basic.integration.render.dto.job.CreatePreviewResponse;
|
||||
import com.ycwl.basic.integration.render.dto.job.MaterialDTO;
|
||||
import com.ycwl.basic.integration.render.service.RenderJobIntegrationService;
|
||||
import com.ycwl.basic.repository.MemberRelationRepository;
|
||||
import com.ycwl.basic.repository.SourceRepository;
|
||||
import com.ycwl.basic.utils.JacksonUtil;
|
||||
@@ -115,13 +119,11 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
@Autowired
|
||||
private MemberRelationRepository memberRelationRepository;
|
||||
@Autowired
|
||||
private ZtMessageProducerService ztMessageProducerService;
|
||||
@Autowired
|
||||
private NotificationAuthUtils notificationAuthUtils;
|
||||
@Autowired
|
||||
private WechatSubscribeNotifyTriggerService notifyTriggerService;
|
||||
@Autowired
|
||||
private FaceStatusManager faceStatusManager;
|
||||
@Autowired
|
||||
private RenderJobIntegrationService renderJobIntegrationService;
|
||||
|
||||
private RenderWorkerEntity getWorker(@NonNull WorkerAuthReqVo req) {
|
||||
String accessKey = req.getAccessKey();
|
||||
@@ -462,6 +464,8 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
} else {
|
||||
taskMapper.add(taskEntity);
|
||||
}
|
||||
// 灰度测试:创建渲染预览任务(异步,不影响主流程)
|
||||
tryCreateRenderPreviewJobAsync(taskEntity.getId(), templateId, face.getScenicId(), faceId, face.getMemberId(), sourcesMap);
|
||||
memberVideoEntity.setTaskId(taskEntity.getId());
|
||||
} else {
|
||||
TaskRespVO existingTask = list.getFirst();
|
||||
@@ -667,4 +671,55 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
public TaskRespVO taskInfo(Long taskId) {
|
||||
return taskMapper.getById(taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 灰度测试:异步创建渲染预览任务
|
||||
* 不管zt-render-worker服务返回什么或者报错,都不影响现有流程
|
||||
*/
|
||||
private void tryCreateRenderPreviewJobAsync(Long taskId, Long templateId, Long scenicId, Long faceId, Long memberId, Map<String, List<SourceEntity>> sourcesMap) {
|
||||
Thread.ofVirtual().start(() -> {
|
||||
try {
|
||||
log.info("[灰度测试] 开始创建渲染预览任务, taskId: {}, templateId: {}, scenicId: {}, faceId: {}",
|
||||
taskId, templateId, scenicId, faceId);
|
||||
|
||||
CreatePreviewRequest request = new CreatePreviewRequest();
|
||||
request.setTemplateId(templateId);
|
||||
request.setScenicId(scenicId);
|
||||
request.setFaceId(faceId);
|
||||
request.setMemberId(memberId);
|
||||
|
||||
// 转换素材映射
|
||||
Map<String, List<MaterialDTO>> materialsBySlot = new java.util.HashMap<>();
|
||||
if (sourcesMap != null && !sourcesMap.isEmpty()) {
|
||||
sourcesMap.forEach((slotKey, sources) -> {
|
||||
List<MaterialDTO> materials = sources.stream()
|
||||
.map(source -> {
|
||||
MaterialDTO material = new MaterialDTO();
|
||||
// 优先使用videoUrl,其次使用url
|
||||
if (StringUtils.isNotBlank(source.getVideoUrl())) {
|
||||
material.setUrl(source.getVideoUrl());
|
||||
material.setType("video");
|
||||
} else {
|
||||
material.setUrl(source.getUrl());
|
||||
material.setType(source.getType() != null && source.getType() == 2 ? "image" : "video");
|
||||
}
|
||||
material.setFacePos(source.getPosJson());
|
||||
return material;
|
||||
})
|
||||
.toList();
|
||||
materialsBySlot.put(slotKey, materials);
|
||||
});
|
||||
}
|
||||
request.setMaterialsBySlot(materialsBySlot);
|
||||
|
||||
CreatePreviewResponse response = renderJobIntegrationService.createPreview(request);
|
||||
log.info("[灰度测试] 渲染预览任务创建成功, taskId: {}, renderJobId: {}, playUrl: {}",
|
||||
taskId, response.getJobId(), response.getPlayUrl());
|
||||
} catch (Exception e) {
|
||||
// 灰度测试:不管返回什么或者报错,都不影响现有流程
|
||||
log.warn("[灰度测试] 渲染预览任务创建失败,不影响主流程, taskId: {}, templateId: {}, error: {}",
|
||||
taskId, templateId, e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user