package com.winhc.service.impl; import com.alibaba.fastjson.JSON; 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.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author π * @Description:股东关系 人->公司 * @date 2021/1/11 10:03 */ @Slf4j @Service("personMergeImpl") @AllArgsConstructor public class PersonMergeImpl implements RelationService { private final Driver driver; @Override public String save(List> 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 (m:个人{person_id:row.merge_human_pid})\n" + "MATCH (n:个人{person_id:row.deleted_human_pid})-[r]-(x:企业)\n" + "with m,n,r,x\n" + "CALL apoc.merge.relationship(m, TYPE(r), properties(r),{}, x,{}) YIELD rel\n" + "SET m:" + CompanyUtils.getIncrPersonLabel("新增") + "\n" + "SET n:" + CompanyUtils.getIncrPersonLabel("删除") + "\n" + "DELETE r"; log.info("consumer size: {}, cql:{}", batch_list.size(), cql); String data = CompanyUtils.writeNeo4j(session, cql, new HashMap() {{ put("batch_list", batch_list); }}); session.close(); log.info("class:{} | save size:{} | cost:{}", PersonMergeImpl.class.getSimpleName(), batch_list.size(), (System.currentTimeMillis() - start)); return data; } }