Jelajahi Sumber

write mongo

supeng 1 bulan lalu
induk
melakukan
ef9029fa2c

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

@@ -44,10 +44,14 @@ public class PipelineServiceImpl implements PipelineService {
     @Autowired
     private MongoTemplate mongoTemplate;
 
+    private static final String COLLECTION_NAME = "content_understanding_info";
+
     @Override
     public void execute(ContentAnalyseParam param) {
         // 1.获取pipeline配置
         Long pipelineId = param.getPipelineId();
+        String content = param.getContent();
+        Long videoId = param.getVideoId();
         CuPipelineStepExample example = new CuPipelineStepExample();
         example.createCriteria().andPipelineIdEqualTo(pipelineId);
         List<CuPipelineStep> stepList = cuPipelineStepMapper.selectByExample(example);
@@ -56,8 +60,9 @@ public class PipelineServiceImpl implements PipelineService {
         }
         // 2.构建tree结构
         PipelineTreeNode root = buildTree(stepList);
+        root.setInput(content);
         // 3.按照步骤执行pipeline每一步动作
-        executeTreeNodeBFS(root);
+        executeTreeNodeBFS(root, videoId);
     }
 
     public PipelineTreeNode buildTree(List<CuPipelineStep> stepList) {
@@ -90,7 +95,7 @@ public class PipelineServiceImpl implements PipelineService {
         return root;
     }
 
-    public void executeTreeNodeBFS(PipelineTreeNode root) {
+    public void executeTreeNodeBFS(PipelineTreeNode root, Long videoId) {
         if (root == null) {
             return;
         }
@@ -108,7 +113,8 @@ public class PipelineServiceImpl implements PipelineService {
                     //异常不阻塞其他分支执行
                     try {
                         Map<String, Object> resultMap = JSON.parseObject(result,new TypeReference<Map<String, Object>>() {});
-                        mongoTemplate.insert(resultMap);
+                        resultMap.put("video_id", videoId);
+                        mongoTemplate.insert(resultMap, COLLECTION_NAME);
                     } catch (Exception e) {
                         log.error("step execute error step = {}, result = {}", e, JSON.toJSONString(step), result);
                     }

+ 2 - 6
content-understanding-server/src/main/resources/application-dev.yml

@@ -1,5 +1,5 @@
 server:
-  port: 8080
+  port: 8081
 
 eureka:
   instance:
@@ -26,11 +26,7 @@ spring:
 
   data:
     mongodb:
-      uri:
-      username:
-      password:
-      host:
-      port:
+      uri: mongodb://content_user:Content123&@s-bp15728065fa22a4.mongodb.rds.aliyuncs.com:3717,s-bp12258b064c3ef4.mongodb.rds.aliyuncs.com:3717/content_test
 
 
 logging:

+ 2 - 5
content-understanding-server/src/main/resources/application-pre.yml

@@ -25,11 +25,8 @@ spring:
       connection-test-query: SELECT 1
   data:
     mongodb:
-      uri:
-      username:
-      password:
-      host:
-      port:
+      uri: mongodb://content_user:Content123&@s-bp15728065fa22a4.mongodb.rds.aliyuncs.com:3717,s-bp12258b064c3ef4.mongodb.rds.aliyuncs.com:3717/content
+
 logging:
   file:
     path: /datalog/weblog/${project.name}

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

@@ -25,11 +25,7 @@ spring:
       connection-test-query: SELECT 1
   data:
     mongodb:
-      uri:
-      username:
-      password:
-      host:
-      port:
+      uri: mongodb://content_user:Content123&@s-bp15728065fa22a4.mongodb.rds.aliyuncs.com:3717,s-bp12258b064c3ef4.mongodb.rds.aliyuncs.com:3717/content
 logging:
   file:
     path: /datalog/weblog/${project.name}

+ 2 - 5
content-understanding-server/src/main/resources/application-stress.yml

@@ -25,11 +25,8 @@ spring:
       connection-test-query: SELECT 1
   data:
     mongodb:
-      uri:
-      username:
-      password:
-      host:
-      port:
+      uri: mongodb://content_user:Content123&@s-bp15728065fa22a4.mongodb.rds.aliyuncs.com:3717,s-bp12258b064c3ef4.mongodb.rds.aliyuncs.com:3717/content_test
+
 logging:
   file:
     path: /datalog/weblog/${project.name}

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

@@ -25,11 +25,7 @@ spring:
       connection-test-query: SELECT 1
   data:
     mongodb:
-      uri:
-      username:
-      password:
-      host:
-      port:
+      uri: mongodb://content_user:Content123&@s-bp15728065fa22a4.mongodb.rds.aliyuncs.com:3717,s-bp12258b064c3ef4.mongodb.rds.aliyuncs.com:3717/content_test
 
 logging:
   file:

+ 10 - 0
content-understanding-server/src/test/java/com/tzld/piaoquan/content/understanding/service/DemoServiceTest.java

@@ -3,14 +3,24 @@ package com.tzld.piaoquan.content.understanding.service;
 import com.tzld.piaoquan.content.understanding.BaseTest;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+
+import java.util.HashMap;
+import java.util.Map;
 
 public class DemoServiceTest extends BaseTest {
 
     @Autowired
     DemoService demoService;
 
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
     @Test
     void test(){
 //        demoService
+        Map<String,Object> map = new HashMap<>();
+        map.put("video_id",1);
+        mongoTemplate.insert(map, "content_understanding_info");
     }
 }