top图数据解析
This commit is contained in:
parent
c6693dae67
commit
42c1fda3f4
|
|
@ -34,6 +34,7 @@ export default {
|
||||||
getDefaultCfg() {
|
getDefaultCfg() {
|
||||||
return {
|
return {
|
||||||
multiple: true,
|
multiple: true,
|
||||||
|
start:0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getEvents() {
|
getEvents() {
|
||||||
|
|
@ -60,12 +61,16 @@ export default {
|
||||||
if (nodes) {
|
if (nodes) {
|
||||||
nodes.forEach((node) => {
|
nodes.forEach((node) => {
|
||||||
const model = node.getModel();
|
const model = node.getModel();
|
||||||
if (model.column.length < 9) {
|
if (model.column.length < 9 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const idx = model.startIndex || 0;
|
const idx = model.startIndex || 0;
|
||||||
|
this.start=idx
|
||||||
let startX = model.startX || 0.5;
|
let startX = model.startX || 0.5;
|
||||||
let startIndex = idx + e.deltaY * 0.02;
|
let startIndex = idx + e.deltaY * 0.02;
|
||||||
|
if ((model.column.length-idx)<10 && startIndex > idx){
|
||||||
|
return;
|
||||||
|
}
|
||||||
startX -= e.deltaX;
|
startX -= e.deltaX;
|
||||||
if (startIndex < 0) {
|
if (startIndex < 0) {
|
||||||
startIndex = 0;
|
startIndex = 0;
|
||||||
|
|
@ -169,7 +174,7 @@ export default {
|
||||||
});
|
});
|
||||||
vm.selectedNodeParams = {
|
vm.selectedNodeParams = {
|
||||||
label: clickNodeModel.label || "",
|
label: clickNodeModel.label || "",
|
||||||
column:clickNodeModel.column,
|
columns:clickNodeModel.columns,
|
||||||
appConfig: { ...nodeAppConfig, ...clickNodeModel.appConfig }
|
appConfig: { ...nodeAppConfig, ...clickNodeModel.appConfig }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,12 +94,22 @@ export default {
|
||||||
return item
|
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", {
|
self.drawEdge.currentLine = self.graph.addItem("edge", {
|
||||||
// id: G6.Util.uniqueId(), // 这种生成id的方式有bug,会重复
|
// id: G6.Util.uniqueId(), // 这种生成id的方式有bug,会重复
|
||||||
id: utils.generateUUID(),
|
id: utils.generateUUID(),
|
||||||
// 起始节点
|
// 起始节点
|
||||||
source: sourceNodeModel.id,
|
source: sourceNodeModel.id,
|
||||||
sourceColumn:sourceNodeModel.attrs,
|
sourceColumn:columns,
|
||||||
sourceAnchor: sourceAnchor ? sourceAnchor.anchorIndex : "",
|
sourceAnchor: sourceAnchor ? sourceAnchor.anchorIndex : "",
|
||||||
// 终止节点/位置
|
// 终止节点/位置
|
||||||
relational: relational,
|
relational: relational,
|
||||||
|
|
@ -156,11 +166,19 @@ export default {
|
||||||
y: event.y
|
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, {
|
self.graph.updateItem(self.drawEdge.currentLine, {
|
||||||
target: targetNodeModel.id,
|
target: targetNodeModel.id,
|
||||||
relationalItem:relationalItem,
|
relationalItem:relationalItem,
|
||||||
targetAnchor: targetAnchor ? targetAnchor.anchorIndex : "",
|
targetAnchor: targetAnchor ? targetAnchor.anchorIndex : "",
|
||||||
targetColumn: targetNodeModel.attrs,
|
targetColumn: columns,
|
||||||
});
|
});
|
||||||
|
|
||||||
// ************** 记录historyData的逻辑 start **************
|
// ************** 记录historyData的逻辑 start **************
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onNodeOut(event) {
|
onNodeOut(event) {
|
||||||
console.log(hourItem)
|
|
||||||
const name = event.shape.get("name");
|
const name = event.shape.get("name");
|
||||||
let hoverNode = event.item;
|
let hoverNode = event.item;
|
||||||
if (name && name.startsWith("marker")) {
|
if (name && name.startsWith("marker")) {
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,13 @@ export default {
|
||||||
};
|
};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
column = [],
|
columns = [],
|
||||||
startIndex = 0,
|
startIndex = 0,
|
||||||
selectedIndex,
|
selectedIndex,
|
||||||
collapsed,
|
collapsed,
|
||||||
icon,
|
icon,
|
||||||
} = cfg;
|
} = cfg;
|
||||||
const list = column;
|
const list = columns;
|
||||||
const afterList = list.slice(
|
const afterList = list.slice(
|
||||||
Math.floor(startIndex),
|
Math.floor(startIndex),
|
||||||
Math.floor(startIndex + itemCount - 1)
|
Math.floor(startIndex + itemCount - 1)
|
||||||
|
|
@ -176,7 +176,7 @@ export default {
|
||||||
attrs: {
|
attrs: {
|
||||||
y: 30 +
|
y: 30 +
|
||||||
barStyle.padding +
|
barStyle.padding +
|
||||||
(startIndex / list.length) * (height - 30),
|
(startIndex / (list.length-8)) * (height - 30),
|
||||||
x: width - barStyle.padding - barStyle.width,
|
x: width - barStyle.padding - barStyle.width,
|
||||||
width: barStyle.width,
|
width: barStyle.width,
|
||||||
height: Math.min(height, indexHeight),
|
height: Math.min(height, indexHeight),
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@
|
||||||
<span>字段信息</span>
|
<span>字段信息</span>
|
||||||
<template>
|
<template>
|
||||||
<el-table
|
<el-table
|
||||||
:data="selectedNodeParams.attrs"
|
:data="selectedNodeParams.columns"
|
||||||
max-height="350px"
|
max-height="350px"
|
||||||
style="width: 100%">
|
style="width: 100%">
|
||||||
<el-table-column
|
<el-table-column
|
||||||
|
|
@ -201,11 +201,14 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<el-dialog :title="selectedNodeParams.label" width="1200px"
|
<el-dialog :title="selectedNodeParams.label" width="1200px"
|
||||||
:visible.sync="tableColumnEditOpen"
|
:visible.sync="tableColumnEditOpen"
|
||||||
@close="closeEditColumns">
|
@close="closeEditColumns">
|
||||||
<el-table
|
<el-table
|
||||||
:data="selectedNodeParams.attrs"
|
:data="selectedNodeParams.columns"
|
||||||
max-height="650px"
|
max-height="650px"
|
||||||
style="width: 100%">
|
style="width: 100%">
|
||||||
<el-table-column width="120px" prop="columnName" label="字段名称"/>
|
<el-table-column width="120px" prop="columnName" label="字段名称"/>
|
||||||
|
|
@ -452,7 +455,7 @@ export default {
|
||||||
this.selectedNodeParamsTimeout = setTimeout(() => {
|
this.selectedNodeParamsTimeout = setTimeout(() => {
|
||||||
selectedNodeModel.label = newVal.label
|
selectedNodeModel.label = newVal.label
|
||||||
selectedNodeModel.appConfig = newVal.appConfig
|
selectedNodeModel.appConfig = newVal.appConfig
|
||||||
selectedNodeModel.attrs = newVal.attrs
|
selectedNodeModel.columns = newVal.columns
|
||||||
try {
|
try {
|
||||||
this.selectedNode.update(selectedNodeModel)
|
this.selectedNode.update(selectedNodeModel)
|
||||||
}catch (e) {
|
}catch (e) {
|
||||||
|
|
@ -516,21 +519,21 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
//todo
|
//todo
|
||||||
ucTypeChang(index, row) {
|
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') {
|
if (row.ucType == 'input' && row.ucCon != 'BETWEEN') {
|
||||||
this.selectedNodeParams.attrs[index].type = 1
|
this.selectedNodeParams.columns[index].type = 1
|
||||||
if (typeof (this.selectedNodeParams.attrs[index].ucMock) != 'string') {
|
if (typeof (this.selectedNodeParams.columns[index].ucMock) != 'string') {
|
||||||
this.selectedNodeParams.attrs[index].ucMock = ''
|
this.selectedNodeParams.columns[index].ucMock = ''
|
||||||
}
|
}
|
||||||
} else if (row.ucType == 'input' && row.ucCon == 'BETWEEN') {
|
} else if (row.ucType == 'input' && row.ucCon == 'BETWEEN') {
|
||||||
this.selectedNodeParams.attrs[index].type = 2
|
this.selectedNodeParams.columns[index].type = 2
|
||||||
this.selectedNodeParams.attrs[index].ucMock = {begin: '', end: ''}
|
this.selectedNodeParams.columns[index].ucMock = {begin: '', end: ''}
|
||||||
} else if (row.ucType == 'datetime' && row.ucCon != 'BETWEEN') {
|
} else if (row.ucType == 'datetime' && row.ucCon != 'BETWEEN') {
|
||||||
this.selectedNodeParams.attrs[index].type = 3
|
this.selectedNodeParams.columns[index].type = 3
|
||||||
this.selectedNodeParams.attrs[index].ucMock = ''
|
this.selectedNodeParams.columns[index].ucMock = ''
|
||||||
} else if (row.ucType == 'datetime' && row.ucCon == 'BETWEEN') {
|
} else if (row.ucType == 'datetime' && row.ucCon == 'BETWEEN') {
|
||||||
this.selectedNodeParams.attrs[index].type = 4
|
this.selectedNodeParams.columns[index].type = 4
|
||||||
this.selectedNodeParams.attrs[index].ucMock = []
|
this.selectedNodeParams.columns[index].ucMock = []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -1196,16 +1199,16 @@ export default {
|
||||||
// 开始添加
|
// 开始添加
|
||||||
if (starts){
|
if (starts){
|
||||||
let droppoint = graph.getPointByClient(clientX, clientY)
|
let droppoint = graph.getPointByClient(clientX, clientY)
|
||||||
let column = []
|
let columns = []
|
||||||
for (let i = 0; i < nodeType.topSearchColumnList.length; i++) {
|
for (let i = 0; i < nodeType.topSearchColumnList.length; i++) {
|
||||||
let item = nodeType.topSearchColumnList[i]
|
let item = nodeType.topSearchColumnList[i]
|
||||||
if (item.isUse === 1) {
|
if (item.isUse === 1) {
|
||||||
item.isQuery = 0
|
item.isQuery = 0
|
||||||
item.ucCon = null
|
item.ucCon = ''
|
||||||
item.ucType = null
|
item.ucType = ''
|
||||||
item.type = 1
|
item.type = 1
|
||||||
item.ucMock = null
|
item.ucMock = ''
|
||||||
column.push(item)
|
columns.push(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1221,7 +1224,7 @@ export default {
|
||||||
tableId: nodeType.id,
|
tableId: nodeType.id,
|
||||||
table: nodeType.tableName,
|
table: nodeType.tableName,
|
||||||
type: 'dice-er-box',
|
type: 'dice-er-box',
|
||||||
column: column,
|
columns: columns,
|
||||||
size: [300, 500],
|
size: [300, 500],
|
||||||
width: 250,
|
width: 250,
|
||||||
height: 316,
|
height: 316,
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -145,7 +145,14 @@ export default {
|
||||||
this.topId = this.$route.params && this.$route.params.topId;
|
this.topId = this.$route.params && this.$route.params.topId;
|
||||||
getQuery(this.topId).then(res =>{
|
getQuery(this.topId).then(res =>{
|
||||||
this.baseData = res.data
|
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)
|
let graphData = deepClone(this.graphData)
|
||||||
this.$refs.topology.initTopo(graphData)
|
this.$refs.topology.initTopo(graphData)
|
||||||
this.randomChange()
|
this.randomChange()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.ebts.generator.entity;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: Clay
|
||||||
|
* @date: 2021/7/26 16:04
|
||||||
|
* @description:TopEdge
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
* @description:TopNode
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -9,12 +9,15 @@ import com.ebts.generator.dao.QueryDao;
|
||||||
import com.ebts.generator.dao.RelationalMapDao;
|
import com.ebts.generator.dao.RelationalMapDao;
|
||||||
import com.ebts.generator.dao.TopSearchTableDao;
|
import com.ebts.generator.dao.TopSearchTableDao;
|
||||||
import com.ebts.generator.entity.RelationalMap;
|
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 com.ebts.generator.service.TopQueryService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -28,6 +31,7 @@ import java.util.Map;
|
||||||
@Service
|
@Service
|
||||||
public class TopQueryServiceImpl implements TopQueryService {
|
public class TopQueryServiceImpl implements TopQueryService {
|
||||||
private final Logger logger = LoggerFactory.getLogger(TopQueryServiceImpl.class);
|
private final Logger logger = LoggerFactory.getLogger(TopQueryServiceImpl.class);
|
||||||
|
private int index = 0;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TopSearchTableDao topSearchTableDao;
|
private TopSearchTableDao topSearchTableDao;
|
||||||
|
|
@ -49,37 +53,171 @@ public class TopQueryServiceImpl implements TopQueryService {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
JSONObject graphData = JSON.parseObject(jsonData);
|
JSONObject graphData = JSON.parseObject(jsonData);
|
||||||
JSONArray nodes = graphData.getJSONArray("nodes");
|
List<TopEdge> topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class);
|
||||||
JSONArray edges = graphData.getJSONArray("edges");
|
List<TopNode> topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class);
|
||||||
JSONObject node = nodes.getJSONObject(0);
|
System.out.println(topNodes);
|
||||||
|
for (int i = 0; i < topEdges.size(); i++) {
|
||||||
StringBuffer sql = new StringBuffer("select ");
|
for (int j = 0; j < topEdges.size(); j++) {
|
||||||
|
if (i != j) {
|
||||||
JSONArray attrs = node.getJSONArray("attrs");
|
TopEdge topEdgeJ = topEdges.get(j);
|
||||||
boolean start = false;
|
if (topEdges.get(i).getSource().equals(topEdgeJ.getTarget())) {
|
||||||
for (int i = 0; i < attrs.size(); i++) {
|
topEdges.get(i).setSourceEdge(topEdgeJ.getId());
|
||||||
JSONObject column = attrs.getJSONObject(i);
|
}
|
||||||
if (column.getInteger("isUse") == 1) {
|
// if (topEdges.get(i).getTarget().equals(topEdgeJ.getSource())) {
|
||||||
if (start) {
|
// topEdges.get(i).setTargetEdge(topEdgeJ.getId());
|
||||||
sql.append(", ");
|
// }
|
||||||
}
|
}
|
||||||
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"));
|
String tableId = "";
|
||||||
System.out.println(sql.toString());
|
List<TopEdge> targets = new ArrayList<>();
|
||||||
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
|
for (int i = 0; i < topEdges.size(); i++) {
|
||||||
return new ServerResult<>(true, dataMap);
|
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) {
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<>(false, 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue