|
@@ -2,7 +2,18 @@ package com.tzld.piaoquan.content.understanding.rocketmq.consumer;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.tzld.piaoquan.content.understanding.common.enums.ExceptionEnum;
|
|
|
+import com.tzld.piaoquan.content.understanding.common.enums.TaskStatusEnum;
|
|
|
+import com.tzld.piaoquan.content.understanding.common.exception.CommonException;
|
|
|
+import com.tzld.piaoquan.content.understanding.dao.mapper.CuPipelineMapper;
|
|
|
+import com.tzld.piaoquan.content.understanding.dao.mapper.CuPipelineStepMapper;
|
|
|
+import com.tzld.piaoquan.content.understanding.dao.mapper.CuTaskMapper;
|
|
|
+import com.tzld.piaoquan.content.understanding.model.dto.ContentAnalyseDTO;
|
|
|
+import com.tzld.piaoquan.content.understanding.model.dto.PipelineTaskMessageDTO;
|
|
|
+import com.tzld.piaoquan.content.understanding.model.dto.TreeNode;
|
|
|
+import com.tzld.piaoquan.content.understanding.model.po.*;
|
|
|
import com.tzld.piaoquan.content.understanding.service.ContentService;
|
|
|
+import com.tzld.piaoquan.content.understanding.service.PipelineService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.rocketmq.client.annotation.RocketMQMessageListener;
|
|
|
import org.apache.rocketmq.client.apis.consumer.ConsumeResult;
|
|
@@ -15,6 +26,7 @@ import org.springframework.stereotype.Component;
|
|
|
import java.nio.ByteBuffer;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -33,30 +45,72 @@ public class ContentUnderstandingPipelineTaskConsumer implements RocketMQListene
|
|
|
@Autowired
|
|
|
private ContentService contentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PipelineService pipelineService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CuTaskMapper cuTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CuPipelineMapper cuPipelineMapper;
|
|
|
+ @Autowired
|
|
|
+ private CuPipelineStepMapper cuPipelineStepMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public ConsumeResult consume(MessageView messageView) {
|
|
|
log.info("Receive message {}", messageView);
|
|
|
-// MessageId messageId = messageView.getMessageId();
|
|
|
-// try {
|
|
|
-// ByteBuffer body = messageView.getBody();
|
|
|
-// Charset charset = StandardCharsets.UTF_8;
|
|
|
-// String messageStr = charset.decode(body).toString();
|
|
|
-// Map<String, Object> messageMap = JSON.parseObject(messageStr, new TypeReference<Map<String, Object>>() {
|
|
|
-// });
|
|
|
-// Object videoIdObj = messageMap.get("videoId");
|
|
|
-// if (Objects.isNull(videoIdObj)) {
|
|
|
-// //错误消息 清理掉
|
|
|
-// return ConsumeResult.SUCCESS;
|
|
|
-// }
|
|
|
-// Long videoId = Long.parseLong(videoIdObj.toString());
|
|
|
-// boolean flag = contentService.remainVideoUnderstandingHandler(videoId);
|
|
|
-// if (flag) {
|
|
|
-// log.info("Message is acknowledged successfully, messageId={}", messageId);
|
|
|
-// return ConsumeResult.SUCCESS;
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("Message is failed to be acknowledged, messageId={}", messageId, e);
|
|
|
-// }
|
|
|
+ MessageId messageId = messageView.getMessageId();
|
|
|
+ try {
|
|
|
+ ByteBuffer body = messageView.getBody();
|
|
|
+ Charset charset = StandardCharsets.UTF_8;
|
|
|
+ String messageStr = charset.decode(body).toString();
|
|
|
+ PipelineTaskMessageDTO messageDTO = JSON.parseObject(messageStr, PipelineTaskMessageDTO.class);
|
|
|
+ String taskId = messageDTO.getTaskId();
|
|
|
+ Long videoId = messageDTO.getVideoId();
|
|
|
+ Map<String, Object> extMap = messageDTO.getExtMap();
|
|
|
+ CuTaskExample example = new CuTaskExample();
|
|
|
+ example.createCriteria().andTaskIdEqualTo(taskId).andTaskStatusEqualTo(TaskStatusEnum.SUBMIT.getValue());
|
|
|
+ List<CuTask> list = cuTaskMapper.selectByExample(example);
|
|
|
+ if (Objects.isNull(list) || list.isEmpty()) {
|
|
|
+ //无需处理
|
|
|
+ log.info("task 数据无效 taskId = {}", taskId);
|
|
|
+ return ConsumeResult.SUCCESS;
|
|
|
+ }
|
|
|
+ CuTask cuTask = list.get(0);
|
|
|
+ Long pipelineId = cuTask.getPipelineId();
|
|
|
+ String input = cuTask.getInput();
|
|
|
+ if (input == null || input.isEmpty()) {
|
|
|
+ //没有输入内容
|
|
|
+ return ConsumeResult.SUCCESS;
|
|
|
+ }
|
|
|
+ CuPipeline cuPipeline = cuPipelineMapper.selectByPrimaryKey(pipelineId);
|
|
|
+ if (Objects.isNull(cuPipeline)) {
|
|
|
+ //pipeline 无数据
|
|
|
+ log.info("pipeline 数据无效 pipelineId = {}", pipelineId);
|
|
|
+ return ConsumeResult.SUCCESS;
|
|
|
+ }
|
|
|
+ // 2.获取pipeline配置
|
|
|
+ Integer contentType = cuPipeline.getContentType();
|
|
|
+ CuPipelineStepExample stepExample = new CuPipelineStepExample();
|
|
|
+ stepExample.createCriteria().andPipelineIdEqualTo(pipelineId);
|
|
|
+ List<CuPipelineStep> stepList = cuPipelineStepMapper.selectByExample(stepExample);
|
|
|
+ if (Objects.isNull(stepList) || stepList.isEmpty()) {
|
|
|
+ return ConsumeResult.SUCCESS;
|
|
|
+ }
|
|
|
+ // 3.构建tree结构
|
|
|
+ TreeNode root = pipelineService.buildTree(stepList);
|
|
|
+ root.setType(contentType);
|
|
|
+ root.setInput(input);
|
|
|
+ ContentAnalyseDTO dto1 = new ContentAnalyseDTO();
|
|
|
+ dto1.setTaskId(taskId);
|
|
|
+ dto1.setVideoId(videoId);
|
|
|
+ dto1.setContent(input);
|
|
|
+ dto1.setExtMap(extMap);
|
|
|
+ // 4.按照步骤执行pipeline每一步动作
|
|
|
+ pipelineService.executeTaskTreeNodeBFS(root, dto1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Message is failed to be acknowledged, messageId={}", messageId, e);
|
|
|
+ }
|
|
|
return ConsumeResult.FAILURE;
|
|
|
}
|
|
|
}
|