top图解析对接预览完成

This commit is contained in:
clay 2021-07-28 16:52:58 +08:00
parent 42c1fda3f4
commit ab4a25b524
16 changed files with 385 additions and 172 deletions

View File

@ -335,7 +335,6 @@ export default {
}, },
// //
form: { form: {
roleIds:[]
}, },
// //
rules: { rules: {
@ -448,7 +447,6 @@ export default {
} }
this.relationalMapList.push(item) this.relationalMapList.push(item)
} }
console.log(this.topSearchColumnList)
this.open = true; this.open = true;
this.title = "修改top万能查询主"; this.title = "修改top万能查询主";
}); });

View File

@ -215,7 +215,7 @@
<el-table-column <el-table-column
prop="key" prop="key"
width="150px" width="150px"
label="字段"> label="字段名">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input v-model="scope.row.columnComment" placeholder="请输入列别名" /> <el-input v-model="scope.row.columnComment" placeholder="请输入列别名" />
</template> </template>
@ -231,11 +231,19 @@
<el-table-column <el-table-column
prop="isQuery" prop="isQuery"
width="50px" width="50px"
label="是否使用"> label="是否查询">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox :true-label="1" :false-label="0" v-model="scope.row.isQuery"></el-checkbox> <el-checkbox :true-label="1" :false-label="0" v-model="scope.row.isQuery"></el-checkbox>
</template> </template>
</el-table-column> </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="条件"> <el-table-column label="条件">
<template slot-scope="scope"> <template slot-scope="scope">
<el-select v-model="scope.row.ucCon" @change="ucTypeChang(scope.$index,scope.row)"> <el-select v-model="scope.row.ucCon" @change="ucTypeChang(scope.$index,scope.row)">
@ -1208,6 +1216,7 @@ export default {
item.ucType = '' item.ucType = ''
item.type = 1 item.type = 1
item.ucMock = '' item.ucMock = ''
item.ucName = ''
columns.push(item) columns.push(item)
} }
} }

View File

