top图数据解析

This commit is contained in:
clay 2021-07-27 00:03:49 +08:00
parent c6693dae67
commit 42c1fda3f4
10 changed files with 423 additions and 108 deletions

View File

@ -34,6 +34,7 @@ export default {
getDefaultCfg() {
return {
multiple: true,
start:0,
};
},
getEvents() {
@ -60,12 +61,16 @@ export default {
if (nodes) {
nodes.forEach((node) => {
const model = node.getModel();
if (model.column.length < 9) {
if (model.column.length < 9 ) {
return;
}
const idx = model.startIndex || 0;
this.start=idx
let startX = model.startX || 0.5;
let startIndex = idx + e.deltaY * 0.02;
if ((model.column.length-idx)<10 && startIndex > idx){
return;
}
startX -= e.deltaX;
if (startIndex < 0) {
startIndex = 0;
@ -169,7 +174,7 @@ export default {
});
vm.selectedNodeParams = {
label: clickNodeModel.label || "",
column:clickNodeModel.column,
columns:clickNodeModel.columns,
appConfig: { ...nodeAppConfig, ...clickNodeModel.appConfig }
};
}

View File

@ -94,12 +94,22 @@ export default {
return item
}
})
//item.columnName+':'+item.columnComment
let columns = []
for (let i = 0; i < sourceNodeModel.columns.length; i++) {
let column = {
columnName:sourceNodeModel.columns[i].columnName,
columnComment:sourceNodeModel.columns[i].columnComment
}
columns.push(column)
}
self.drawEdge.currentLine = self.graph.addItem("edge", {
// id: G6.Util.uniqueId(), // 这种生成id的方式有bug会重复
id: utils.generateUUID(),
// 起始节点
source: sourceNodeModel.id,
sourceColumn:sourceNodeModel.attrs,
sourceColumn:columns,
sourceAnchor: sourceAnchor ? sourceAnchor.anchorIndex : "",
// 终止节点/位置
relational: relational,
@ -156,11 +166,19 @@ export default {
y: event.y
});
}
let columns = []
for (let i = 0; i < targetNodeModel.columns.length; i++) {
let column = {
columnName:targetNodeModel.columns[i].columnName,
columnComment:targetNodeModel.columns[i].columnComment
}
columns.push(column)
}
self.graph.updateItem(self.drawEdge.currentLine, {
target: targetNodeModel.id,
relationalItem:relationalItem,
targetAnchor: targetAnchor ? targetAnchor.anchorIndex : "",
targetColumn: targetNodeModel.attrs,
targetColumn: columns,
});
// ************** 记录historyData的逻辑 start **************

View File

@ -49,7 +49,6 @@ export default {
}
},
onNodeOut(event) {
console.log(hourItem)
const name = event.shape.get("name");
let hoverNode = event.item;
if (name && name.startsWith("marker")) {

View File

@ -33,13 +33,13 @@ export default {
};
const {
column = [],
columns = [],
startIndex = 0,
selectedIndex,
collapsed,
icon,
} = cfg;
const list = column;
const list = columns;
const afterList = list.slice(
Math.floor(startIndex),
Math.floor(startIndex + itemCount - 1)
@ -176,7 +176,7 @@ export default {
attrs: {
y: 30 +
barStyle.padding +
(startIndex / list.length) * (height - 30),
(startIndex / (list.length-8)) * (height - 30),
x: width - barStyle.padding - barStyle.width,
width: barStyle.width,
height: Math.min(height, indexHeight),

View File

@ -89,7 +89,7 @@
<span>字段信息</span>
<template>
<el-table
:data="selectedNodeParams.attrs"
:data="selectedNodeParams.columns"
max-height="350px"
style="width: 100%">
<el-table-column
@ -201,11 +201,14 @@
</div>
<div>
<el-dialog :title="selectedNodeParams.label" width="1200px"
:visible.sync="tableColumnEditOpen"
@close="closeEditColumns">
<el-table
:data="selectedNodeParams.attrs"
:data="selectedNodeParams.columns"
max-height="650px"
style="width: 100%">
<el-table-column width="120px" prop="columnName" label="字段名称"/>
@ -452,7 +455,7 @@ export default {
this.selectedNodeParamsTimeout = setTimeout(() => {
selectedNodeModel.label = newVal.label
selectedNodeModel.appConfig = newVal.appConfig
selectedNodeModel.attrs = newVal.attrs
selectedNodeModel.columns = newVal.columns
try {
this.selectedNode.update(selectedNodeModel)
}catch (e) {
@ -516,21 +519,21 @@ export default {
methods: {
//todo
ucTypeChang(index, row) {
console.log(typeof this.selectedNodeParams.attrs[index].ucMock)
console.log(typeof this.selectedNodeParams.columns[index].ucMock)
if (row.ucType == 'input' && row.ucCon != 'BETWEEN') {
this.selectedNodeParams.attrs[index].type = 1
if (typeof (this.selectedNodeParams.attrs[index].ucMock) != 'string') {
this.selectedNodeParams.attrs[index].ucMock = ''
this.selectedNodeParams.columns[index].type = 1
if (typeof (this.selectedNodeParams.columns[index].ucMock) != 'string') {
this.selectedNodeParams.columns[index].ucMock = ''
}
} else if (row.ucType == 'input' && row.ucCon == 'BETWEEN') {
this.selectedNodeParams.attrs[index].type = 2
this.selectedNodeParams.attrs[index].ucMock = {begin: '', end: ''}
this.selectedNodeParams.columns[index].type = 2
this.selectedNodeParams.columns[index].ucMock = {begin: '', end: ''}
} else if (row.ucType == 'datetime' && row.ucCon != 'BETWEEN') {
this.selectedNodeParams.attrs[index].type = 3
this.selectedNodeParams.attrs[index].ucMock = ''
this.selectedNodeParams.columns[index].type = 3
this.selectedNodeParams.columns[index].ucMock = ''
} else if (row.ucType == 'datetime' && row.ucCon == 'BETWEEN') {
this.selectedNodeParams.attrs[index].type = 4
this.selectedNodeParams.attrs[index].ucMock = []
this.selectedNodeParams.columns[index].type = 4
this.selectedNodeParams.columns[index].ucMock = []
}
},
@ -1196,16 +1199,16 @@ export default {
//
if (starts){
let droppoint = graph.getPointByClient(clientX, clientY)
let column = []
let columns = []
for (let i = 0; i < nodeType.topSearchColumnList.length; i++) {
let item = nodeType.topSearchColumnList[i]
if (item.isUse === 1) {
item.isQuery = 0
item.ucCon = null
item.ucType = null
item.ucCon = ''
item.ucType = ''
item.type = 1
item.ucMock = null
column.push(item)
item.ucMock = ''
columns.push(item)
}
}
@ -1221,7 +1224,7 @@ export default {
tableId: nodeType.id,
table: nodeType.tableName,
type: 'dice-er-box',
column: column,
columns: columns,
size: [300, 500],
width: 250,
height: 316,

View File

@ -1,57 +0,0 @@
/**
* @author: clay
* @data: 2021/5/11 17:33
* @email: clay@hchyun.com
* @description: node
*/
export default function(e){
e.preventDefault();
const {
graph
} = this;
const nodes = graph.getNodes().filter((n) => {
const bbox = n.getBBox();
return isInBBox(graph.getPointByClient(e.clientX, e.clientY), bbox);
});
if (nodes) {
nodes.forEach((node) => {
const model = node.getModel();
if (model.attrs.length < 9) {
return;
}
const idx = model.startIndex || 0;
let startX = model.startX || 0.5;
let startIndex = idx + e.deltaY * 0.02;
startX -= e.deltaX;
if (startIndex < 0) {
startIndex = 0;
}
if (startX > 0) {
startX = 0;
}
if (startIndex > model.attrs.length - 1) {
startIndex = model.attrs.length - 1;
}
graph.update(node, {
startIndex,
startX,
});
});
}
}
const isInBBox = (point, bbox) => {
const {
x,
y
} = point;
const {
minX,
minY,
maxX,
maxY
} = bbox;
return x < maxX && x > minX && y > minY && y < maxY;
};

View File

@ -145,7 +145,14 @@ export default {
this.topId = this.$route.params && this.$route.params.topId;
getQuery(this.topId).then(res =>{
this.baseData = res.data
this.graphData = JSON.parse(res.data.topJson)
if (res.data.topJson){
this.graphData = JSON.parse(res.data.topJson)
}else {
this.graphData ={
nodes:[],
edges:[]
}
}
let graphData = deepClone(this.graphData)
this.$refs.topology.initTopo(graphData)
this.randomChange()

View File

@ -0,0 +1,81 @@
package com.ebts.generator.entity;
import com.alibaba.fastjson.JSONObject;
/**
* @author: Clay
* @date: 2021/7/26 16:04
* @descriptionTopEdge
* @email: clay@hchyun.com
*/
public class TopEdge {
private String id;
private String source;
private String sourceEdge;
private String target;
private String targetEdge;
private JSONObject appConfig;
public TopEdge() {
}
public TopEdge(String id,String source, String target, JSONObject appConfig) {
this.id = id;
this.source = source;
this.target = target;
this.appConfig = appConfig;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSourceEdge() {
return sourceEdge;
}
public void setSourceEdge(String sourceEdge) {
this.sourceEdge = sourceEdge;
}
public String getTargetEdge() {
return targetEdge;
}
public void setTargetEdge(String targetEdge) {
this.targetEdge = targetEdge;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public JSONObject getAppConfig() {
return appConfig;
}
public void setAppConfig(JSONObject appConfig) {
this.appConfig = appConfig;
}
}

View File

@ -0,0 +1,121 @@
package com.ebts.generator.entity;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ebts.common.utils.StringUtils;
/**
* @author: Clay
* @date: 2021/7/26 17:26
* @descriptionTopNode
* @email: clay@hchyun.com
*/
public class TopNode {
private String id;
private String table;
private String relTable;
private StringBuffer tableSQL = new StringBuffer(" ");
private StringBuffer conditions = new StringBuffer();
private JSONArray columns;
public String getConditions() {
return conditions.toString();
}
public String getRelTable() {
return relTable;
}
public String getTableSQL() {
return tableSQL.toString();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
this.relTable = StringUtils.sqlFormat(table);
boolean start = false;
for (int i = 0; i < this.columns.size(); i++) {
JSONObject column = this.columns.getJSONObject(i);
if (column.getInteger("isUse") == 1) {
if (start) {
tableSQL.append(", ");
}
tableSQL.append(this.relTable).append(".").append(column.getString("columnName"));
if (StringUtils.isNotNull(column.getString("columnComment"))) {
tableSQL.append(" as ").append("'").append(column.getString("columnComment")).append("'");
}
start = true;
}
if (column.getInteger("isQuery") == 1 ) {
String sql = " and " + relTable + "." + column.getString("columnName");
switch (column.getString("ucCon")) {
case "EQ":
sql += " = '" + column.getString("ucMock") + "'";
break;
case "NE":
sql += " != '" + column.getString("ucMock") + "'";
break;
case "GT":
sql += " > '" + column.getString("ucMock") + "'";
break;
case "GTE":
sql += " >= '" + column.getString("ucMock") + "'";
break;
case "LT":
sql += " < '" + column.getString("ucMock") + "'";
break;
case "LTE":
sql += " <= '" + column.getString("ucMock") + "'";
break;
case "LIKE":
sql += " like '%" + column.getString("ucMock") + "%'";
break;
case "BETWEEN":
try {
JSONObject jsonObject = JSONObject.parseObject(column.getString("ucMock"));
if ("input".equals(column.getString("ucType"))) {
Object begin = jsonObject.get("begin");
Object end = jsonObject.get("end");
if (begin != null && end != null) {
sql += " between '" + begin + "' AND '" + end + "'";
} else {
sql = "";
}
} else if ("datetime".equals(column.getString("ucType"))) {
Object startTime = jsonObject.get("startTime");
Object endTime = jsonObject.get("endTime");
sql += " between '" + startTime + "' AND '" + endTime + "'";
}
} catch (RuntimeException e) {
sql = "";
}
break;
}
conditions.append(sql);
}
}
}
public JSONArray getColumns() {
return columns;
}
public void setColumns(JSONArray columns) {
this.columns = columns;
}
}

View File

@ -9,12 +9,15 @@ import com.ebts.generator.dao.QueryDao;
import com.ebts.generator.dao.RelationalMapDao;
import com.ebts.generator.dao.TopSearchTableDao;
import com.ebts.generator.entity.RelationalMap;
import com.ebts.generator.entity.TopEdge;
import com.ebts.generator.entity.TopNode;
import com.ebts.generator.service.TopQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -28,6 +31,7 @@ import java.util.Map;
@Service
public class TopQueryServiceImpl implements TopQueryService {
private final Logger logger = LoggerFactory.getLogger(TopQueryServiceImpl.class);
private int index = 0;
@Autowired
private TopSearchTableDao topSearchTableDao;
@ -49,37 +53,171 @@ public class TopQueryServiceImpl implements TopQueryService {
try {
JSONObject graphData = JSON.parseObject(jsonData);
JSONArray nodes = graphData.getJSONArray("nodes");
JSONArray edges = graphData.getJSONArray("edges");
JSONObject node = nodes.getJSONObject(0);
StringBuffer sql = new StringBuffer("select ");
JSONArray attrs = node.getJSONArray("attrs");
boolean start = false;
for (int i = 0; i < attrs.size(); i++) {
JSONObject column = attrs.getJSONObject(i);
if (column.getInteger("isUse") == 1) {
if (start) {
sql.append(", ");
List<TopEdge> topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class);
List<TopNode> topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class);
System.out.println(topNodes);
for (int i = 0; i < topEdges.size(); i++) {
for (int j = 0; j < topEdges.size(); j++) {
if (i != j) {
TopEdge topEdgeJ = topEdges.get(j);
if (topEdges.get(i).getSource().equals(topEdgeJ.getTarget())) {
topEdges.get(i).setSourceEdge(topEdgeJ.getId());
}
// if (topEdges.get(i).getTarget().equals(topEdgeJ.getSource())) {
// topEdges.get(i).setTargetEdge(topEdgeJ.getId());
// }
}
sql.append(column.getString("columnName"));
if (StringUtils.isNotNull(column.getString("columnComment"))){
sql.append(" as ");
sql.append("'" + column.getString("columnComment") + "'");
}
start=true;
}
}
sql.append(" from " + node.getString("table"));
System.out.println(sql.toString());
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
return new ServerResult<>(true, dataMap);
String tableId = "";
List<TopEdge> targets = new ArrayList<>();
for (int i = 0; i < topEdges.size(); i++) {
if (topEdges.get(i).getSourceEdge() == null) {
targets.add(topEdges.get(i));
tableId = topEdges.get(i).getSource();
}
}
String relSql = "";
for (int i = 0; i < targets.size(); i++) {
relSql+= getRelSql(topNodes,topEdges,targets.get(i));
}
// TopEdge edge = targets.get(0);
// StringBuffer sql = new StringBuffer(" ");
// while (true) {
// TopNode source = getNode(topNodes,edge.getSource());
// TopNode target = getNode(topNodes,edge.getTarget());
// sql.append(target.getTable()).append(" ").append(target.getRelTable()).append(" ")
// .append(edge.getAppConfig().getString("associated")).append(" join ")
// .append(target.getRelTable()).append(".").append(edge.getAppConfig()
// .getString("relComment")).append(" = ").append(source.getRelTable())
// .append(".").append(edge.getAppConfig().getString("tableComment")).append("\n");
// edge = getEdgeById(topEdges,edge.getTargetEdge());
// if (edge == null){
// break;
// }
// }
// boolean start = false;
// for (int i = 0; i < columns.size(); i++) {
// JSONObject column = columns.getJSONObject(i);
// if (column.getInteger("isUse") == 1) {
// if (start) {
// sql.append(", ");
// }
// sql.append(column.getString("columnName"));
// if (StringUtils.isNotNull(column.getString("columnComment"))){
// sql.append(" as ");
// sql.append("'" + column.getString("columnComment") + "'");
// }
// start=true;
// }
// }
System.out.println(relSql);
// List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
return new ServerResult<>(true, "123456");
} catch (RuntimeException e) {
e.printStackTrace();
logger.error(e.getMessage());
return new ServerResult<>(false, e.getMessage());
}
}
TopNode getNode(List<TopNode> nodes, String id) {
for (int i = 0; i < nodes.size(); i++) {
if (nodes.get(i).getId().equals(id)) {
return nodes.get(i);
}
}
return null;
}
TopEdge getEdgeById(List<TopEdge> edges, String id){
for (TopEdge edge : edges) {
if (edge.getId().equals(id)){
return edge;
}
}
return null;
}
List<TopEdge> getEdgeListById(List<TopEdge> edges, String id){
List<TopEdge> targetEdge = new ArrayList<>();
for (TopEdge edge : edges) {
if (edge.getSource().equals(id)){
targetEdge.add(edge);
}
}
return targetEdge;
}
String getRelSql(List<TopNode> nodes,List<TopEdge> edges,TopEdge edge){
StringBuffer sql = new StringBuffer(" ");
List<TopEdge> targetEdge = new ArrayList<>();
while (true) {
TopNode source = getNode(nodes,edge.getSource());
TopNode target = getNode(nodes,edge.getTarget());
sql.append(target.getTable()).append(" ").append(target.getRelTable()).append(" ")
.append(edge.getAppConfig().getString("associated")).append(" join ")
.append(target.getRelTable()).append(".").append(edge.getAppConfig()
.getString("relComment")).append(" = ").append(source.getRelTable())
.append(".").append(edge.getAppConfig().getString("tableComment")).append("\n");
if (StringUtils.isNull(edge.getTarget())){
break;
}
targetEdge = getEdgeListById(edges,edge.getTarget());
if (targetEdge.size()==1){
edge = targetEdge.get(0);
}else if (targetEdge.size()>1){
while (index<targetEdge.size()){
sql.append(getRelSql(nodes,edges,targetEdge.get(index)));
index++;
}
break;
// for (TopEdge topEdge : targetEdge) {
// }
}else {
break;
}
}
return sql.toString();
}
TopEdge getId(List<TopEdge> topEdges, String id) {
for (int i = 0; i < topEdges.size(); i++) {
if (StringUtils.isNull(topEdges.get(i).getSourceEdge())){
return null;
}
if (topEdges.get(i).getSourceEdge() == id) {
return topEdges.get(i);
}
}
return null;
}
String getSQl(List<TopEdge> topEdges, boolean type) {
List<TopEdge> target = new ArrayList<>();
String start = null;
if (type) {
start = null;
}
for (int i = 0; i < topEdges.size(); i++) {
if (topEdges.get(i).getSourceEdge() == start) {
target.add(topEdges.get(i));
}
}
return null;
}
}