feat(数据集): 表字段抽象,字段编辑、选择

This commit is contained in:
junjie 2021-02-24 18:06:21 +08:00
parent ab8d232169
commit 32502591df
2 changed files with 20 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import io.dataease.base.mapper.DatasourceMapper;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.SessionUtils;
import io.dataease.controller.request.dataset.DataSetTableRequest;
import io.dataease.datasource.constants.DatasourceTypes;
import io.dataease.datasource.dto.TableFiled;
import io.dataease.datasource.provider.DatasourceProvider;
import io.dataease.datasource.provider.ProviderFactory;
@ -21,9 +22,11 @@ import io.dataease.dto.dataset.DataTableInfoDTO;
import jnr.ffi.Struct;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.python.apache.xerces.xs.StringList;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -99,7 +102,7 @@ public class DataSetTableService {
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(ds);
String table = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getTable();
datasourceRequest.setQuery("SELECT * FROM " + table + ";");
datasourceRequest.setQuery(createQuerySQL(ds.getType(), table, new String[]{"*"}));
return datasourceProvider.getData(datasourceRequest);
}
@ -117,7 +120,8 @@ public class DataSetTableService {
List<DatasetTableField> fields = dataSetTableFieldsService.list(datasetTableField);
String[] fieldArray = fields.stream().map(DatasetTableField::getOriginName).toArray(String[]::new);
datasourceRequest.setQuery("SELECT " + StringUtils.join(fieldArray, ",") + " FROM " + table + " LIMIT 0,10;");
// datasourceRequest.setQuery("SELECT " + StringUtils.join(fieldArray, ",") + " FROM " + table + " LIMIT 0,10;");
datasourceRequest.setQuery(createQuerySQL(ds.getType(), table, fieldArray) + " LIMIT 0,10;");
List<String[]> data = new ArrayList<>();
try {
@ -163,4 +167,16 @@ public class DataSetTableService {
}
}
}
public String createQuerySQL(String type, String table, String[] fields) {
DatasourceTypes datasourceType = DatasourceTypes.valueOf(type);
switch (datasourceType) {
case mysql:
return MessageFormat.format("SELECT {0} FROM {1}", StringUtils.join(fields, ","), table);
case sqlServer:
return MessageFormat.format("SELECT {0} FROM {1}", StringUtils.join(fields, ","), table);
default:
return MessageFormat.format("SELECT {0} FROM {1}", StringUtils.join(fields, ","), table);
}
}
}

View File

@ -36,12 +36,12 @@
<el-table :data="tableFields" size="mini" max-height="600px">
<el-table-column property="type" :label="$t('dataset.field_type')" width="100">
</el-table-column>
<el-table-column property="name" :label="$t('dataset.field_name')" width="160">
<el-table-column property="name" :label="$t('dataset.field_name')" width="180">
<template slot-scope="scope">
<el-input v-model="scope.row.name" size="mini"></el-input>
</template>
</el-table-column>
<el-table-column property="originName" :label="$t('dataset.field_origin_name')" width="160">
<el-table-column property="originName" :label="$t('dataset.field_origin_name')" width="180">
</el-table-column>
<el-table-column property="checked" :label="$t('dataset.field_check')" width="80">
<template slot-scope="scope">