@ -15,8 +15,8 @@
> >
</topology> </topology>
<el-dialog :title="previewDate.title" width="1400px" :visible.sync="previewDate.open"> <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 ref="ucon" :inline="true" v-show="previewDate.showSearch" label-width="68px">
<el-form-item v-for="item in uconList" <el-form-item v-for="item in previewDate.uconList"
:key="item.id" :key="item.id"
:label="item.ucName"> :label="item.ucName">
@ -72,7 +72,7 @@
>导出 >导出
</el-button> </el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="handleQuery"></right-toolbar> <right-toolbar :showSearch.sync="previewDate.showSearch" @queryTable="handleQuery"></right-toolbar>
</el-row> </el-row>
<el-table :data="previewDate.data"> <el-table :data="previewDate.data">
<el-table-column v-for="item in previewDate.header" <el-table-column v-for="item in previewDate.header"
@ -86,7 +86,7 @@
:total="previewDate.total" :total="previewDate.total"
:page.sync="queryParams.pageNum" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" :limit.sync="queryParams.pageSize"
@pagination="previewQuery" @pagination="handleQuery"
/> />
</el-dialog> </el-dialog>
@ -98,7 +98,8 @@
import Topology from './packages/topology/src/topology' import Topology from './packages/topology/src/topology'
import { deepClone } from './utils/index' import { deepClone } from './utils/index'
import {getQuery,getTables,updateQuery,preview} from '@/api/tool/top' import {getQuery,getTables,updateQuery,preview} from '@/api/tool/top'
import {RealData} from "@/api/system/data"
import { exportReal } from '../../../api/system/data'
export default { export default {
name: 'DemoTopology', name: 'DemoTopology',
components: { components: {
@ -116,7 +117,9 @@ export default {
title:"预览", title:"预览",
data:[], data:[],
header:[], header:[],
total:0 total:0,
uconList:[],
showSearch:false,
}, },
graphData: { 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":[]}, // "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() this.randomChange()
}) })
getTables().then(res =>{ getTables().then(res =>{
console.log(res)
this.nodeTypeList = res.data.tables this.nodeTypeList = res.data.tables
this.relationalMap = res.data.relationalMap this.relationalMap = res.data.relationalMap
}) })
}, },
methods: { 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) { doAutoRefresh(interval) {
if (interval === -1) { if (interval === -1) {
clearInterval(this.autoRefreshTimer) clearInterval(this.autoRefreshTimer)
@ -198,10 +244,19 @@ export default {
}, },
doPreview(graphData){ doPreview(graphData){
if (graphData.nodes&&graphData.nodes.length>0){ if (graphData.nodes&&graphData.nodes.length>0){
preview({jsonData:JSON.stringify(graphData)}).then(res=>{ let data = {
this.previewDate.data = res.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 = [] 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.header.push(key)
} }
this.previewDate.title = this.baseData.uqName + "数据预览" this.previewDate.title = this.baseData.uqName + "数据预览"

View File

@ -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 # url: jdbc:mysql://114.215.82.135:3306/hcybase?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: hcybase # username: hcybase
# password: hcybase@2020 # 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 url: jdbc:mysql://13.75.92.40:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: gen username: gen
# password: zcsbKxPseM8LhFdT password: zcsbKxPseM8LhFdT
url: jdbc:mysql://127.0.0.1:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # url: jdbc:mysql://127.0.0.1:3306/gen?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root # username: root
password: 926425 # password: 926425
# 从库数据源 # 从库数据源
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭

View File

@ -4,6 +4,7 @@ import java.beans.PropertyEditorSupport;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.ebts.common.core.page.TableDataTop;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.WebDataBinder;
@ -66,6 +67,19 @@ public class BaseController {
rspData.setTotal(new PageInfo(list).getTotal()); rspData.setTotal(new PageInfo(list).getTotal());
return rspData; 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;
}
/** /**
* 响应返回结果 * 响应返回结果

View File

@ -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;
}
}

View File

@ -1,10 +1,12 @@
package com.ebts.generator.controller; package com.ebts.generator.controller;
import com.ebts.common.annotation.Log; import com.ebts.common.annotation.Log;
import com.ebts.common.core.controller.BaseController;
import com.ebts.common.core.entity.AjaxResult; import com.ebts.common.core.entity.AjaxResult;
import com.ebts.common.enums.BusinessType; import com.ebts.common.enums.BusinessType;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
import com.ebts.common.utils.StringUtils; import com.ebts.common.utils.StringUtils;
import com.ebts.generator.dto.TopResult;
import com.ebts.generator.entity.UniQuery; import com.ebts.generator.entity.UniQuery;
import com.ebts.generator.service.TopQueryService; import com.ebts.generator.service.TopQueryService;
import com.ebts.generator.service.TopSearchTableService; 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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -25,7 +29,7 @@ import java.util.Map;
*/ */
@RestController @RestController
@RequestMapping("/top") @RequestMapping("/top")
public class TopQueryController { public class TopQueryController extends BaseController {
@Autowired @Autowired
private TopSearchTableService topSearchTableService; private TopSearchTableService topSearchTableService;
@ -92,13 +96,13 @@ public class TopQueryController {
@PreAuthorize("@ebts.hasPermi('top:preview')") @PreAuthorize("@ebts.hasPermi('top:preview')")
@Log(title = "top预览", businessType = BusinessType.OTHER) @Log(title = "top预览", businessType = BusinessType.OTHER)
@PostMapping("/preview") @PostMapping("/preview")
public AjaxResult preview(@RequestBody Map<String,String> params){ public Serializable preview(@RequestBody Map<String,String> params){
if (StringUtils.isNull(params.get("jsonData"))){ if (StringUtils.isNull(params.get("jsonData"))){
return AjaxResult.error("缺少必要参数!"); 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()){ if (serverResult.isStart()){
return AjaxResult.success(serverResult.getData()); return getDataTable(serverResult.getData().getDataMap(),serverResult.getData().getUniCons());
}else { }else {
return AjaxResult.error(serverResult.getMsg()); return AjaxResult.error(serverResult.getMsg());
} }

View File

@ -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
* @descriptionTopResult
* @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;
}
}

View File

@ -15,7 +15,6 @@ public class TopEdge {
private String source; private String source;
private String sourceEdge; private String sourceEdge;
private String target; private String target;
private String targetEdge;
private JSONObject appConfig; private JSONObject appConfig;
@ -47,14 +46,6 @@ public class TopEdge {
this.sourceEdge = sourceEdge; this.sourceEdge = sourceEdge;
} }
public String getTargetEdge() {
return targetEdge;
}
public void setTargetEdge(String targetEdge) {
this.targetEdge = targetEdge;
}
public String getSource() { public String getSource() {
return source; return source;
} }

View File

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ebts.common.utils.StringUtils; import com.ebts.common.utils.StringUtils;
import java.util.List;
/** /**
* @author: Clay * @author: Clay
* @date: 2021/7/26 17:26 * @date: 2021/7/26 17:26
@ -15,11 +17,11 @@ public class TopNode {
private String table; private String table;
private String relTable; private String relTable;
private StringBuffer tableSQL = new StringBuffer(" "); private StringBuffer tableSQL = new StringBuffer(" ");
private StringBuffer conditions = new StringBuffer(); private StringBuffer querySql = new StringBuffer(" ");
private JSONArray columns; private JSONArray columns;
public String getConditions() { public String getQuerySql() {
return conditions.toString(); return querySql.toString();
} }
public String getRelTable() { public String getRelTable() {
@ -104,7 +106,7 @@ public class TopNode {
} }
break; break;
} }
conditions.append(sql); querySql.append(sql);
} }
} }
} }

View File

@ -60,6 +60,18 @@ public class UniCon {
*/ */
private Integer type; 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() { public String getUcType() {
return ucType; return ucType;
} }

View File

@ -1,8 +1,8 @@
package com.ebts.generator.service; package com.ebts.generator.service;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
import com.ebts.generator.dto.TopResult;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -15,5 +15,5 @@ public interface TopQueryService {
Map<String, Object> selectTopSearchTables(); Map<String, Object> selectTopSearchTables();
ServerResult<List<Map<String, Object>>> preview(String jsonData); ServerResult<TopResult> preview(String jsonData, String id);
} }

View File

@ -4,18 +4,19 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ebts.common.utils.ServerResult; import com.ebts.common.utils.ServerResult;
import com.ebts.common.utils.StringUtils;
import com.ebts.generator.dao.QueryDao; 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.dao.UniQueryDao;
import com.ebts.generator.entity.TopEdge; import com.ebts.generator.dto.TopResult;
import com.ebts.generator.entity.TopNode; import com.ebts.generator.entity.*;
import com.ebts.generator.service.TopQueryService; import com.ebts.generator.service.TopQueryService;
import com.github.pagehelper.PageHelper;
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 org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -31,7 +32,6 @@ 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;
@ -39,6 +39,8 @@ public class TopQueryServiceImpl implements TopQueryService {
private RelationalMapDao relationalMapDao; private RelationalMapDao relationalMapDao;
@Autowired @Autowired
private QueryDao queryDao; private QueryDao queryDao;
@Autowired
private UniQueryDao uniQueryDao;
@Override @Override
public Map<String, Object> selectTopSearchTables() { public Map<String, Object> selectTopSearchTables() {
@ -49,77 +51,91 @@ public class TopQueryServiceImpl implements TopQueryService {
} }
@Override @Override
public ServerResult<List<Map<String, Object>>> preview(String jsonData) { @Transactional(rollbackFor = Exception.class)
public ServerResult<TopResult> preview(String jsonData, String id) {
try { try {
JSONObject graphData = JSON.parseObject(jsonData); JSONObject graphData = JSON.parseObject(jsonData);
//将数据格式化为自定义的java类列表
List<TopEdge> topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class); List<TopEdge> topEdges = JSON.parseArray(graphData.getString("edges"), TopEdge.class);
List<TopNode> topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class); List<TopNode> topNodes = JSON.parseArray(graphData.getString("nodes"), TopNode.class);
System.out.println(topNodes); if (topNodes.size() == 0) {
for (int i = 0; i < topEdges.size(); i++) { return new ServerResult<>(false, "top图结构有误,请整理后在试");
for (int j = 0; j < topEdges.size(); j++) { }
if (i != j) { //整理连线的关系
TopEdge topEdgeJ = topEdges.get(j); StringBuffer sql = new StringBuffer("");
if (topEdges.get(i).getSource().equals(topEdgeJ.getTarget())) { StringBuilder selectSql = new StringBuilder("select ");
topEdges.get(i).setSourceEdge(topEdgeJ.getId()); 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) {
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()); }
// } // 解析出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));
}
}
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));
}
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);
} }
} }
} }
String tableId = "";
List<TopEdge> targets = new ArrayList<>(); int query = uniQueryDao.updateUniQuery(uniQuery);
for (int i = 0; i < topEdges.size(); i++) { if (query > 0) {
if (topEdges.get(i).getSourceEdge() == null) { if (uniQuery.getUniCons() != null && uniQuery.getUniCons().size() > 0) {
targets.add(topEdges.get(i)); queryDao.deleteUniCon(uniQuery.getId());
tableId = topEdges.get(i).getSource(); queryDao.insertUniCon(uniCons);
} }
} }
String relSql = ""; sql.append(selectQuery);
for (int i = 0; i < targets.size(); i++) { PageHelper.startPage(1, 10, "");
relSql+= getRelSql(topNodes,topEdges,targets.get(i)); List<Map<String, Object>> dataMap = queryDao.UniQuery(sql.toString());
} TopResult topResult = new TopResult(dataMap,uniCons);
return new ServerResult<>(true, topResult);
// 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(); e.printStackTrace();
logger.error(e.getMessage()); 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) { TopNode getNode(List<TopNode> nodes, String id) {
for (int i = 0; i < nodes.size(); i++) { for (int i = 0; i < nodes.size(); i++) {
@ -136,88 +167,49 @@ public class TopQueryServiceImpl implements TopQueryService {
} }
return null; return null;
} }
TopEdge getEdgeById(List<TopEdge> edges, String id){
for (TopEdge edge : edges) { List<TopEdge> getEdgeListById(List<TopEdge> edges, String id) {
if (edge.getId().equals(id)){
return edge;
}
}
return null;
}
List<TopEdge> getEdgeListById(List<TopEdge> edges, String id){
List<TopEdge> targetEdge = new ArrayList<>(); List<TopEdge> targetEdge = new ArrayList<>();
for (TopEdge edge : edges) { for (TopEdge edge : edges) {
if (edge.getSource().equals(id)){ if (edge.getSource().equals(id)) {
targetEdge.add(edge); targetEdge.add(edge);
} }
} }
return targetEdge; return targetEdge;
} }
String getRelSql(List<TopNode> nodes,List<TopEdge> edges,TopEdge edge){ String getRelSql(List<TopNode> nodes, List<TopEdge> edges, TopEdge edge) {
StringBuffer sql = new StringBuffer(" "); int i = 0;
List<TopEdge> targetEdge = new ArrayList<>(); // 定义sql 变量
StringBuffer sql = new StringBuffer("");
List<TopEdge> targetEdge;
while (true) { while (true) {
TopNode source = getNode(nodes,edge.getSource()); // 获取到连线的两个表
TopNode target = getNode(nodes,edge.getTarget()); TopNode source = getNode(nodes, edge.getSource());
sql.append(target.getTable()).append(" ").append(target.getRelTable()).append(" ") TopNode target = getNode(nodes, edge.getTarget());
.append(edge.getAppConfig().getString("associated")).append(" join ") //进行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() .append(target.getRelTable()).append(".").append(edge.getAppConfig()
.getString("relComment")).append(" = ").append(source.getRelTable()) .getString("relComment")).append(" = ").append(source.getRelTable())
.append(".").append(edge.getAppConfig().getString("tableComment")).append("\n"); .append(".").append(edge.getAppConfig().getString("tableComment"));
if (StringUtils.isNull(edge.getTarget())){ // 获取到target 连接表的连线
break; targetEdge = getEdgeListById(edges, edge.getTarget());
} // 判断连线条数
targetEdge = getEdgeListById(edges,edge.getTarget()); if (targetEdge.size() == 1) {
if (targetEdge.size()==1){
edge = targetEdge.get(0); edge = targetEdge.get(0);
}else if (targetEdge.size()>1){ } else if (targetEdge.size() > 1) {
while (index<targetEdge.size()){ //多条则进行递归解析
sql.append(getRelSql(nodes,edges,targetEdge.get(index))); while (i < targetEdge.size()) {
index++; sql.append(getRelSql(nodes, edges, targetEdge.get(i)));
i++;
} }
break; break;
// for (TopEdge topEdge : targetEdge) { } else {
// } //没有则退出循环返回解析好的sql
}else {
break; break;
} }
} }
return sql.toString(); 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;
}
} }

View File

@ -52,7 +52,7 @@ public class TopSearchTableServiceImpl implements TopSearchTableService {
public ServerResult<TopSearchTable> selectTopSearchTableById(Long id) { public ServerResult<TopSearchTable> selectTopSearchTableById(Long id) {
try { try {
TopSearchTable topSearchTable = topSearchTableDao.selectTopSearchTableById(id); 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()] ; Long[] roles = new Long[roleList.size()] ;
for (int i = 0; i < roleList.size(); i++) { for (int i = 0; i < roleList.size(); i++) {
roles[i] = roleList.get(i).getRoleId(); roles[i] = roleList.get(i).getRoleId();

View File

@ -151,9 +151,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete> </delete>
<insert id="batchTopSearchColumn"> <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=","> <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> </foreach>
</insert> </insert>
</mapper> </mapper>

View File

@ -68,15 +68,19 @@ public class RealQueryServiceImpl implements RealQueryService {
return new ServerResult<>(true, dataMap, realUniQuery.getUqName()); return new ServerResult<>(true, dataMap, realUniQuery.getUqName());
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
e.printStackTrace();
logger.error(e.getMessage()); logger.error(e.getMessage());
throw new EbtsException(ReturnConstants.OP_ERROR,e); throw new EbtsException(ReturnConstants.OP_ERROR,e);
} }
} }
public String conversionReal(RealUniCon realUniCon) { public String conversionReal(RealUniCon realUniCon) {
if (realUniCon.getUcReal() == null&&!realUniCon.getUcReal().equals("")) { if (realUniCon.getUcReal() == null) {
return ""; return "";
} else { } else if (realUniCon.getUcReal().equals("")){
return "";
}
else {
String sql = " and "; String sql = " and ";
switch (realUniCon.getUcCon()) { switch (realUniCon.getUcCon()) {
case "EQ": case "EQ":