提交 7056db3b authored 作者: junjie's avatar junjie

feat(数据集): 数据库表:mysql直连模式,表字段 类型 数据 读取展示

上级 9272a0b9
...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @Author gin * @Author gin
...@@ -50,7 +51,12 @@ public class DataSetTableController { ...@@ -50,7 +51,12 @@ public class DataSetTableController {
} }
@PostMapping("getData") @PostMapping("getData")
public List<Object> getData(@RequestBody DataSetTableRequest dataSetTableRequest) throws Exception { public List<String[]> getData(@RequestBody DataSetTableRequest dataSetTableRequest) throws Exception {
return dataSetTableService.getData(dataSetTableRequest); return dataSetTableService.getData(dataSetTableRequest);
} }
@PostMapping("getPreviewData")
public Map<String, Object> getPreviewData(@RequestBody DataSetTableRequest dataSetTableRequest) throws Exception {
return dataSetTableService.getPreviewData(dataSetTableRequest);
}
} }
...@@ -19,7 +19,9 @@ import org.apache.commons.lang3.StringUtils; ...@@ -19,7 +19,9 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @Author gin * @Author gin
...@@ -80,15 +82,26 @@ public class DataSetTableService { ...@@ -80,15 +82,26 @@ public class DataSetTableService {
return datasourceProvider.getTableFileds(datasourceRequest); return datasourceProvider.getTableFileds(datasourceRequest);
} }
public List<Object> getData(DataSetTableRequest dataSetTableRequest) throws Exception { public List<String[]> getData(DataSetTableRequest dataSetTableRequest) throws Exception {
Datasource ds = datasourceMapper.selectByPrimaryKey(dataSetTableRequest.getDataSourceId()); Datasource ds = datasourceMapper.selectByPrimaryKey(dataSetTableRequest.getDataSourceId());
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType()); DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest(); DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(ds); datasourceRequest.setDatasource(ds);
String table = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getTable(); String table = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getTable();
datasourceRequest.setQuery("SELECT * FROM " + table + " LIMIT 0,100;"); datasourceRequest.setQuery("SELECT * FROM " + table + ";");
return datasourceProvider.getData(datasourceRequest);
}
public Map<String, Object> getPreviewData(DataSetTableRequest dataSetTableRequest) throws Exception {
Datasource ds = datasourceMapper.selectByPrimaryKey(dataSetTableRequest.getDataSourceId());
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(ds);
String table = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getTable();
datasourceRequest.setTable(table);
datasourceRequest.setQuery("SELECT * FROM " + table + " LIMIT 0,10;");
List<TableFiled> fields = getFields(dataSetTableRequest); List<TableFiled> fields = datasourceProvider.getTableFileds(datasourceRequest);
List<String[]> data = datasourceProvider.getData(datasourceRequest); List<String[]> data = datasourceProvider.getData(datasourceRequest);
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
...@@ -100,6 +113,10 @@ public class DataSetTableService { ...@@ -100,6 +113,10 @@ public class DataSetTableService {
jsonArray.add(jsonObject); jsonArray.add(jsonObject);
}); });
return jsonArray; Map<String, Object> map = new HashMap<>();
map.put("fields",fields);
map.put("data",jsonArray);
return map;
} }
} }
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-row> </el-row>
<el-row> <el-row style="overflow: auto;height: 600px;">
<el-checkbox-group v-model="checkTableList" size="small"> <el-checkbox-group v-model="checkTableList" size="small">
<el-checkbox <el-checkbox
border border
......
...@@ -53,6 +53,7 @@ export default { ...@@ -53,6 +53,7 @@ export default {
}, },
computed: { computed: {
tableId() { tableId() {
console.log(this.$store.state.dataset.table);
this.initTable(this.$store.state.dataset.table); this.initTable(this.$store.state.dataset.table);
return this.$store.state.dataset.table; return this.$store.state.dataset.table;
} }
...@@ -70,29 +71,33 @@ export default { ...@@ -70,29 +71,33 @@ export default {
initTable(id) { initTable(id) {
console.log(id); console.log(id);
if (id !== null) { if (id !== null) {
this.fields = [];
this.data = []; this.data = [];
this.$post('/dataset/table/get/' + id, null, response => { this.$post('/dataset/table/get/' + id, null, response => {
this.table = response.data; this.table = response.data;
this.initTableFields(); this.initPreviewData();
}) })
} }
}, },
initPreviewData() {
if (this.table.id) {
this.$post('/dataset/table/getPreviewData', this.table, response => {
this.fields = response.data.fields;
this.data = response.data.data;
});
}
},
initTableFields() { initTableFields() {
if (this.table.id) { if (this.table.id) {
this.$post('/dataset/table/getFields', this.table, response => { this.$post('/dataset/table/getFields', this.table, response => {
// console.log(response.data);
this.fields = response.data;
this.initTableData();
}); });
} }
}, },
initTableData() { initTableData() {
if (this.table.id) { if (this.table.id) {
this.$post('/dataset/table/getData', this.table, response => { this.$post('/dataset/table/getData', this.table, response => {
// console.log(response.data);
this.data = response.data;
console.log(this.data)
}); });
} }
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论