|
@@ -0,0 +1,60 @@
|
|
|
+package com.winhc.service.impl;
|
|
|
+
|
|
|
+import com.winhc.common.enums.CompanyEnum;
|
|
|
+import com.winhc.service.RelationService;
|
|
|
+import com.winhc.utils.CompanyUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.neo4j.driver.Driver;
|
|
|
+import org.neo4j.driver.Session;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author π
|
|
|
+ * @Description:人员合并
|
|
|
+ * @date 2021/1/11 10:03
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service("personMergeV2Impl")
|
|
|
+@AllArgsConstructor
|
|
|
+public class PersonMergeV2Impl implements RelationService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("DriverV1")
|
|
|
+ Driver driver;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String save(List<Map<String, Object>> batch_list) {
|
|
|
+ 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" +
|
|
|
+ "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" +
|
|
|
+ //"SET p:" + CompanyUtils.getIncrPersonLabelV2("新增", CompanyEnum.SPLIT_HOUR) + "\n" +
|
|
|
+ "WITH p as first_node, collect(distinct q) as other_nodes\n" +
|
|
|
+ "UNWIND other_nodes as other_node\n" +
|
|
|
+ "MATCH (other_node)-[r]-(x:" + CompanyEnum.Lable.COMPANY.code + ")\n" +
|
|
|
+ "WITH first_node,r,other_node,x\n" +
|
|
|
+ "CALL apoc.merge.relationship(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";
|
|
|
+ log.info("consumer size: {}, cql:{}", batch_list.size(), cql);
|
|
|
+ String data = CompanyUtils.writeNeo4j(session, cql, new HashMap<String, Object>() {{
|
|
|
+ put("batch_list", batch_list);
|
|
|
+ }});
|
|
|
+ session.close();
|
|
|
+ log.info("class:{} | save size:{} | cost:{}", PersonMergeV2Impl.class.getSimpleName(), batch_list.size(), (System.currentTimeMillis() - start));
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+}
|