|
|
|
@ -1,18 +1,20 @@ |
|
|
|
package com.ruoyi.api.controller; |
|
|
|
|
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.GsonBuilder; |
|
|
|
import com.ruoyi.api.WebSocketService; |
|
|
|
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; |
|
|
|
@ -27,18 +29,8 @@ public class TestXiaoTuPuController extends BaseController { |
|
|
|
@Autowired |
|
|
|
PointService pointService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
WebSocketService webSocketService; |
|
|
|
|
|
|
|
@GetMapping("testsocket") |
|
|
|
public void testsocket(){ |
|
|
|
webSocketService.sendToUser("123","wahahaooo"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ZhyPointMapper zhyPointMapper; |
|
|
|
|
|
|
|
private static final Gson gson = new GsonBuilder().create(); |
|
|
|
private static final Type LIST_MAP_TYPE = new TypeToken<List<Map<String, Object>>>(){}.getType(); |
|
|
|
@ -53,8 +45,6 @@ public class TestXiaoTuPuController extends BaseController { |
|
|
|
neo4jUtil.excuteCypherSql(cypher); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("test2") |
|
|
|
public void test2() { |
|
|
|
try { |
|
|
|
@ -97,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<String, Object> test5(@PathVariable("name")String name) { |
|
|
|
|
|
|
|
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); |
|
|
|
Object node1 = graphNode.get("node"); |
|
|
|
|
|
|
|
|
|
|
|
List<Map> kk1 = (List<Map>) node1; |
|
|
|
List<Map> rrk1 = (List<Map>) graphNode.get("relationship"); |
|
|
|
System.out.println(kk1); |
|
|
|
System.out.println(rrk1); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> a = convertToGraphFormat(kk1,rrk1); |
|
|
|
return a; |
|
|
|
} |
|
|
|
|
|
|
|
// 查询所有节点的所有关系
|
|
|
|
@ -148,14 +158,15 @@ public class TestXiaoTuPuController extends BaseController { |
|
|
|
Map<String, Object> 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); |
|
|
|
} |
|
|
|
|