CompanyController.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package io.github.qifan777.knowledge.graph.company;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import io.github.qifan777.knowledge.graph.model.Form10K;
  4. import lombok.AllArgsConstructor;
  5. import lombok.SneakyThrows;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.data.neo4j.core.Neo4jClient;
  8. import org.springframework.web.bind.annotation.PostMapping;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import java.io.File;
  12. @RestController
  13. @RequestMapping("company")
  14. @Slf4j
  15. @AllArgsConstructor
  16. public class CompanyController {
  17. private final CompanyRepository companyRepository;
  18. private final Neo4jClient neo4jClient;
  19. @SneakyThrows
  20. @PostMapping("nodes")
  21. public void createNodes() {
  22. var fileDir = new File("F:\\workspace\\code\\learn\\sec-edgar-notebooks\\data\\sample\\form10k");
  23. File[] files = fileDir.listFiles();
  24. for (File file : files) {
  25. if (!file.getName().contains(".json")) continue;
  26. var form10K = new ObjectMapper().readValue(file, Form10K.class);
  27. var company = Company.builder().cusip6(form10K.getCusip6())
  28. .cusips(form10K.getCusip())
  29. .names(form10K.getNames())
  30. .name(form10K.getNames().get(0))
  31. .build();
  32. companyRepository.save(company);
  33. }
  34. }
  35. @PostMapping("relationship/filed")
  36. public void createFiledRelationship() {
  37. // 创建公司和form关系
  38. neo4jClient.query("""
  39. MATCH (com:Company), (form:Form)
  40. WHERE com.cusip6 = form.cusip6
  41. MERGE (com)-[:FILED]->(form)
  42. """)
  43. .run();
  44. }
  45. }