Merge pull request #223 from dataease/pr@dev@feat_excel上传后可修改字段类型再保存

feat: excel上传后可编辑字段类型再保存
This commit is contained in:
XiaJunjie2020 2021-07-13 12:33:13 +08:00 committed by GitHub
commit 0188ca497c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package io.dataease.controller.request.dataset;
import io.dataease.base.domain.DatasetTable;
import io.dataease.datasource.dto.TableFiled;
import lombok.Getter;
import lombok.Setter;
@ -21,4 +22,5 @@ public class DataSetTableRequest extends DatasetTable {
private Integer editType;
private Boolean isRename;
private List<String> typeFilter;
private List<TableFiled> fields;
}

View File

@ -97,7 +97,7 @@ public class DataSetTableService {
}
}
private void extractData(DataSetTableRequest datasetTable) throws Exception{
private void extractData(DataSetTableRequest datasetTable) throws Exception {
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) {
commonThreadPool.addTask(() -> {
extractDataService.extractExcelData(datasetTable.getId(), "all_scope");
@ -154,7 +154,7 @@ public class DataSetTableService {
});
} else if (datasetTable.getEditType() == 1) {
commonThreadPool.addTask(() -> {
extractDataService.extractExcelData(datasetTable.getId(), "add_scope");
extractDataService.extractExcelData(datasetTable.getId(), "add_scope");
});
}
}
@ -664,11 +664,12 @@ public class DataSetTableService {
datasourceRequest.setQuery(sqlAsTable);
fields = datasourceProvider.fetchResultField(datasourceRequest);
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) {
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
/*DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
String path = dataTableInfoDTO.getData();
File file = new File(path);
Map<String, Object> map = parseExcel(path.substring(path.lastIndexOf("/") + 1), new FileInputStream(file), false);
fields = (List<TableFiled>) map.get("fields");
fields = (List<TableFiled>) map.get("fields");*/
fields = dataSetTableRequest.getFields();
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
// save field
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
@ -882,7 +883,7 @@ public class DataSetTableService {
String filename = file.getOriginalFilename();
// parse file
Map<String, Object> fileMap = parseExcel(filename, file.getInputStream(), true);
if(StringUtils.isNotEmpty(tableId)){
if (StringUtils.isNotEmpty(tableId)) {
List<DatasetTableField> datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(tableId);
datasetTableFields.sort((o1, o2) -> {
if (o1.getColumnIndex() == null) {
@ -893,9 +894,9 @@ public class DataSetTableService {
}
return o1.getColumnIndex().compareTo(o2.getColumnIndex());
});
List<TableFiled> fields = (List<TableFiled>)fileMap.get("fields");
List<TableFiled> fields = (List<TableFiled>) fileMap.get("fields");
List<String> newFields = fields.stream().map(TableFiled::getRemarks).collect(Collectors.toList());
List<String> oldFields = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList());
List<String> oldFields = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList());
if (!oldFields.equals(newFields)) {
DataEaseException.throwException(Translator.get("i18n_excel_colume_change"));
}
@ -1073,7 +1074,7 @@ public class DataSetTableService {
double eps = 1e-10;
if (value - Math.floor(value) < eps) {
if (cellType) {
if (StringUtils.isEmpty(tableFiled.getFieldType()) || tableFiled.getFieldType().equalsIgnoreCase("TEXT")){
if (StringUtils.isEmpty(tableFiled.getFieldType()) || tableFiled.getFieldType().equalsIgnoreCase("TEXT")) {
tableFiled.setFieldType("LONG");
}
}
@ -1124,7 +1125,7 @@ public class DataSetTableService {
double eps = 1e-10;
if (value - Math.floor(value) < eps) {
if (cellType) {
if (StringUtils.isEmpty(tableFiled.getFieldType()) || tableFiled.getFieldType().equalsIgnoreCase("TEXT")){
if (StringUtils.isEmpty(tableFiled.getFieldType()) || tableFiled.getFieldType().equalsIgnoreCase("TEXT")) {
tableFiled.setFieldType("LONG");
}
}

View File

@ -69,7 +69,52 @@
:field="field.fieldName"
:title="field.remarks"
:resizable="true"
/>
>
<template slot="header" slot-scope="scope">
<span v-if="!param.tableId" style="display: flex;align-items: center;">
<span style="display: inline-block;font-size: 12px;">
<div style="display: inline-block;">
<el-select v-model="field.fieldType" size="mini" style="display: inline-block;width: 120px;">
<el-option
v-for="item in fieldOptions"
:key="item.value"
:label="item.label"
:value="item.value"
>
<span style="float: left">
<svg-icon v-if="item.value === 'TEXT'" icon-class="field_text" class="field-icon-text" />
<svg-icon v-if="item.value === 'DATETIME'" icon-class="field_time" class="field-icon-time" />
<svg-icon v-if="item.value === 'LONG' || item.value === 'DOUBLE'" icon-class="field_value" class="field-icon-value" />
</span>
<span style="float: left; color: #8492a6; font-size: 12px">{{ item.label }}</span>
</el-option>
</el-select>
</div>
<!-- <span style="margin-left: 8px;">-->
<!-- <span v-if="field.fieldType === 'TEXT'">-->
<!-- <svg-icon v-if="field.fieldType === 'TEXT'" icon-class="field_text" class="field-icon-text" />-->
<!-- <span class="field-class">{{ $t('dataset.text') }}</span>-->
<!-- </span>-->
<!-- <span v-if="field.fieldType === 'DATETIME'">-->
<!-- <svg-icon v-if="field.fieldType === 'DATETIME'" icon-class="field_time" class="field-icon-time" />-->
<!-- <span class="field-class">{{ $t('dataset.time') }}</span>-->
<!-- </span>-->
<!-- <span v-if="field.fieldType === 'LONG' || field.fieldType === 'DOUBLE'">-->
<!-- <svg-icon v-if="field.fieldType === 'LONG' || field.fieldType === 'DOUBLE'" icon-class="field_value" class="field-icon-value" />-->
<!-- <span v-if="field.fieldType === 'LONG'" class="field-class">{{ $t('dataset.value') }}</span>-->
<!-- <span v-if="field.fieldType === 'DOUBLE'" class="field-class">{{ $t('dataset.value') + '(' + $t('dataset.float') + ')' }}</span>-->
<!-- </span>-->
<!-- </span>-->
</span>
<span style="font-size: 12px;margin-left: 10px;">
{{ field.remarks }}
</span>
</span>
<span v-else style="font-size: 12px;">
{{ field.remarks }}
</span>
</template>
</ux-table-column>
</ux-grid>
</div>
</el-card>
@ -109,7 +154,13 @@ export default {
headers: { Authorization: token, 'Accept-Language': i18n.locale.replace('_', '-') },
baseUrl: process.env.VUE_APP_BASE_API,
path: '',
uploading: false
uploading: false,
fieldOptions: [
{ label: this.$t('dataset.text'), value: 'TEXT' },
{ label: this.$t('dataset.time'), value: 'DATETIME' },
{ label: this.$t('dataset.value'), value: 'LONG' },
{ label: this.$t('dataset.value') + '(' + this.$t('dataset.float') + ')', value: 'DOUBLE' }
]
}
},
watch: {
@ -207,7 +258,8 @@ export default {
type: 'excel',
mode: parseInt(this.mode),
// info: '{"data":"' + this.path + '"}',
info: JSON.stringify({ data: this.path })
info: JSON.stringify({ data: this.path }),
fields: this.fields
}
} else {
table = {