-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a352031
commit 06991e5
Showing
332 changed files
with
965 additions
and
78,301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.eis.frontend.config; | ||
|
||
import org.neo4j.driver.AuthTokens; | ||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.GraphDatabase; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class Neo4jConfig { | ||
|
||
@Bean | ||
public Driver neo4jDriver() { | ||
return GraphDatabase.driver( | ||
"bolt://localhost:7687", | ||
AuthTokens.basic("neo4j", "dbvalar412") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/org/eis/frontend/controller/Neo4jEnterpriseController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.eis.frontend.controller; | ||
|
||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.Session; | ||
import org.neo4j.driver.Result; | ||
import org.neo4j.driver.Values; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.http.MediaType; | ||
import java.util.*; | ||
|
||
@RestController | ||
public class Neo4jEnterpriseController { | ||
|
||
private final Driver driver; | ||
|
||
public Neo4jEnterpriseController(Driver driver) { | ||
this.driver = driver; | ||
} | ||
|
||
@GetMapping(path = "/api/related-enterprises", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public List<String> getRelatedEnterprises(@RequestParam(name = "name") String name) { | ||
try (Session session = driver.session()) { | ||
String query = """ | ||
MATCH (c1:企业 {name: $name})-[r]-(c2:企业) | ||
WITH c2, | ||
CASE WHEN '经营范围' IN collect(type(r)) THEN 1 ELSE 0 END as scopeCount, | ||
collect(type(r)) as allTypes | ||
WITH c2, | ||
size([x IN allTypes WHERE x <> '经营范围']) + scopeCount as relationCount, | ||
[x IN allTypes WHERE x <> '经营范围'] + | ||
CASE WHEN '经营范围' IN allTypes THEN ['经营范围'] ELSE [] END as relationTypes | ||
WHERE relationCount >= 3 | ||
RETURN c2.name as 关联企业 | ||
ORDER BY relationCount DESC | ||
LIMIT 10 | ||
"""; | ||
|
||
Result result = session.run(query, Values.parameters("name", name)); | ||
List<String> enterprises = new ArrayList<>(); | ||
|
||
while (result.hasNext()) { | ||
enterprises.add(result.next().get("关联企业").asString()); | ||
} | ||
|
||
return enterprises; | ||
} catch (Exception e) { | ||
return new ArrayList<>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.