feat(数据集): 数据库表:mysql直连模式,表字段 类型 数据 读取展示
This commit is contained in:
parent
9272a0b954
commit
7056db3b53
@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
@ -50,7 +51,12 @@ public class DataSetTableController {
|
||||
}
|
||||
|
||||
@PostMapping("getData")
|
||||
public List<Object> getData(@RequestBody DataSetTableRequest dataSetTableRequest) throws Exception {
|
||||
public List<String[]> getData(@RequestBody DataSetTableRequest dataSetTableRequest) throws Exception {
|
||||
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;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
@ -80,15 +82,26 @@ public class DataSetTableService {
|
||||
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());
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(ds);
|
||||
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);
|
||||
}
|
||||
|
||||
List<TableFiled> fields = getFields(dataSetTableRequest);
|
||||
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 = datasourceProvider.getTableFileds(datasourceRequest);
|
||||
List<String[]> data = datasourceProvider.getData(datasourceRequest);
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
@ -100,6 +113,10 @@ public class DataSetTableService {
|
||||
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 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-row style="overflow: auto;height: 600px;">
|
||||
<el-checkbox-group v-model="checkTableList" size="small">
|
||||
<el-checkbox
|
||||
border
|
||||
|
||||
@ -53,6 +53,7 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
tableId() {
|
||||
console.log(this.$store.state.dataset.table);
|
||||
this.initTable(this.$store.state.dataset.table);
|
||||
return this.$store.state.dataset.table;
|
||||
}
|
||||
@ -70,29 +71,33 @@ export default {
|
||||
initTable(id) {
|
||||
console.log(id);
|
||||
if (id !== null) {
|
||||
this.fields = [];
|
||||
this.data = [];
|
||||
this.$post('/dataset/table/get/' + id, null, response => {
|
||||
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() {
|
||||
if (this.table.id) {
|
||||
this.$post('/dataset/table/getFields', this.table, response => {
|
||||
// console.log(response.data);
|
||||
this.fields = response.data;
|
||||
this.initTableData();
|
||||
});
|
||||
}
|
||||
},
|
||||
initTableData() {
|
||||
if (this.table.id) {
|
||||
this.$post('/dataset/table/getData', this.table, response => {
|
||||
// console.log(response.data);
|
||||
this.data = response.data;
|
||||
console.log(this.data)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user