supeng 4 周之前
父节点
当前提交
5ce88bc7aa

+ 16 - 0
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/model/dto/ContentAnalyseDTO.java

@@ -0,0 +1,16 @@
+package com.tzld.piaoquan.content.understanding.model.dto;
+
+import lombok.Data;
+
+@Data
+public class ContentAnalyseDTO {
+    /**
+     * 内容
+     * 文本 or 图片url or 视频url
+     */
+    private String content;
+    /**
+     *
+     */
+    private Long videoId;
+}

+ 4 - 0
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/model/dto/PipelineTreeNode.java

@@ -16,6 +16,10 @@ public class PipelineTreeNode {
      * 要执行的步骤
      */
     private CuPipelineStep step;
+    /**
+     * @see com.tzld.piaoquan.content.understanding.common.enums.ContentTypeEnum
+     */
+    private Integer type;
     /**
      * 上一步执行结果
      */

+ 18 - 8
content-understanding-core/src/main/java/com/tzld/piaoquan/content/understanding/service/impl/PipelineServiceImpl.java

@@ -7,6 +7,7 @@ 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.CuPromptMapper;
+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.param.ActionParam;
 import com.tzld.piaoquan.content.understanding.model.param.ContentAnalyseParam;
@@ -16,6 +17,7 @@ import com.tzld.piaoquan.content.understanding.model.po.CuPrompt;
 import com.tzld.piaoquan.content.understanding.service.Action;
 import com.tzld.piaoquan.content.understanding.service.PipelineService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.stereotype.Service;
@@ -51,7 +53,7 @@ public class PipelineServiceImpl implements PipelineService {
         // 1.获取pipeline配置
         Long pipelineId = param.getPipelineId();
         String content = param.getContent();
-        Long videoId = param.getVideoId();
+        Integer type = param.getType();
         CuPipelineStepExample example = new CuPipelineStepExample();
         example.createCriteria().andPipelineIdEqualTo(pipelineId);
         List<CuPipelineStep> stepList = cuPipelineStepMapper.selectByExample(example);
@@ -60,9 +62,12 @@ public class PipelineServiceImpl implements PipelineService {
         }
         // 2.构建tree结构
         PipelineTreeNode root = buildTree(stepList);
+        root.setType(type);
         root.setInput(content);
+        ContentAnalyseDTO dto = new ContentAnalyseDTO();
+        BeanUtils.copyProperties(param, dto);
         // 3.按照步骤执行pipeline每一步动作
-        executeTreeNodeBFS(root, videoId);
+        executeTreeNodeBFS(root, dto);
     }
 
     public PipelineTreeNode buildTree(List<CuPipelineStep> stepList) {
@@ -95,24 +100,28 @@ public class PipelineServiceImpl implements PipelineService {
         return root;
     }
 
-    public void executeTreeNodeBFS(PipelineTreeNode root, Long videoId) {
-        if (root == null) {
+    public void executeTreeNodeBFS(PipelineTreeNode root, ContentAnalyseDTO dto) {
+        if (Objects.isNull(root) || Objects.isNull(dto) || Objects.isNull(dto.getVideoId())) {
             return;
         }
         Queue<PipelineTreeNode> queue = new LinkedList<>();
         queue.offer(root);
 
+        Long videoId = dto.getVideoId();
+
         while (!queue.isEmpty()) {
             PipelineTreeNode currentNode = queue.poll();
             CuPipelineStep step = currentNode.getStep();
+            Integer type = currentNode.getType();
             String input = currentNode.getInput() == null ? "" : currentNode.getInput();
             // 执行action
-            String result = executeStep(step, input);
+            String result = executeStep(step, input, type);
             if (Objects.isNull(currentNode.getChildren()) || currentNode.getChildren().isEmpty()) {
                 if (Objects.nonNull(result)) {
                     //异常不阻塞其他分支执行
                     try {
-                        Map<String, Object> resultMap = JSON.parseObject(result,new TypeReference<Map<String, Object>>() {});
+                        Map<String, Object> resultMap = JSON.parseObject(result, new TypeReference<Map<String, Object>>() {
+                        });
                         resultMap.put("video_id", videoId);
                         mongoTemplate.insert(resultMap, COLLECTION_NAME);
                     } catch (Exception e) {
@@ -135,7 +144,7 @@ public class PipelineServiceImpl implements PipelineService {
      * @param input
      * @return
      */
-    public String executeStep(CuPipelineStep step, String input) {
+    public String executeStep(CuPipelineStep step, String input, Integer type) {
         CuPrompt cuPrompt = cuPromptMapper.selectByPrimaryKey(step.getPromptId());
         if (Objects.isNull(cuPrompt) || Objects.isNull(cuPrompt.getId())) {
             return null;
@@ -144,7 +153,8 @@ public class PipelineServiceImpl implements PipelineService {
 
         Action action = actionMap.get(step.getAction());
         ActionParam actionParam = new ActionParam();
-        actionParam.setInput(prompt);
+        actionParam.setType(type);
+        actionParam.setInput(input);
         actionParam.setPrompt(prompt);
         return action.execute(actionParam);
     }