diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/controller/EsTestController.java b/ruoyi-api/src/main/java/com/ruoyi/api/controller/EsTestController.java index 0d71aba..fec4319 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/controller/EsTestController.java +++ b/ruoyi-api/src/main/java/com/ruoyi/api/controller/EsTestController.java @@ -9,7 +9,6 @@ import com.ruoyi.api.domain.ESDao; import org.elasticsearch.search.SearchHits; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java b/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java index d21e773..c8d52c6 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java +++ b/ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java @@ -1,17 +1,20 @@ package com.ruoyi.api.controller; +import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import com.ruoyi.api.mapper.ZhyPointMapper; import com.ruoyi.api.service.impl.PointService; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.utils.Neo4jUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; + import java.io.IOException; +import java.lang.reflect.Type; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,6 +29,9 @@ public class TestXiaoTuPuController extends BaseController { @Autowired PointService pointService; + @Autowired + ZhyPointMapper zhyPointMapper; + private static final Gson gson = new GsonBuilder().create(); private static final Type LIST_MAP_TYPE = new TypeToken>>(){}.getType(); @@ -81,17 +87,37 @@ public class TestXiaoTuPuController extends BaseController { } // 查询某个节点的关系信息 - @GetMapping("test5") - public void test5() { - String cypher = "MATCH (n:TestNode)-[r]-(m:TestNode) WHERE id(n) = 24 OR id(m) = 24 RETURN n, m, r"; + @GetMapping("test5/{name}") + public Map test5(@PathVariable("name")String name) { + + List list = zhyPointMapper.selectPointByName(name); + if (list.size()==0){ + Map map = new HashMap<>(); + map.put("nodes",new ArrayList<>()); + map.put("links",new ArrayList<>()); + return map; + } + Integer uuid = Integer.valueOf(String.valueOf(list.get(0).get("uuid"))); + + String cypher ="MATCH (center:TestNode)\n" + + "WHERE id(center) = "+uuid+"\n" + + "MATCH path = (center)-[*1..2]-(other:TestNode)\n" + + "UNWIND relationships(path) AS r\n" + + "WITH r, startNode(r) AS n, endNode(r) AS m\n" + + "RETURN DISTINCT n, m, r"; + + HashMap graphNode = neo4jUtil.getGraphNodeAndShip(cypher); Object node1 = graphNode.get("node"); - List kk1 = (List) node1; List rrk1 = (List) graphNode.get("relationship"); System.out.println(kk1); System.out.println(rrk1); + + + Map a = convertToGraphFormat(kk1,rrk1); + return a; } // 查询所有节点的所有关系 @@ -132,14 +158,15 @@ public class TestXiaoTuPuController extends BaseController { Map newNode = new HashMap<>(); String id = String.valueOf(node.get("uuid")); String text = String.valueOf(node.get("name")); + String type = String.valueOf(node.get("type")); // 过滤 null 和 "null" if ("null".equals(id)) id = UUID.randomUUID().toString(); // 安全兜底 if ("null".equals(text)) text = "未知节点"; + if ("null".equals(type)) type = "null"; newNode.put("id", id); + newNode.put("type", type); newNode.put("text", text); - -// newNode.put("color",) // newNode.put("data", new HashMap<>()); // 可扩展 nodes.add(newNode); }