|
@@ -13,6 +13,12 @@ import java.util.*;
|
|
@Repository
|
|
@Repository
|
|
public class BaseNodeRepository {
|
|
public class BaseNodeRepository {
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据名字和标签查询实体属性
|
|
|
|
+ * @param label
|
|
|
|
+ * @param name
|
|
|
|
+ * @return 实体map
|
|
|
|
+ */
|
|
public Map<String,Object> findNodeByName(String label,String name) {
|
|
public Map<String,Object> findNodeByName(String label,String name) {
|
|
String query = String.format("MATCH (n:`%s`) WHERE n.name = $name and n.is_deleted = 'N' RETURN n", label);
|
|
String query = String.format("MATCH (n:`%s`) WHERE n.name = $name and n.is_deleted = 'N' RETURN n", label);
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
@@ -30,6 +36,11 @@ public class BaseNodeRepository {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据id查询实体属性
|
|
|
|
+ * @param id
|
|
|
|
+ * @return 实体map
|
|
|
|
+ */
|
|
public Map<String,Object> findNodeById(Long id) {
|
|
public Map<String,Object> findNodeById(Long id) {
|
|
String query = "MATCH (n) WHERE id(n) = $nodeId and n.is_deleted = 'N' RETURN n";
|
|
String query = "MATCH (n) WHERE id(n) = $nodeId and n.is_deleted = 'N' RETURN n";
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
@@ -47,8 +58,14 @@ public class BaseNodeRepository {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据名字模糊查询实体
|
|
|
|
+ * @param label
|
|
|
|
+ * @param name
|
|
|
|
+ * @return 实体map列表
|
|
|
|
+ */
|
|
public List<Map<String,Object>> findNodeListByName(String label, String name) {
|
|
public List<Map<String,Object>> findNodeListByName(String label, String name) {
|
|
- String query = String.format("MATCH (n:`%s`) WHERE n.name =~ %s$name%s and n.is_deleted = 'N' RETURN n", label,".*",".*");
|
|
|
|
|
|
+ String query = String.format("MATCH (n:`%s`) WHERE n.name contains $name and n.is_deleted = 'N' RETURN n", label);
|
|
|
|
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
StatementResult result = session.run(query,Values.parameters("name", name));
|
|
StatementResult result = session.run(query,Values.parameters("name", name));
|
|
@@ -70,6 +87,12 @@ public class BaseNodeRepository {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 新增实体
|
|
|
|
+ * @param label
|
|
|
|
+ * @param properties
|
|
|
|
+ * @return 实体map
|
|
|
|
+ */
|
|
public Map<String, Object> createNode(String label, Map<String, Object> properties) {
|
|
public Map<String, Object> createNode(String label, Map<String, Object> properties) {
|
|
StringBuilder createClause = new StringBuilder();
|
|
StringBuilder createClause = new StringBuilder();
|
|
properties.put("is_deleted","N");
|
|
properties.put("is_deleted","N");
|
|
@@ -96,10 +119,16 @@ public class BaseNodeRepository {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 更新实体名称
|
|
|
|
+ * @param nodeId
|
|
|
|
+ * @param name
|
|
|
|
+ * @return 实体map
|
|
|
|
+ */
|
|
public Map<String, Object> updateNode(Long nodeId, String name) {
|
|
public Map<String, Object> updateNode(Long nodeId, String name) {
|
|
String query = "MATCH (n) WHERE id(n) = $nodeId SET n.name=$name RETURN n";
|
|
String query = "MATCH (n) WHERE id(n) = $nodeId SET n.name=$name RETURN n";
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
try(Session session = Neo4jUtil.getSession()) {
|
|
- StatementResult result = session.run(query,Values.parameters("name", name));
|
|
|
|
|
|
+ StatementResult result = session.run(query,Values.parameters("nodeId", nodeId,"name", name));
|
|
Map<String,Object> map = new HashMap<>();
|
|
Map<String,Object> map = new HashMap<>();
|
|
if(result.hasNext()) {
|
|
if(result.hasNext()) {
|
|
Node node = result.single().get("n").asNode();
|
|
Node node = result.single().get("n").asNode();
|
|
@@ -111,6 +140,10 @@ public class BaseNodeRepository {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 删除实体
|
|
|
|
+ * @param nodeId
|
|
|
|
+ */
|
|
public void deleteNode(Long nodeId) {
|
|
public void deleteNode(Long nodeId) {
|
|
String query = "MATCH (n) WHERE id(n) = $nodeId SET n.is_deleted = 'Y' " +
|
|
String query = "MATCH (n) WHERE id(n) = $nodeId SET n.is_deleted = 'Y' " +
|
|
"WITH n MATCH (n)-[r]-() " +
|
|
"WITH n MATCH (n)-[r]-() " +
|