Browse Source

controller

zxm
菅振宇 7 months ago
parent
commit
264e45f10d
  1. 1
      ruoyi-api/src/main/java/com/ruoyi/api/controller/EsTestController.java
  2. 45
      ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java

1
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.elasticsearch.search.SearchHits;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;

45
ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java

@ -1,17 +1,20 @@
package com.ruoyi.api.controller; package com.ruoyi.api.controller;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder; 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.api.service.impl.PointService;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.Neo4jUtil; import com.ruoyi.common.utils.Neo4jUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; 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.io.IOException;
import java.lang.reflect.Type;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -26,6 +29,9 @@ public class TestXiaoTuPuController extends BaseController {
@Autowired @Autowired
PointService pointService; PointService pointService;
@Autowired
ZhyPointMapper zhyPointMapper;
private static final Gson gson = new GsonBuilder().create(); private static final Gson gson = new GsonBuilder().create();
private static final Type LIST_MAP_TYPE = new TypeToken<List<Map<String, Object>>>(){}.getType(); private static final Type LIST_MAP_TYPE = new TypeToken<List<Map<String, Object>>>(){}.getType();
@ -81,17 +87,37 @@ public class TestXiaoTuPuController extends BaseController {
} }
// 查询某个节点的关系信息 // 查询某个节点的关系信息
@GetMapping("test5") @GetMapping("test5/{name}")
public void test5() { public Map<String, Object> test5(@PathVariable("name")String name) {
String cypher = "MATCH (n:TestNode)-[r]-(m:TestNode) WHERE id(n) = 24 OR id(m) = 24 RETURN n, m, r";
List<Map> 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<String, Object> graphNode = neo4jUtil.getGraphNodeAndShip(cypher); HashMap<String, Object> graphNode = neo4jUtil.getGraphNodeAndShip(cypher);
Object node1 = graphNode.get("node"); Object node1 = graphNode.get("node");
List<Map> kk1 = (List<Map>) node1; List<Map> kk1 = (List<Map>) node1;
List<Map> rrk1 = (List<Map>) graphNode.get("relationship"); List<Map> rrk1 = (List<Map>) graphNode.get("relationship");
System.out.println(kk1); System.out.println(kk1);
System.out.println(rrk1); System.out.println(rrk1);
Map<String, Object> a = convertToGraphFormat(kk1,rrk1);
return a;
} }
// 查询所有节点的所有关系 // 查询所有节点的所有关系
@ -132,14 +158,15 @@ public class TestXiaoTuPuController extends BaseController {
Map<String, Object> newNode = new HashMap<>(); Map<String, Object> newNode = new HashMap<>();
String id = String.valueOf(node.get("uuid")); String id = String.valueOf(node.get("uuid"));
String text = String.valueOf(node.get("name")); String text = String.valueOf(node.get("name"));
String type = String.valueOf(node.get("type"));
// 过滤 null 和 "null" // 过滤 null 和 "null"
if ("null".equals(id)) id = UUID.randomUUID().toString(); // 安全兜底 if ("null".equals(id)) id = UUID.randomUUID().toString(); // 安全兜底
if ("null".equals(text)) text = "未知节点"; if ("null".equals(text)) text = "未知节点";
if ("null".equals(type)) type = "null";
newNode.put("id", id); newNode.put("id", id);
newNode.put("type", type);
newNode.put("text", text); newNode.put("text", text);
// newNode.put("color",)
// newNode.put("data", new HashMap<>()); // 可扩展 // newNode.put("data", new HashMap<>()); // 可扩展
nodes.add(newNode); nodes.add(newNode);
} }

Loading…
Cancel
Save