|
@@ -43,29 +43,44 @@ public class PersonMergeV2Impl implements RelationService {
|
|
if (batch_list.isEmpty()) return null;
|
|
if (batch_list.isEmpty()) return null;
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
Session session = driver.session();
|
|
Session session = driver.session();
|
|
-
|
|
|
|
- final String cql =
|
|
|
|
- "\nWITH {batch_list} AS batch_list \n" +
|
|
|
|
- "UNWIND batch_list AS row \n" +
|
|
|
|
- "MATCH (p:" + CompanyEnum.Lable.PERSON.code + "{person_id: row.person_id})-[*0..3]-(q:" + CompanyEnum.Lable.PERSON.code + "{name:row.name})\n" +
|
|
|
|
- "WHERE ID(p) <> ID(q)\n" +
|
|
|
|
- "WITH p.person_id as person_id, p as first_node, apoc.coll.sort(collect(distinct ID(q))) as all_ids\n" +
|
|
|
|
- "UNWIND all_ids as all_id\n" +
|
|
|
|
- "MATCH(m:" + CompanyEnum.Lable.PERSON.code + ")-[r]-(x:" + CompanyEnum.Lable.COMPANY.code + ")\n" +
|
|
|
|
- "WHERE ID(m) = all_id\n" +
|
|
|
|
- "WITH person_id, first_node, m as other_node, x, r\n" +
|
|
|
|
- "CALL apoc.merge.relationship.eager(first_node, TYPE(r), properties(r),{}, x,{}) YIELD rel\n" +
|
|
|
|
- "SET first_node:" + CompanyUtils.getIncrPersonLabelV2("新增", CompanyEnum.SPLIT_HOUR) + "\n" +
|
|
|
|
- "SET other_node:" + CompanyUtils.getIncrPersonLabelV2("删除", CompanyEnum.SPLIT_HOUR) + "\n" +
|
|
|
|
- "DELETE r" + "\n" +
|
|
|
|
- "RETURN first_node.person_id as new_human_pid,first_node.name as new_human_name,other_node.person_id as old_human_pid,other_node.name as old_human_name" + "\n";
|
|
|
|
- log.info("consumer size: {}, cql:{}", batch_list.size(), cql);
|
|
|
|
- String data = CompanyUtils.writeNeo4j2(session, cql, new HashMap<String, Object>() {{
|
|
|
|
|
|
+ //1.查询关联人员
|
|
|
|
+ final String query_cql = "\nWITH {batch_list} AS batch_list \n" +
|
|
|
|
+ "UNWIND batch_list AS row \n" +
|
|
|
|
+ "MATCH (p:" + CompanyEnum.Lable.PERSON.code + "{person_id: row.person_id})-[*0..3]-(q:" + CompanyEnum.Lable.PERSON.code + "{name:row.name})\n" +
|
|
|
|
+ "WHERE ID(p) <> ID(q)\n" +
|
|
|
|
+ "WITH p.person_id as person_id, p as first_node, apoc.coll.sort(collect(distinct ID(p)) + collect(distinct ID(q))) as all_ids\n" +
|
|
|
|
+ "UNWIND all_ids as all_id\n" +
|
|
|
|
+ "MATCH(m:" + CompanyEnum.Lable.PERSON.code + ")-[r]-(x:" + CompanyEnum.Lable.COMPANY.code + ")\n" +
|
|
|
|
+ "WHERE ID(m) = all_id\n" +
|
|
|
|
+ "WITH person_id, first_node, m as other_node, count(distinct x) as cnt\n" +
|
|
|
|
+ "RETURN first_node.person_id as new_human_pid, first_node.name as new_human_name, other_node.person_id as old_human_pid, other_node.name as old_human_name, cnt" + "\n";
|
|
|
|
+ log.info("query size: {}, cql:{}", batch_list.size(), query_cql);
|
|
|
|
+ List<Map<String, String>> mergeData = CompanyUtils.writeNeo4j1(session, query_cql, new HashMap<String, Object>() {{
|
|
put("batch_list", batch_list);
|
|
put("batch_list", batch_list);
|
|
}});
|
|
}});
|
|
|
|
+
|
|
|
|
+ //2.合并逻辑
|
|
|
|
+ String data = null;
|
|
|
|
+ if (!mergeData.isEmpty()) {
|
|
|
|
+ final String merge_cql =
|
|
|
|
+ "\nWITH {merge_list} AS batch_list \n" +
|
|
|
|
+ "UNWIND batch_list AS row\n" +
|
|
|
|
+ "MATCH (p:个人 {person_id:row.new_human_pid}),(q:个人 {person_id:row.old_human_pid})-[r]-(x:企业)\n" +
|
|
|
|
+ "WITH p as first_node, q as other_node, x, r\n" +
|
|
|
|
+ "CALL apoc.merge.relationship.eager(first_node, TYPE(r), properties(r),{}, x,{}) YIELD rel\n" +
|
|
|
|
+ "SET first_node:" + CompanyUtils.getIncrPersonLabelV2("新增", CompanyEnum.SPLIT_HOUR) + "\n" +
|
|
|
|
+ "SET other_node:" + CompanyUtils.getIncrPersonLabelV2("删除", CompanyEnum.SPLIT_HOUR) + "\n" +
|
|
|
|
+ "DELETE r\n" +
|
|
|
|
+ "RETURN first_node.person_id as new_human_pid,first_node.name as new_human_name,other_node.person_id as old_human_pid,other_node.name as old_human_name";
|
|
|
|
+ log.info("merge size: {}, cql2:{}", mergeData.size(), merge_cql);
|
|
|
|
+ data = CompanyUtils.writeNeo4j2(session, merge_cql, new HashMap<String, Object>() {{
|
|
|
|
+ put("merge_list", mergeData);
|
|
|
|
+ }});
|
|
|
|
+ }
|
|
session.close();
|
|
session.close();
|
|
- log.info("class:{} | save size:{} | cost:{}", PersonMergeV2Impl.class.getSimpleName(), batch_list.size(), (System.currentTimeMillis() - start));
|
|
|
|
- //发送变更人员记录
|
|
|
|
|
|
+ log.info("class:{} | save size:{} | merge size:{} |cost:{}", PersonMergeV2Impl.class.getSimpleName(), batch_list.size(), mergeData.size(), (System.currentTimeMillis() - start));
|
|
|
|
+
|
|
|
|
+ //3.发送变更人员记录
|
|
if (StringUtils.isNotBlank(data)) {
|
|
if (StringUtils.isNotBlank(data)) {
|
|
kafkaProduce.produce(configConstant.topic_pid_update_v1, data);
|
|
kafkaProduce.produce(configConstant.topic_pid_update_v1, data);
|
|
}
|
|
}
|