Commit 4f494223 by yuwei

2.0.0项目初始化

parent d99fc897
...@@ -15,5 +15,6 @@ public class SqlConsoleVo implements Serializable { ...@@ -15,5 +15,6 @@ public class SqlConsoleVo implements Serializable {
private Long time; private Long time;
private Boolean success; private Boolean success;
private Integer count; 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; ...@@ -3,13 +3,8 @@ package cn.datax.service.data.factory.sql.console.concurrent;
import cn.datax.service.data.factory.api.vo.SqlConsoleVo; import cn.datax.service.data.factory.api.vo.SqlConsoleVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.Reader;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@Slf4j @Slf4j
...@@ -34,7 +29,8 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> { ...@@ -34,7 +29,8 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
Statement stmt = null; Statement stmt = null;
ResultSet rs = 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; Integer updateCount = null;
SqlConsoleVo sqlConsoleVo = new SqlConsoleVo(); SqlConsoleVo sqlConsoleVo = new SqlConsoleVo();
...@@ -59,6 +55,7 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> { ...@@ -59,6 +55,7 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
for (int i = 1; i <= colunmCount; i++) { for (int i = 1; i <= colunmCount; i++) {
// 获取列名 // 获取列名
String columnName = rsmd.getColumnName(i); String columnName = rsmd.getColumnName(i);
columnList.add(columnName);
Object val = null; Object val = null;
switch (rsmd.getColumnType(i)) { switch (rsmd.getColumnType(i)) {
case Types.ARRAY: case Types.ARRAY:
...@@ -127,7 +124,7 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> { ...@@ -127,7 +124,7 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
} }
map.put(columnName, val); map.put(columnName, val);
} }
list.add(map); dataList.add(map);
} }
} else { } else {
// 执行新增、修改、删除受影响行数 // 执行新增、修改、删除受影响行数
...@@ -167,7 +164,8 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> { ...@@ -167,7 +164,8 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
log.info("线程查询数据用时:" + (end - start) + "ms"); log.info("线程查询数据用时:" + (end - start) + "ms");
sqlConsoleVo.setSql(sql); sqlConsoleVo.setSql(sql);
sqlConsoleVo.setCount(updateCount); sqlConsoleVo.setCount(updateCount);
sqlConsoleVo.setData(list); sqlConsoleVo.setColumnList(columnList);
sqlConsoleVo.setDataList(dataList);
sqlConsoleVo.setTime(end - start); sqlConsoleVo.setTime(end - start);
return sqlConsoleVo; 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 @@ ...@@ -9,7 +9,7 @@
<el-col :span="24"> <el-col :span="24">
<el-button size="mini" round @click="runData" :disabled="sqlExecuting">运行</el-button> <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="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-button size="mini" round @click="refreshData" :disabled="sqlExecuting">重置</el-button>
</el-col> </el-col>
</el-row> </el-row>
...@@ -46,7 +46,24 @@ ...@@ -46,7 +46,24 @@
<pre>{{executeResultInfo}}</pre> <pre>{{executeResultInfo}}</pre>
</el-tab-pane> </el-tab-pane>
<el-tab-pane v-for="(item,index) in sqlConsole" :key="(index+1)" :name="'table'+(index+1)" :label="'结果'+(index+1)"> <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-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
...@@ -62,6 +79,7 @@ ...@@ -62,6 +79,7 @@
import sqlFormatter from 'sql-formatter' import sqlFormatter from 'sql-formatter'
import SqlEditor from '@/components/SqlEditor' import SqlEditor from '@/components/SqlEditor'
import { listDataSource } from '@/api/factory/datasource' import { listDataSource } from '@/api/factory/datasource'
import { runData, stopData } from '@/api/factory/dataconsole'
export default { export default {
name: 'SqlConsole', name: 'SqlConsole',
...@@ -98,42 +116,58 @@ export default { ...@@ -98,42 +116,58 @@ export default {
}) })
}, },
runData () { runData () {
if (!this.sqlDataSource) {
this.$message.error("数据源不能为空")
return
}
if (!this.sqlText) {
this.$message.error("查询SQL不能为空")
return
}
this.sqlExecuting = true this.sqlExecuting = true
this.sqlExecutorId = (new Date()).getTime() this.sqlExecutorId = (new Date()).getTime() + Math.ceil(Math.random() * 1000)
this.sqlConsole = [] this.sqlConsole = []
this.sqlConsole.push({ let data = {}
sql: 'sql', data.sqlKey = this.sqlExecutorId
time: 20, data.sourceId = this.sqlDataSource
success: true, data.sqlText = this.sqlText
count: 3, runData(data).then(response => {
name: 'name' if (response.success) {
}) const { data } = response
setTimeout(() => { let resultStr = ''
let resultStr = '' for (let i = 0; i < data.length; i++) {
for (let i = 0; i < this.sqlConsole.length; i++) { let item = data[i]
let item = this.sqlConsole[i] resultStr += item.sql
resultStr += item.sql resultStr += '\n> 状态:' + ((item.success) ? '成功' : '失败')
resultStr += '\n> 状态:' + ((item.success) ? '成功' : '失败') if (item.count && item.count >= 0) {
if (item.count && item.count >= 0) { resultStr += '\n> 影响行数:' + item.count
resultStr += '\n> 影响行数:' + item.count }
resultStr += '\n> 耗时:' + (item.time || 0) / 1000 + 's'
resultStr += '\n\n'
} }
resultStr += '\n> 耗时:' + (item.time || 0) / 1000 + 's' this.executeResultInfo = resultStr
resultStr += '\n\n' this.sqlConsole = data
this.sqlExecuting = false
} }
// console.log(Object.keys(list[0])) })
this.executeResultInfo = resultStr
this.sqlExecuting = false
}, 2000)
}, },
stopData () { stopData () {
this.sqlExecuting = false 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) { changeTextarea (val) {
this.sqlText = val this.sqlText = val
}, },
formaterSql () { formaterSql () {
let sqleditor = this.$refs.sqleditor this.$refs.sqleditor.editor.setValue(sqlFormatter.format(this.$refs.sqleditor.editor.getValue()))
sqleditor.editor.setValue(sqlFormatter.format(sqleditor.editor.getValue()))
}, },
refreshData () { refreshData () {
this.sqlExecuting = false this.sqlExecuting = false
...@@ -142,6 +176,7 @@ export default { ...@@ -142,6 +176,7 @@ export default {
this.sqlText = '' this.sqlText = ''
this.$refs.sqleditor.editor.setValue('') this.$refs.sqleditor.editor.setValue('')
this.sqlConsole = [] 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