diff --git a/ebts-ui/src/api/tool/top.js b/ebts-ui/src/api/tool/top.js index 7561bd8..037ab59 100644 --- a/ebts-ui/src/api/tool/top.js +++ b/ebts-ui/src/api/tool/top.js @@ -29,3 +29,12 @@ export function updateQuery(data) { data:data }) } + +// 查询万能查询详细 +export function preview(data) { + return request({ + url: '/top/preview', + method: 'post', + data:data + }) +} diff --git a/ebts-ui/src/views/tool/top/packages/elements/button.vue b/ebts-ui/src/views/tool/top/packages/elements/button.vue index 52d48c6..891e7e3 100644 --- a/ebts-ui/src/views/tool/top/packages/elements/button.vue +++ b/ebts-ui/src/views/tool/top/packages/elements/button.vue @@ -1,11 +1,11 @@ -.cc-button { +.top-button { display: inline-block; line-height: 1; white-space: nowrap; @@ -76,17 +76,17 @@ export default { border-radius: 4px; } -.cc-button:focus, .cc-button:hover { +.top-button:focus, .top-button:hover { color: #409eff; border-color: #c6e2ff; background-color: #ecf5ff; } -.cc-button--mini, .cc-button--mini.is-round { +.top-button--mini, .top-button--mini.is-round { padding: 7px 15px; } -.cc-button--mini, .cc-button--small { +.top-button--mini, .top-button--small { font-size: 12px; border-radius: 3px; } diff --git a/ebts-ui/src/views/tool/top/packages/topology/src/toolbar-edit.vue b/ebts-ui/src/views/tool/top/packages/topology/src/toolbar-edit.vue index 10eacef..ed0f39e 100644 --- a/ebts-ui/src/views/tool/top/packages/topology/src/toolbar-edit.vue +++ b/ebts-ui/src/views/tool/top/packages/topology/src/toolbar-edit.vue @@ -2,12 +2,13 @@ - + - + + 返回 @@ -31,24 +32,26 @@ - + - + @change="$parent.changeEdgeShapeHandler"> + + - 自动布局 + 自动布局 - - 返回 - 保存 + 预览 + + + 保存 @@ -59,8 +62,8 @@ import { Button, Dropdown } from '../../elements'; export default { name: "ToolbarEdit", components: { - "cc-button": Button, - "cc-dropdown": Dropdown + "top-button": Button, + "top-dropdown": Dropdown } }; @@ -155,7 +158,7 @@ export default { } } - .cc-button { + .top-button { margin: 0 5px; } } diff --git a/ebts-ui/src/views/tool/top/packages/topology/src/topology.vue b/ebts-ui/src/views/tool/top/packages/topology/src/topology.vue index c21cc1f..b5b2ab6 100644 --- a/ebts-ui/src/views/tool/top/packages/topology/src/topology.vue +++ b/ebts-ui/src/views/tool/top/packages/topology/src/topology.vue @@ -881,7 +881,10 @@ export default { // // this.graph.$C.edge.type = this.currentEdgeShape["guid"]; }, - + // 返回 + reBack(){ + this.$router.replace('/tool/er-top') + }, undoHandler() { if (this.historyIndex > 0 && this.historyIndex - (this.undoCount + 1) >= 0) { this.undoCount += 1 @@ -1410,6 +1413,12 @@ export default { this.changeGraphTheme('defaultStyle') this.$emit('doChangeMode', graphMode) }, + // todo 预览 + searchPreview(){ + let graphData = this.getGraphData() + // console.log(graphData) + this.$emit('doPreview', graphData) + }, // 保存函数 saveDataHandler() { let graphData = this.getGraphData() diff --git a/ebts-ui/src/views/tool/top/topology.vue b/ebts-ui/src/views/tool/top/topology.vue index df90786..df81157 100644 --- a/ebts-ui/src/views/tool/top/topology.vue +++ b/ebts-ui/src/views/tool/top/topology.vue @@ -11,8 +11,85 @@ @doManualRefresh="doManualRefresh" @doChangeMode="doChangeMode" @doSaveData="doSaveData" + @doPreview="doPreview" > + + + + + + + + + + + + + + + + + + + + + 搜索 + 重置 + + + + + 导出 + + + + + + + + + + @@ -20,7 +97,7 @@ /* 局部注册 */ import Topology from './packages/topology/src/topology' import { deepClone } from './utils/index' -import {getQuery,getTables,updateQuery} from '@/api/tool/top' +import {getQuery,getTables,updateQuery,preview} from '@/api/tool/top' export default { name: 'DemoTopology', @@ -29,6 +106,18 @@ export default { }, data() { return { + queryParams: { + pageNum: 1, + pageSize: 10, + }, + baseData:null, + previewDate:{ + open:false, + title:"预览", + data:[], + header:[], + total:0 + }, 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","sourceAttrs":[{"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,"targetAttrs":[{"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":[]}, }, @@ -55,7 +144,7 @@ export default { mounted() { this.topId = this.$route.params && this.$route.params.topId; getQuery(this.topId).then(res =>{ - console.log(res) + this.baseData = res.data this.graphData = JSON.parse(res.data.topJson) let graphData = deepClone(this.graphData) this.$refs.topology.initTopo(graphData) @@ -99,7 +188,21 @@ export default { updateQuery(data).then(res =>{ console.log(res) }) - + }, + doPreview(graphData){ + if (graphData.nodes&&graphData.nodes.length>0){ + preview({jsonData:JSON.stringify(graphData)}).then(res=>{ + this.previewDate.data = res.data + this.previewDate.header = [] + for (var key in this.previewDate.data[0]) { + this.previewDate.header.push(key) + } + this.previewDate.title = this.baseData.uqName + "数据预览" + this.previewDate.open = true + }) + }else { + this.msgError("top数据有误,请再次检查") + } }, randomChange() { let graphData = deepClone(this.$refs.topology.getGraphData()) diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java index 27e2a40..875faac 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/controller/TopQueryController.java @@ -13,6 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import java.util.List; +import java.util.Map; + /** * @author: Clay @@ -64,10 +67,10 @@ public class TopQueryController { } /** - * 简单修改万能能查询 + * 简单修改top万能能查询 */ @PreAuthorize("@ebts.hasPermi('top:edit')") - @Log(title = "万能查询", businessType = BusinessType.UPDATE) + @Log(title = "top万能查询", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody UniQuery uniQuery) { if (uniQuery.getId()<0){ @@ -83,6 +86,21 @@ public class TopQueryController { return AjaxResult.error(ServerResult.getMsg()); } } - - + /** + * 简单修改top万能能查询 + */ + @PreAuthorize("@ebts.hasPermi('top:preview')") + @Log(title = "top预览", businessType = BusinessType.OTHER) + @PostMapping("/preview") + public AjaxResult preview(@RequestBody Map params){ + if (StringUtils.isNull(params.get("jsonData"))){ + return AjaxResult.error("缺少必要参数!"); + } + ServerResult>> serverResult = topQueryService.preview(params.get("jsonData")); + if (serverResult.isStart()){ + return AjaxResult.success(serverResult.getData()); + }else { + return AjaxResult.error(serverResult.getMsg()); + } + } } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java index 2cef5cf..1611f59 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopQueryService.java @@ -1,7 +1,6 @@ package com.ebts.generator.service; -import com.ebts.generator.entity.TopSearchTable; -import org.apache.poi.ss.formula.functions.T; +import com.ebts.common.utils.ServerResult; import java.util.List; import java.util.Map; @@ -15,4 +14,6 @@ import java.util.Map; public interface TopQueryService { Map selectTopSearchTables(); + + ServerResult>> preview(String jsonData); } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java index debf537..08aee3b 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/TopSearchTableService.java @@ -8,15 +8,14 @@ import com.ebts.generator.entity.TopSearchTable; /** * top万能查询主Service接口 - * + * * @author clay * @date 2021-07-20 */ -public interface TopSearchTableService -{ +public interface TopSearchTableService { /** * 查询top万能查询主 - * + * * @param id top万能查询主ID * @return top万能查询主 */ @@ -24,22 +23,22 @@ public interface TopSearchTableService /** * 查询top万能查询主列表 - * + * * @param topSearchTable top万能查询主 * @return top万能查询主集合 */ ServerResult> selectTopSearchTableList(TopSearchTable topSearchTable); /** - * * @return */ ServerResult> selectTopSearchTableInfo(); List selectTableColumns(Long id); + /** * 新增top万能查询主 - * + * * @param topSearchTable top万能查询主 * @return 结果 */ @@ -47,7 +46,7 @@ public interface TopSearchTableService /** * 修改top万能查询主 - * + * * @param topSearchTable top万能查询主 * @return 结果 */ @@ -59,7 +58,7 @@ public interface TopSearchTableService /** * 批量删除top万能查询主 - * + * * @param ids 需要删除的top万能查询主ID * @return 结果 */ @@ -67,7 +66,7 @@ public interface TopSearchTableService /** * 删除top万能查询主信息 - * + * * @param id top万能查询主ID * @return 结果 */ diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/QueryServiceImpl.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/QueryServiceImpl.java index 3d70346..346a2c9 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/QueryServiceImpl.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/QueryServiceImpl.java @@ -139,7 +139,7 @@ public class QueryServiceImpl implements QueryService { return new ServerResult<>(true, dataMap); } catch (RuntimeException e) { logger.error(e.getMessage()); - throw new EbtsException(ReturnConstants.OP_ERROR,e); + return new ServerResult<>(false, e.getMessage()); } } diff --git a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java index 6db0a2b..a418293 100644 --- a/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java +++ b/ebts/ebts-generator/src/main/java/com/ebts/generator/service/impl/TopQueryServiceImpl.java @@ -1,13 +1,21 @@ package com.ebts.generator.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ebts.common.utils.ServerResult; +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.service.TopQueryService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -18,16 +26,57 @@ import java.util.Map; */ @Service public class TopQueryServiceImpl implements TopQueryService { + private final Logger logger = LoggerFactory.getLogger(TopQueryServiceImpl.class); + @Autowired private TopSearchTableDao topSearchTableDao; @Autowired private RelationalMapDao relationalMapDao; + @Autowired + private QueryDao queryDao; @Override public Map selectTopSearchTables() { - Map modeMap = new HashMap<>(); - modeMap.put("tables",topSearchTableDao.selectTopSearchTables()); - modeMap.put("relationalMap",relationalMapDao.selectRelationalMapList(new RelationalMap())); + Map modeMap = new HashMap<>(); + modeMap.put("tables", topSearchTableDao.selectTopSearchTables()); + modeMap.put("relationalMap", relationalMapDao.selectRelationalMapList(new RelationalMap())); return modeMap; } + + @Override + public ServerResult>> preview(String jsonData) { + try { + + JSONObject graphData = JSON.parseObject(jsonData); + JSONArray nodes = graphData.getJSONArray("nodes"); + JSONArray edges = graphData.getJSONArray("edges"); + JSONObject node = nodes.getJSONObject(0); + + StringBuffer sql = new StringBuffer("select "); + + JSONArray attrs = node.getJSONArray("attrs"); + boolean start = false; + for (int i = 0; i < attrs.size(); i++) { + JSONObject column = attrs.getJSONObject(i); + if (column.getInteger("isUse") == 1) { + if (start) { + sql.append(", "); + } + sql.append(column.getString("columnName")); + sql.append(" as "); + sql.append("'" + column.getString("columnComment") + "'"); + start=true; + } + } + sql.append(" from " + node.getString("table")); + System.out.println(sql.toString()); + List> dataMap = queryDao.UniQuery(sql.toString()); + return new ServerResult<>(true, dataMap); + } catch (RuntimeException e) { + logger.error(e.getMessage()); + return new ServerResult<>(false, e.getMessage()); + } + } + + }