CaseNodeUpdateImpl.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.winhc.service.impl;
  2. import com.winhc.service.RelationService;
  3. import com.winhc.utils.CompanyUtils;
  4. import lombok.AllArgsConstructor;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.neo4j.driver.Driver;
  7. import org.neo4j.driver.Session;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.beans.factory.annotation.Qualifier;
  10. import org.springframework.stereotype.Service;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14. /**
  15. * @author π
  16. * @Description:案件-更新节点
  17. * @date 2021/5/17 10:03
  18. */
  19. @Slf4j
  20. @Service("caseNodeUpdateImpl")
  21. @AllArgsConstructor
  22. public class CaseNodeUpdateImpl implements RelationService {
  23. @Autowired
  24. @Qualifier("DriverV2")
  25. Driver driver;
  26. @Override
  27. public String save(List<Map<String, Object>> batch_list) {
  28. if (batch_list.isEmpty()) return null;
  29. long start = System.currentTimeMillis();
  30. Session session = driver.session();
  31. // final String cql = "\nWITH {batch_list} AS batch_list \n" +
  32. // "UNWIND batch_list AS row \n" +
  33. // " MERGE(s:CASE{case_id:row.start_id})\n" +
  34. // " SET s.case_id = row.start_id\n" +
  35. // " WITH s\n" +
  36. // " CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
  37. // " WITH node,s\n" +
  38. // " SET node.component_id = -id(s)\n" +
  39. // " SET node:" + CompanyUtils.getIncrPersonLabelV2("新增");
  40. final String cql = "\nWITH {batch_list} AS batch_list \n" +
  41. "UNWIND batch_list AS row\n" +
  42. "MERGE (s:CASE{case_id:row.start_id})\n" +
  43. "WITH s\n" +
  44. "CALL apoc.path.subgraphNodes(s, {maxLevel:-1}) YIELD node\n" +
  45. "WITH ID(s) as id,apoc.coll.max(collect(node.component_id) + collect(-ID(s))) as update_id,collect(node) as nodes\n" +
  46. "UNWIND nodes AS n\n" +
  47. "SET n.component_id = update_id\n" +
  48. "SET n:" + CompanyUtils.getIncrPersonLabelV2("新增");
  49. log.info("consumer size: {}, cql:{}", batch_list.size(), cql);
  50. String data = CompanyUtils.writeNeo4j(session, cql, new HashMap<String, Object>() {{
  51. put("batch_list", batch_list);
  52. }});
  53. session.close();
  54. log.info("class:{} | save size:{} | cost:{}", CaseNodeUpdateImpl.class.getSimpleName(), batch_list.size(), (System.currentTimeMillis() - start));
  55. return data;
  56. }
  57. }