数据预览优化,SQL组装移到后端
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
package com.zyplayer.doc.db.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.util.TypeUtils;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.core.util.StringUtil;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.support.consts.DocAuthConst;
|
||||
import com.zyplayer.doc.db.controller.param.DataViewParam;
|
||||
import com.zyplayer.doc.db.framework.consts.DbAuthType;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteParam;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteResult;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteType;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.SqlExecutor;
|
||||
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
|
||||
import com.zyplayer.doc.db.framework.utils.JSONUtil;
|
||||
import com.zyplayer.doc.db.service.DbBaseFactory;
|
||||
import com.zyplayer.doc.db.service.DbBaseService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 表数据查看控制器
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2021年5月16日
|
||||
*/
|
||||
@AuthMan
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-doc-db/data-view")
|
||||
public class DbDataViewController {
|
||||
private static Logger logger = LoggerFactory.getLogger(DbDataViewController.class);
|
||||
|
||||
@Resource
|
||||
SqlExecutor sqlExecutor;
|
||||
@Resource
|
||||
DbBaseFactory dbBaseFactory;
|
||||
|
||||
@PostMapping(value = "/query")
|
||||
public ResponseJson execute(DataViewParam dataViewParam) {
|
||||
boolean manageAuth = DocUserUtil.haveAuth(DocAuthConst.DB_DATASOURCE_MANAGE);
|
||||
boolean select = DocUserUtil.haveCustomAuth(DbAuthType.SELECT.getName(), DocAuthConst.DB + dataViewParam.getSourceId());
|
||||
boolean update = DocUserUtil.haveCustomAuth(DbAuthType.UPDATE.getName(), DocAuthConst.DB + dataViewParam.getSourceId());
|
||||
if (!manageAuth && !select && !update) {
|
||||
return DocDbResponseJson.warn("没有该数据源的执行权限");
|
||||
}
|
||||
// 数据查询
|
||||
ExecuteType executeType = (manageAuth || update) ? ExecuteType.ALL : ExecuteType.SELECT;
|
||||
DbBaseService dbBaseService = dbBaseFactory.getDbBaseService(dataViewParam.getSourceId());
|
||||
String queryPageSql = dbBaseService.getQueryPageSql(dataViewParam);
|
||||
ExecuteResult executeResult = this.query(dataViewParam.getSourceId(), dataViewParam.getExecuteId(), executeType, queryPageSql);
|
||||
// 数据组装
|
||||
List<String> resultList = new LinkedList<>();
|
||||
resultList.add(JSON.toJSONString(executeResult, JSONUtil.serializeConfig, SerializerFeature.WriteMapNullValue));
|
||||
DocDbResponseJson responseJson = DocDbResponseJson.ok(resultList);
|
||||
// 计算总条数,第一页才查询总条数
|
||||
if (CollectionUtils.isNotEmpty(executeResult.getResult()) && Objects.equals(dataViewParam.getPageNum(), 1)) {
|
||||
responseJson.setTotal((long) executeResult.getResult().size());
|
||||
if (executeResult.getResult().size() >= dataViewParam.getPageSize()) {
|
||||
String queryCountSql = dbBaseService.getQueryCountSql(dataViewParam);
|
||||
ExecuteResult countResult = this.query(dataViewParam.getSourceId(), dataViewParam.getExecuteId(), executeType, queryCountSql);
|
||||
if (CollectionUtils.isNotEmpty(countResult.getResult()) && MapUtils.isNotEmpty(countResult.getResult().get(0))) {
|
||||
Map<String, Object> countMap = countResult.getResult().get(0);
|
||||
Optional<Object> countAny = countMap.values().stream().findAny();
|
||||
countAny.ifPresent(count -> responseJson.setTotal(TypeUtils.castToLong(count)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return responseJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行数据查询
|
||||
*
|
||||
* @param sourceId
|
||||
* @param executeId
|
||||
* @param executeType
|
||||
* @param executeSql
|
||||
* @return
|
||||
*/
|
||||
private ExecuteResult query(Long sourceId, String executeId, ExecuteType executeType, String executeSql) {
|
||||
try {
|
||||
ExecuteParam executeParam = new ExecuteParam();
|
||||
executeParam.setDatasourceId(sourceId);
|
||||
executeParam.setExecuteId(executeId);
|
||||
executeParam.setExecuteType(executeType);
|
||||
executeParam.setSql(executeSql);
|
||||
executeParam.setMaxRows(1000);
|
||||
return sqlExecutor.execute(executeParam);
|
||||
} catch (Exception e) {
|
||||
logger.error("执行出错", e);
|
||||
return ExecuteResult.error(StringUtil.getException(e), executeSql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.zyplayer.doc.db.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
@@ -21,6 +19,7 @@ import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteResult;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteType;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.SqlExecutor;
|
||||
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
|
||||
import com.zyplayer.doc.db.framework.utils.JSONUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -84,10 +82,7 @@ public class DbSqlExecutorController {
|
||||
executeParam.setSql(sqlItem);
|
||||
executeParam.setMaxRows(1000);
|
||||
ExecuteResult executeResult = sqlExecutor.execute(executeParam);
|
||||
SerializeConfig mapping = new SerializeConfig();
|
||||
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
mapping.put(Timestamp.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
String resultJsonStr = JSON.toJSONString(executeResult, mapping, SerializerFeature.WriteMapNullValue);
|
||||
String resultJsonStr = JSON.toJSONString(executeResult, JSONUtil.serializeConfig, SerializerFeature.WriteMapNullValue);
|
||||
resultList.add(resultJsonStr);
|
||||
} catch (Exception e) {
|
||||
logger.error("执行出错", e);
|
||||
@@ -146,5 +141,6 @@ public class DbSqlExecutorController {
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.zyplayer.doc.db.controller.param;
|
||||
|
||||
public class DataViewParam {
|
||||
private Long sourceId;
|
||||
private String executeId;
|
||||
private Integer pageSize;
|
||||
private Integer pageNum;
|
||||
private String dbName;
|
||||
private String tableName;
|
||||
private String orderColumn;
|
||||
private String orderType;
|
||||
private String condition;
|
||||
|
||||
public Integer getOffset() {
|
||||
return ((this.pageNum - 1) * this.pageSize);
|
||||
}
|
||||
|
||||
public Long getSourceId() {
|
||||
return sourceId;
|
||||
}
|
||||
|
||||
public void setSourceId(Long sourceId) {
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
|
||||
public String getExecuteId() {
|
||||
return executeId;
|
||||
}
|
||||
|
||||
public void setExecuteId(String executeId) {
|
||||
this.executeId = executeId;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setDbName(String dbName) {
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getOrderColumn() {
|
||||
return orderColumn;
|
||||
}
|
||||
|
||||
public void setOrderColumn(String orderColumn) {
|
||||
this.orderColumn = orderColumn;
|
||||
}
|
||||
|
||||
public String getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(String orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setCondition(String condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.zyplayer.doc.db.framework.utils;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
public class JSONUtil {
|
||||
|
||||
public static SerializeConfig serializeConfig = new SerializeConfig();
|
||||
|
||||
static {
|
||||
serializeConfig.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
serializeConfig.put(Timestamp.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.zyplayer.doc.db.service;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.support.consts.DocAuthConst;
|
||||
import com.zyplayer.doc.db.controller.param.DataViewParam;
|
||||
import com.zyplayer.doc.db.controller.param.ProcedureListParam;
|
||||
import com.zyplayer.doc.db.controller.vo.TableColumnVo;
|
||||
import com.zyplayer.doc.db.controller.vo.TableDdlVo;
|
||||
@@ -335,4 +336,28 @@ public abstract class DbBaseService {
|
||||
// 需要各数据服务自己实现,各数据库产品的实现都不一样
|
||||
throw new ConfirmException("暂未支持的数据库类型");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页查询的SQL
|
||||
*
|
||||
* @return 分页查询的SQL
|
||||
* @author 暮光:城中城
|
||||
* @since 2020年4月24日
|
||||
*/
|
||||
public String getQueryPageSql(DataViewParam dataViewParam) {
|
||||
// 需要各数据服务自己实现,各数据库产品的实现都不一样
|
||||
throw new ConfirmException("暂未支持的数据库类型");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询总条数的SQL
|
||||
*
|
||||
* @return 查询总条数的SQL
|
||||
* @author 暮光:城中城
|
||||
* @since 2020年4月24日
|
||||
*/
|
||||
public String getQueryCountSql(DataViewParam dataViewParam) {
|
||||
// 需要各数据服务自己实现,各数据库产品的实现都不一样
|
||||
throw new ConfirmException("暂未支持的数据库类型");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.zyplayer.doc.db.service;
|
||||
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.db.controller.vo.TableStatusVo;
|
||||
import com.zyplayer.doc.db.framework.db.dto.QueryTableColumnDescDto;
|
||||
import com.zyplayer.doc.db.framework.db.dto.TableColumnDescDto;
|
||||
import com.zyplayer.doc.db.framework.db.dto.TableDescDto;
|
||||
import com.zyplayer.doc.db.framework.db.dto.TableInfoDto;
|
||||
import com.zyplayer.doc.db.framework.db.enums.DatabaseProductEnum;
|
||||
import com.zyplayer.doc.db.framework.db.mapper.base.BaseMapper;
|
||||
@@ -24,4 +29,29 @@ public class HiveServiceImpl extends DbBaseService {
|
||||
}
|
||||
return tableList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableColumnDescDto> getTableColumnDescList(Long sourceId, String tableName) {
|
||||
throw new ConfirmException("不支持的操作");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QueryTableColumnDescDto> getTableAndColumnBySearch(Long sourceId, String dbName, String searchText) {
|
||||
throw new ConfirmException("不支持的操作");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableDescDto> getTableDescList(Long sourceId, String dbName, String tableName) {
|
||||
throw new ConfirmException("不支持的操作");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTableDesc(Long sourceId, String dbName, String tableName, String newDesc) {
|
||||
throw new ConfirmException("不支持的操作");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTableColumnDesc(Long sourceId, String dbName, String tableName, String columnName, String newDesc) {
|
||||
throw new ConfirmException("不支持的操作");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.zyplayer.doc.db.service;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.zyplayer.doc.db.controller.param.DataViewParam;
|
||||
import com.zyplayer.doc.db.controller.vo.TableDdlVo;
|
||||
import com.zyplayer.doc.db.framework.db.dto.ColumnInfoDto;
|
||||
import com.zyplayer.doc.db.framework.db.dto.ProcedureDto;
|
||||
@@ -125,4 +126,28 @@ public class MysqlServiceImpl extends DbBaseService {
|
||||
return ExecuteResult.error(e.getMessage(), procSql);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryPageSql(DataViewParam dataViewParam) {
|
||||
StringBuilder sqlSb = new StringBuilder();
|
||||
sqlSb.append(String.format("select * from %s.%s", dataViewParam.getDbName(), dataViewParam.getTableName()));
|
||||
if (StringUtils.isNotBlank(dataViewParam.getCondition())) {
|
||||
sqlSb.append(String.format(" where %s", dataViewParam.getCondition()));
|
||||
}
|
||||
if (StringUtils.isNotBlank(dataViewParam.getOrderColumn()) && StringUtils.isNotBlank(dataViewParam.getOrderType())) {
|
||||
sqlSb.append(String.format(" order by %s %s", dataViewParam.getOrderColumn(), dataViewParam.getOrderType()));
|
||||
}
|
||||
sqlSb.append(String.format(" limit %s offset %s", dataViewParam.getPageSize(), dataViewParam.getOffset()));
|
||||
return sqlSb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryCountSql(DataViewParam dataViewParam) {
|
||||
StringBuilder sqlSb = new StringBuilder();
|
||||
sqlSb.append(String.format("select count(1) as counts from %s.%s", dataViewParam.getDbName(), dataViewParam.getTableName()));
|
||||
if (StringUtils.isNotBlank(dataViewParam.getCondition())) {
|
||||
sqlSb.append(String.format(" where %s", dataViewParam.getCondition()));
|
||||
}
|
||||
return sqlSb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/app.b6b9fe42.css rel=preload as=style><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=js/app.412c8ca9.js rel=preload as=script><link href=js/chunk-vendors.d40f789d.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/app.b6b9fe42.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.d40f789d.js></script><script src=js/app.412c8ca9.js></script></body></html>
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/app.b6b9fe42.css rel=preload as=style><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=js/app.bfcb0d3d.js rel=preload as=script><link href=js/chunk-vendors.d40f789d.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/app.b6b9fe42.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.d40f789d.js></script><script src=js/app.bfcb0d3d.js></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
@@ -101,6 +101,9 @@ export default {
|
||||
procedureLogDetail: data => {
|
||||
return request({url: '/zyplayer-doc-db/procedure/log/detail', method: 'post', data: Qs.stringify(data)});
|
||||
},
|
||||
dataViewQuery: data => {
|
||||
return request({url: '/zyplayer-doc-db/data-view/query', method: 'post', data: Qs.stringify(data)});
|
||||
},
|
||||
systemUpgradeInfo: data => {
|
||||
return request({url: '/system/info/upgrade', method: 'post', data: Qs.stringify(data)});
|
||||
},
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
<div class="data-executor-vue">
|
||||
<div style="padding: 0 10px 10px;height: 100%;box-sizing: border-box;">
|
||||
<el-card style="margin-bottom: 10px;">
|
||||
<pre id="sqlExecutorEditor" style="width: 100%;height: 500px;margin-top: 0;"></pre>
|
||||
<pre id="sqlExecutorEditor" style="width: 100%;height: 500px;margin-top: 0;margin-bottom: 10px;"></pre>
|
||||
<div>
|
||||
<el-button v-if="sqlExecuting" v-on:click="cancelExecutorSql" type="primary" plain size="small" icon="el-icon-video-pause">取消执行</el-button>
|
||||
<el-tooltip v-else effect="dark" content="Ctrl+R、Ctrl+Enter" placement="top">
|
||||
<el-button v-on:click="doExecutorClick" type="primary" plain size="small" icon="el-icon-video-play">执行</el-button>
|
||||
<el-button v-on:click="doExecutorClick" type="primary" plain size="small" icon="el-icon-video-play">筛选</el-button>
|
||||
</el-tooltip>
|
||||
<el-button icon="el-icon-brush" size="small" @click="formatterSql">SQL美化</el-button>
|
||||
<el-button icon="el-icon-refresh-left" size="small" @click="refreshData">重置</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
@@ -23,21 +22,6 @@
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="'结果'+resultItem.index" :name="'table'+resultItem.index" v-for="resultItem in executeResultList" v-if="!!resultItem.index">
|
||||
<div v-if="!!resultItem.errMsg" style="color: #f00;">{{resultItem.errMsg}}</div>
|
||||
<!-- <pl-table v-else-->
|
||||
<!-- :datas="resultItem.dataList"-->
|
||||
<!-- :height="tableMaxHeight"-->
|
||||
<!-- header-drag-style-->
|
||||
<!-- :row-height="40">-->
|
||||
<!-- <template slot="empty">暂无数据</template>-->
|
||||
<!-- <pl-table-column width="60px" v-if="resultItem.dataCols.length > 0">-->
|
||||
<!-- <template slot-scope="scope">{{scope.row._index}}</template>-->
|
||||
<!-- </pl-table-column>-->
|
||||
<!-- <pl-table-column sortable v-for="item in resultItem.dataCols" :prop="item.prop" :label="item.prop" :width="item.width">-->
|
||||
<!-- <template slot-scope="scope">-->
|
||||
<!-- <textarea readonly :value="scope.row[item.prop]" class="el-textarea__inner" rows="1"></textarea>-->
|
||||
<!-- </template>-->
|
||||
<!-- </pl-table-column>-->
|
||||
<!-- </pl-table>-->
|
||||
<el-table v-else :data="resultItem.dataList" stripe border
|
||||
style="width: 100%; margin-bottom: 5px;"
|
||||
class="execute-result-table" :max-height="tableMaxHeight"
|
||||
@@ -53,7 +37,6 @@
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-show="needShowPage"
|
||||
style="margin-top: 10px;"
|
||||
@size-change="handlePageSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
@@ -97,12 +80,11 @@
|
||||
tableTotalCount: 0,
|
||||
tableSort: {},
|
||||
tableMaxHeight: 600,
|
||||
needShowPage: true,
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
let that = this;
|
||||
this.sqlExecutorEditor = this.initAceEditor("sqlExecutorEditor", 6);
|
||||
this.sqlExecutorEditor = this.initAceEditor("sqlExecutorEditor", 5);
|
||||
this.sqlExecutorEditor.setFontSize(16);
|
||||
this.sqlExecutorEditor.commands.addCommand({
|
||||
name: "execute-sql",
|
||||
@@ -148,45 +130,21 @@
|
||||
this.currentPage = 1;
|
||||
this.doExecutorSql();
|
||||
},
|
||||
formatterSql() {
|
||||
let dataSql = this.sqlExecutorEditor.getSelectedText();
|
||||
if (!!dataSql) {
|
||||
let range = this.sqlExecutorEditor.getSelectionRange();
|
||||
this.sqlExecutorEditor.remove(range);
|
||||
} else {
|
||||
dataSql = this.sqlExecutorEditor.getValue();
|
||||
this.sqlExecutorEditor.setValue('', 1);
|
||||
}
|
||||
if (!!dataSql) {
|
||||
dataSql = sqlFormatter.format(dataSql);
|
||||
this.sqlExecutorEditor.insert(dataSql);
|
||||
}
|
||||
},
|
||||
cancelExecutorSql() {
|
||||
datasourceApi.executeSqlCancel({executeId: this.nowExecutorId}).then(() => {
|
||||
this.$message.success("取消成功");
|
||||
});
|
||||
},
|
||||
doExecutorClick() {
|
||||
let dataSql = this.sqlExecutorEditor.getSelectedText();
|
||||
if (!dataSql) {
|
||||
dataSql = this.sqlExecutorEditor.getValue();
|
||||
}
|
||||
if (!dataSql) {
|
||||
this.$message.error("查询SQL不能为空");
|
||||
return;
|
||||
}
|
||||
this.needShowPage = false;
|
||||
this.doExecutorSqlCommon(dataSql);
|
||||
let conditionSql = this.sqlExecutorEditor.getSelectedText();
|
||||
conditionSql = conditionSql || this.sqlExecutorEditor.getValue();
|
||||
conditionSql = conditionSql || "";
|
||||
this.doExecutorSqlCommon(conditionSql);
|
||||
},
|
||||
doExecutorSql() {
|
||||
let dataSql = this.getExecuteSql();
|
||||
let countSql = this.getExecuteCountSql();
|
||||
this.sqlExecutorEditor.setValue(dataSql, 1);
|
||||
this.needShowPage = true;
|
||||
this.doExecutorSqlCommon(dataSql, countSql);
|
||||
this.doExecutorSqlCommon();
|
||||
},
|
||||
doExecutorSqlCommon(dataSql, countSql) {
|
||||
doExecutorSqlCommon(conditionSql) {
|
||||
if (!this.vueQueryParam.sourceId) {
|
||||
this.$message.error("请先选择数据源");
|
||||
return;
|
||||
@@ -194,28 +152,23 @@
|
||||
this.executeError = "";
|
||||
this.executeUseTime = "";
|
||||
this.executeResultList = [];
|
||||
this.tableMaxHeight = document.body.clientHeight - 230;
|
||||
|
||||
this.tableMaxHeight = document.body.clientHeight - 400;
|
||||
this.nowExecutorId = (new Date()).getTime() + Math.ceil(Math.random() * 1000);
|
||||
this.sqlExecuting = true;
|
||||
let param = {
|
||||
sourceId: this.vueQueryParam.sourceId,
|
||||
dbName: this.vueQueryParam.dbName,
|
||||
tableName: this.vueQueryParam.tableName,
|
||||
executeId: this.nowExecutorId,
|
||||
sql: countSql,
|
||||
condition: conditionSql,
|
||||
pageNum: this.currentPage,
|
||||
pageSize: this.pageSize,
|
||||
orderColumn: this.tableSort.prop,
|
||||
orderType: (this.tableSort.order === 'ascending' ? 'asc' : 'desc'),
|
||||
params: '',
|
||||
};
|
||||
// 第一页才查询总条数
|
||||
if (!!countSql && this.currentPage == 1) {
|
||||
datasourceApi.queryExecuteSql(param).then(res => {
|
||||
if (res.errCode != 200 || !res.data || res.data.length <= 0) return;
|
||||
let objItem = JSON.parse(res.data[0]);
|
||||
if(!objItem.result || objItem.result.length <= 0) return;
|
||||
this.tableTotalCount = objItem.result[0].counts || 0;
|
||||
});
|
||||
}
|
||||
param.sql = dataSql;
|
||||
datasourceApi.queryExecuteSql(param).then(json => {
|
||||
if (json.errCode != 200) {
|
||||
datasourceApi.dataViewQuery(param).then(json => {
|
||||
if (json.errCode !== 200) {
|
||||
this.executeError = json.errMsg;
|
||||
this.sqlExecuting = false;
|
||||
return;
|
||||
@@ -232,32 +185,16 @@
|
||||
itemIndex++;
|
||||
}
|
||||
executeResultList.push(resultItem);
|
||||
}
|
||||
this.executeShowTable = (itemIndex === 1) ? "table0" : "table1";
|
||||
this.executeResultInfo = executeResultInfo;
|
||||
this.executeResultList = executeResultList;
|
||||
}
|
||||
if (!!json.total) {
|
||||
this.tableTotalCount = json.total || 0;
|
||||
}
|
||||
this.executeShowTable = (itemIndex === 1) ? "table0" : "table1";
|
||||
this.executeResultInfo = executeResultInfo;
|
||||
this.executeResultList = executeResultList;
|
||||
this.sqlExecuting = false;
|
||||
});
|
||||
},
|
||||
getExecuteSql() {
|
||||
if (this.vueQueryParam.dbType == 'mysql') {
|
||||
let tableSort = ' ';
|
||||
if (!!this.tableSort.prop && !!this.tableSort.order) {
|
||||
tableSort = ' order by ' + this.tableSort.prop + ' ' + (this.tableSort.order === 'ascending' ? 'asc' : 'desc');
|
||||
}
|
||||
return 'select * from ' + this.vueQueryParam.dbName + '.' + this.vueQueryParam.tableName
|
||||
+ tableSort
|
||||
+ ' limit ' + this.pageSize + ' offset ' + ((this.currentPage - 1) * this.pageSize);
|
||||
}
|
||||
this.$message.error("暂未支持的数据库类型表数据预览");
|
||||
return '';
|
||||
},
|
||||
getExecuteCountSql() {
|
||||
if (this.vueQueryParam.dbType == 'mysql') {
|
||||
return 'select count(1) as counts from ' + this.vueQueryParam.dbName + '.' + this.vueQueryParam.tableName;
|
||||
}
|
||||
return '';
|
||||
},
|
||||
getExecuteInfoStr(resultData) {
|
||||
var resultStr = resultData.sql;
|
||||
resultStr += "\n> 状态:" + ((!!resultData.errMsg) ? "ERROR" : "OK");
|
||||
@@ -306,7 +243,7 @@
|
||||
enableSnippets: true,
|
||||
enableLiveAutocompletion: true,
|
||||
minLines: minLines,
|
||||
maxLines: 40,
|
||||
maxLines: 5
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div slot="header" class="clearfix">
|
||||
表信息
|
||||
<span style="float: right;margin-top: -5px;">
|
||||
<el-button class="search-submit" size="small" type="primary" icon="el-icon-search" @click="previewTableData">表数据预览</el-button>
|
||||
<el-button class="search-submit" size="small" type="primary" icon="el-icon-search" @click="previewTableData">查看表数据</el-button>
|
||||
</span>
|
||||
</div>
|
||||
<el-row class="status-info-row">
|
||||
|
||||
Reference in New Issue
Block a user