|
@@ -2,13 +2,15 @@ package com.tzld.piaoquan.content.understanding.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
|
+import com.tzld.piaoquan.content.understanding.common.enums.ContentTypeEnum;
|
|
import com.tzld.piaoquan.content.understanding.common.enums.ExceptionEnum;
|
|
import com.tzld.piaoquan.content.understanding.common.enums.ExceptionEnum;
|
|
import com.tzld.piaoquan.content.understanding.common.exception.CommonException;
|
|
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.CuPipelineMapper;
|
|
import com.tzld.piaoquan.content.understanding.dao.mapper.CuPipelineStepMapper;
|
|
import com.tzld.piaoquan.content.understanding.dao.mapper.CuPipelineStepMapper;
|
|
import com.tzld.piaoquan.content.understanding.dao.mapper.CuPromptMapper;
|
|
import com.tzld.piaoquan.content.understanding.dao.mapper.CuPromptMapper;
|
|
import com.tzld.piaoquan.content.understanding.model.dto.ContentAnalyseDTO;
|
|
import com.tzld.piaoquan.content.understanding.model.dto.ContentAnalyseDTO;
|
|
-import com.tzld.piaoquan.content.understanding.model.dto.PipelineTreeNode;
|
|
|
|
|
|
+import com.tzld.piaoquan.content.understanding.model.dto.ContentUnderstandDTO;
|
|
|
|
+import com.tzld.piaoquan.content.understanding.model.dto.TreeNode;
|
|
import com.tzld.piaoquan.content.understanding.model.param.ActionParam;
|
|
import com.tzld.piaoquan.content.understanding.model.param.ActionParam;
|
|
import com.tzld.piaoquan.content.understanding.model.param.ContentAnalyseParam;
|
|
import com.tzld.piaoquan.content.understanding.model.param.ContentAnalyseParam;
|
|
import com.tzld.piaoquan.content.understanding.model.po.CuPipelineStep;
|
|
import com.tzld.piaoquan.content.understanding.model.po.CuPipelineStep;
|
|
@@ -61,7 +63,7 @@ public class PipelineServiceImpl implements PipelineService {
|
|
throw new CommonException(ExceptionEnum.CONFIG_ERROR, "无配置 pipelineId:" + pipelineId);
|
|
throw new CommonException(ExceptionEnum.CONFIG_ERROR, "无配置 pipelineId:" + pipelineId);
|
|
}
|
|
}
|
|
// 2.构建tree结构
|
|
// 2.构建tree结构
|
|
- PipelineTreeNode root = buildTree(stepList);
|
|
|
|
|
|
+ TreeNode root = buildTree(stepList);
|
|
root.setType(type);
|
|
root.setType(type);
|
|
root.setInput(content);
|
|
root.setInput(content);
|
|
ContentAnalyseDTO dto = new ContentAnalyseDTO();
|
|
ContentAnalyseDTO dto = new ContentAnalyseDTO();
|
|
@@ -70,13 +72,59 @@ public class PipelineServiceImpl implements PipelineService {
|
|
executeTreeNodeBFS(root, dto);
|
|
executeTreeNodeBFS(root, dto);
|
|
}
|
|
}
|
|
|
|
|
|
- public PipelineTreeNode buildTree(List<CuPipelineStep> stepList) {
|
|
|
|
- Map<Long, PipelineTreeNode> nodeMap = new HashMap<>();
|
|
|
|
- PipelineTreeNode root = null;
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void execute(ContentUnderstandDTO dto) {
|
|
|
|
+ // 1.获取pipeline配置
|
|
|
|
+ Long pipelineId = dto.getPipelineId();
|
|
|
|
+ Integer contentType = dto.getContentType();
|
|
|
|
+ CuPipelineStepExample example = new CuPipelineStepExample();
|
|
|
|
+ example.createCriteria().andPipelineIdEqualTo(pipelineId);
|
|
|
|
+ List<CuPipelineStep> stepList = cuPipelineStepMapper.selectByExample(example);
|
|
|
|
+ if (Objects.isNull(stepList) || stepList.isEmpty()) {
|
|
|
|
+ throw new CommonException(ExceptionEnum.CONFIG_ERROR, "无配置 pipelineId:" + pipelineId);
|
|
|
|
+ }
|
|
|
|
+ // 2.构建tree结构
|
|
|
|
+ TreeNode root = buildTree(stepList);
|
|
|
|
+ root.setType(contentType);
|
|
|
|
+ String content = getContent(dto, contentType);
|
|
|
|
+ if (Objects.isNull(content)) {
|
|
|
|
+ throw new CommonException(ExceptionEnum.DATA_ERROR, "数据异常content:" + content);
|
|
|
|
+ }
|
|
|
|
+ root.setInput(content);
|
|
|
|
+ ContentAnalyseDTO dto1 = new ContentAnalyseDTO();
|
|
|
|
+ dto1.setVideoId(dto.getVideoId());
|
|
|
|
+ dto1.setContent(content);
|
|
|
|
+ // 3.按照步骤执行pipeline每一步动作
|
|
|
|
+ executeTreeNodeBFS(root, dto1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getContent(ContentUnderstandDTO dto, Integer contentType) {
|
|
|
|
+ String content = null;
|
|
|
|
+ if (Objects.equals(contentType, ContentTypeEnum.TITLE.getValue())) {
|
|
|
|
+ content = dto.getTitle();
|
|
|
|
+ } else if (Objects.equals(contentType, ContentTypeEnum.COVER.getValue())) {
|
|
|
|
+ content = dto.getCoverUrl();
|
|
|
|
+ } else if (Objects.equals(contentType, ContentTypeEnum.VIDEO.getValue())) {
|
|
|
|
+ content = dto.getVideoUrl();
|
|
|
|
+ } else if (Objects.equals(contentType, ContentTypeEnum.INTRODUCTION.getValue())) {
|
|
|
|
+ content = dto.getIntroduction();
|
|
|
|
+ } else if (Objects.equals(contentType, ContentTypeEnum.AUDIO.getValue())) {
|
|
|
|
+ content = dto.getAudioUrl();
|
|
|
|
+ } else if (Objects.equals(contentType, ContentTypeEnum.SRT.getValue())) {
|
|
|
|
+ content = dto.getSrt();
|
|
|
|
+ } else if (Objects.equals(contentType, ContentTypeEnum.VTT.getValue())) {
|
|
|
|
+ content = dto.getVtt();
|
|
|
|
+ }
|
|
|
|
+ return content;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public TreeNode buildTree(List<CuPipelineStep> stepList) {
|
|
|
|
+ Map<Long, TreeNode> nodeMap = new HashMap<>();
|
|
|
|
+ TreeNode root = null;
|
|
|
|
|
|
// 将所有节点放入 Map 中,方便后续查找
|
|
// 将所有节点放入 Map 中,方便后续查找
|
|
for (CuPipelineStep step : stepList) {
|
|
for (CuPipelineStep step : stepList) {
|
|
- PipelineTreeNode node = new PipelineTreeNode();
|
|
|
|
|
|
+ TreeNode node = new TreeNode();
|
|
node.setStep(step);
|
|
node.setStep(step);
|
|
nodeMap.put(step.getId(), node);
|
|
nodeMap.put(step.getId(), node);
|
|
}
|
|
}
|
|
@@ -87,9 +135,9 @@ public class PipelineServiceImpl implements PipelineService {
|
|
if (Objects.isNull(parentId) || parentId == 0) {
|
|
if (Objects.isNull(parentId) || parentId == 0) {
|
|
root = nodeMap.get(step.getId());
|
|
root = nodeMap.get(step.getId());
|
|
} else if (nodeMap.containsKey(parentId)) {
|
|
} else if (nodeMap.containsKey(parentId)) {
|
|
- PipelineTreeNode parentNode = nodeMap.get(parentId);
|
|
|
|
- PipelineTreeNode currentNode = nodeMap.get(step.getId());
|
|
|
|
- List<PipelineTreeNode> children = parentNode.getChildren();
|
|
|
|
|
|
+ TreeNode parentNode = nodeMap.get(parentId);
|
|
|
|
+ TreeNode currentNode = nodeMap.get(step.getId());
|
|
|
|
+ List<TreeNode> children = parentNode.getChildren();
|
|
if (Objects.isNull(children)) {
|
|
if (Objects.isNull(children)) {
|
|
children = new ArrayList<>();
|
|
children = new ArrayList<>();
|
|
parentNode.setChildren(children);
|
|
parentNode.setChildren(children);
|
|
@@ -100,17 +148,23 @@ public class PipelineServiceImpl implements PipelineService {
|
|
return root;
|
|
return root;
|
|
}
|
|
}
|
|
|
|
|
|
- public void executeTreeNodeBFS(PipelineTreeNode root, ContentAnalyseDTO dto) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 遍历树结构
|
|
|
|
+ *
|
|
|
|
+ * @param root 根节点
|
|
|
|
+ * @param dto 数据
|
|
|
|
+ */
|
|
|
|
+ public void executeTreeNodeBFS(TreeNode root, ContentAnalyseDTO dto) {
|
|
if (Objects.isNull(root) || Objects.isNull(dto) || Objects.isNull(dto.getVideoId())) {
|
|
if (Objects.isNull(root) || Objects.isNull(dto) || Objects.isNull(dto.getVideoId())) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- Queue<PipelineTreeNode> queue = new LinkedList<>();
|
|
|
|
|
|
+ Queue<TreeNode> queue = new LinkedList<>();
|
|
queue.offer(root);
|
|
queue.offer(root);
|
|
|
|
|
|
Long videoId = dto.getVideoId();
|
|
Long videoId = dto.getVideoId();
|
|
|
|
|
|
while (!queue.isEmpty()) {
|
|
while (!queue.isEmpty()) {
|
|
- PipelineTreeNode currentNode = queue.poll();
|
|
|
|
|
|
+ TreeNode currentNode = queue.poll();
|
|
CuPipelineStep step = currentNode.getStep();
|
|
CuPipelineStep step = currentNode.getStep();
|
|
Integer type = currentNode.getType();
|
|
Integer type = currentNode.getType();
|
|
String input = currentNode.getInput() == null ? "" : currentNode.getInput();
|
|
String input = currentNode.getInput() == null ? "" : currentNode.getInput();
|
|
@@ -130,7 +184,7 @@ public class PipelineServiceImpl implements PipelineService {
|
|
}
|
|
}
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- for (PipelineTreeNode child : currentNode.getChildren()) {
|
|
|
|
|
|
+ for (TreeNode child : currentNode.getChildren()) {
|
|
child.setInput(result);
|
|
child.setInput(result);
|
|
queue.offer(child);
|
|
queue.offer(child);
|
|
}
|
|
}
|