Browse Source

更新逻辑

xufei 3 years ago
parent
commit
9a70a9deac

+ 18 - 8
src/main/java/com/winhc/service/impl/CaseNodeUpdateImpl.java

@@ -33,15 +33,25 @@ public class CaseNodeUpdateImpl implements RelationService {
         if (batch_list.isEmpty()) return null;
         long start = System.currentTimeMillis();
         Session session = driver.session();
+//        final String cql = "\nWITH  {batch_list} AS batch_list \n" +
+//                "UNWIND batch_list AS row \n" +
+//                " MERGE(s:CASE{case_id:row.start_id})\n" +
+//                " SET s.case_id = row.start_id\n" +
+//                " WITH s\n" +
+//                " CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
+//                " WITH node,s\n" +
+//                " SET node.component_id = -id(s)\n" +
+//                " SET node:" + CompanyUtils.getIncrPersonLabelV2("新增");
+
         final String cql = "\nWITH  {batch_list} AS batch_list \n" +
-                "UNWIND batch_list AS row \n" +
-                " MERGE(s:CASE{case_id:row.start_id})\n" +
-                " SET s.case_id = row.start_id\n" +
-                " WITH s\n" +
-                " CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
-                " WITH node,s\n" +
-                " SET node.component_id = -id(s)\n" +
-                " SET node:" + CompanyUtils.getIncrPersonLabelV2("新增");
+                "UNWIND batch_list AS row\n" +
+                "MERGE (s:CASE{case_id:row.start_id})\n" +
+                "WITH s\n" +
+                "CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
+                "WITH ID(s) as id,apoc.coll.max(collect(node.component_id) + collect(-ID(s))) as update_id,collect(node) as nodes\n" +
+                "UNWIND nodes AS n\n" +
+                "SET n.component_id = update_id\n" +
+                "SET n:" + CompanyUtils.getIncrPersonLabelV2("新增");
         log.info("consumer size: {}, cql:{}", batch_list.size(), cql);
         String data = CompanyUtils.writeNeo4j(session, cql, new HashMap<String, Object>() {{
             put("batch_list", batch_list);

+ 24 - 11
src/main/java/com/winhc/service/impl/CaseRelationUpdateImpl.java

@@ -33,19 +33,32 @@ public class CaseRelationUpdateImpl implements RelationService {
         if (batch_list.isEmpty()) return null;
         long start = System.currentTimeMillis();
         Session session = driver.session();
+//        final String cql = "\nWITH  {batch_list} AS batch_list \n" +
+//                "UNWIND batch_list AS row \n" +
+//                " MERGE(s:CASE{case_id:row.start_id})\n" +
+//                " SET s.case_id = row.start_id\n" +
+//                " MERGE(m:CASE{case_id:row.end_id})\n" +
+//                " SET m.case_id = row.end_id\n" +
+//                " MERGE(s)-[r:RELATION]->(m)\n" +
+//                " SET r.connect_type=row.connect_type\n" +
+//                " WITH s,m\n" +
+//                " CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
+//                " WITH node,s\n" +
+//                " SET node.component_id = -id(s)\n" +
+//                " SET node:" + CompanyUtils.getIncrPersonLabelV2("新增");
+
         final String cql = "\nWITH  {batch_list} AS batch_list \n" +
                 "UNWIND batch_list AS row \n" +
-                " MERGE(s:CASE{case_id:row.start_id})\n" +
-                " SET s.case_id = row.start_id\n" +
-                " MERGE(m:CASE{case_id:row.end_id})\n" +
-                " SET m.case_id = row.end_id\n" +
-                " MERGE(s)-[r:RELATION]->(m)\n" +
-                " SET r.connect_type=row.connect_type\n" +
-                " WITH s,m\n" +
-                " CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
-                " WITH node,s\n" +
-                " SET node.component_id = -id(s)\n" +
-                " SET node:" + CompanyUtils.getIncrPersonLabelV2("新增");
+                "MERGE(s:CASE{case_id:row.start_id})\n" +
+                "MERGE(m:CASE{case_id:row.end_id})\n" +
+                "MERGE(s)-[r:RELATION]->(m)\n" +
+                "SET r.connect_type=row.connect_type\n" +
+                "WITH s,m\n" +
+                "CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
+                "WITH ID(s) as id,apoc.coll.max(collect(node.component_id) + collect(-ID(s))) as update_id,collect(node) as nodes\n" +
+                "UNWIND nodes AS n\n" +
+                "SET n.component_id = update_id\n" +
+                "SET n:" + CompanyUtils.getIncrPersonLabelV2("新增");
         log.info("consumer size: {}, cql:{}", batch_list.size(), cql);
         String data = CompanyUtils.writeNeo4j(session, cql, new HashMap<String, Object>() {{
             put("batch_list", batch_list);

+ 1 - 1
src/main/java/com/winhc/utils/CompanyUtils.java

@@ -113,7 +113,7 @@ public class CompanyUtils {
     }
 
     public static String getIncrPersonLabelV2(String label) {
-        return getIncrPersonLabelV2(label, 12);
+        return getIncrPersonLabelV2(label, 10);
     }
 
     public static String getIncrPersonLabelV2(String label, int split_hour) {

+ 2 - 2
src/main/resources/application-dev.properties

@@ -15,8 +15,8 @@ spring.data.neo4j.uri.v1=bolt://127.0.0.1:7687
 #Neo4j配置(第二台机器)
 spring.data.neo4j.username.v2=neo4j
 spring.data.neo4j.password.v2=neo4j168
-spring.data.neo4j.uri.v2=bolt://139.224.197.164:7687
-#spring.data.neo4j.uri.v2=bolt://192.168.2.60:7687
+#spring.data.neo4j.uri.v2=bolt://139.224.197.164:7687
+spring.data.neo4j.uri.v2=bolt://127.0.0.1:7687
 
 #数据库uri地址
 #spring.data.neo4j.uri=http://10.29.26.76:7474