Browse Source

add mongo

supeng 1 month ago
parent
commit
bc53711147

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

@@ -1,5 +1,7 @@
 package com.tzld.piaoquan.content.understanding.service.impl;
 
+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.exception.CommonException;
 import com.tzld.piaoquan.content.understanding.dao.mapper.CuPipelineMapper;
@@ -15,6 +17,7 @@ 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.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -38,6 +41,9 @@ public class PipelineServiceImpl implements PipelineService {
     @Autowired
     private Map<String, Action> actionMap;
 
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
     @Override
     public void execute(ContentAnalyseParam param) {
         // 1.获取pipeline配置
@@ -98,7 +104,15 @@ public class PipelineServiceImpl implements PipelineService {
             // 执行action
             String result = executeStep(step, input);
             if (Objects.isNull(currentNode.getChildren()) || currentNode.getChildren().isEmpty()) {
-                //TODO 保存 result
+                if (Objects.nonNull(result)) {
+                    //异常不阻塞其他分支执行
+                    try {
+                        Map<String, Object> resultMap = JSON.parseObject(result,new TypeReference<Map<String, Object>>() {});
+                        mongoTemplate.insert(resultMap);
+                    } catch (Exception e) {
+                        log.error("step execute error step = {}, result = {}", e, JSON.toJSONString(step), result);
+                    }
+                }
                 continue;
             }
             for (PipelineTreeNode child : currentNode.getChildren()) {

+ 9 - 0
content-understanding-server/src/main/resources/application-dev.yml

@@ -24,6 +24,15 @@ spring:
       maximum-pool-size: 20
       connection-test-query: SELECT 1
 
+  data:
+    mongodb:
+      uri:
+      username:
+      password:
+      host:
+      port:
+
+
 logging:
   file:
     path: ./datalog/weblog/${project.name}

+ 7 - 1
content-understanding-server/src/main/resources/application-pre.yml

@@ -23,7 +23,13 @@ spring:
       minimum-idle: 10
       maximum-pool-size: 20
       connection-test-query: SELECT 1
-
+  data:
+    mongodb:
+      uri:
+      username:
+      password:
+      host:
+      port:
 logging:
   file:
     path: /datalog/weblog/${project.name}

+ 7 - 1
content-understanding-server/src/main/resources/application-prod.yml

@@ -23,7 +23,13 @@ spring:
       minimum-idle: 10
       maximum-pool-size: 20
       connection-test-query: SELECT 1
-
+  data:
+    mongodb:
+      uri:
+      username:
+      password:
+      host:
+      port:
 logging:
   file:
     path: /datalog/weblog/${project.name}

+ 7 - 1
content-understanding-server/src/main/resources/application-stress.yml

@@ -23,7 +23,13 @@ spring:
       minimum-idle: 10
       maximum-pool-size: 20
       connection-test-query: SELECT 1
-
+  data:
+    mongodb:
+      uri:
+      username:
+      password:
+      host:
+      port:
 logging:
   file:
     path: /datalog/weblog/${project.name}

+ 7 - 1
content-understanding-server/src/main/resources/application-test.yml

@@ -23,7 +23,13 @@ spring:
       minimum-idle: 10
       maximum-pool-size: 20
       connection-test-query: SELECT 1
-
+  data:
+    mongodb:
+      uri:
+      username:
+      password:
+      host:
+      port:
 
 logging:
   file:

+ 4 - 0
pom.xml

@@ -77,6 +77,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-redis</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-mongodb</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>