执行器库表信息查询修改,展示优化,增加快捷键执行

This commit is contained in:
暮光:城中城
2019-09-02 22:47:24 +08:00
parent 9c29f4c8fd
commit abc24b424f
15 changed files with 255 additions and 186 deletions

View File

@@ -1,9 +1,10 @@
package com.zyplayer.doc.data.repository.manage.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
@@ -23,6 +24,11 @@ public class DbFavorite implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 数据源ID
*/
private Long datasourceId;
/**
* 收藏标题
*/
@@ -115,4 +121,12 @@ public class DbFavorite implements Serializable {
", yn=" + yn +
"}";
}
public Long getDatasourceId() {
return datasourceId;
}
public void setDatasourceId(Long datasourceId) {
this.datasourceId = datasourceId;
}
}

View File

@@ -27,6 +27,7 @@ import com.zyplayer.doc.db.framework.db.dto.*;
import com.zyplayer.doc.db.framework.db.mapper.base.BaseMapper;
import com.zyplayer.doc.db.framework.db.mapper.mysql.MysqlMapper;
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.mybatis.spring.SqlSessionTemplate;
@@ -89,6 +90,7 @@ public class DatabaseDocController {
/**
* 获取编辑器所需的所有信息,用于自动补全
* 此接口会返回所有库表结构,介意的话请自己手动屏蔽调此接口
* @param sourceId
* @return
*/
@@ -109,21 +111,37 @@ public class DatabaseDocController {
List<DatabaseInfoDto> dbNameDtoList = baseMapper.getDatabaseList();
Map<String, List<TableInfoDto>> dbTableMap = new HashMap<>();
Map<String, List<TableColumnDescDto>> tableColumnsMap = new HashMap<>();
Map<String, List<TableInfoDto>> tableMapList = new HashMap<>();
// MYSQL可以一次性查询所有库表
if (databaseFactoryBean.getDatabaseProduct() == DatabaseProduct.MYSQL) {
List<TableInfoDto> dbTableList = baseMapper.getTableList(null);
tableMapList = dbTableList.stream().collect(Collectors.groupingBy(TableInfoDto::getDbName));
}
for (DatabaseInfoDto infoDto : dbNameDtoList) {
List<TableInfoDto> dbTableList = baseMapper.getTableList(infoDto.getDbName());
dbTableMap.put(infoDto.getDbName(), dbTableList);
for (TableInfoDto tableInfoDto : dbTableList) {
TableColumnVo tableColumnVo = this.getTableColumnVo(databaseFactoryBean, infoDto.getDbName(), tableInfoDto.getTableName());
// 重新组装一下,只返回两个字段,减少返回数据量
List<TableColumnDescDto> descDtoList = tableColumnVo.getColumnList().stream().map(val -> {
TableColumnDescDto dto = new TableColumnDescDto();
dto.setName(val.getName());
dto.setDescription(val.getDescription());
return dto;
}).collect(Collectors.toList());
List<TableInfoDto> tableInfoDtoList = tableMapList.get(infoDto.getDbName());
// SQLSERVER必须要库才能查
if (databaseFactoryBean.getDatabaseProduct() == DatabaseProduct.SQLSERVER) {
tableInfoDtoList = baseMapper.getTableList(infoDto.getDbName());
}
if (CollectionUtils.isEmpty(tableInfoDtoList)) {
continue;
}
dbTableMap.put(infoDto.getDbName(), tableInfoDtoList);
// 小于10个库查所有库否则只查询当前链接的库防止库表太多数据量太大
// 如果觉得没必要就自己改吧!
Map<String, List<TableColumnDescDto>> columnDescDtoMap = new HashMap<>();
if (dbNameDtoList.size() <= 10 || Objects.equals(databaseFactoryBean.getDbName(), infoDto.getDbName())) {
List<TableColumnDescDto> columnDescDto = baseMapper.getTableColumnList(infoDto.getDbName(), null);
columnDescDtoMap = columnDescDto.stream().collect(Collectors.groupingBy(TableColumnDescDto::getTableName));
}
for (TableInfoDto tableInfoDto : tableInfoDtoList) {
List<TableColumnDescDto> descDtoList = columnDescDtoMap.get(tableInfoDto.getTableName());
if (CollectionUtils.isNotEmpty(descDtoList)) {
tableColumnsMap.put(tableInfoDto.getTableName(), descDtoList);
}
}
}
Map<String, Object> dbResultMap = new HashMap<>();
dbResultMap.put("db", dbNameDtoList);
dbResultMap.put("table", dbTableMap);
@@ -177,9 +195,9 @@ public class DatabaseDocController {
}
@PostMapping(value = "/getTableDescList")
public ResponseJson getTableDescList(Long sourceId, String tableName) {
public ResponseJson getTableDescList(Long sourceId, String dbName, String tableName) {
BaseMapper baseMapper = this.getViewAuthBaseMapper(sourceId);
List<TableDescDto> columnDescDto = baseMapper.getTableDescList(tableName);
List<TableDescDto> columnDescDto = baseMapper.getTableDescList(dbName, tableName);
return DocDbResponseJson.ok(columnDescDto);
}
@@ -274,7 +292,7 @@ public class DatabaseDocController {
tableColumnVo.setColumnList(columnDescDto);
// 表注释
TableInfoVo tableInfoVo = new TableInfoVo();
List<TableDescDto> tableDescList = baseMapper.getTableDescList(tableName);
List<TableDescDto> tableDescList = baseMapper.getTableDescList(dbName, tableName);
String description = null;
if (tableDescList.size() > 0) {
TableDescDto descDto = tableDescList.get(0);

View File

@@ -58,6 +58,8 @@ public class DbSqlExecutorController {
if (!manageAuth && !select && !update) {
return DocDbResponseJson.warn("没有该数据源的执行权限");
}
// 保留历史记录
dbHistoryService.saveHistory(sql.trim(), sourceId);
List<String> resultList = new LinkedList<>();
// 支持;分割的多个sql执行
String[] sqlArr = sql.split(";");
@@ -99,9 +101,10 @@ public class DbSqlExecutorController {
}
@PostMapping(value = "/favorite/list")
public ResponseJson favoriteList() {
public ResponseJson favoriteList(Long sourceId) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
UpdateWrapper<DbFavorite> wrapper = new UpdateWrapper<>();
wrapper.eq(sourceId != null, "datasource_id", sourceId);
wrapper.eq("create_user_id", currentUser.getUserId());
wrapper.eq("yn", 1);
wrapper.orderByDesc("id");
@@ -112,9 +115,12 @@ public class DbSqlExecutorController {
@PostMapping(value = "/favorite/add")
public ResponseJson addFavorite(DbFavorite dbFavorite) {
Integer yn = Optional.ofNullable(dbFavorite.getYn()).orElse(1);
if (yn == 1 && StringUtils.isBlank(dbFavorite.getContent())) {
if (yn == 1) {
if (StringUtils.isBlank(dbFavorite.getContent())) {
return DocDbResponseJson.warn("收藏的SQL不能为空");
}
dbFavorite.setContent(dbFavorite.getContent().trim());
}
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
if (dbFavorite.getId() != null && dbFavorite.getId() > 0) {
dbFavoriteService.updateById(dbFavorite);

View File

@@ -1,6 +1,7 @@
package com.zyplayer.doc.db.framework.db.dto;
public class TableColumnDescDto {
private String tableName;
private String name;
private String isidenity;
private String type;
@@ -65,4 +66,11 @@ public class TableColumnDescDto {
this.description = description;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
}

View File

@@ -1,6 +1,7 @@
package com.zyplayer.doc.db.framework.db.dto;
public class TableInfoDto {
private String dbName;
private String tableName;
private String tableComment;
private String tableId;
@@ -29,4 +30,11 @@ public class TableInfoDto {
this.tableComment = tableComment;
}
public String getDbName() {
return dbName;
}
public void setDbName(String dbName) {
this.dbName = dbName;
}
}

View File

@@ -65,7 +65,7 @@ public interface BaseMapper {
* @param tableName 可不传,传了只查询指定表的注释
* @return 表注释
*/
List<TableDescDto> getTableDescList(@Param("tableName") String tableName);
List<TableDescDto> getTableDescList(@Param("dbName") String dbName, @Param("tableName") String tableName);
/**
* 增加表注释

View File

@@ -18,7 +18,7 @@ public class ExecuteResult {
private List<Map<String, Object>> result;
public ExecuteResult() {
this.updateCount = 0;
this.updateCount = -1;
this.useTime = 0;
this.result = Collections.emptyList();
}

View File

@@ -5,11 +5,9 @@ import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.zyplayer.doc.data.service.manage.DbHistoryService;
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
import com.zyplayer.doc.db.framework.db.bean.DatabaseRegistrationBean;
import com.zyplayer.doc.db.framework.db.interceptor.SqlLogUtil;
import org.apache.ibatis.builder.SqlSourceBuilder;
import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.parsing.GenericTokenParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,30 +70,28 @@ public class SqlExecutor {
* @author 暮光:城中城
* @since 2019年8月18日
*/
public ExecuteResult execute(DatabaseFactoryBean factoryBean, String executeId, ExecuteType executeType, String sql, Map<String, Object> paramMap, ResultHandler handler) {
public ExecuteResult execute(DatabaseFactoryBean factoryBean, String executeId, ExecuteType executeType, String sqlStr, Map<String, Object> paramMap, ResultHandler handler) {
if (factoryBean == null) {
return new ExecuteResult();
}
BoundSql boundSql = getBoundSql(sql, paramMap);
sql = boundSql.getSql();
String sqlStr = SqlLogUtil.getSqlString(paramMap, boundSql);
// BoundSql boundSql = getBoundSql(sql, paramMap);
// sql = boundSql.getSql();
// String sqlStr = SqlLogUtil.getSqlString(paramMap, boundSql);
logger.info("sql ==> {}", sqlStr);
// 保留历史记录
dbHistoryService.saveHistory(sqlStr, factoryBean.getId());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
// List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
PreparedStatement preparedStatement = null;
DruidPooledConnection connection = null;
// 执行查询
try {
long startTime = System.currentTimeMillis();
connection = factoryBean.getDataSource().getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement = connection.prepareStatement(sqlStr);
// 设置当前的PreparedStatement
statementMap.put(executeId, preparedStatement);
for (int i = 0; i < parameterMappings.size(); i++) {
preparedStatement.setObject(i + 1, paramMap.get(parameterMappings.get(i).getProperty()));
}
// for (int i = 0; i < parameterMappings.size(); i++) {
// preparedStatement.setObject(i + 1, paramMap.get(parameterMappings.get(i).getProperty()));
// }
// 限制下最大数量
preparedStatement.setMaxRows(1000);
if (ExecuteType.SELECT.equals(executeType)) {
@@ -120,11 +116,10 @@ public class SqlExecutor {
}
}
}
// 更新的数量
// 更新的数量小于0代表不是更新语句
int updateCount = preparedStatement.getUpdateCount();
updateCount = (updateCount < 0) ? 0 : updateCount;
long useTime = System.currentTimeMillis() - startTime;
return new ExecuteResult(updateCount, resultList, useTime, sql);
return new ExecuteResult(updateCount, resultList, useTime, sqlStr);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {

View File

@@ -3,6 +3,7 @@
<mapper namespace="com.zyplayer.doc.db.framework.db.mapper.base.BaseMapper">
<resultMap id="TableColumnDescDtoMap" type="com.zyplayer.doc.db.framework.db.dto.TableColumnDescDto" >
<result column="TABLE_NAME" property="tableName" jdbcType="VARCHAR" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
<result column="ISIDENITY" property="isidenity" jdbcType="VARCHAR" />
<result column="TYPE" property="type" jdbcType="VARCHAR" />
@@ -25,15 +26,16 @@
</select>
<select id="getTableList" resultType="com.zyplayer.doc.db.framework.db.dto.TableInfoDto">
select table_name tableName, table_comment as tableComment
select table_schema dbName,table_name tableName, table_comment as tableComment
from information_schema.tables
where table_schema=#{dbName}
<if test="dbName != null">where table_schema=#{dbName}</if>
</select>
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
SELECT COLUMN_NAME NAME,column_comment DESCRIPTION,column_type TYPE,if(is_nullable='YES',1,0) NULLABLE
SELECT table_name as TABLE_NAME,COLUMN_NAME NAME,column_comment DESCRIPTION,column_type TYPE,if(is_nullable='YES',1,0) NULLABLE
FROM INFORMATION_SCHEMA.Columns
WHERE table_schema=#{dbName} AND table_name=#{tableName}
WHERE table_schema=#{dbName}
<if test="tableName != null">and table_name=#{tableName}</if>
ORDER BY ordinal_position
</select>
@@ -50,9 +52,10 @@
<select id="getTableDescList" resultType="com.zyplayer.doc.db.framework.db.dto.TableDescDto">
select table_name tableName, table_comment as description
from information_schema.tables
<if test="tableName != null">
where table_name=#{tableName}
</if>
<where>
<if test="dbName != null">and table_schema=#{dbName}</if>
<if test="tableName != null">and table_name=#{tableName}</if>
</where>
</select>
<insert id="updateTableDesc">

File diff suppressed because one or more lines are too long

View File

@@ -1,2 +1,2 @@
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"d0fd867e51634f6a3bdb",1:"0a0403eb1820498dc9bc"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
//# sourceMappingURL=doc-db-manifest.js.map?2fb9e03777eaeb893be9
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"80bc97c8e1f56e403c39",1:"0a0403eb1820498dc9bc"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
//# sourceMappingURL=doc-db-manifest.js.map?42eca50901b3d81e2837

View File

@@ -8,7 +8,7 @@
<body>
<div id="app"></div>
<script type="text/javascript" src="doc-db-manifest.js?2fb9e03777eaeb893be9"></script><script type="text/javascript" src="doc-db-vendor.js?0a0403eb1820498dc9bc"></script><script type="text/javascript" src="doc-db-index.js?d0fd867e51634f6a3bdb"></script></body>
<script type="text/javascript" src="doc-db-manifest.js?42eca50901b3d81e2837"></script><script type="text/javascript" src="doc-db-vendor.js?0a0403eb1820498dc9bc"></script><script type="text/javascript" src="doc-db-index.js?80bc97c8e1f56e403c39"></script></body>
</html>

View File

@@ -9,6 +9,7 @@
CREATE TABLE `db_favorite` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
`datasource_id` bigint(20) NULL COMMENT '数据源ID',
`name` varchar(50) DEFAULT NULL COMMENT '收藏标题',
`content` varchar(10000) DEFAULT NULL COMMENT '收藏内容',
`create_user_id` bigint(20) DEFAULT NULL COMMENT '创建人ID',
@@ -39,6 +40,7 @@ INSERT INTO `auth_info`(`auth_name`, `auth_desc`, `can_edit`, `create_uid`, `cre
VALUES ( 'DB_DESC_EDIT_', '表字段注释修改权', 0, 1, '2019-08-18 23:25:17', 0);
-- ALTER TABLE `db_history` ADD COLUMN `datasource_id` bigint(0) NULL COMMENT '数据源ID';
-- ALTER TABLE `db_favorite` ADD COLUMN `datasource_id` bigint(0) NULL COMMENT '数据源ID';
-- ------------------------全新的库:------------------------

View File

@@ -147,6 +147,10 @@
},
handleNodeClick(node) {
console.log("点击节点:", node);
// 执行器里面点击库表不跳转页面
// if (this.$router.currentRoute.path == "/data/executor") {
// return;
// }
if (node.type == 1) {
this.nowClickPath = {sourceId: this.choiceDatasourceId, host: node.host, dbName: node.dbName, tableName: node.tableName};
this.$router.push({path: '/table/database', query: this.nowClickPath});
@@ -217,7 +221,7 @@
if (app.databaseList.length > 0) {
return;
}
this.choiceDatasourceId = sourceId;
this.choiceDatasourceId = parseInt(sourceId);
this.loadDatabaseList(sourceId, host, function () {
app.databaseExpandedKeys = [host];
});

View File

@@ -13,10 +13,10 @@
<pre id="sqlExecutorEditor" style="width: 100%;height: 500px;"></pre>
<div>
<el-button v-if="sqlExecuting" v-on:click="cancelExecutorSql" type="primary" plain size="small" icon="el-icon-video-pause">取消执行</el-button>
<el-button v-else v-on:click="doExecutorSql" type="primary" plain size="small" icon="el-icon-video-play">执行</el-button>
<el-tooltip v-else effect="dark" content="Ctrl+R、Ctrl+Enter" placement="top">
<el-button v-on:click="doExecutorSql" type="primary" plain size="small" icon="el-icon-video-play">执行</el-button>
</el-tooltip>
<div style="float: right;">
<span v-if="!!executeUpdateCount" class="execute-use-time">影响行数{{executeUpdateCount}}</span>
<span v-if="!!executeUseTime" class="execute-use-time">查询时间{{executeUseTime/1000}}s</span>
<el-button v-on:click="addFavorite('')" plain size="small" icon="el-icon-star-off">收藏</el-button>
<el-button v-on:click="loadHistoryAndFavoriteList" plain size="small" icon="el-icon-tickets">收藏及历史</el-button>
</div>
@@ -26,11 +26,11 @@
<div v-if="!!executeError" style="color: #f00;">{{executeError}}</div>
<div v-else-if="executeResultList.length <= 0" v-loading="sqlExecuting">暂无数据</div>
<div v-else>
<el-tabs value="table1">
<el-tabs :value="executeShowTable">
<el-tab-pane label="信息" name="table0">
<pre type="textarea" :rows="10" readonly v1-model="">{{executeResultInfo}}</pre>
<pre>{{executeResultInfo}}</pre>
</el-tab-pane>
<el-tab-pane :label="'结果'+(index+1)" :name="'table'+(index+1)" v-for="(resultItem, index) in executeResultList">
<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>
<el-table v-else :data="resultItem.dataList" stripe border style="width: 100%; margin-bottom: 5px;" class="execute-result-table" max-height="600">
<el-table-column width="60px" v-if="resultItem.dataCols.length > 0">
@@ -52,9 +52,11 @@
<el-tabs value="favorite">
<el-tab-pane label="我的收藏" name="favorite">
<el-table :data="myFavoriteList" stripe border style="width: 100%; margin-bottom: 5px;" v-infinite-scroll>
<!-- <el-table-column prop="name" label="标题"></el-table-column>-->
<el-table-column prop="content" label="SQL"></el-table-column>
<!-- <el-table-column prop="createTime" label="收藏时间" width="160px"></el-table-column>-->
<el-table-column prop="content" label="SQL">
<template slot-scope="scope">
<pre style="margin: 0;">{{scope.row.content}}</pre>
</template>
</el-table-column>
<el-table-column label="操作" width="150px">
<template slot-scope="scope">
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row.content)">输入</el-button>
@@ -102,8 +104,7 @@
sqlExecuting: false,
executeResultList: [],
executeResultInfo: "",
executeUseTime: 0,
executeUpdateCount: 0,
executeShowTable: "table1",
sqlExecutorEditor: {},
nowExecutorId: 1,
executeError: "",
@@ -119,6 +120,13 @@
// 下面两行先后顺序不能改
this.addEditorCompleter();
app.sqlExecutorEditor = app.initAceEditor("sqlExecutorEditor", 15);
app.sqlExecutorEditor.commands.addCommand({
name: "execute-sql",
bindKey: {win: "Ctrl-R|Ctrl-Shift-R|Ctrl-Enter", mac: "Command-R|Command-Shift-R|Command-Enter"},
exec: function (editor) {
app.doExecutorSql();
}
});
},
methods: {
initAceEditor(editor, minLines) {
@@ -145,7 +153,7 @@
this.loadFavoriteList();
},
loadFavoriteList() {
this.common.post(this.apilist1.favoriteList, {}, function (json) {
this.common.post(this.apilist1.favoriteList, {sourceId: this.choiceDatasourceId}, function (json) {
app.myFavoriteList = json.data || [];
});
},
@@ -161,7 +169,7 @@
sqlValue = this.sqlExecutorEditor.getValue();
}
}
var param = {name: '我的收藏', content: sqlValue};
var param = {name: '我的收藏', content: sqlValue, datasourceId: this.choiceDatasourceId};
this.common.post(this.apilist1.updateFavorite, param, function (json) {
app.$message.success("收藏成功");
app.loadFavoriteList();
@@ -206,19 +214,19 @@
}
var resultList = json.data || [];
var executeResultList = [];
var executeUpdateCount = 0, executeUseTime = 0;
var executeResultInfo = "";
var executeResultInfo = "", itemIndex = 1;
for (var i = 0; i < resultList.length; i++) {
var objItem = JSON.parse(resultList[i]);
executeUpdateCount += (objItem.updateCount || 0);
executeUseTime += (objItem.useTime || 0);
executeResultInfo += app.getExecuteInfoStr(objItem);
var resultItem = app.dealExecuteResult(objItem);
if (resultItem.updateCount < 0) {
resultItem.index = itemIndex;
itemIndex++;
}
executeResultList.push(resultItem);
}
app.executeShowTable = (itemIndex === 1) ? "table0" : "table1";
app.executeResultInfo = executeResultInfo;
app.executeUseTime = executeUseTime;
app.executeUpdateCount = executeUpdateCount;
app.executeResultList = executeResultList;
});
},
@@ -250,8 +258,11 @@
},
getExecuteInfoStr(resultData) {
var resultStr = resultData.sql;
resultStr += "\n> " + ((!!resultData.errMsg) ? "ERROR" : "OK");
resultStr += "\n> " + (resultData.useTime || 0) / 1000 + "s";
resultStr += "\n> 状态:" + ((!!resultData.errMsg) ? "ERROR" : "OK");
if (resultData.updateCount >= 0) {
resultStr += "\n> 影响行数:" + resultData.updateCount;
}
resultStr += "\n> 耗时:" + (resultData.useTime || 0) / 1000 + "s";
resultStr += "\n\n";
return resultStr;
},
@@ -280,7 +291,7 @@
resultObj.dataCols = executeResultCols;
resultObj.useTime = resultData.useTime || 0;
resultObj.errMsg = resultData.errMsg || "";
resultObj.updateCount = resultData.updateCount || 0;
resultObj.updateCount = resultData.updateCount;
return resultObj;
},
addEditorCompleter() {