SQL执行的动态参数保存,数据预览列表头移上去展示列说明

This commit is contained in:
暮光:城中城
2021-07-17 12:22:51 +08:00
parent eda81c36bc
commit 1d5c57d516
15 changed files with 84 additions and 27 deletions

View File

@@ -58,6 +58,11 @@ public class DbFavorite implements Serializable {
* 是否有效 0=无效 1=有效 * 是否有效 0=无效 1=有效
*/ */
private Integer yn; private Integer yn;
/**
* 执行参数JSON
*/
private String paramJson;
public Long getId() { public Long getId() {
return id; return id;
@@ -129,4 +134,12 @@ public class DbFavorite implements Serializable {
public void setDatasourceId(Long datasourceId) { public void setDatasourceId(Long datasourceId) {
this.datasourceId = datasourceId; this.datasourceId = datasourceId;
} }
public String getParamJson() {
return paramJson;
}
public void setParamJson(String paramJson) {
this.paramJson = paramJson;
}
} }

View File

@@ -7,7 +7,7 @@ import java.io.Serializable;
/** /**
* <p> * <p>
* *
* </p> * </p>
* *
* @author 暮光:城中城 * @author 暮光:城中城
@@ -53,6 +53,11 @@ public class DbHistory implements Serializable {
*/ */
private Integer yn; private Integer yn;
/**
* 执行参数JSON
*/
private String paramJson;
public Long getId() { public Long getId() {
return id; return id;
} }
@@ -115,4 +120,12 @@ public class DbHistory implements Serializable {
public void setDatasourceId(Long datasourceId) { public void setDatasourceId(Long datasourceId) {
this.datasourceId = datasourceId; this.datasourceId = datasourceId;
} }
public String getParamJson() {
return paramJson;
}
public void setParamJson(String paramJson) {
this.paramJson = paramJson;
}
} }

View File

@@ -13,6 +13,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/ */
public interface DbHistoryService extends IService<DbHistory> { public interface DbHistoryService extends IService<DbHistory> {
void saveHistory(String content, Long datasourceId); void saveHistory(String content, String paramJson, Long datasourceId);
} }

View File

@@ -26,11 +26,12 @@ public class DbHistoryServiceImpl extends ServiceImpl<DbHistoryMapper, DbHistory
DbHistoryMapper dbHistoryMapper; DbHistoryMapper dbHistoryMapper;
@Override @Override
public void saveHistory(String content, Long datasourceId) { public void saveHistory(String content, String paramJson, Long datasourceId) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser(); DocUserDetails currentUser = DocUserUtil.getCurrentUser();
DbHistory dbHistory = new DbHistory(); DbHistory dbHistory = new DbHistory();
dbHistory.setDatasourceId(datasourceId); dbHistory.setDatasourceId(datasourceId);
dbHistory.setContent(content); dbHistory.setContent(content);
dbHistory.setParamJson(paramJson);
dbHistory.setCreateTime(new Date()); dbHistory.setCreateTime(new Date());
dbHistory.setCreateUserId(currentUser.getUserId()); dbHistory.setCreateUserId(currentUser.getUserId());
dbHistory.setCreateUserName(currentUser.getUsername()); dbHistory.setCreateUserName(currentUser.getUsername());

View File

@@ -70,7 +70,7 @@ public class DbSqlExecutorController {
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId); DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
String useDbSql = dbBaseService.getUseDbSql(dbName); String useDbSql = dbBaseService.getUseDbSql(dbName);
// 保留历史记录 // 保留历史记录
dbHistoryService.saveHistory(sql.trim(), sourceId); dbHistoryService.saveHistory(sql.trim(), params, sourceId);
// 参数处理 // 参数处理
Map<String, Object> paramMap = JSON.parseObject(params); Map<String, Object> paramMap = JSON.parseObject(params);
List<String> resultList = new LinkedList<>(); List<String> resultList = new LinkedList<>();

View File

@@ -1 +1 @@
.about-zyplayer-doc{text-align:left;line-height:normal}.about-zyplayer-doc .el-dialog__body{padding:20px}#app,.el-container,.el-menu{height:100%}.el-header{background-color:#1d4e89!important}.database-list-tree{background-color:#fafafa}.database-list-tree .el-tree-node>.el-tree-node__children{overflow:unset}.el-tree-node__content .el-icon-more{margin-left:5px;color:#606266;font-size:12px;display:none;padding:2px 5px}.el-tree-node__content:hover .el-icon-more{display:inline-block}.login-container{border-radius:5px;-moz-border-radius:5px;background-clip:padding-box;margin:0 auto;width:350px;padding:35px 35px 15px 35px;background:#fff;border:1px solid #eaeaea;-webkit-box-shadow:0 0 25px #cac6c6;box-shadow:0 0 25px #cac6c6}.title{margin:0 auto 40px auto;text-align:center;color:#505458}.remember{margin:0 0 35px 0}.my-info-vue .box-card{margin:10px}.table-info-vue{padding:0 20px}.table-info-vue .el-dialog__body{padding:0 20px 10px}.table-info-vue .el-form-item{margin-bottom:5px}.table-info-vue .edit-table-desc{cursor:pointer;color:#409eff}.table-info-vue .description{cursor:pointer;min-height:23px}.table-info-vue .el-table td,.table-info-vue .el-table th{padding:5px 0}.table-info-vue .status-info-row{padding:8px 0}.table-info-vue .status-info-row .label{width:80px;display:inline-block;text-align:right;color:#606266}.table-database-vue .el-table td,.table-database-vue .el-table th{padding:5px 0}.table-database-vue .label{width:140px;text-align:right}.table-database-vue .el-table th,.table-procedure-edit-vue .el-table td,.table-procedure-vue .el-table td{padding:5px 0}body,html{margin:0;padding:0;height:100%}.header-right-user-name{color:#fff;padding-right:5px}.el-menu-vertical{border-right:0}.el-menu-vertical,.el-menu-vertical .el-menu{background:#fafafa}.el-header{background-color:#409eff;color:#333;line-height:40px;text-align:right;height:40px!important}.data-executor-vue .ace-monokai .ace_print-margin{display:none}.data-executor-vue .el-card__body{padding:10px}.data-executor-vue .sql-params .el-input-group{width:auto;margin:10px 10px 0 0}.data-executor-vue .sql-params .el-input__inner{width:200px}.data-executor-vue .el-table td,.el-table th{padding:6px 0}.data-executor-vue .execute-result-table .el-input__inner{height:25px;line-height:25px;padding:0 5px}.data-executor-vue .execute-result-table .el-textarea__inner{height:27px;min-height:27px;line-height:25px;padding:0 5px;resize:none}.data-executor-vue .sql-content-line{margin:0;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}.data-executor-vue .execute-use-time{font-size:12px;margin-right:10px}.data-executor-vue-out .el-tabs__nav-scroll{padding-left:20px}.data-executor-vue-out .el-button+.el-button{margin-left:0}.data-executor-vue-out .el-table__body-wrapper{height:calc(100vh - 180px);overflow-y:auto}.data-transfer-vue .el-button+.el-button{margin-left:4px} .about-zyplayer-doc{text-align:left;line-height:normal}.about-zyplayer-doc .el-dialog__body{padding:20px}#app,.el-container,.el-menu{height:100%}.el-header{background-color:#1d4e89!important}.database-list-tree{background-color:#fafafa}.database-list-tree .el-tree-node>.el-tree-node__children{overflow:unset}.el-tree-node__content .el-icon-more{margin-left:5px;color:#606266;font-size:12px;display:none;padding:2px 5px}.el-tree-node__content:hover .el-icon-more{display:inline-block}.login-container{border-radius:5px;-moz-border-radius:5px;background-clip:padding-box;margin:0 auto;width:350px;padding:35px 35px 15px 35px;background:#fff;border:1px solid #eaeaea;-webkit-box-shadow:0 0 25px #cac6c6;box-shadow:0 0 25px #cac6c6}.title{margin:0 auto 40px auto;text-align:center;color:#505458}.remember{margin:0 0 35px 0}.my-info-vue .box-card{margin:10px}.table-info-vue{padding:0 20px}.table-info-vue .el-dialog__body{padding:0 20px 10px}.table-info-vue .el-form-item{margin-bottom:5px}.table-info-vue .edit-table-desc{cursor:pointer;color:#409eff}.table-info-vue .description{cursor:pointer;min-height:23px}.table-info-vue .el-table td,.table-info-vue .el-table th{padding:5px 0}.table-info-vue .status-info-row{padding:8px 0}.table-info-vue .status-info-row .label{width:80px;display:inline-block;text-align:right;color:#606266}.table-database-vue .el-table td,.table-database-vue .el-table th{padding:5px 0}.table-database-vue .label{width:140px;text-align:right}.table-database-vue .el-table th,.table-procedure-edit-vue .el-table td,.table-procedure-vue .el-table td{padding:5px 0}body,html{margin:0;padding:0;height:100%}.header-right-user-name{color:#fff;padding-right:5px}.el-menu-vertical{border-right:0}.el-menu-vertical,.el-menu-vertical .el-menu{background:#fafafa}.el-header{background-color:#409eff;color:#333;line-height:40px;text-align:right;height:40px!important}.data-executor-vue .ace-monokai .ace_print-margin{display:none}.data-executor-vue .el-card__body{padding:10px}.data-executor-vue .sql-params .el-input-group{width:auto;margin:10px 10px 0 0}.data-executor-vue .sql-params .el-input__inner{width:200px}.data-executor-vue .el-table td,.el-table th{padding:6px 0}.data-executor-vue .execute-result-table .el-input__inner{height:25px;line-height:25px;padding:0 5px}.data-executor-vue .execute-result-table .el-textarea__inner{height:27px;min-height:27px;line-height:25px;padding:0 5px;resize:none}.data-executor-vue .sql-content-line{margin:0;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}.data-executor-vue .execute-use-time{font-size:12px;margin-right:10px}.data-executor-vue-out .el-tabs__nav-scroll{padding-left:20px}.data-executor-vue-out .el-button+.el-button{margin-left:0}.data-executor-vue-out .el-table__body-wrapper{height:calc(100vh - 180px);overflow-y:auto}.data-transfer-vue .el-button+.el-button{margin-left:4px}

View File

@@ -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.5c9df0aa.css rel=preload as=style><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=js/app.612a825e.js rel=preload as=script><link href=js/chunk-vendors.22b87709.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/app.5c9df0aa.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.22b87709.js></script><script src=js/app.612a825e.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/chunk-vendors.8924efc6.css rel=preload as=style><link href=css/index.5c9df0aa.css rel=preload as=style><link href=js/chunk-vendors.22b87709.js rel=preload as=script><link href=js/index.fe7dd667.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/index.5c9df0aa.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.22b87709.js></script><script src=js/index.fe7dd667.js></script></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -93,6 +93,7 @@ CREATE TABLE `db_favorite` (
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`yn` tinyint(4) NULL DEFAULT NULL COMMENT '是否有效 0=无效 1=有效', `yn` tinyint(4) NULL DEFAULT NULL COMMENT '是否有效 0=无效 1=有效',
`datasource_id` bigint(20) NULL DEFAULT NULL COMMENT '数据源ID', `datasource_id` bigint(20) NULL DEFAULT NULL COMMENT '数据源ID',
`param_json` varchar(1024) DEFAULT NULL COMMENT '执行参数JSON',
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
@@ -112,6 +113,7 @@ CREATE TABLE `db_history` (
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`yn` tinyint(4) NULL DEFAULT NULL COMMENT '是否有效 0=无效 1=有效', `yn` tinyint(4) NULL DEFAULT NULL COMMENT '是否有效 0=无效 1=有效',
`datasource_id` bigint(20) NULL DEFAULT NULL COMMENT '数据源ID', `datasource_id` bigint(20) NULL DEFAULT NULL COMMENT '数据源ID',
`param_json` varchar(1024) DEFAULT NULL COMMENT '执行参数JSON',
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 135 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; ) ENGINE = InnoDB AUTO_INCREMENT = 135 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

View File

@@ -21,5 +21,6 @@ CREATE TABLE `db_table_relation` (
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='表关系'; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='表关系';
-- 增加执行参数JSON
alter table db_history add `param_json` varchar(1024) DEFAULT NULL COMMENT '执行参数JSON';
alter table db_favorite add `param_json` varchar(1024) DEFAULT NULL COMMENT '执行参数JSON';

View File

@@ -45,6 +45,11 @@
<el-table-column type="selection" width="55"></el-table-column> <el-table-column type="selection" width="55"></el-table-column>
<el-table-column type="index" width="50"></el-table-column> <el-table-column type="index" width="50"></el-table-column>
<el-table-column sortable v-for="item in resultItem.dataCols" :prop="item.prop" :label="item.prop" :width="item.width"> <el-table-column sortable v-for="item in resultItem.dataCols" :prop="item.prop" :label="item.prop" :width="item.width">
<template slot="header" slot-scope="scope">
<el-tooltip effect="dark" :content="item.desc" placement="top">
<span>{{item.prop}}</span>
</el-tooltip>
</template>
<template slot-scope="scope"> <template slot-scope="scope">
<textarea readonly :value="scope.row[item.prop]" class="el-textarea__inner" rows="1"></textarea> <textarea readonly :value="scope.row[item.prop]" class="el-textarea__inner" rows="1"></textarea>
</template> </template>
@@ -170,7 +175,8 @@
minLines: 3, minLines: 3,
maxLines: 3, maxLines: 3,
}, },
executorSource: {} executorSource: {},
columnMap: {},
} }
}, },
components: { components: {
@@ -188,12 +194,15 @@
// }, 500); // }, 500);
}, },
methods: { methods: {
init(param) { init(param, columnList) {
if (this.pageParam.sourceId == param.sourceId) { if (this.pageParam.sourceId == param.sourceId) {
return; return;
} }
this.pageParam = param; this.pageParam = param;
this.executorSource = {sourceId: param.sourceId, dbName: param.dbName, tableName: param.tableName}; this.executorSource = {sourceId: param.sourceId, dbName: param.dbName, tableName: param.tableName};
let columnMap = {};
columnList.forEach(item => columnMap[item.name] = item);
this.columnMap = columnMap;
this.doExecutorSqlCommon(); this.doExecutorSqlCommon();
// this.vueQueryParam = to.query; // this.vueQueryParam = to.query;
// let newName = {key: this.$route.fullPath, val: '数据-'+this.vueQueryParam.tableName}; // let newName = {key: this.$route.fullPath, val: '数据-'+this.vueQueryParam.tableName};
@@ -328,7 +337,8 @@
var width = (width1 > width2) ? width1 : width2; var width = (width1 > width2) ? width1 : width2;
width = (width < 50) ? 50 : width; width = (width < 50) ? 50 : width;
width = (width > 200) ? 200 : width; width = (width > 200) ? 200 : width;
executeResultCols.push({prop: key, width: width + 50}); let column = this.columnMap[key] || {};
executeResultCols.push({prop: key, width: width + 50, desc: (column.description || key)});
} }
} }
var resultObj = {}; var resultObj = {};

