Commit d99fc897 by yuwei

2.0.0项目初始化

parent 9a857bbd
......@@ -9,6 +9,6 @@ import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(contextId = "dataSourceServiceFeign", value = "datax-service-data-factory", fallbackFactory = DataSourceServiceFeignFallbackFactory.class)
public interface DataSourceServiceFeign {
@GetMapping("/dataSource/{id}")
@GetMapping("/dataSources/{id}")
R getDataSourceById(@PathVariable("id") String id);
}
......@@ -3,6 +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;
......@@ -52,20 +54,78 @@ public class DateHander extends CallableTemplate<SqlConsoleVo> {
ResultSetMetaData rsmd = rs.getMetaData();
// 获取列字段的个数
int colunmCount = rsmd.getColumnCount();
// 存储列名的数组
String[] columnNames = new String[colunmCount];
for (int i = 0; i < colunmCount; i++) {
// 获取所有的字段名称
columnNames[i] = rsmd.getColumnLabel(i + 1);
}
while(rs.next()){
Map<String, Object> map = new HashMap<>();
for (int i = 0; i < colunmCount; i++) {
for (int i = 1; i <= colunmCount; i++) {
// 获取列名
String columnName = columnNames[i];
// 获取该列对应的值
Object value = rs.getObject(columnName);
map.put(columnName, value);
String columnName = rsmd.getColumnName(i);
Object val = null;
switch (rsmd.getColumnType(i)) {
case Types.ARRAY:
val = rs.getArray(columnName);
break;
case Types.BIGINT:
val = rs.getLong(columnName);
break;
case Types.BOOLEAN:
case Types.BIT:
val = rs.getBoolean(columnName);
break;
case Types.DOUBLE:
val = rs.getDouble(columnName);
break;
case Types.FLOAT:
case Types.REAL:
val = rs.getFloat(columnName);
break;
case Types.INTEGER:
val = rs.getInt(columnName);
break;
case Types.NVARCHAR:
case Types.NCHAR:
case Types.LONGNVARCHAR:
val = rs.getNString(columnName);
break;
case Types.VARCHAR:
case Types.CHAR:
case Types.LONGVARCHAR:
val = rs.getString(columnName);
break;
case Types.TINYINT:
case Types.BINARY:
case Types.VARBINARY:
val = rs.getByte(columnName);
break;
case Types.SMALLINT:
val = rs.getShort(columnName);
break;
case Types.DATE:
val = rs.getDate(columnName);
break;
case Types.TIME:
val = rs.getTime(columnName);
break;
case Types.TIMESTAMP:
val = rs.getTimestamp(columnName);
break;
case Types.NUMERIC:
case Types.DECIMAL:
val = rs.getBigDecimal(columnName);
break;
case Types.BLOB:
case Types.CLOB:
case Types.LONGVARBINARY:
case Types.DATALINK:
case Types.REF:
case Types.STRUCT:
case Types.DISTINCT:
case Types.JAVA_OBJECT:
break;
default:
val = rs.getObject(columnName);
break;
}
map.put(columnName, val);
}
list.add(map);
}
......
......@@ -16,7 +16,8 @@ import cn.datax.service.data.factory.sql.console.concurrent.DateHander;
import cn.datax.service.data.factory.sql.console.service.SqlConsoleService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
......@@ -42,6 +43,9 @@ public class SqlConsoleServiceImpl implements SqlConsoleService {
@Autowired
private DataSourceServiceFeign dataSourceServiceFeign;
@Autowired
private ObjectMapper objectMapper;
private static Map<String, List<Connection>> connectionMap = new ConcurrentHashMap<>();
@Override
......@@ -62,7 +66,11 @@ public class SqlConsoleServiceImpl implements SqlConsoleService {
if(sourceResult == null || !sourceResult.isSuccess() || ObjectUtil.isEmpty(sourceResult.getData())){
throw new DataException("SQL工作台查询数据源出错");
}
DataSourceEntity dataSource = JSON.parseObject(JSON.toJSONString(sourceResult.getData()), DataSourceEntity.class);
DataSourceEntity dataSource = null;
try {
dataSource = objectMapper.readValue(objectMapper.writeValueAsString(sourceResult.getData()), DataSourceEntity.class);
} catch (JsonProcessingException e) {
}
DbSchema dbSchema = dataSource.getDbSchema();
DbQueryProperty dbQueryProperty = new DbQueryProperty(dataSource.getDbType(), dbSchema.getHost(),
dbSchema.getUsername(), dbSchema.getPassword(), dbSchema.getPort(), dbSchema.getDbName());
......
......@@ -15,6 +15,19 @@
</el-row>
<el-row>
<el-col :span="24">
<el-select v-model="sqlDataSource" placeholder="请选择数据源">
<el-option
v-for="source in sourceOptions"
:key="source.id"
:label="source.sourceName"
:value="source.id"
:disabled="source.status === '0'"
></el-option>
</el-select>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<sql-editor
ref="sqleditor"
:value="sqlText"
......@@ -48,6 +61,7 @@
<script>
import sqlFormatter from 'sql-formatter'
import SqlEditor from '@/components/SqlEditor'
import { listDataSource } from '@/api/factory/datasource'
export default {
name: 'SqlConsole',
......@@ -61,15 +75,28 @@ export default {
height: document.body.offsetHeight - 240 + 'px'
},
title: 'SQL工作台',
// 数据源数据字典
sourceOptions: [],
sqlDataSource: '',
sqlText: '',
sqlExecuting: false,
activeTabName: 'table0',
sqlExecutorId: undefined,
sqlText: '',
sqlConsole: [],
executeResultInfo: ''
}
},
created () {
this.getDataSourceList()
},
methods: {
getDataSourceList () {
listDataSource().then(response => {
if (response.success) {
this.sourceOptions = response.data
}
})
},
runData () {
this.sqlExecuting = true
this.sqlExecutorId = (new Date()).getTime()
......
......@@ -166,7 +166,7 @@ export default {
this.statusOptions = response.data
}
})
this.getConfigKey('sys.user.initPassword').then(response => {
this.getConfigKey('sys.user.password').then(response => {
if (response.success) {
this.initPassword = response.data
this.form.password = this.initPassword
......
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