top图解析对接预览完成
This commit is contained in:
parent
42c1fda3f4
commit
ab4a25b524
|
|
@ -335,7 +335,6 @@ export default {
|
|||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
roleIds:[]
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
|
|
@ -448,7 +447,6 @@ export default {
|
|||
}
|
||||
this.relationalMapList.push(item)
|
||||
}
|
||||
console.log(this.topSearchColumnList)
|
||||
this.open = true;
|
||||
this.title = "修改top万能查询主";
|
||||
});
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@
|
|||
<el-table-column
|
||||
prop="key"
|
||||
width="150px"
|
||||
label="字段名称">
|
||||
label="字段别名">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row.columnComment" placeholder="请输入列别名" />
|
||||
</template>
|
||||
|
|
@ -231,11 +231,19 @@
|
|||
<el-table-column
|
||||
prop="isQuery"
|
||||
width="50px"
|
||||
label="是否使用">
|
||||
label="是否查询">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox :true-label="1" :false-label="0" v-model="scope.row.isQuery"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="key"
|
||||
width="150px"
|
||||
label="字段别名">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row.ucName" placeholder="请输入列别名" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="条件">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.ucCon" @change="ucTypeChang(scope.$index,scope.row)">
|
||||
|
|
@ -1208,6 +1216,7 @@ export default {
|
|||
item.ucType = ''
|
||||
item.type = 1
|
||||
item.ucMock = ''
|
||||
item.ucName = ''
|
||||
columns.push(item)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
>
|
||||
</topology>
|
||||
<el-dialog :title="previewDate.title" width="1400px" :visible.sync="previewDate.open">
|
||||
<el-form ref="ucon" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item v-for="item in uconList"
|
||||
<el-form ref="ucon" :inline="true" v-show="previewDate.showSearch" label-width="68px">
|
||||
<el-form-item v-for="item in previewDate.uconList"
|
||||
:key="item.id"
|
||||
:label="item.ucName">
|
||||
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
>导出
|
||||
</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="handleQuery"></right-toolbar>
|
||||
<right-toolbar :showSearch.sync="previewDate.showSearch" @queryTable="handleQuery"></right-toolbar>
|
||||
</el-row>
|
||||
<el-table :data="previewDate.data">
|
||||
<el-table-column v-for="item in previewDate.header"
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
:total="previewDate.total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="previewQuery"
|
||||
@pagination="handleQuery"
|
||||
/>
|
||||
</el-dialog>
|
||||
|
||||
|
|
@ -98,7 +98,8 @@
|
|||
import Topology from './packages/topology/src/topology'
|
||||
import { deepClone } from './utils/index'
|
||||
import {getQuery,getTables,updateQuery,preview} from '@/api/tool/top'
|
||||
|
||||
import {RealData} from "@/api/system/data"
|
||||
import { exportReal } from '../../../api/system/data'
|
||||
export default {
|
||||
name: 'DemoTopology',
|
||||
components: {
|
||||
|
|
@ -116,7 +117,9 @@ export default {
|
|||
title:"预览",
|
||||
data:[],
|
||||
header:[],
|
||||
total:0
|
||||
total:0,
|
||||
uconList:[],
|
||||
showSearch:false,
|
||||
},
|
||||
graphData: {
|
||||
// "nodes":[{"id":"305bfbdd-31cc-4028-b2b1-2f504968356d","x":304.8223042174235,"y":131.0267312661499,"label":"客户端","table":"test_table","type":"dice-er-box","attrs":[{"key":"id","type":"number(6)","comment":"主键id","isUse":0},{"key":"key","type":"varchar(255)","comment":"关键字","isUse":1},{"key":"gender","type":"enum(M, F)","comment":"gender","isUse":1},{"key":"birthday","type":"date","comment":"生日","isUse":0},{"key":"hometown","type":"varchar(255)","comment":"家乡","isUse":0},{"key":"country","type":"varchar(255)","comment":"国家","isUse":1},{"key":"nation","type":"varchar(255)","comment":"nation","isUse":1},{"key":"jobId","type":"number(3)","comment":"工作id","isUse":1},{"key":"phone","type":"varchar(255)","comment":"电话","isUse":1}],"size":[55,55],"width":250,"height":316,"anchorPoints":[[0.5,0],[1,0.5],[0.5,1],[0,0.5]],"appState":{"alert":false},"labelCfg":{"position":"bottom"},"style":{"default":{"stroke":"#CED4D9","fill":"transparent","shadowBlur":10,"shadowColor":"rgba(13, 26, 38, 0.08)","lineWidth":1,"radius":4,"strokeOpacity":0.7},"selected":{"shadowColor":"#ff240b","shadowBlur":2},"unselected":{"shadowColor":""}},"selectedIndex":null,"appConfig":{},"depth":0},{"id":"be9b52e5-9c2f-4e5c-990a-afbf19dcfeed","x":-94.51187075489108,"y":127.35469287559994,"label":"防火墙","table":"test_table","type":"dice-er-box","attrs":[{"key":"id","type":"number(6)","comment":"主键id","isUse":0},{"key":"key","type":"varchar(255)","comment":"关键字","isUse":1},{"key":"gender","type":"enum(M, F)","comment":"gender","isUse":0},{"key":"birthday","type":"date","comment":"生日","isUse":1},{"key":"hometown","type":"varchar(255)","comment":"家乡","isUse":1},{"key":"country","type":"varchar(255)","comment":"国家","isUse":0},{"key":"nation","type":"varchar(255)","comment":"nation","isUse":1},{"key":"jobId","type":"number(3)","comment":"工作id","isUse":1},{"key":"phone","type":"varchar(255)","comment":"电话","isUse":1}],"size":[55,55],"width":250,"height":316,"anchorPoints":[[0.5,0],[1,0.5],[0.5,1],[0,0.5]],"appState":{"alert":false},"labelCfg":{"position":"bottom"},"style":{"default":{"stroke":"#CED4D9","fill":"transparent","shadowBlur":10,"shadowColor":"rgba(13, 26, 38, 0.08)","lineWidth":1,"radius":4,"strokeOpacity":0.7},"selected":{"shadowColor":"#ff240b","shadowBlur":2},"unselected":{"shadowColor":""}},"selectedIndex":null,"appConfig":{},"startIndex":0,"startX":0,"depth":0}],"edges":[{"id":"8bc0249e-ee5d-4dd7-84e0-e4e32c217f2a","source":"be9b52e5-9c2f-4e5c-990a-afbf19dcfeed","sourceColumn":[{"key":"id","type":"number(6)","comment":"主键id","isUse":1},{"key":"key","type":"varchar(255)","comment":"关键字","isUse":1},{"key":"gender","type":"enum(M, F)","comment":"gender","isUse":1},{"key":"birthday","type":"date","comment":"生日","isUse":1},{"key":"hometown","type":"varchar(255)","comment":"家乡","isUse":1},{"key":"country","type":"varchar(255)","comment":"国家","isUse":1},{"key":"nation","type":"varchar(255)","comment":"nation","isUse":1},{"key":"jobId","type":"number(3)","comment":"工作id","isUse":1},{"key":"phone","type":"varchar(255)","comment":"电话","isUse":1}],"sourceAnchor":1,"target":"305bfbdd-31cc-4028-b2b1-2f504968356d","type":"top-cubic","style":{"active":{"stroke":"rgb(95, 149, 255)","lineWidth":1},"selected":{"stroke":"rgb(95, 149, 255)","lineWidth":2,"shadowColor":"rgb(95, 149, 255)","shadowBlur":10,"text-shape":{"fontWeight":500}},"highlight":{"stroke":"rgb(95, 149, 255)","lineWidth":2,"text-shape":{"fontWeight":500}},"inactive":{"stroke":"rgb(234, 234, 234)","lineWidth":1},"disable":{"stroke":"rgb(245, 245, 245)","lineWidth":1},"edgeStyle":{"default":{"stroke":"#e2e2e2","lineWidth":3,"lineAppendWidth":10},"selected":{"shadowColor":"#626262","shadowBlur":3}},"stroke":"#A3B1BF","lineWidth":2,"strokeOpacity":0.92,"lineAppendWidth":10},"labelCfg":{"position":"center","autoRotate":false},"startPoint":{"x":155.98812924510892,"y":285.35469287559994,"anchorIndex":1},"endPoint":{"x":304.3223042174235,"y":289.0267312661499,"anchorIndex":3},"curveOffset":[-20,20],"curvePosition":[0.5,0.5],"targetAnchor":3,"targetColumn":[{"key":"id","type":"number(6)","comment":"主键id","isUse":1},{"key":"key","type":"varchar(255)","comment":"关键字","isUse":1},{"key":"gender","type":"enum(M, F)","comment":"gender","isUse":1},{"key":"birthday","type":"date","comment":"生日","isUse":1},{"key":"hometown","type":"varchar(255)","comment":"家乡","isUse":1},{"key":"country","type":"varchar(255)","comment":"国家","isUse":1},{"key":"nation","type":"varchar(255)","comment":"nation","isUse":1},{"key":"jobId","type":"number(3)","comment":"工作id","isUse":1},{"key":"phone","type":"varchar(255)","comment":"电话","isUse":1}],"depth":0}],"combos":[]},
|
||||
|
|
@ -158,12 +161,55 @@ export default {
|
|||
this.randomChange()
|
||||
})
|
||||
getTables().then(res =>{
|
||||
console.log(res)
|
||||
this.nodeTypeList = res.data.tables
|
||||
this.relationalMap = res.data.relationalMap
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 重置
|
||||
*/
|
||||
resetQuery() {
|
||||
for (let i = 0; this.previewDate.uconList.length; i++) {
|
||||
this.previewDate.uconList[i].ucReal = null
|
||||
}
|
||||
},
|
||||
/** 导出按钮操作 */
|
||||
handleExport() {
|
||||
var that = this
|
||||
this.$confirm('是否确认导出查询数据项?', "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function () {
|
||||
let data = {
|
||||
id:that.topId,
|
||||
uniCons:that.previewDate.uconList,
|
||||
}
|
||||
return exportReal(data)
|
||||
}).then(response => {
|
||||
this.download(response.msg);
|
||||
})
|
||||
},
|
||||
handleQuery() {
|
||||
let data = {
|
||||
id: this.topId,
|
||||
pageNum: this.queryParams.pageNum,
|
||||
pageSize: this.queryParams.pageSize,
|
||||
}
|
||||
data.uniCons = this.previewDate.uconList
|
||||
RealData(data).then(res => {
|
||||
this.previewDate.data = res.rows
|
||||
this.total = res.total
|
||||
this.previewDate.header = []
|
||||
for (const key in this.previewDate.data[0]) {
|
||||
this.previewDate.header.push(key)
|
||||
}
|
||||
})
|
||||
},
|
||||
outPlaceholder(item) {
|
||||
return "请输入" + item.ucName
|
||||
},
|
||||
doAutoRefresh(interval) {
|
||||
if (interval === -1) {
|
||||
clearInterval(this.autoRefreshTimer)
|
||||
|
|
@ -198,10 +244,19 @@ export default {
|
|||
},
|
||||
doPreview(graphData){
|
||||
if (graphData.nodes&&graphData.nodes.length>0){
|
||||
preview({jsonData:JSON.stringify(graphData)}).then(res=>{
|
||||
this.previewDate.data = res.data
|
||||
let data = {
|
||||
jsonData:JSON.stringify(graphData),
|
||||
id:this.topId
|
||||
}
|
||||
preview(data).then(res=>{
|
||||
this.previewDate.data = res.rows
|
||||
this.previewDate.total = res.total
|
||||
this.previewDate.uconList = res.uconList
|
||||
if (this.previewDate.uconList.length>0){
|
||||
this.previewDate.showSearch = true
|
||||
}
|
||||
this.previewDate.header = []
|
||||
for (var key in this.previewDate.data[0]) {
|
||||
for (const key in this.previewDate.data[0]) {
|
||||
this.previewDate.header.push(key)
|
||||
}
|
||||
this.previewDate.title = this.baseData.uqName + "数据预览"
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ spring:
|
|||
# url: jdbc:mysql://114.215.82.135:3306/hcybase?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
# username: hcybase
|
||||
# password: hcybase@2020
|
||||
# url: jdbc:mysql://13.75.92.40:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
# username: gen
|
||||
# password: zcsbKxPseM8LhFdT
|
||||
url: jdbc:mysql://127.0.0.1:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: 926425
|
||||
url: jdbc:mysql://13.75.92.40:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: gen
|
||||
password: zcsbKxPseM8LhFdT
|
||||
# url: jdbc:mysql://127.0.0.1:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
# username: root
|
||||
# password: 926425
|
||||
# 从库数据源
|
||||
slave:
|
||||
# 从数据源开关/默认关闭
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.beans.PropertyEditorSupport;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.ebts.common.core.page.TableDataTop;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
|
|
@ -66,6 +67,19 @@ public class BaseController {
|
|||
rspData.setTotal(new PageInfo(list).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
/**
|
||||
* 响应请求分页数据
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
protected TableDataTop getDataTable(List<?> list, List<?> uconList) {
|
||||
TableDataTop rspData = new TableDataTop();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(list);
|
||||
rspData.setUconList(uconList);
|
||||
rspData.setTotal(new PageInfo(list).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应返回结果
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
package com.ebts.common.core.page;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表格分页数据对象
|
||||
*
|
||||
* @author binlin
|
||||
*/
|
||||
public class TableDataTop implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
private long total;
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
private List<?> rows;
|
||||
|
||||
private List<?> uconList;
|
||||
|
||||
/**
|
||||
* 消息状态码
|
||||
*/
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 表格数据对象
|
||||
*/
|
||||
public TableDataTop() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public TableDataTop(List<?> list, int total) {
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
|
||||
public List<?> getUconList() {
|
||||
return uconList;
|
||||
}
|
||||
|
||||
public void setUconList(List<?> uconList) {
|
||||
this.uconList = uconList;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<?> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<?> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
package com.ebts.generator.controller;
|
||||
|
||||
import com.ebts.common.annotation.Log;
|
||||
import com.ebts.common.core.controller.BaseController;
|
||||
import com.ebts.common.core.entity.AjaxResult;
|
||||
import com.ebts.common.enums.BusinessType;
|
||||
import com.ebts.common.utils.ServerResult;
|
||||
import com.ebts.common.utils.StringUtils;
|
||||
import com.ebts.generator.dto.TopResult;
|
||||
import com.ebts.generator.entity.UniQuery;
|
||||
import com.ebts.generator.service.TopQueryService;
|
||||
import com.ebts.generator.service.TopSearchTableService;
|
||||
|
|
@ -13,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -25,7 +29,7 @@ import java.util.Map;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/top")
|
||||
public class TopQueryController {
|
||||
public class TopQueryController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private TopSearchTableService topSearchTableService;
|
||||
|
|
@ -92,13 +96,13 @@ public class TopQueryController {
|
|||
@PreAuthorize("@ebts.hasPermi('top:preview')")
|
||||
@Log(title = "top预览", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/preview")
|
||||
public AjaxResult preview(@RequestBody Map<String,String> params){
|
||||
public Serializable preview(@RequestBody Map<String,String> params){
|
||||
if (StringUtils.isNull(params.get("jsonData"))){
|
||||
return AjaxResult.error("缺少必要参数!");
|
||||
}
|
||||
ServerResult<List<Map<String, Object>>> serverResult = topQueryService.preview(params.get("jsonData"));
|
||||
ServerResult<TopResult> serverResult = topQueryService.preview(params.get("jsonData"),params.get("id"));
|
||||
if (serverResult.isStart()){
|
||||
return AjaxResult.success(serverResult.getData());
|
||||
return getDataTable(serverResult.getData().getDataMap(),serverResult.getData().getUniCons());
|
||||
}else {
|
||||
return AjaxResult.error(serverResult.getMsg());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.ebts.generator.dto;
|
||||
|
||||
import com.ebts.generator.entity.UniCon;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: Clay
|
||||
* @date: 2021/7/27 19:26
|
||||
* @description:TopResult
|
||||
* @email: clay@hchyun.com
|
||||
*/
|
||||
public class TopResult {
|
||||
private List<Map<String, Object>> dataMap;
|
||||
private List<UniCon> uniCons;
|
||||
|
||||
|
||||
public TopResult(List<Map<String, Object>> dataMap, List<UniCon> uniCons) {
|
||||
this.dataMap = dataMap;
|
||||
this.uniCons = uniCons;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getDataMap() {
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public void setDataMap(List<Map<String, Object>> dataMap) {
|
||||
this.dataMap = dataMap;
|
||||
}
|
||||
|
||||
public List<UniCon> getUniCons() {
|
||||
return uniCons;
|
||||
}
|
||||
|
||||
public void setUniCons(List<UniCon> uniCons) {
|
||||
this.uniCons = uniCons;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ public class TopEdge {
|
|||
private String source;
|
||||
private String sourceEdge;
|
||||
private String target;
|
||||
private String targetEdge;
|
||||
private JSONObject appConfig;
|
||||
|
||||
|
||||
|
|
@ -47,14 +46,6 @@ public class TopEdge {
|
|||
this.sourceEdge = sourceEdge;
|
||||
}
|
||||
|
||||
public String getTargetEdge() {
|
||||
return targetEdge;
|
||||
}
|
||||
|
||||
public void setTargetEdge(String targetEdge) {
|
||||
this.targetEdge = targetEdge;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ebts.common.utils.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: Clay
|
||||
* @date: 2021/7/26 17:26
|
||||
|
|
@ -15,11 +17,11 @@ public class TopNode {
|
|||
private String table;
|
||||
private String relTable;
|
||||
private StringBuffer tableSQL = new StringBuffer(" ");
|
||||
private StringBuffer conditions = new StringBuffer();
|
||||
private StringBuffer querySql = new StringBuffer(" ");
|
||||
private JSONArray columns;
|
||||
|
||||
public String getConditions() {
|
||||
return conditions.toString();
|
||||
public String getQuerySql() {
|
||||
return querySql.toString();
|
||||
}
|
||||
|
||||
public String getRelTable() {
|
||||
|
|
@ -104,7 +106,7 @@ public class TopNode {
|
|||
}
|
||||
break;
|
||||
}
|
||||
conditions.append(sql);
|
||||
querySql.append(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,18 @@ public class UniCon {
|
|||
*/
|
||||
private Integer type;
|
||||
|
||||
public UniCon() {
|
||||
}
|
||||
|
||||
public UniCon(Long uqId, String ucName, String ucKey, String ucCon, String ucType, Integer type) {
|
||||
this.uqId = uqId;
|
||||
this.ucName = ucName;
|
||||
this.ucKey = ucKey;
|
||||
this.ucCon = ucCon;
|
||||
this.ucType = ucType;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getUcType() {
|
||||
return ucType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.ebts.generator.service;
|
||||
|
||||
import com.ebts.common.utils.ServerResult;
|
||||
import com.ebts.generator.dto.TopResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -15,5 +15,5 @@ public interface TopQueryService {
|
|||
|
||||
Map<String, Object> selectTopSearchTables();
|
||||
|
||||
ServerResult<List<Map<String, Object>>> preview(String jsonData);
|
||||
ServerResult<TopResult> preview(String jsonData, String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,19 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ebts.common.utils.ServerResult;
|
||||
import com.ebts.common.utils.StringUtils;
|
||||
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.dao.UniQueryDao;
|
||||
import com.ebts.generator.dto.TopResult;
|
||||
import com.ebts.generator.entity.*;
|
||||
import com.ebts.generator.service.TopQueryService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -31,7 +32,6 @@ 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;
|
||||
|
|
@ -39,6 +39,8 @@ public class TopQueryServiceImpl implements TopQueryService {
|
|||
private RelationalMapDao relationalMapDao;
|
||||
@Autowired
|
||||
private QueryDao queryDao;
|
||||
@Autowired
|
||||
private UniQueryDao uniQueryDao;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectTopSearchTables() {
|
||||
|
|
@ -49,13 +51,23 @@ public class TopQueryServiceImpl implements TopQueryService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ServerResult<List<Map<String, Object>>> preview(String jsonData) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ServerResult<TopResult> preview(String jsonData, String id) {
|
||||
try {
|
||||
|
||||
JSONObject graphData = JSON.parseObject(jsonData);
|
||||
//将数据格式化为自定义的java类列表
|
||||
List<TopEdge> topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class);
|
||||
List<TopNode> topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class);
|
||||
System.out.println(topNodes);
|
||||
if (topNodes.size() == 0) {
|
||||
return new ServerResult<>(false, "top图结构有误,请整理后在试");
|
||||
}
|
||||
//整理连线的关系
|
||||
StringBuffer sql = new StringBuffer("");
|
||||
StringBuilder selectSql = new StringBuilder("select ");
|
||||
StringBuilder selectQuery = new StringBuilder(" where 1=1 ");
|
||||
TopNode mainNode = null;
|
||||
if (topNodes.size() > 1) {
|
||||
for (int i = 0; i < topEdges.size(); i++) {
|
||||
for (int j = 0; j < topEdges.size(); j++) {
|
||||
if (i != j) {
|
||||
|
|
@ -63,63 +75,67 @@ public class TopQueryServiceImpl implements TopQueryService {
|
|||
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());
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
String tableId = "";
|
||||
// 解析出top图中与主表的连线,可能为多条
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
mainNode = getNode(topNodes, targets.get(0).getSource());
|
||||
// 组合查询字段信息
|
||||
ParseSelectSQL(mainNode, topNodes, selectSql, selectQuery);
|
||||
|
||||
// 组合表与表之间得到关联关系sql
|
||||
String relSql = "";
|
||||
for (int i = 0; i < targets.size(); i++) {
|
||||
relSql+= getRelSql(topNodes,topEdges,targets.get(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;
|
||||
// }
|
||||
// }
|
||||
sql.append(selectSql).append(" from ").append(mainNode.getTable()).append(" ")
|
||||
.append(mainNode.getRelTable()).append(relSql);
|
||||
|
||||
} else {
|
||||
mainNode = topNodes.get(0);
|
||||
selectSql.append(mainNode.getTableSQL());
|
||||
selectQuery.append(mainNode.getQuerySql());
|
||||
sql.append(selectSql).append(" from ").append(mainNode.getTable()).append(" ")
|
||||
.append(mainNode.getRelTable());
|
||||
}
|
||||
UniQuery uniQuery = new UniQuery();
|
||||
uniQuery.setId(Long.valueOf(id));
|
||||
uniQuery.setUqSql(sql.toString());
|
||||
List<UniCon> uniCons = uniQuery.getUniCons();
|
||||
for (TopNode node : topNodes) {
|
||||
JSONArray columns = node.getColumns();
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
if (columns.getJSONObject(i).getInteger("isQuery") == 1) {
|
||||
JSONObject column = columns.getJSONObject(i);
|
||||
UniCon uniCon = new UniCon(uniQuery.getId(), column.getString("ucName"), node.getRelTable() + "." + column.getString("columnName"), column.getString("ucCon"), column.getString("ucType"), column.getInteger("type"));
|
||||
uniCons.add(uniCon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int query = uniQueryDao.updateUniQuery(uniQuery);
|
||||
if (query > 0) {
|
||||
if (uniQuery.getUniCons() != null && uniQuery.getUniCons().size() > 0) {
|
||||
queryDao.deleteUniCon(uniQuery.getId());
|
||||
queryDao.insertUniCon(uniCons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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");
|
||||
sql.append(selectQuery);
|
||||
PageHelper.startPage(1, 10, "");
|
||||
List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
|
||||
TopResult topResult = new TopResult(dataMap,uniCons);
|
||||
return new ServerResult<>(true, topResult);
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage());
|
||||
|
|
@ -127,6 +143,21 @@ public class TopQueryServiceImpl implements TopQueryService {
|
|||
}
|
||||
}
|
||||
|
||||
void ParseSelectSQL(TopNode mainNode, List<TopNode> topNodes, StringBuilder selectSql, StringBuilder selectQuery) {
|
||||
selectSql.append(mainNode.getTableSQL());
|
||||
selectQuery.append(mainNode.getQuerySql());
|
||||
for (TopNode node : topNodes) {
|
||||
if (node.getId().equals(mainNode.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (node.getTableSQL().trim().equals("")){
|
||||
continue;
|
||||
}
|
||||
selectSql.append(", ").append(node.getTableSQL());
|
||||
selectQuery.append(node.getQuerySql());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TopNode getNode(List<TopNode> nodes, String id) {
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
|
|
@ -136,88 +167,49 @@ public class TopQueryServiceImpl implements TopQueryService {
|
|||
}
|
||||
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> getEdgeListById(List<TopEdge> edges, String id) {
|
||||
List<TopEdge> targetEdge = new ArrayList<>();
|
||||
for (TopEdge edge : edges) {
|
||||
if (edge.getSource().equals(id)){
|
||||
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<>();
|
||||
String getRelSql(List<TopNode> nodes, List<TopEdge> edges, TopEdge edge) {
|
||||
int i = 0;
|
||||
// 定义sql 变量
|
||||
StringBuffer sql = new StringBuffer("");
|
||||
List<TopEdge> targetEdge;
|
||||
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 ")
|
||||
// 获取到连线的两个表
|
||||
TopNode source = getNode(nodes, edge.getSource());
|
||||
TopNode target = getNode(nodes, edge.getTarget());
|
||||
//进行sql拼接
|
||||
sql.append(" ").append(edge.getAppConfig().getString("associated")).append(" join ")
|
||||
.append(target.getTable()).append(" ").append(target.getRelTable()).append(" on ")
|
||||
.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){
|
||||
.append(".").append(edge.getAppConfig().getString("tableComment"));
|
||||
// 获取到target 连接表的连线
|
||||
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++;
|
||||
} else if (targetEdge.size() > 1) {
|
||||
//多条则进行递归解析
|
||||
while (i < targetEdge.size()) {
|
||||
sql.append(getRelSql(nodes, edges, targetEdge.get(i)));
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
// for (TopEdge topEdge : targetEdge) {
|
||||
// }
|
||||
}else {
|
||||
} else {
|
||||
//没有则退出循环返回解析好的sql
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
|
|||
public ServerResult<TopSearchTable> selectTopSearchTableById(Long id) {
|
||||
try {
|
||||
TopSearchTable topSearchTable = topSearchTableDao.selectTopSearchTableById(id);
|
||||
List<SearchTableRole> roleList = searchTableRoleDao.selectSearchTableRoleList(new SearchTableRole());
|
||||
List<SearchTableRole> roleList = searchTableRoleDao.selectSearchTableRoleList(new SearchTableRole(id,null));
|
||||
Long[] roles = new Long[roleList.size()] ;
|
||||
for (int i = 0; i < roleList.size(); i++) {
|
||||
roles[i] = roleList.get(i).getRoleId();
|
||||
|
|
|
|||
|
|
@ -151,9 +151,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</delete>
|
||||
|
||||
<insert id="batchTopSearchColumn">
|
||||
insert into gen_top_search_column(search_table_id,column_name,column_comment,column_type,is_use,create_by,create_time,update_by,update_time) values
|
||||
insert into gen_top_search_column(search_table_id,column_name,column_comment,column_type,create_by,create_time,update_by,update_time) values
|
||||
<foreach item="item" index="index" collection="list" separator=",">
|
||||
(#{item.searchTableId},#{item.columnName},#{item.columnComment},#{item.columnType},#{item.isUse},#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime})
|
||||
(#{item.searchTableId},#{item.columnName},#{item.columnComment},#{item.columnType},#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
|
@ -68,15 +68,19 @@ public class RealQueryServiceImpl implements RealQueryService {
|
|||
return new ServerResult<>(true, dataMap, realUniQuery.getUqName());
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage());
|
||||
throw new EbtsException(ReturnConstants.OP_ERROR,e);
|
||||
}
|
||||
}
|
||||
|
||||
public String conversionReal(RealUniCon realUniCon) {
|
||||
if (realUniCon.getUcReal() == null&&!realUniCon.getUcReal().equals("")) {
|
||||
if (realUniCon.getUcReal() == null) {
|
||||
return "";
|
||||
} else {
|
||||
} else if (realUniCon.getUcReal().equals("")){
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
String sql = " and ";
|
||||
switch (realUniCon.getUcCon()) {
|
||||
case "EQ":
|
||||
|
|
|
|||
Loading…
Reference in New Issue