Browse Source

Merge branch 'hanyuqing' of http://124.70.32.114:3100/jianzhenyu/Changsha_tupu into small-tupu

small-tupu
菅振宇 7 months ago
parent
commit
a15c2ff4df
  1. 6
      gyxtp/src/api/api/graph.js
  2. 24
      gyxtp/src/view/small.vue
  3. 70
      ruoyi-api/src/main/java/com/ruoyi/api/controller/TestXiaoTuPuController.java

6
gyxtp/src/api/api/graph.js

@ -75,3 +75,9 @@ export const getpoinByName = (param) => {
method: 'get',
});
};
export const getKeyWorlds = () => {
return request({
url: '/api/test/getKeyWorlds',
method: 'get',
});
};

24
gyxtp/src/view/small.vue

@ -236,7 +236,7 @@ import { demoData } from '@/assets/demo2.js'
import HeaderInfo from "@/components/UseAll/headerInfo.vue";
import leftInfo from "@/components/UseAll/leftInfo.vue";
import { getAllTitle, getDocInfo } from "@/api/api/doc";
import {getDomainGraphTest, getpoinAll, getpoinByName} from "@/api/api/graph";
import {getDomainGraphTest, getKeyWorlds, getpoinAll, getpoinByName} from "@/api/api/graph";
import { Picture } from "@element-plus/icons-vue";
import { selectAticleByRelation } from '@/api/api/article'
@ -589,16 +589,8 @@ export default {
// },
async onLineClick(lineObject, linkObject, event) {
const from = linkObject.fromNode.data.docId
const to = linkObject.toNode.data.docId
const data = {
sourceId: from,
targetId: to,
}
this.tableData = await selectAticleByRelation(data);
this.drawer = true;
console.log(this.tableData)
console.log(this.drawer)
console.log(linkObject.data)
console.log(linkObject.relations[0].data)
},
//
zhengl(data) {
@ -681,6 +673,10 @@ export default {
// this.getAll();
// this.drawGraphData()
getKeyWorlds().then((res)=>{
console.log(res)
})
getpoinByName(this.getpoinName).then((res) => {
let nodes = []
let links = []
@ -695,12 +691,18 @@ export default {
}
nodes.push(t_data)
}
// console.log(res.links)
for (let i = 0;i<res.links.length;i++){
let t_data = {
from:res.links[i].from,
to:res.links[i].to,
text:res.links[i].text,
data:{
uuids:res.links[i].uuids,
num:res.links[i].num
}
}
console.log(t_data)
links.push(t_data)
}

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

@ -88,7 +88,7 @@ public class TestXiaoTuPuController extends BaseController {
// 查询某个节点的关系信息
@GetMapping("test5/{name}")
public Map<String, Object> test5(@PathVariable("name")String name) {
public Map<String, List<Map<String, Object>>> test5(@PathVariable("name")String name) {
List<Map> list = zhyPointMapper.selectPointByName(name);
if (list.size()==0){
@ -112,17 +112,19 @@ public class TestXiaoTuPuController extends BaseController {
List<Map> kk1 = (List<Map>) node1;
List<Map> rrk1 = (List<Map>) graphNode.get("relationship");
System.out.println(kk1);
System.out.println(rrk1);
Map<String, List<Map<String, Object>>> a = convertToGraphFormat(kk1,rrk1);
System.out.println(a.get("links"));
List<Map<String, Object>> relationships = mergeRelationships(a.get("links"));
a.put("links",relationships);
Map<String, Object> a = convertToGraphFormat(kk1,rrk1);
System.out.println(a.get("links"));
return a;
}
// 查询所有节点的所有关系
@GetMapping("test6")
public Map<String, Object> test6() {
public Map<String, List<Map<String, Object>>> test6() {
String cypher = "MATCH (n:TestNode)-[r]-(m:TestNode) RETURN n, m, r";
HashMap<String, Object> graphNode = neo4jUtil.getGraphNodeAndShip(cypher);
Object node1 = graphNode.get("node");
@ -132,7 +134,7 @@ public class TestXiaoTuPuController extends BaseController {
System.out.println(rrk1);
Map<String, Object> a = convertToGraphFormat(kk1,rrk1);
Map<String, List<Map<String, Object>>> a = convertToGraphFormat(kk1,rrk1);
return a;
}
@ -164,7 +166,7 @@ public class TestXiaoTuPuController extends BaseController {
public Map<String, Object> convertToGraphFormat(List<Map> rawNodes, List<Map> rawRelationships) {
public Map<String, List<Map<String, Object>>> convertToGraphFormat(List<Map> rawNodes, List<Map> rawRelationships) {
List<Map<String, Object>> nodes = new ArrayList<>();
List<Map<String, Object>> links = new ArrayList<>();
@ -197,6 +199,7 @@ public class TestXiaoTuPuController extends BaseController {
String from = String.valueOf(rel.get("sourceid"));
String to = String.valueOf(rel.get("targetid"));
String data = String.valueOf(rel.get("data"));
String uuid = String.valueOf(rel.get("uuid"));
Map<String, String> datamap = convertStringToMap(data);
String relType = datamap.get("relType"); // 默认值
@ -208,13 +211,14 @@ public class TestXiaoTuPuController extends BaseController {
newLink.put("from", from);
newLink.put("to", to);
newLink.put("uuid",uuid);
newLink.put("text", relType.isEmpty() ? "关联" : relType);
links.add(newLink);
}
}
// 返回前端格式
Map<String, Object> result = new HashMap<>();
Map<String, List<Map<String, Object>>> result = new HashMap<>();
result.put("nodes", nodes);
result.put("links", links);
return result;
@ -279,6 +283,56 @@ public class TestXiaoTuPuController extends BaseController {
return map;
}
public static List<Map<String, Object>> mergeRelationships(List<Map<String, Object>> relationships) {
Map<String, Map<String, Object>> merged = new HashMap<>();
for (Map rel : relationships) {
// 提取关键字段
String from = String.valueOf(rel.get("from")) ;
String to =String.valueOf(rel.get("to"));
String text = String.valueOf(rel.get("text")); // 可作为业务类型,比如 "相关作者"
String uuid = String.valueOf(rel.get("uuid"));
// 构建唯一键:from -> to
String key = from + "->" + to;
if (!merged.containsKey(key)) {
// 第一次出现,创建新关系
Map<String, Object> newRel = new HashMap<>();
newRel.put("from", from);
newRel.put("to", to);
newRel.put("text", text);
// 复制其他非核心字段(可选,如 style, color 等)
for (Object k : rel.keySet()) {
String field = (String) k;
if (!Arrays.asList("from", "to", "text", "uuid").contains(field)) {
newRel.put(field, rel.get(field));
}
}
// 初始化合并字段
newRel.put("num", 1);
List<String> uuids = new ArrayList<>();
if (uuid != null) uuids.add(uuid);
newRel.put("uuids", uuids);
merged.put(key, newRel);
} else {
// 已存在,进行合并
Map<String, Object> existing = merged.get(key);
existing.put("num", (int) existing.get("num") + 1);
List<String> uuids = (List<String>) existing.get("uuids");
if (uuid != null && !uuids.contains(uuid)) {
uuids.add(uuid);
}
}
}
return new ArrayList<>(merged.values());
}
}

Loading…
Cancel
Save