Browse Source

yangshi

small-tupu
菅振宇 7 months ago
parent
commit
ef97021510
  1. 503
      gyxtp/src/view/graphPageCopy.vue
  2. 12
      ruoyi-api/src/main/java/com/ruoyi/api/controller/EsTestController.java
  3. 19
      ruoyi-api/src/main/java/com/ruoyi/api/domain/ESDao.java
  4. 4
      ruoyi-api/src/main/java/com/ruoyi/api/service/impl/GraphServiceImpl.java
  5. 3
      ruoyi-system/src/main/resources/mapper/system/ZhyDocRelationMapper.xml

503
gyxtp/src/view/graphPageCopy.vue

@ -228,6 +228,7 @@ import {getAllTitle, getDocInfo} from "@/api/api/doc";
import {getDomainGraphTest, getheightLight} from "@/api/api/graph"; import {getDomainGraphTest, getheightLight} from "@/api/api/graph";
import {Picture} from "@element-plus/icons-vue"; import {Picture} from "@element-plus/icons-vue";
import {selectAticleByRelation} from '@/api/api/article' import {selectAticleByRelation} from '@/api/api/article'
import {height} from "fontfaceobserver";
export default { export default {
components: { components: {
@ -521,22 +522,53 @@ export default {
"nodes": res.nodes.hits, "nodes": res.nodes.hits,
"links":res.links.hits "links":res.links.hits
} }
console.log(this.heightLight)
getDomainGraphTest({}).then((r) => { getDomainGraphTest({}).then((r) => {
this.zhengl(r.data); this.zhengl(r.data);
}) })
}) })
}, },
getNodeClass(id){ getNodeClass(name) {
if (this.heightLight=={}){
return "" // this.heightLight.nodes
const nodes = this.heightLight.nodes;
if (!Array.isArray(nodes) || nodes.length === 0) {
return "";
} }
if (id) { // id
this.heightLight.nodes const targetId = String(name).trim();
// nodes id targetId
const found = nodes.some(node => {
const nodeId = node.sourceAsMap.abstracts
return nodeId === targetId;
});
// 'nodeclass' ''
return found ? 'nodeclass' : '';
},
getLinesClass(from) {
const lines = this.heightLight.links;
if (lines == undefined){
return
} }
return ""
return "nodeclass" // id
const targetId = String(from).trim();
const found = lines.some(line => {
const data = line.sourceAsMap.data
return data.some(item => {
const source = item.source;
console.log(source)
console.log(targetId)
return source === targetId;
});
});
// 'nodeclass' ''
return found ? 'lineclass' : '';
}, },
async onLineClick(lineObject, linkObject, event) { async onLineClick(lineObject, linkObject, event) {
const from = linkObject.fromNode.data.docId const from = linkObject.fromNode.data.docId
@ -552,6 +584,7 @@ export default {
// //
// //
zhengl(data) { zhengl(data) {
console.log(data)
const nodes = [] const nodes = []
const links = [] const links = []
const nodeList = data.nodes; const nodeList = data.nodes;
@ -708,7 +741,7 @@ export default {
color: color, color: color,
font: `normal ${fontSize} Arial`, font: `normal ${fontSize} Arial`,
fontColor: fontColor, fontColor: fontColor,
styleClass:this.getNodeClass(node.id), styleClass:this.getNodeClass(node.name),
}); });
}); });
}); });
@ -801,7 +834,7 @@ export default {
color: color, color: color,
font: `normal ${fontSize} Arial`, font: `normal ${fontSize} Arial`,
fontColor: fontColor, fontColor: fontColor,
styleClass:"nodeclass", styleClass:this.getNodeClass(node.name),
}); });
}); });
} else { } else {
@ -884,7 +917,7 @@ export default {
color: color, color: color,
font: `normal ${fontSize} Arial`, font: `normal ${fontSize} Arial`,
fontColor: fontColor, fontColor: fontColor,
styleClass:"nodeclass", styleClass:this.getNodeClass(node.name),
}); });
currentLeftX -= 200; currentLeftX -= 200;
@ -952,7 +985,7 @@ export default {
color: color, color: color,
font: `normal ${fontSize} Arial`, font: `normal ${fontSize} Arial`,
fontColor: fontColor, fontColor: fontColor,
styleClass:"nodeclass", styleClass:this.getNodeClass(node.name),
}); });
currentRightX += 200; currentRightX += 200;
@ -960,9 +993,9 @@ export default {
} }
}); });
}); });
// 线 // 线
lineList.forEach(line => { lineList.forEach(line => {
console.log(line)
links.push({ links.push({
from: line.source, from: line.source,
to: line.target, to: line.target,
@ -972,451 +1005,9 @@ export default {
line.num <= 10 ? 'rgb(0, 255, 0)' : // 绿 line.num <= 10 ? 'rgb(0, 255, 0)' : // 绿
line.num <= 15 ? 'rgb(255, 255, 0)' : // line.num <= 15 ? 'rgb(255, 255, 0)' : //
'rgb(178,246,255)', // line.num <= 2020 'rgb(178,246,255)', // line.num <= 2020
lineWidth:10, lineWidth:1,
lineShape: 1,
styleClass:"lineclass",
})
});
this.graphData = {
'rootId': this.rootId,
nodes,
links
};
//
this.$nextTick(() => {
if (this.$refs.graphRef) {
this.$refs.graphRef.setOptions(this.graphOptions);
this.$refs.graphRef.setJsonData(this.graphData);
this.$refs.graphRef.refresh();
}
});
},
zhengl1(data) {
const nodes = []
const links = []
const nodeList = data.nodes;
const lineList = data.links;
// 便
const nodeMap = {};
nodeList.forEach(node => {
nodeMap[node.id] = node;
});
//
const connectedNodeIds = new Set();
lineList.forEach(line => {
connectedNodeIds.add(line.source);
connectedNodeIds.add(line.target);
});
//
const isolatedNodesByGroupAndLevel = {};
nodeList.forEach(node => {
if (!connectedNodeIds.has(node.id)) {
const groupId = node.groupId || '1';
const level = node.docLeve || '0';
if (!isolatedNodesByGroupAndLevel[groupId]) {
isolatedNodesByGroupAndLevel[groupId] = {};
}
if (!isolatedNodesByGroupAndLevel[groupId][level]) {
isolatedNodesByGroupAndLevel[groupId][level] = [];
}
isolatedNodesByGroupAndLevel[groupId][level].push(node);
}
});
//
const levelGroupPositions = {};
//
if (nodeList != undefined) {
//
const groupedNodes = {
'0': {levels: {}},
'1': {levels: {}},
'2': {levels: {}}
};
//
nodeList.forEach(node => {
if (connectedNodeIds.has(node.id)) {
const groupId = node.groupId || '1';
const level = node.docLeve || '1';
if (!groupedNodes[groupId]) groupedNodes[groupId] = {levels: {}};
if (!groupedNodes[groupId].levels[level]) groupedNodes[groupId].levels[level] = [];
groupedNodes[groupId].levels[level].push(node);
}
});
//
const groupOffsets = {
'0': -10200, //
'1': 0, //
'2': 10200 //
};
//
Object.keys(groupedNodes).forEach(groupId => {
const groupData = groupedNodes[groupId];
const groupOffsetX = groupOffsets[groupId] || 0;
//
Object.keys(groupData.levels).sort().forEach(level => {
const levelNodes = groupData.levels[level].sort((a, b) => a.docId - b.docId);
const levelNum = parseInt(level);
// X
const startX = groupOffsetX - (levelNodes.length * 200) / 2;
//
const levelGroupKey = `${levelNum}_${groupId}`;
if (!levelGroupPositions[levelGroupKey]) {
levelGroupPositions[levelGroupKey] = {
minX: startX,
maxX: startX + levelNodes.length * 200,
leftAvailableX: startX - 200, //
rightAvailableX: startX + levelNodes.length * 200 + 200, //
hasConnectedNodes: levelNodes.length > 0
};
}
levelNodes.forEach((node, index) => {
if (levelNum === 0) this.rootId = node.id;
//
let color, fontSize, fontColor;
switch (levelNum) {
case 0:
color = 'rgb(227,203,0)';
fontSize = '70px';
fontColor = 'rgb(255,255,255)';
break;
case 1:
color = 'rgb(47,47,230)';
fontSize = '68px';
fontColor = 'rgb(255,255,255)';
break;
case 2:
color = 'rgb(255,138,0)';
fontSize = '50px';
fontColor = 'rgb(255,255,255)';
break;
case 3:
color = 'rgb(30,255,0)';
fontSize = '40px';
fontColor = 'rgb(0,0,0)';
break;
case 4:
color = 'rgb(248,143,248)';
fontSize = '32px';
fontColor = 'rgb(255,255,255)';
break;
case 5:
color = 'rgb(65,154,255)';
fontSize = '30px';
fontColor = 'rgb(255,255,255)';
break;
case 6:
color = 'rgb(0,228,255)';
fontSize = '28px';
fontColor = 'rgb(0,0,0)';
break;
default:
color = 'rgb(200,200,200)';
fontSize = '24px';
fontColor = 'rgb(255,255,255)';
}
const x = startX + index * 200;
const y = levelNum * 1400;
//
nodes.push({
id: node.id,
text: node.name,
data: {
docId: node.docId,
group: node.groupId
},
level: levelNum,
x: x,
y: y,
fixed: true,
width: 150,
height: 150,
color: color,
font: `normal ${fontSize} Arial`,
fontColor: fontColor
});
});
});
});
}
// - 线
Object.keys(isolatedNodesByGroupAndLevel).sort().forEach(groupId => {
const groupData = isolatedNodesByGroupAndLevel[groupId];
const groupOffsetX = groupId === '0' ? -10200 : groupId === '1' ? 0 : 10200;
Object.keys(groupData).sort().forEach(level => {
const levelNodes = groupData[level];
const levelNum = parseInt(level);
// Y
const y = levelNum * 1400;
//
const levelGroupKey = `${levelNum}_${groupId}`;
// docId
const sortedIsolatedNodes = levelNodes.sort((a, b) => a.docId - b.docId);
if (!levelGroupPositions[levelGroupKey] || !levelGroupPositions[levelGroupKey].hasConnectedNodes) {
//
const totalWidth = sortedIsolatedNodes.length * 200;
const startX = groupOffsetX - totalWidth / 2;
//
sortedIsolatedNodes.forEach((node, index) => {
//
let color, fontSize, fontColor;
switch (levelNum) {
case 0:
color = 'rgb(227,203,0)';
fontSize = '70px';
fontColor = 'rgb(255,255,255)';
break;
case 1:
color = 'rgb(47,47,230)';
fontSize = '68px';
fontColor = 'rgb(255,255,255)';
break;
case 2:
color = 'rgb(255,138,0)';
fontSize = '50px';
fontColor = 'rgb(255,255,255)';
break;
case 3:
color = 'rgb(30,255,0)';
fontSize = '40px';
fontColor = 'rgb(0,0,0)';
break;
case 4:
color = 'rgb(248,143,248)';
fontSize = '32px';
fontColor = 'rgb(255,255,255)';
break;
case 5:
color = 'rgb(65,154,255)';
fontSize = '30px';
fontColor = 'rgb(255,255,255)';
break;
case 6:
color = 'rgb(0,228,255)';
fontSize = '28px';
fontColor = 'rgb(0,0,0)';
break;
default:
color = 'rgb(200,200,200)';
fontSize = '24px';
fontColor = 'rgb(255,255,255)';
}
const x = startX + index * 200;
nodes.push({
id: node.id,
text: node.name,
data: {
docId: node.docId,
group: node.groupId
},
x: x,
y: y,
fixed: true,
width: 150,
height: 150,
color: color,
font: `normal ${fontSize} Arial`,
fontColor: fontColor
});
});
} else {
//
const positionInfo = levelGroupPositions[levelGroupKey];
//
const leftNodes = [];
const rightNodes = [];
sortedIsolatedNodes.forEach((node, index) => {
if (index % 2 === 0) {
leftNodes.push(node); //
} else {
rightNodes.push(node); //
}
});
//
let currentLeftX = positionInfo.leftAvailableX;
for (let i = leftNodes.length - 1; i >= 0; i--) {
const node = leftNodes[i];
//
let color, fontSize, fontColor;
switch (levelNum) {
case 0:
color = 'rgb(227,203,0)';
fontSize = '70px';
fontColor = 'rgb(255,255,255)';
break;
case 1:
color = 'rgb(47,47,230)';
fontSize = '68px';
fontColor = 'rgb(255,255,255)';
break;
case 2:
color = 'rgb(255,138,0)';
fontSize = '50px';
fontColor = 'rgb(255,255,255)';
break;
case 3:
color = 'rgb(30,255,0)';
fontSize = '40px';
fontColor = 'rgb(0,0,0)';
break;
case 4:
color = 'rgb(248,143,248)';
fontSize = '32px';
fontColor = 'rgb(255,255,255)';
break;
case 5:
color = 'rgb(65,154,255)';
fontSize = '30px';
fontColor = 'rgb(255,255,255)';
break;
case 6:
color = 'rgb(0,228,255)';
fontSize = '28px';
fontColor = 'rgb(0,0,0)';
break;
default:
color = 'rgb(200,200,200)';
fontSize = '24px';
fontColor = 'rgb(255,255,255)';
}
nodes.push({
id: node.id,
text: node.name,
data: {
docId: node.docId,
group: node.groupId
},
x: currentLeftX,
y: y,
fixed: true,
width: 150,
height: 150,
color: color,
font: `normal ${fontSize} Arial`,
fontColor: fontColor
});
currentLeftX -= 200;
}
//
let currentRightX = positionInfo.rightAvailableX;
rightNodes.forEach(node => {
//
let color, fontSize, fontColor;
switch (levelNum) {
case 0:
color = 'rgb(227,203,0)';
fontSize = '70px';
fontColor = 'rgb(255,255,255)';
break;
case 1:
color = 'rgb(47,47,230)';
fontSize = '68px';
fontColor = 'rgb(255,255,255)';
break;
case 2:
color = 'rgb(255,138,0)';
fontSize = '50px';
fontColor = 'rgb(255,255,255)';
break;
case 3:
color = 'rgb(30,255,0)';
fontSize = '40px';
fontColor = 'rgb(0,0,0)';
break;
case 4:
color = 'rgb(248,143,248)';
fontSize = '32px';
fontColor = 'rgb(255,255,255)';
break;
case 5:
color = 'rgb(65,154,255)';
fontSize = '30px';
fontColor = 'rgb(255,255,255)';
break;
case 6:
color = 'rgb(0,228,255)';
fontSize = '28px';
fontColor = 'rgb(0,0,0)';
break;
default:
color = 'rgb(200,200,200)';
fontSize = '24px';
fontColor = 'rgb(255,255,255)';
}
nodes.push({
id: node.id,
text: node.name,
data: {
docId: node.docId,
group: node.groupId
},
x: currentRightX,
y: y,
fixed: true,
width: 150,
height: 150,
color: color,
font: `normal ${fontSize} Arial`,
fontColor: fontColor
});
currentRightX += 200;
});
}
});
});
// 线
lineList.forEach(line => {
links.push({
from: line.source,
to: line.target,
text: line.relate || '相关',
color:
line.num <= 5 ? 'rgb(255, 255, 255)' : //
line.num <= 10 ? 'rgb(0, 255, 0)' : // 绿
line.num <= 15 ? 'rgb(255, 255, 0)' : //
'rgb(255, 0, 0)', // line.num <= 2020
lineWidth:
line.num <= 5 ? 1 :
line.num <= 10 ? 1.1 :
line.num <= 15 ? 1.2 :
line.num <= 20 ? 15 : 1.3,
lineShape: 1, lineShape: 1,
styleClass:this.getLinesClass(line.source),
}) })
}); });

12
ruoyi-api/src/main/java/com/ruoyi/api/controller/EsTestController.java

@ -9,7 +9,9 @@ import com.ruoyi.api.domain.ESDao;
import com.ruoyi.api.domain.ZhyDocApi; import com.ruoyi.api.domain.ZhyDocApi;
import com.ruoyi.api.mapper.ZhyDocApiMapper; import com.ruoyi.api.mapper.ZhyDocApiMapper;
import com.ruoyi.system.domain.ZhyArticle; import com.ruoyi.system.domain.ZhyArticle;
import com.ruoyi.system.domain.ZhyDocRelation;
import com.ruoyi.system.mapper.ZhyArticleMapper; import com.ruoyi.system.mapper.ZhyArticleMapper;
import com.ruoyi.system.mapper.ZhyDocRelationMapper;
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;
@ -45,6 +47,8 @@ public class EsTestController {
@Autowired @Autowired
ZhyArticleMapper zhyArticleMapper; ZhyArticleMapper zhyArticleMapper;
@Autowired
ZhyDocRelationMapper zhyDocRelationMapper;
@Autowired @Autowired
private org.elasticsearch.client.RestHighLevelClient client; private org.elasticsearch.client.RestHighLevelClient client;
@ -57,7 +61,8 @@ public class EsTestController {
@GetMapping("/esdeleteIndex") @GetMapping("/esdeleteIndex")
public boolean deleteIndex() throws IOException { public boolean deleteIndex() throws IOException {
return elasticSearchUtil.deleteIndex("111"); elasticSearchUtil.deleteIndex("nodes");
return elasticSearchUtil.deleteIndex("links");
} }
@GetMapping("/esQuery2") @GetMapping("/esQuery2")
public SearchHits indexCreate2() throws Throwable { public SearchHits indexCreate2() throws Throwable {
@ -116,6 +121,7 @@ public class EsTestController {
esDao.DBid = id; esDao.DBid = id;
esDao.type = "node"; esDao.type = "node";
esDao.abstracts = abstracts; esDao.abstracts = abstracts;
esDao.data = null;
bookList.add(esDao); bookList.add(esDao);
} }
elasticSearchUtil.addDocBatch("nodes", bookList, ESDao.class, "id"); elasticSearchUtil.addDocBatch("nodes", bookList, ESDao.class, "id");
@ -126,12 +132,16 @@ public class EsTestController {
for (int i=0;i<lineList.size();i++){ for (int i=0;i<lineList.size();i++){
String abstracts = lineList.get(i).getName()+lineList.get(i).getKeywords()+lineList.get(i).getSummary(); String abstracts = lineList.get(i).getName()+lineList.get(i).getKeywords()+lineList.get(i).getSummary();
String id = String.valueOf(lineList.get(i).getId()); String id = String.valueOf(lineList.get(i).getId());
ZhyDocRelation zhyDocRelation = new ZhyDocRelation();
zhyDocRelation.setArticleId(lineList.get(i).getId());
List<Map> a = zhyDocRelationMapper.selectZhyRelationshipArticle(zhyDocRelation);
ESDao esDao = new ESDao(); ESDao esDao = new ESDao();
esDao.id = id; esDao.id = id;
esDao.DBid = id; esDao.DBid = id;
esDao.type = "line"; esDao.type = "line";
esDao.abstracts = abstracts; esDao.abstracts = abstracts;
esDao.data = a;
bookList.add(esDao); bookList.add(esDao);
} }
elasticSearchUtil.addDocBatch("links", bookList, ESDao.class, "id"); elasticSearchUtil.addDocBatch("links", bookList, ESDao.class, "id");

19
ruoyi-api/src/main/java/com/ruoyi/api/domain/ESDao.java

@ -1,25 +1,38 @@
package com.ruoyi.api.domain; package com.ruoyi.api.domain;
import java.util.List;
import java.util.Map;
public class ESDao { public class ESDao {
public String id; public String id;
public String DBid; //图谱中线id public String DBid; //图谱中线id
public String type; public String type;
public String abstracts; //摘要 public String abstracts; //摘要
public List<Map> data;
public String getId() { public String getId() {
return id; return id;
} }
public List<Map> getData() {
return data;
}
@Override @Override
public String toString() { public String toString() {
return "ESDao{" + return "ESDao{" +
"id=" + id + "id='" + id + '\'' +
", DBid=" + DBid + ", DBid='" + DBid + '\'' +
", type=" + type + ", type='" + type + '\'' +
", abstracts='" + abstracts + '\'' + ", abstracts='" + abstracts + '\'' +
", data=" + data +
'}'; '}';
} }
public void setData(List<Map> data) {
this.data = data;
}
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }

4
ruoyi-api/src/main/java/com/ruoyi/api/service/impl/GraphServiceImpl.java

@ -872,6 +872,9 @@ public class GraphServiceImpl implements GraphService {
Map<String, HashMap<String, Object>> mergedMap = new LinkedHashMap<>(); Map<String, HashMap<String, Object>> mergedMap = new LinkedHashMap<>();
for (HashMap<String, Object> rel : relations) { for (HashMap<String, Object> rel : relations) {
// System.out.println(rel);
String sourceId = String.valueOf(rel.get("sourceid")); String sourceId = String.valueOf(rel.get("sourceid"));
String targetId = String.valueOf(rel.get("targetid")); String targetId = String.valueOf(rel.get("targetid"));
String key = sourceId + "->" + targetId; String key = sourceId + "->" + targetId;
@ -880,6 +883,7 @@ public class GraphServiceImpl implements GraphService {
link.put("source", sourceId); link.put("source", sourceId);
link.put("target", targetId); link.put("target", targetId);
link.put("relate", rel.get("name")); link.put("relate", rel.get("name"));
link.put("id",rel.get("uuid"));
HashMap<String, Object> srcNode = nodeIndex.get(sourceId); HashMap<String, Object> srcNode = nodeIndex.get(sourceId);
HashMap<String, Object> tgtNode = nodeIndex.get(targetId); HashMap<String, Object> tgtNode = nodeIndex.get(targetId);

3
ruoyi-system/src/main/resources/mapper/system/ZhyDocRelationMapper.xml

@ -132,6 +132,9 @@ from zhy_relationship </sql>
<if test="targetName != null and targetName != ''"> <if test="targetName != null and targetName != ''">
AND r.targetName = #{targetName} AND r.targetName = #{targetName}
</if> </if>
<if test="articleId != null and articleId != ''">
AND r.article_id = #{articleId}
</if>
</where> </where>
ORDER BY r.create_time DESC ORDER BY r.create_time DESC

Loading…
Cancel
Save