修改SQL执行逻辑,解决一个sql中字段名重复取值混乱问题,优化SQL编辑器
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package com.zyplayer.doc.db.controller;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbFavorite;
|
||||
@@ -14,10 +18,7 @@ import com.zyplayer.doc.data.repository.support.consts.DocSysType;
|
||||
import com.zyplayer.doc.data.service.manage.DbFavoriteService;
|
||||
import com.zyplayer.doc.data.service.manage.DbHistoryService;
|
||||
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.db.mapper.base.*;
|
||||
import com.zyplayer.doc.db.framework.db.transfer.SqlParseUtil;
|
||||
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
|
||||
import com.zyplayer.doc.db.framework.utils.JSONUtil;
|
||||
@@ -47,7 +48,7 @@ public class DbSqlExecutorController {
|
||||
private static Logger logger = LoggerFactory.getLogger(DbSqlExecutorController.class);
|
||||
|
||||
@Resource
|
||||
SqlExecutor sqlExecutor;
|
||||
ColumnSqlExecutor columnSqlExecutor;
|
||||
@Resource
|
||||
DbHistoryService dbHistoryService;
|
||||
@Resource
|
||||
@@ -72,44 +73,44 @@ public class DbSqlExecutorController {
|
||||
dbHistoryService.saveHistory(sql.trim(), params, sourceId);
|
||||
// 参数处理
|
||||
Map<String, Object> paramMap = JSON.parseObject(params);
|
||||
List<String> resultList = new LinkedList<>();
|
||||
// 支持;分割的多个sql执行
|
||||
String[] sqlArr = sql.split(";");
|
||||
// 解析出多个执行的SQL
|
||||
List<String> analysisQuerySqlList = new LinkedList<>();
|
||||
try {
|
||||
List<SQLStatement> sqlStatements = new MySqlStatementParser(sql).parseStatementList();
|
||||
for (SQLStatement sqlStatement : sqlStatements) {
|
||||
analysisQuerySqlList.add(sqlStatement.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return DocDbResponseJson.warn("SQL解析失败:" + e.getMessage());
|
||||
}
|
||||
// 执行条数太多,反应慢,展示结果栏太多,也不应该在这一次执行很多条语句,应该使用导入
|
||||
if (sqlArr.length > 20) {
|
||||
return DocDbResponseJson.warn("单次执行最多支持20条语句同时执行,当前语句条数:" + sqlArr.length);
|
||||
if (analysisQuerySqlList.size() > 20) {
|
||||
return DocDbResponseJson.warn("单次执行最多支持20条语句同时执行,当前语句条数:" + analysisQuerySqlList.size());
|
||||
}
|
||||
for (String sqlItem : sqlArr) {
|
||||
if (StringUtils.isBlank(sqlItem)) {
|
||||
continue;
|
||||
}
|
||||
sqlItem = sqlItem.trim();
|
||||
ExecuteResult executeResult;
|
||||
ExecuteParam executeParam = new ExecuteParam();
|
||||
List<ColumnExecuteResult> resultList = new LinkedList<>();
|
||||
for (String singleSql : analysisQuerySqlList) {
|
||||
ColumnExecuteResult executeResult;
|
||||
try {
|
||||
ExecuteType executeType = (manageAuth || update) ? ExecuteType.ALL : ExecuteType.SELECT;
|
||||
executeParam = SqlParseUtil.getSingleExecuteParam(sqlItem, paramMap);
|
||||
ExecuteParam executeParam = SqlParseUtil.getSingleExecuteParam(singleSql, paramMap);
|
||||
executeParam.setDatasourceId(sourceId);
|
||||
executeParam.setExecuteId(executeId);
|
||||
executeParam.setExecuteType(executeType);
|
||||
executeParam.setPrefixSql(useDbSql);
|
||||
executeParam.setMaxRows(1000);
|
||||
executeResult = sqlExecutor.execute(executeParam);
|
||||
executeResult = columnSqlExecutor.execute(executeParam);
|
||||
} catch (Exception e) {
|
||||
logger.error("执行出错", e);
|
||||
executeResult = ExecuteResult.error(e.getMessage(), sqlItem);
|
||||
executeResult = ColumnExecuteResult.error(singleSql, e.getMessage(), e);
|
||||
}
|
||||
// 执行的sql处理
|
||||
String executeSqlLog = SqlLogUtil.parseLogSql(executeParam.getSql(), executeParam.getParameterMappings(), executeParam.getParamList());
|
||||
executeResult.setSql(executeSqlLog);
|
||||
resultList.add(JSON.toJSONString(executeResult, JSONUtil.serializeConfig, SerializerFeature.WriteMapNullValue));
|
||||
resultList.add(executeResult);
|
||||
}
|
||||
return DocDbResponseJson.ok(resultList);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/cancel")
|
||||
public DocDbResponseJson cancel(String executeId) {
|
||||
sqlExecutor.cancel(executeId);
|
||||
columnSqlExecutor.cancel(executeId);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.zyplayer.doc.db.framework.db.mapper.base;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SQL执行结果对象
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-08-19
|
||||
*/
|
||||
@Data
|
||||
public class ColumnExecuteResult {
|
||||
private Long queryTime;
|
||||
private Integer errCode;
|
||||
private String errMsg;
|
||||
private Exception exception;
|
||||
private String executeSql;
|
||||
private Integer updateCount;
|
||||
// 查询结果表头
|
||||
private List<String> header;
|
||||
// 查询结果数据
|
||||
private List<List<Object>> data;
|
||||
|
||||
public ColumnExecuteResult() {
|
||||
this.updateCount = 0;
|
||||
}
|
||||
|
||||
public static ColumnExecuteResult ok(String sql) {
|
||||
ColumnExecuteResult result = new ColumnExecuteResult();
|
||||
result.setExecuteSql(sql);
|
||||
result.setErrCode(ExecuteResultCode.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ColumnExecuteResult warn(String sql, String errMsg) {
|
||||
ColumnExecuteResult result = new ColumnExecuteResult();
|
||||
result.setExecuteSql(sql);
|
||||
result.setErrMsg(errMsg);
|
||||
result.setErrCode(ExecuteResultCode.WARN);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ColumnExecuteResult error(String sql, String errMsg, Exception e) {
|
||||
ColumnExecuteResult result = new ColumnExecuteResult();
|
||||
result.setExecuteSql(sql);
|
||||
result.setErrMsg(errMsg);
|
||||
result.setException(e);
|
||||
result.setErrCode(ExecuteResultCode.ERROR);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static class ExecuteResultCode {
|
||||
public static Integer SUCCESS = 0;
|
||||
public static Integer WARN = -1;
|
||||
public static Integer ERROR = -2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断错误并抛出异常
|
||||
*/
|
||||
public ColumnExecuteResult judgeAndThrow() {
|
||||
if (ExecuteResultCode.SUCCESS.equals(errCode)) {
|
||||
return this;
|
||||
}
|
||||
if (ExecuteResultCode.WARN.equals(errCode)) {
|
||||
throw new RuntimeException(errMsg);
|
||||
}
|
||||
if (ExecuteResultCode.ERROR.equals(errCode)) {
|
||||
if (exception != null) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
throw new RuntimeException(errMsg);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package com.zyplayer.doc.db.framework.db.mapper.base;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
|
||||
import com.zyplayer.doc.db.framework.db.bean.DatabaseRegistrationBean;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.mapping.ParameterMapping;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 新版的SQL执行类,返回结果有比较大的差异,为了兼容之前的代码就不在原有基础上修改
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2023-02-12
|
||||
*/
|
||||
@Repository
|
||||
public class ColumnSqlExecutor {
|
||||
private static Logger logger = LoggerFactory.getLogger(SqlExecutor.class);
|
||||
|
||||
@Resource
|
||||
DatabaseRegistrationBean databaseRegistrationBean;
|
||||
|
||||
// 执行中的PreparedStatement信息,用于强制取消执行
|
||||
private static final Map<String, PreparedStatement> statementMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 取消执行
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年8月18日
|
||||
*/
|
||||
public boolean cancel(String executeId) {
|
||||
PreparedStatement preparedStatement = statementMap.remove(executeId);
|
||||
try {
|
||||
if (preparedStatement != null) {
|
||||
preparedStatement.cancel();
|
||||
return true;
|
||||
}
|
||||
logger.error("未找到指定任务,取消执行失败:{}", executeId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql,返回结果
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年8月18日
|
||||
*/
|
||||
public ColumnExecuteResult execute(ExecuteParam param) {
|
||||
DatabaseFactoryBean factoryBean = databaseRegistrationBean.getOrCreateFactoryById(param.getDatasourceId());
|
||||
return this.execute(factoryBean, param, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql,返回结果
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年8月18日
|
||||
*/
|
||||
public ColumnExecuteResult execute(ExecuteParam param, ResultHandler handler) {
|
||||
DatabaseFactoryBean factoryBean = databaseRegistrationBean.getOrCreateFactoryById(param.getDatasourceId());
|
||||
return this.execute(factoryBean, param, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql,可通过handler回调每一行的结果
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年8月18日
|
||||
*/
|
||||
public ColumnExecuteResult execute(DatabaseFactoryBean factoryBean, ExecuteParam executeParam, ResultHandler handler) {
|
||||
// 有参数的时候不输出日志,暂时只有导数据才有参数
|
||||
if (CollectionUtils.isEmpty(executeParam.getParamList())) {
|
||||
if (StringUtils.isNotBlank(executeParam.getPrefixSql())) {
|
||||
logger.info("prefix sql ==> {}", executeParam.getPrefixSql());
|
||||
}
|
||||
logger.info("sql ==> {}", executeParam.getSql());
|
||||
}
|
||||
if (factoryBean == null) {
|
||||
return ColumnExecuteResult.error(executeParam.getSql(), "未找到数据库连接", null);
|
||||
}
|
||||
long startExecuteTime = System.currentTimeMillis();
|
||||
ColumnExecuteResult executeResult = ColumnExecuteResult.ok(executeParam.getSql());
|
||||
PreparedStatement preparedStatement = null;
|
||||
PreparedStatement prefixStatement = null;
|
||||
DruidPooledConnection connection = null;
|
||||
ResultSet resultSet = null;
|
||||
// 执行查询
|
||||
try {
|
||||
connection = factoryBean.getDataSource().getConnection();
|
||||
if (StringUtils.isNotBlank(executeParam.getPrefixSql())) {
|
||||
prefixStatement = connection.prepareStatement(executeParam.getPrefixSql());
|
||||
prefixStatement.execute();
|
||||
}
|
||||
preparedStatement = connection.prepareStatement(executeParam.getSql());
|
||||
// 设置当前的PreparedStatement
|
||||
statementMap.put(executeParam.getExecuteId(), preparedStatement);
|
||||
List<ParameterMapping> parameterMappings = executeParam.getParameterMappings();
|
||||
List<Object> paramDataList = executeParam.getParamList();
|
||||
if (parameterMappings.size() > 0 && paramDataList.size() > 0) {
|
||||
int parameterCount = 99999;
|
||||
try {
|
||||
parameterCount = preparedStatement.getParameterMetaData().getParameterCount();
|
||||
} catch (Exception e) {
|
||||
logger.info("不支持获取总数:" + e.getMessage());
|
||||
}
|
||||
for (int paramIndex = 0; paramIndex < parameterMappings.size() && paramIndex < parameterCount; paramIndex++) {
|
||||
preparedStatement.setObject(paramIndex + 1, paramDataList.get(paramIndex));
|
||||
}
|
||||
}
|
||||
// 最大限制1分钟
|
||||
preparedStatement.setQueryTimeout(60);
|
||||
// 限制下最大数量
|
||||
if (executeParam.getMaxRows() != null) {
|
||||
preparedStatement.setMaxRows(executeParam.getMaxRows());
|
||||
}
|
||||
if (ExecuteType.SELECT.equals(executeParam.getExecuteType())) {
|
||||
preparedStatement.executeQuery();
|
||||
} else {
|
||||
preparedStatement.execute();
|
||||
}
|
||||
// 查询的结果集
|
||||
resultSet = preparedStatement.getResultSet();
|
||||
List<String> headerList = new LinkedList<>();
|
||||
List<List<Object>> dataList = new LinkedList<>();
|
||||
if (resultSet != null) {
|
||||
int columnCount = resultSet.getMetaData().getColumnCount();
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
headerList.add(resultSet.getMetaData().getColumnLabel(i + 1));
|
||||
}
|
||||
while (resultSet.next()) {
|
||||
List<Object> tempList = new LinkedList<>();
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
tempList.add(resultSet.getObject(i + 1));
|
||||
}
|
||||
dataList.add(tempList);
|
||||
}
|
||||
}
|
||||
// 更新的数量
|
||||
executeResult.setData(dataList);
|
||||
executeResult.setHeader(headerList);
|
||||
executeResult.setUpdateCount(Math.max(preparedStatement.getUpdateCount(), 0));
|
||||
} catch (Exception e) {
|
||||
logger.error("执行出错", e);
|
||||
executeResult.setException(e);
|
||||
executeResult.setErrMsg(e.getMessage());
|
||||
executeResult.setErrCode(ColumnExecuteResult.ExecuteResultCode.ERROR);
|
||||
} finally {
|
||||
statementMap.remove(executeParam.getExecuteId());
|
||||
IoUtil.close(resultSet);
|
||||
IoUtil.close(prefixStatement);
|
||||
IoUtil.close(preparedStatement);
|
||||
IoUtil.close(connection);
|
||||
}
|
||||
executeResult.setQueryTime(System.currentTimeMillis() - startExecuteTime);
|
||||
return executeResult;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zyplayer.doc.db.framework.db.mapper.base;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
|
||||
import com.zyplayer.doc.db.framework.db.bean.DatabaseRegistrationBean;
|
||||
@@ -98,6 +99,7 @@ public class SqlExecutor {
|
||||
PreparedStatement preparedStatement = null;
|
||||
PreparedStatement prefixStatement = null;
|
||||
DruidPooledConnection connection = null;
|
||||
ResultSet resultSet = null;
|
||||
// 执行查询
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
@@ -128,7 +130,7 @@ public class SqlExecutor {
|
||||
preparedStatement.execute();
|
||||
}
|
||||
// 查询的结果集
|
||||
ResultSet resultSet = preparedStatement.getResultSet();
|
||||
resultSet = preparedStatement.getResultSet();
|
||||
List<Map<String, Object>> resultList = new LinkedList<>();
|
||||
if (resultSet != null) {
|
||||
while (resultSet.next()) {
|
||||
@@ -153,27 +155,10 @@ public class SqlExecutor {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
statementMap.remove(executeParam.getExecuteId());
|
||||
try {
|
||||
if (prefixStatement != null && !prefixStatement.isClosed()) {
|
||||
prefixStatement.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("关闭Statement失败");
|
||||
}
|
||||
try {
|
||||
if (preparedStatement != null && !preparedStatement.isClosed()) {
|
||||
preparedStatement.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("关闭Statement失败");
|
||||
}
|
||||
try {
|
||||
if (connection != null && !connection.isClosed()) {
|
||||
connection.recycle();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("回收connection失败");
|
||||
}
|
||||
IoUtil.close(resultSet);
|
||||
IoUtil.close(prefixStatement);
|
||||
IoUtil.close(preparedStatement);
|
||||
IoUtil.close(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,10 +242,12 @@ public class UserInfoController {
|
||||
userAuth.setDelFlag(0);
|
||||
createList.add(userAuth);
|
||||
}
|
||||
}
|
||||
userAuthService.saveBatch(createList);
|
||||
for (Long userId : userIdsList) {
|
||||
List<UserAuthInfo> userAuthListNew = userAuthService.getUserAuthSet(userId);
|
||||
DocUserUtil.setUserAuth(userId, userAuthListNew);
|
||||
}
|
||||
userAuthService.saveBatch(createList);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
|
||||
14066
zyplayer-doc-ui/db-ui/package-lock.json
generated
14066
zyplayer-doc-ui/db-ui/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,30 +2,20 @@
|
||||
<div class="data-executor-vue">
|
||||
<div style="padding: 0 10px 10px;height: 100%;box-sizing: border-box;">
|
||||
<el-card style="margin-bottom: 10px;">
|
||||
<ace-editor v-model="sqlExecutorContent" ref="sqlEditor" @init="sqlExecutorInit" lang="sql" theme="monokai"
|
||||
width="100%" height="500" :options="sqlEditorConfig" :source="executorSource"
|
||||
style="margin-bottom: 10px;">
|
||||
</ace-editor>
|
||||
<ace-editor v-model="sqlExecutorContent" ref="sqlEditor" @init="sqlExecutorInit" lang="sql" theme="monokai" width="100%" height="500" :options="sqlEditorConfig" :source="executorSource" style="margin-bottom: 10px;"></ace-editor>
|
||||
<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-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="doExecutorSql" type="primary" plain size="small" icon="el-icon-video-play">执行
|
||||
</el-button>
|
||||
<el-button v-on:click="doExecutorSql" 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 v-on:click="addFavorite('')" plain size="small" icon="el-icon-star-off">收藏</el-button>
|
||||
<div style="float: right;">
|
||||
<el-select v-model="choiceDatasourceId" @change="datasourceChangeEvents" size="small" filterable
|
||||
placeholder="请选择数据源" style="width: 300px;margin-left: 10px;">
|
||||
<el-option v-for="item in datasourceOptions" :key="item.id" :label="item.name"
|
||||
:value="item.id"></el-option>
|
||||
<el-select v-model="choiceDatasourceId" @change="datasourceChangeEvents" size="small" filterable placeholder="请选择数据源" style="width: 300px;margin-left: 10px;">
|
||||
<el-option v-for="item in datasourceOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
|
||||
</el-select>
|
||||
<el-select v-model="choiceDatabase" @change="databaseChangeEvents" size="small" filterable
|
||||
placeholder="请选择数据库" style="width: 200px;margin-left: 10px;">
|
||||
<el-option v-for="item in databaseList" :key="item.dbName" :label="item.dbName"
|
||||
:value="item.dbName"></el-option>
|
||||
<el-select v-model="choiceDatabase" @change="databaseChangeEvents" size="small" filterable placeholder="请选择数据库" style="width: 200px;margin-left: 10px;">
|
||||
<el-option v-for="item in databaseList" :key="item.dbName" :label="item.dbName" :value="item.dbName"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -39,8 +29,7 @@
|
||||
<div style="position: relative;">
|
||||
<div style="position: absolute;right: 0;z-index: 1;">
|
||||
<!-- 复制选中行 -->
|
||||
<el-dropdown @command="handleCopyCheckLineCommand"
|
||||
v-show="this.choiceResultObj[this.executeShowTable] && this.choiceResultObj[this.executeShowTable].length > 0">
|
||||
<el-dropdown @command="handleCopyCheckLineCommand" v-show="this.choiceResultObj[this.executeShowTable] && this.choiceResultObj[this.executeShowTable].length > 0">
|
||||
<el-button type="primary" size="small" icon="el-icon-document-copy">
|
||||
复制选中行<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</el-button>
|
||||
@@ -57,16 +46,13 @@
|
||||
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
|
||||
<el-table-column prop="content" label="SQL">
|
||||
<template slot-scope="scope">
|
||||
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row)"
|
||||
:title="scope.row.content">{{ scope.row.content }}</pre>
|
||||
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row)" :title="scope.row.content">{{ scope.row.content }}</pre>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="160px">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="primary" @click="inputFavoriteSql(scope.row)">输入</el-button>
|
||||
<el-button size="mini" type="success" @click="addFavorite(scope.row.content)"
|
||||
style="margin-left: 10px;">收藏
|
||||
</el-button>
|
||||
<el-button size="mini" type="success" @click="addFavorite(scope.row.content)" style="margin-left: 10px;">收藏</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -76,46 +62,35 @@
|
||||
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
|
||||
<el-table-column prop="content" label="SQL">
|
||||
<template slot-scope="scope">
|
||||
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row)"
|
||||
:title="scope.row.content">{{ scope.row.content }}</pre>
|
||||
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row)" :title="scope.row.content">{{ scope.row.content }}</pre>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="160px">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row)">输入</el-button>
|
||||
<el-button size="mini" type="danger" v-on:click="delFavorite(scope.row)" style="margin-left: 10px;">
|
||||
删除
|
||||
</el-button>
|
||||
<el-button size="mini" type="danger" v-on:click="delFavorite(scope.row)" style="margin-left: 10px;">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="信息" name="tabInfo" v-if="!!executeResultInfo">
|
||||
<pre style="white-space: pre-wrap;">{{ executeResultInfo }}</pre>
|
||||
<pre class="execute-result-info">{{ executeResultInfo }}</pre>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="错误" name="tabError" v-if="!!executeError">
|
||||
<div style="color: #f00;">{{ executeError }}</div>
|
||||
</el-tab-pane>
|
||||
<template v-else>
|
||||
<el-tab-pane :label="'结果'+resultItem.index" :name="resultItem.name"
|
||||
v-for="resultItem in executeResultList" v-if="!!resultItem.index">
|
||||
<el-tab-pane :label="resultItem.label" :name="resultItem.name" v-for="resultItem in executeResultList" lazy>
|
||||
<div v-if="!!resultItem.errMsg" style="color: #f00;">{{ resultItem.errMsg }}</div>
|
||||
<div v-else-if="resultItem.dataList.length <= 0"
|
||||
style="text-align: center; color: #aaa; padding: 20px 0;">暂无数据
|
||||
</div>
|
||||
<ux-grid v-else
|
||||
:data="resultItem.dataList"
|
||||
stripe
|
||||
border
|
||||
:height="height"
|
||||
:checkboxConfig="{checkMethod: selectable, highlight: true}"
|
||||
<ux-grid v-else :data="resultItem.dataList"
|
||||
@table-body-scroll="scroll"
|
||||
style="width: 100%; margin-bottom: 5px;" class="execute-result-table" max-height="600"
|
||||
@selection-change="handleSelectionChange">
|
||||
@selection-change="handleSelectionChange"
|
||||
:checkboxConfig="{checkMethod: selectable, highlight: true}"
|
||||
stripe border :height="height" max-height="600"
|
||||
style="width: 100%; margin-bottom: 5px;" class="execute-result-table">
|
||||
<ux-table-column type="checkbox" width="55"></ux-table-column>
|
||||
<ux-table-column type="index" width="50" title=" "></ux-table-column>
|
||||
<ux-table-column v-for="item in resultItem.dataCols" :prop="item.prop" :title="item.prop"
|
||||
:width="item.width">
|
||||
<ux-table-column v-for="item in resultItem.dataCols" :prop="item.prop" :title="item.label" :width="item.width">
|
||||
<template slot-scope="scope">
|
||||
<textarea readonly :value="scope.row[item.prop]" class="el-textarea__inner" rows="1"></textarea>
|
||||
</template>
|
||||
@@ -132,8 +107,7 @@
|
||||
<div>
|
||||
更新条件列:
|
||||
<el-select v-model="conditionDataColsChoice" multiple placeholder="请选择" style="width: 370px;">
|
||||
<el-option v-for="item in conditionDataCols" :key="item.prop" :label="item.prop"
|
||||
:value="item.prop"></el-option>
|
||||
<el-option v-for="item in conditionDataCols" :key="item.prop" :label="item.label" :value="item.prop"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
@@ -345,28 +319,61 @@ export default {
|
||||
executeId: this.nowExecutorId,
|
||||
sql: sqlValue,
|
||||
params: JSON.stringify(sqlParamObj),
|
||||
}).then(json => {
|
||||
}).then(response => {
|
||||
this.sqlExecuting = false;
|
||||
if (json.errCode != 200) {
|
||||
this.executeShowTable = 'tabError';
|
||||
this.executeError = json.errMsg;
|
||||
return;
|
||||
}
|
||||
let resultList = json.data || [];
|
||||
let resIndex = 1;
|
||||
let executeResultList = [];
|
||||
let executeResultInfo = "", itemIndex = 1;
|
||||
for (let i = 0; i < resultList.length; i++) {
|
||||
let objItem = JSON.parse(resultList[i]);
|
||||
executeResultInfo += this.getExecuteInfoStr(objItem);
|
||||
let resultItem = this.dealExecuteResult(objItem);
|
||||
if (resultItem.updateCount < 0) {
|
||||
resultItem.index = itemIndex;
|
||||
resultItem.name = 'tab' + itemIndex;
|
||||
itemIndex++;
|
||||
let resData = response.data || [];
|
||||
let executeResultInfo = "";
|
||||
resData.forEach(result => {
|
||||
let dataListRes = [];
|
||||
let previewColumns = [];
|
||||
executeResultInfo += this.getExecuteInfoStr(result);
|
||||
if (result.errCode === 0) {
|
||||
let dataListTemp = result.data || [];
|
||||
let headerList = result.header || [];
|
||||
// 组装表头
|
||||
let columnSet = {};
|
||||
if (headerList.length > 0) {
|
||||
let headerIndex = 0;
|
||||
headerList.forEach(item => {
|
||||
let key = 'value_' + (headerIndex++);
|
||||
columnSet[key] = item;
|
||||
previewColumns.push({prop: key, label: item});
|
||||
});
|
||||
dataListTemp.forEach(item => {
|
||||
let dataItem = {}, dataIndex = 0;
|
||||
previewColumns.forEach(column => {
|
||||
let key = column.prop;
|
||||
dataItem[key] = item[dataIndex++];
|
||||
if ((dataItem[key] + '').length > columnSet[key].length) {
|
||||
columnSet[key] = dataItem[key] + '';
|
||||
}
|
||||
executeResultList.push(resultItem);
|
||||
});
|
||||
dataListRes.push(dataItem);
|
||||
});
|
||||
previewColumns.forEach(item => {
|
||||
// 动态计算宽度~自己想的一个方法,666
|
||||
document.getElementById("widthCalculate").innerText = columnSet[item.prop];
|
||||
let width = document.getElementById("widthCalculate").offsetWidth;
|
||||
width = width + (columnSet[item.prop] === item.label ? 35 : 55);
|
||||
width = (width < 50) ? 50 : width;
|
||||
item.width = (width > 200) ? 200 : width;
|
||||
});
|
||||
}
|
||||
this.executeShowTable = (itemIndex === 1) ? "tabInfo" : "tab1";
|
||||
}
|
||||
executeResultList.push({
|
||||
label: '结果' + resIndex,
|
||||
name: 'result_' + resIndex,
|
||||
errMsg: result.errMsg,
|
||||
errCode: result.errCode,
|
||||
queryTime: result.queryTime,
|
||||
dataCols: previewColumns,
|
||||
dataList: dataListRes
|
||||
});
|
||||
resIndex++;
|
||||
});
|
||||
this.executeShowTable = (resIndex === 1) ? "tabInfo" : "result_1";
|
||||
this.executeResultInfo = executeResultInfo;
|
||||
this.executeResultList = executeResultList;
|
||||
this.loadHistoryList();
|
||||
@@ -433,12 +440,12 @@ export default {
|
||||
this.executorSource = {sourceId: this.choiceDatasourceId, dbName: this.choiceDatabase};
|
||||
},
|
||||
getExecuteInfoStr(resultData) {
|
||||
var resultStr = resultData.sql;
|
||||
var resultStr = resultData.executeSql;
|
||||
resultStr += "\n> 状态:" + ((!!resultData.errMsg) ? "ERROR" : "OK");
|
||||
if (resultData.updateCount >= 0) {
|
||||
resultStr += "\n> 影响行数:" + resultData.updateCount;
|
||||
}
|
||||
resultStr += "\n> 耗时:" + (resultData.useTime || 0) / 1000 + "s";
|
||||
resultStr += "\n> 耗时:" + (resultData.queryTime || 0) / 1000 + "s";
|
||||
resultStr += "\n\n";
|
||||
return resultStr;
|
||||
},
|
||||
@@ -557,6 +564,16 @@ export default {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.data-executor-vue .execute-result-info {
|
||||
white-space: pre-wrap;
|
||||
max-height: 400px;
|
||||
overflow: auto;
|
||||
background: #263238;
|
||||
color: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.data-executor-vue-out .el-tabs__nav-scroll {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export default {
|
||||
let names = '';
|
||||
dataCols.forEach(col => {
|
||||
if (names.length > 0) names += ', ';
|
||||
names += col.prop;
|
||||
names += (col.label || col.prop);
|
||||
});
|
||||
choiceData.forEach(item => {
|
||||
let values = '';
|
||||
@@ -41,18 +41,19 @@ export default {
|
||||
let values = '', where = '';
|
||||
dataCols.forEach(col => {
|
||||
let val = item[col.prop];
|
||||
let columnName = (col.label || col.prop);
|
||||
if (condition.indexOf(col.prop) >= 0) {
|
||||
if (where.length > 0) where += ' and ';
|
||||
if (val === undefined || val === null || isNaN(val)) {
|
||||
where += col.prop + ' = null';
|
||||
where += columnName + ' = null';
|
||||
} else if (typeof val === 'number' && !isNaN(val)) {
|
||||
where += col.prop + ' = ' + val;
|
||||
where += columnName + ' = ' + val;
|
||||
} else {
|
||||
where += col.prop + ' = ' + "'" + val + "'";
|
||||
where += columnName + ' = ' + "'" + val + "'";
|
||||
}
|
||||
} else {
|
||||
if (values.length > 0) values += ', ';
|
||||
values += col.prop + '=';
|
||||
values += columnName + '=';
|
||||
if (val === undefined || val === null || isNaN(val)) {
|
||||
values += "null";
|
||||
} else if (typeof val === 'number' && !isNaN(val)) {
|
||||
@@ -70,6 +71,15 @@ export default {
|
||||
},
|
||||
json(dataCols, choiceData, dbName, tableName) {
|
||||
// 复制为json
|
||||
return JSON.stringify(choiceData);
|
||||
let copyData = [];
|
||||
choiceData.forEach(item => {
|
||||
let values = {};
|
||||
dataCols.forEach(col => {
|
||||
let columnName = (col.label || col.prop);
|
||||
values[columnName] = item[col.prop];
|
||||
});
|
||||
copyData.push(values);
|
||||
});
|
||||
return JSON.stringify(copyData);
|
||||
},
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export default {
|
||||
let names = '';
|
||||
dataCols.forEach(col => {
|
||||
if (names.length > 0) names += ', ';
|
||||
names += col.prop;
|
||||
names += (col.label || col.prop);
|
||||
});
|
||||
choiceData.forEach(item => {
|
||||
let values = '';
|
||||
@@ -41,18 +41,19 @@ export default {
|
||||
let values = '', where = '';
|
||||
dataCols.forEach(col => {
|
||||
let val = item[col.prop];
|
||||
let columnName = (col.label || col.prop);
|
||||
if (condition.indexOf(col.prop) >= 0) {
|
||||
if (where.length > 0) where += ' and ';
|
||||
if (val === undefined || val === null || isNaN(val)) {
|
||||
where += col.prop + ' = null';
|
||||
where += columnName + ' = null';
|
||||
} else if (typeof val === 'number' && !isNaN(val)) {
|
||||
where += col.prop + ' = ' + val;
|
||||
where += columnName + ' = ' + val;
|
||||
} else {
|
||||
where += col.prop + ' = ' + "'" + val + "'";
|
||||
where += columnName + ' = ' + "'" + val + "'";
|
||||
}
|
||||
} else {
|
||||
if (values.length > 0) values += ', ';
|
||||
values += col.prop + '=';
|
||||
values += columnName + '=';
|
||||
if (val === undefined || val === null || isNaN(val)) {
|
||||
values += "null";
|
||||
} else if (typeof val === 'number' && !isNaN(val)) {
|
||||
@@ -70,6 +71,15 @@ export default {
|
||||
},
|
||||
json(dataCols, choiceData, dbName, tableName) {
|
||||
// 复制为json
|
||||
return JSON.stringify(choiceData);
|
||||
let copyData = [];
|
||||
choiceData.forEach(item => {
|
||||
let values = {};
|
||||
dataCols.forEach(col => {
|
||||
let columnName = (col.label || col.prop);
|
||||
values[columnName] = item[col.prop];
|
||||
});
|
||||
copyData.push(values);
|
||||
});
|
||||
return JSON.stringify(copyData);
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user