Commit 4f494223 by yuwei

2.0.0项目初始化

parent d99fc897
......@@ -15,5 +15,6 @@ public class SqlConsoleVo implements Serializable {
private Long time;
private Boolean success;
private Integer count;
private List<Map<String, Object>> data;
private List<String> columnList;
private List<Map<String, Object>> dataList;
}
......@@ -3,13 +3,8 @@ package cn.datax.service.data.factory.sql.console.concurrent;
import cn.datax.service.data.factory.api.vo.SqlConsoleVo;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.Reader;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.CountDownLatch;
@Slf4j
......@@ -34,7 +29,8 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
Statement stmt = null;
ResultSet rs = null;
// 将查询数据存储到数据中
List<Map<String, Object>> list = new ArrayList<>();
List<Map<String, Object>> dataList = new ArrayList<>();
List<String> columnList = new LinkedList<>();
// 新增、修改、删除受影响行数
Integer updateCount = null;
SqlConsoleVo sqlConsoleVo = new SqlConsoleVo();
......@@ -59,6 +55,7 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
for (int i = 1; i <= colunmCount; i++) {
// 获取列名
String columnName = rsmd.getColumnName(i);
columnList.add(columnName);
Object val = null;
switch (rsmd.getColumnType(i)) {
case Types.ARRAY:
......@@ -127,7 +124,7 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
}
map.put(columnName, val);
}
list.add(map);
dataList.add(map);
}
} else {
// 执行新增、修改、删除受影响行数
......@@ -167,7 +164,8 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
log.info("线程查询数据用时:" + (end - start) + "ms");
sqlConsoleVo.setSql(sql);
sqlConsoleVo.setCount(updateCount);
sqlConsoleVo.setData(list);
sqlConsoleVo.setColumnList(columnList);
sqlConsoleVo.setDataList(dataList);
sqlConsoleVo.setTime(end - start);
return sqlConsoleVo;
}
......
import request from '@/utils/request'
export function runData (data) {
return request({
url: '/data/console/v1/run',
method: 'post',
data: data
})
}
export function stopData (data) {
return request({
url: '/data/console/v1/stop',
method: 'post',
data: data
})
}
......@@ -9,7 +9,7 @@
<el-col :span="24">
<el-button size="mini" round @click="runData" :disabled="sqlExecuting">运行</el-button>
<el-button size="mini" round @click="stopData" :disabled="!sqlExecuting">停止</el-button>
<el-button size="mini" round @click="formaterSql">格式化</el-button>
<el-button size="mini" round @click="formaterSql" :disabled="sqlExecuting">格式化</el-button>
<el-button size="mini" round @click="refreshData" :disabled="sqlExecuting">重置</el-button>
</el-col>
</el-row>
......@@ -46,7 +46,24 @@
<pre>{{executeResultInfo}}</pre>
</el-tab-pane>
<el-tab-pane v-for="(item,index) in sqlConsole" :key="(index+1)" :name="'table'+(index+1)" :label="'结果'+(index+1)">
<span>{{item.name}}</span>
<el-table :data="item.dataList" stripe border
:max-height="300"
style="width: 100%; margin: 15px 0;">
<el-table-column label="序号" width="55" align="center">
<template slot-scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
<template v-for="(column, index) in item.columnList">
<el-table-column
:prop="column"
:label="column"
:key="index"
align="center"
show-overflow-tooltip
/>
</template>
</el-table>
</el-tab-pane>
</el-tabs>
</div>
......@@ -62,6 +79,7 @@
import sqlFormatter from 'sql-formatter'
import SqlEditor from '@/components/SqlEditor'
import { listDataSource } from '@/api/factory/datasource'
import { runData, stopData } from '@/api/factory/dataconsole'
export default {
name: 'SqlConsole',
......@@ -98,20 +116,27 @@ export default {
})
},
runData () {
if (!this.sqlDataSource) {
this.$message.error("数据源不能为空")
return
}
if (!this.sqlText) {
this.$message.error("查询SQL不能为空")
return
}
this.sqlExecuting = true
this.sqlExecutorId = (new Date()).getTime()
this.sqlExecutorId = (new Date()).getTime() + Math.ceil(Math.random() * 1000)
this.sqlConsole = []
this.sqlConsole.push({
sql: 'sql',
time: 20,
success: true,
count: 3,
name: 'name'
})
setTimeout(() => {
let data = {}
data.sqlKey = this.sqlExecutorId
data.sourceId = this.sqlDataSource
data.sqlText = this.sqlText
runData(data).then(response => {
if (response.success) {
const { data } = response
let resultStr = ''
for (let i = 0; i < this.sqlConsole.length; i++) {
let item = this.sqlConsole[i]
for (let i = 0; i < data.length; i++) {
let item = data[i]
resultStr += item.sql
resultStr += '\n> 状态:' + ((item.success) ? '成功' : '失败')
if (item.count && item.count >= 0) {
......@@ -120,20 +145,29 @@ export default {
resultStr += '\n> 耗时:' + (item.time || 0) / 1000 + 's'
resultStr += '\n\n'
}
// console.log(Object.keys(list[0]))
this.executeResultInfo = resultStr
this.sqlConsole = data
this.sqlExecuting = false
}, 2000)
}
})
},
stopData () {
let data = {}
data.sqlKey = this.sqlExecutorId
stopData(data).then(response => {
if (response.success) {
this.sqlExecuting = false
this.$message.success('停止成功')
} else {
this.$message.error('停止失败')
}
})
},
changeTextarea (val) {
this.sqlText = val
},
formaterSql () {
let sqleditor = this.$refs.sqleditor
sqleditor.editor.setValue(sqlFormatter.format(sqleditor.editor.getValue()))
this.$refs.sqleditor.editor.setValue(sqlFormatter.format(this.$refs.sqleditor.editor.getValue()))
},
refreshData () {
this.sqlExecuting = false
......@@ -142,6 +176,7 @@ export default {
this.sqlText = ''
this.$refs.sqleditor.editor.setValue('')
this.sqlConsole = []
this.executeResultInfo = ''
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment