表数据筛选使用性优化,新增动态提示
新增数据库备份工具类
This commit is contained in:
@@ -0,0 +1,124 @@
|
|||||||
|
package com.zyplayer.doc.db.framework.utils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库备份恢复工具类
|
||||||
|
*
|
||||||
|
* @author diantu
|
||||||
|
* @since 2023年2月8日
|
||||||
|
*/
|
||||||
|
public class DatabaseBackupUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQL数据库导出
|
||||||
|
*
|
||||||
|
* @param hostIP MySQL数据库所在服务器地址IP
|
||||||
|
* @param userName 进入数据库所需要的用户名
|
||||||
|
* @param password 进入数据库所需要的密码
|
||||||
|
* @param savePath 数据库导出文件保存路径
|
||||||
|
* @param fileName 数据库导出文件文件名
|
||||||
|
* @param databaseName 要导出的数据库名
|
||||||
|
* @return 返回true表示导出成功,否则返回false。
|
||||||
|
*/
|
||||||
|
public static boolean exportDatabaseForMysql(String mysqldumpPath, String hostIP, String userName, String password, String savePath, String fileName, String databaseName) throws InterruptedException {
|
||||||
|
File saveFile = new File(savePath);
|
||||||
|
if (!saveFile.exists()) {// 如果目录不存在
|
||||||
|
saveFile.mkdirs();// 创建文件夹
|
||||||
|
}
|
||||||
|
if(!savePath.endsWith(File.separator)){
|
||||||
|
savePath = savePath + File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintWriter printWriter = null;
|
||||||
|
BufferedReader bufferedReader = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(savePath + fileName), "utf8"));
|
||||||
|
Process process = Runtime.getRuntime().exec(" "+mysqldumpPath+"/mysqldump -h" + hostIP + " -u" + userName + " -p" + password + " " + databaseName);
|
||||||
|
InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream(), "utf8");
|
||||||
|
bufferedReader = new BufferedReader(inputStreamReader);
|
||||||
|
String line;
|
||||||
|
while((line = bufferedReader.readLine())!= null){
|
||||||
|
printWriter.println(line);
|
||||||
|
}
|
||||||
|
printWriter.flush();
|
||||||
|
if(process.waitFor() == 0){//0 表示线程正常终止。
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (bufferedReader != null) {
|
||||||
|
bufferedReader.close();
|
||||||
|
}
|
||||||
|
if (printWriter != null) {
|
||||||
|
printWriter.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void backup(String savePath) {
|
||||||
|
File file = new File(savePath);
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
String fileName = savePath + "/" + LocalDate.now() + ".sql";
|
||||||
|
/** 默认使用linux*/
|
||||||
|
//String cmdPrefix = "/bin/sh -c ";
|
||||||
|
String c1 = "/bin/sh";
|
||||||
|
String c2 = "-c";
|
||||||
|
String os_name = System.getProperty("os.name");
|
||||||
|
// 判断是否是windows系统
|
||||||
|
if (os_name.toLowerCase().startsWith("win")){
|
||||||
|
//cmdPrefix = "cmd /c ";
|
||||||
|
c1 = "cmd";
|
||||||
|
c2 = "/c";
|
||||||
|
}
|
||||||
|
//参考示例:# /usr/local/mysql/bin/mysqldump -uroot -p123456 -P3306 shuju > shuju.sql
|
||||||
|
String cmd = "mysqldump" // mysqldump的绝对路径,配置环境变量,直接写mysqldump即可
|
||||||
|
+ " -h" + "127.0.0.1" // 数据库端口号
|
||||||
|
+ " -P" + "3306" // 数据库端口号
|
||||||
|
+ " -u" + "root" // 数据库用户名
|
||||||
|
+ " -p" + "root" // 数据库密码
|
||||||
|
+ " " + "zyplayer_doc_manage" // 数据库名
|
||||||
|
+ " > " + fileName; // 最终写入的文件路径
|
||||||
|
try {
|
||||||
|
System.out.println("第一个参数 " + c1);
|
||||||
|
System.out.println("第二个参数 " + c2);
|
||||||
|
System.out.println("具体命令 " + cmd);
|
||||||
|
|
||||||
|
//log.error("数据库备份START" + LocalDateTime.now());
|
||||||
|
/**
|
||||||
|
* exec重载方法有一个参数的,window下执行正常,linux下无法完成备份。
|
||||||
|
* 使用多参数重载方法都可以正常备份
|
||||||
|
*/
|
||||||
|
Process process = Runtime.getRuntime().exec(new String[]{c1, c2, cmd});
|
||||||
|
process.waitFor();
|
||||||
|
//log.error("数据库备份END" + LocalDateTime.now());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
//log.error("数据库备份失败:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
try {
|
||||||
|
if (exportDatabaseForMysql("C:/Program Files/MySQL/MySQL Server 5.7/bin","127.0.0.1", "root", "root", "D:/backupDatabase", "2023-2-8.sql", "zyplayer_doc_manage")) {
|
||||||
|
System.out.println("数据库成功备份!!!");
|
||||||
|
} else {
|
||||||
|
System.out.println("数据库备份失败!!!");
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//backup("D:/backupDatabase");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,17 +2,30 @@
|
|||||||
<div class="data-executor-vue">
|
<div class="data-executor-vue">
|
||||||
<div style="padding: 0 10px 10px;height: 100%;box-sizing: border-box;">
|
<div style="padding: 0 10px 10px;height: 100%;box-sizing: border-box;">
|
||||||
<el-card style="margin-bottom: 10px;">
|
<el-card style="margin-bottom: 10px;">
|
||||||
<ace-editor v-model="sqlExecutorContent" @init="sqlExecutorInit" lang="sql" theme="monokai" width="100%"
|
<div v-show="aceEditorShow">
|
||||||
height="60" :options="sqlEditorConfig" :source="executorSource"
|
<el-alert
|
||||||
style="margin-bottom: 10px;"></ace-editor>
|
title="筛选示例 (支持 and , or 等连接符)"
|
||||||
|
type="info"
|
||||||
|
:description="executorDesc"
|
||||||
|
show-icon>
|
||||||
|
</el-alert>
|
||||||
|
<ace-editor v-model="sqlExecutorContent" @init="sqlExecutorInit" lang="sql" theme="monokai" width="100%"
|
||||||
|
height="60" :options="sqlEditorConfig" :source="executorSource"
|
||||||
|
style="margin-bottom: 10px;">
|
||||||
|
</ace-editor>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
<el-button v-on:click="doAceEditorShow" type="primary" plain size="small" icon="el-icon-search">筛选
|
||||||
|
</el-button>
|
||||||
<el-button v-if="sqlExecuting" v-on:click="cancelExecutorSql" type="primary" plain size="small"
|
<el-button v-if="sqlExecuting" v-on:click="cancelExecutorSql" type="primary" plain size="small"
|
||||||
icon="el-icon-video-pause">取消执行
|
icon="el-icon-video-pause">取消执行
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-tooltip v-else effect="dark" content="Ctrl+R、Ctrl+Enter" placement="top">
|
<el-tooltip v-show="aceEditorShow" 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 v-on:click="doExecutorClick" type="primary" plain size="small"
|
||||||
|
icon="el-icon-video-play">执行
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
|
|
||||||
<el-button icon="el-icon-refresh-left" size="small" @click="refreshData">重置</el-button>
|
<el-button icon="el-icon-refresh-left" size="small" @click="refreshData">重置</el-button>
|
||||||
<el-button @click="downloadTableData" type="success" size="small" icon="el-icon-download" plain
|
<el-button @click="downloadTableData" type="success" size="small" icon="el-icon-download" plain
|
||||||
style="margin-left: 30px;">导出
|
style="margin-left: 30px;">导出
|
||||||
@@ -67,8 +80,8 @@
|
|||||||
:default-sort="tableSort">
|
:default-sort="tableSort">
|
||||||
<ux-table-column type="checkbox" width="55"></ux-table-column>
|
<ux-table-column type="checkbox" width="55"></ux-table-column>
|
||||||
<ux-table-column type="index" width="50" title=" "></ux-table-column>
|
<ux-table-column type="index" width="50" title=" "></ux-table-column>
|
||||||
<ux-table-column sortable v-for="item in resultItem.dataCols" :prop="item.prop" :title="item.prop"
|
<ux-table-column v-for="item in resultItem.dataCols" :prop="item.prop" :title="item.prop"
|
||||||
:width="item.width">
|
:width="item.width" sortable>
|
||||||
<template slot="header" slot-scope="scope">
|
<template slot="header" slot-scope="scope">
|
||||||
<el-tooltip effect="dark" :content="item.desc" placement="top">
|
<el-tooltip effect="dark" :content="item.desc" placement="top">
|
||||||
<span>{{ item.prop }}</span>
|
<span>{{ item.prop }}</span>
|
||||||
@@ -183,6 +196,8 @@ export default {
|
|||||||
name: 'dataPreview',
|
name: 'dataPreview',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
executorDesc: "",
|
||||||
|
aceEditorShow: false,
|
||||||
height: 0,
|
height: 0,
|
||||||
sqlExecuting: false,
|
sqlExecuting: false,
|
||||||
executeResultList: [],
|
executeResultList: [],
|
||||||
@@ -277,6 +292,7 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.tableDataColumns = columnList;
|
this.tableDataColumns = columnList;
|
||||||
|
this.executorDesc = columnList[0].name + " = ?";
|
||||||
// 设置选择展示的列
|
// 设置选择展示的列
|
||||||
this.storageKey.subKey = param.sourceId + '-' + param.dbName + '-' + param.tableName;
|
this.storageKey.subKey = param.sourceId + '-' + param.dbName + '-' + param.tableName;
|
||||||
let storageShowColumns = storageUtil.set.get(this.storageKey.key, this.storageKey.subKey);
|
let storageShowColumns = storageUtil.set.get(this.storageKey.key, this.storageKey.subKey);
|
||||||
@@ -318,8 +334,8 @@ export default {
|
|||||||
this.doExecutorSqlCommon();
|
this.doExecutorSqlCommon();
|
||||||
},
|
},
|
||||||
tableSortChange(sort) {
|
tableSortChange(sort) {
|
||||||
if (this.tableSort.prop === sort.prop && this.tableSort.order === sort.order) return;
|
if (this.tableSort.prop === sort.column.title && this.tableSort.order === sort.order) return;
|
||||||
this.tableSort = {prop: sort.prop, order: sort.order};
|
this.tableSort = {prop: sort.column.title, order: sort.order};
|
||||||
this.doExecutorSqlCommon();
|
this.doExecutorSqlCommon();
|
||||||
},
|
},
|
||||||
refreshData() {
|
refreshData() {
|
||||||
@@ -339,13 +355,16 @@ export default {
|
|||||||
this.currentPage = 1;
|
this.currentPage = 1;
|
||||||
this.doExecutorSqlCommon();
|
this.doExecutorSqlCommon();
|
||||||
},
|
},
|
||||||
|
doAceEditorShow() {
|
||||||
|
this.aceEditorShow = !this.aceEditorShow
|
||||||
|
},
|
||||||
doExecutorSqlCommon() {
|
doExecutorSqlCommon() {
|
||||||
if (!this.pageParam.sourceId) {
|
if (!this.pageParam.sourceId) {
|
||||||
this.$message.error("请先选择数据源");
|
this.$message.error("请先选择数据源");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.tableSort.prop) {
|
if (!this.tableSort.prop) {
|
||||||
this.tableSort = {prop: this.pageParam.orderColumn, order: 'ascending'};
|
this.tableSort = {prop: this.pageParam.orderColumn, order: 'asc'};
|
||||||
}
|
}
|
||||||
let conditionSql = this.sqlExecutorEditor.getSelectedText();
|
let conditionSql = this.sqlExecutorEditor.getSelectedText();
|
||||||
conditionSql = conditionSql || this.sqlExecutorEditor.getValue();
|
conditionSql = conditionSql || this.sqlExecutorEditor.getValue();
|
||||||
@@ -366,7 +385,7 @@ export default {
|
|||||||
pageNum: this.currentPage,
|
pageNum: this.currentPage,
|
||||||
pageSize: this.pageSize,
|
pageSize: this.pageSize,
|
||||||
orderColumn: this.tableSort.prop,
|
orderColumn: this.tableSort.prop,
|
||||||
orderType: (this.tableSort.order === 'ascending' ? 'asc' : 'desc'),
|
orderType: this.tableSort.order,
|
||||||
params: '',
|
params: '',
|
||||||
};
|
};
|
||||||
datasourceApi.dataViewQuery(param).then(json => {
|
datasourceApi.dataViewQuery(param).then(json => {
|
||||||
|
|||||||
Reference in New Issue
Block a user