View File

@@ -46,12 +46,12 @@
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column> <el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
<el-table-column prop="content" label="SQL"> <el-table-column prop="content" label="SQL">
<template slot-scope="scope"> <template slot-scope="scope">
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row.content)" :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> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="160px"> <el-table-column label="操作" width="160px">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" type="primary" @click="inputFavoriteSql(scope.row.content)">输入</el-button> <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> </template>
</el-table-column> </el-table-column>
@@ -62,12 +62,12 @@
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column> <el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
<el-table-column prop="content" label="SQL"> <el-table-column prop="content" label="SQL">
<template slot-scope="scope"> <template slot-scope="scope">
<pre class="sql-content-line" @dblclick="inputFavoriteSql(scope.row.content)" :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> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="160px"> <el-table-column label="操作" width="160px">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row.content)">输入</el-button> <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> </template>
</el-table-column> </el-table-column>
@@ -234,11 +234,22 @@
sqlValue = this.sqlExecutorEditor.getValue(); sqlValue = this.sqlExecutorEditor.getValue();
} }
} }
let param = {name: '我的收藏', content: sqlValue, datasourceId: this.choiceDatasourceId}; let sqlParamObj = {};
datasourceApi.updateFavorite(param).then(() => { this.sqlParams.forEach(item => {
this.$message.success("收藏成功"); if (!!item.value) {
this.loadFavoriteList(); sqlParamObj[item.key] = item.value;
}); }
});
let param = {
name: '我的收藏',
content: sqlValue,
paramJson: JSON.stringify(sqlParamObj),
datasourceId: this.choiceDatasourceId
};
datasourceApi.updateFavorite(param).then(() => {
this.$message.success("收藏成功");
this.loadFavoriteList();
});
}, },
delFavorite(row) { delFavorite(row) {
datasourceApi.updateFavorite({id: row.id, yn: 0}).then(() => { datasourceApi.updateFavorite({id: row.id, yn: 0}).then(() => {
@@ -246,9 +257,15 @@
this.loadFavoriteList(); this.loadFavoriteList();
}); });
}, },
inputFavoriteSql(content) { inputFavoriteSql(item) {
this.sqlExecutorEditor.setValue(content, 1); this.sqlExecutorEditor.setValue(item.content, 1);
}, if (!!item.paramJson) {
let paramJson = JSON.parse(item.paramJson);
for (let key in paramJson) {
this.sqlParamHistory[key] = paramJson[key];
}
}
},
formatterSql() { formatterSql() {
let dataSql = this.sqlExecutorEditor.getSelectedText(); let dataSql = this.sqlExecutorEditor.getSelectedText();
if (!!dataSql) { if (!!dataSql) {

View File

@@ -207,7 +207,7 @@
dbType: this.tableStatusInfo.dbType, dbType: this.tableStatusInfo.dbType,
// 默认排序字段先随便取一个impala等数据库必须排序后才能分页查 // 默认排序字段先随便取一个impala等数据库必须排序后才能分页查
orderColumn: primaryColumn.name, orderColumn: primaryColumn.name,
}); }, this.columnList);
} }
}, },
onCopySuccess(e) { onCopySuccess(e) {