forked from github/dataease
Merge pull request #12948 from dataease/dev-v2@fixexportdata
Dev v2@fixexportdata
This commit is contained in:
commit
3caee0b795
@ -15,6 +15,7 @@ import io.dataease.api.ds.vo.ExcelSheetData;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.extensions.datasource.dto.DatasetTableDTO;
|
||||
import io.dataease.extensions.datasource.dto.DatasourceDTO;
|
||||
import io.dataease.extensions.datasource.dto.DatasourceRequest;
|
||||
import io.dataease.extensions.datasource.dto.TableField;
|
||||
import io.dataease.utils.AuthUtils;
|
||||
@ -40,6 +41,21 @@ public class ExcelUtils {
|
||||
private static TypeReference<List<TableField>> TableFieldListTypeReference = new TypeReference<List<TableField>>() {
|
||||
};
|
||||
|
||||
private static TypeReference<List<ExcelSheetData>> sheets = new TypeReference<List<ExcelSheetData>>() {
|
||||
};
|
||||
|
||||
public static void mergeSheets(CoreDatasource requestDatasource, DatasourceDTO sourceData) {
|
||||
List<ExcelSheetData> newSheets = JsonUtil.parseList(requestDatasource.getConfiguration(), sheets);
|
||||
List<String> tableNames = newSheets.stream().map(ExcelSheetData::getDeTableName).collect(Collectors.toList());
|
||||
List<ExcelSheetData> oldSheets = JsonUtil.parseList(sourceData.getConfiguration(), sheets);
|
||||
for (ExcelSheetData oldSheet : oldSheets) {
|
||||
if (!tableNames.contains(oldSheet.getDeTableName())) {
|
||||
newSheets.add(oldSheet);
|
||||
}
|
||||
}
|
||||
requestDatasource.setConfiguration(JsonUtil.toJSONString(newSheets).toString());
|
||||
}
|
||||
|
||||
public static List<DatasetTableDTO> getTables(DatasourceRequest datasourceRequest) throws DEException {
|
||||
List<DatasetTableDTO> tableDescs = new ArrayList<>();
|
||||
try {
|
||||
|
@ -404,7 +404,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
List<String> tables = ExcelUtils.getTables(datasourceRequest).stream().map(DatasetTableDTO::getTableName).collect(Collectors.toList());
|
||||
if (dataSourceDTO.getEditType() == 0) {
|
||||
toCreateTables = tables;
|
||||
toDeleteTables = sourceTables;
|
||||
toDeleteTables = sourceTables.stream().filter(s -> tables.contains(s)).collect(Collectors.toList());
|
||||
for (String deleteTable : toDeleteTables) {
|
||||
try {
|
||||
datasourceSyncManage.dropEngineTable(deleteTable);
|
||||
@ -422,6 +422,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
datasourceSyncManage.extractExcelData(requestDatasource, "all_scope");
|
||||
dataSourceManage.checkName(dataSourceDTO);
|
||||
ExcelUtils.mergeSheets(requestDatasource, sourceData);
|
||||
dataSourceManage.innerEdit(requestDatasource);
|
||||
} else {
|
||||
datasourceSyncManage.extractExcelData(requestDatasource, "add_scope");
|
||||
@ -735,11 +736,15 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Integer replace = 0;
|
||||
private static final Integer append = 1;
|
||||
|
||||
public ExcelFileData excelUpload(@RequestParam("file") MultipartFile file, @RequestParam("id") long datasourceId, @RequestParam("editType") Integer editType) throws DEException {
|
||||
CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId);
|
||||
|
||||
ExcelUtils excelUtils = new ExcelUtils();
|
||||
ExcelFileData excelFileData = excelUtils.excelSaveAndParse(file);
|
||||
if (editType == 1 || editType == 0) { //按照excel sheet 名称匹配
|
||||
CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId);
|
||||
if (Objects.equals(editType, append)) { //按照excel sheet 名称匹配,替换:0;追加:1
|
||||
if (coreDatasource != null) {
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(transDTO(coreDatasource));
|
||||
@ -757,7 +762,6 @@ public class DatasourceServer implements DatasourceApi {
|
||||
oldTableFields.sort((o1, o2) -> {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
});
|
||||
|
||||
if (isEqual(newTableFields, oldTableFields)) {
|
||||
sheet.setDeTableName(datasetTableDTO.getTableName());
|
||||
excelSheetDataList.add(sheet);
|
||||
@ -770,8 +774,21 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
excelFileData.setSheets(excelSheetDataList);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (coreDatasource != null) {
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(transDTO(coreDatasource));
|
||||
List<DatasetTableDTO> datasetTableDTOS = ExcelUtils.getTables(datasourceRequest);
|
||||
for (ExcelSheetData sheet : excelFileData.getSheets()) {
|
||||
for (DatasetTableDTO datasetTableDTO : datasetTableDTOS) {
|
||||
if (excelDataTableName(datasetTableDTO.getTableName()).equals(sheet.getTableName()) || isCsv(file.getOriginalFilename())) {
|
||||
sheet.setDeTableName(datasetTableDTO.getTableName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
for (ExcelSheetData sheet : excelFileData.getSheets()) {
|
||||
for (int i = 0; i < sheet.getFields().size() - 1; i++) {
|
||||
for (int j = i + 1; j < sheet.getFields().size(); j++) {
|
||||
@ -1155,8 +1172,11 @@ public class DatasourceServer implements DatasourceApi {
|
||||
if (!Arrays.asList("API", "Excel", "folder").contains(coreDatasource.getType())) {
|
||||
calciteProvider.updateDsPoolAfterCheckStatus(datasourceDTO);
|
||||
}
|
||||
} catch (DEException e) {
|
||||
datasourceDTO.setStatus("Error");
|
||||
DEException.throwException(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
coreDatasource.setStatus("Error");
|
||||
datasourceDTO.setStatus("Error");
|
||||
DEException.throwException(e.getMessage());
|
||||
} finally {
|
||||
coreDatasource.setStatus(datasourceDTO.getStatus());
|
||||
|
@ -380,7 +380,6 @@ const initSearch = () => {
|
||||
state.filterTable = tableData.value.filter(ele =>
|
||||
ele.tableName.toLowerCase().includes(nickName.value.toLowerCase())
|
||||
)
|
||||
console.log(tableData.value)
|
||||
state.paginationConfig.total = state.filterTable.length
|
||||
}
|
||||
|
||||
@ -867,7 +866,6 @@ const operation = (cmd: string, data: Tree, nodeType: string) => {
|
||||
}
|
||||
|
||||
const handleClick = (tabName: TabPaneName) => {
|
||||
console.log(tabName)
|
||||
switch (tabName) {
|
||||
case 'config':
|
||||
listDatasourceTables({ datasourceId: nodeInfo.id }).then(res => {
|
||||
@ -1091,8 +1089,22 @@ const getMenuList = (val: boolean) => {
|
||||
:title="node.label"
|
||||
class="label-tooltip ellipsis"
|
||||
:class="data.type === 'Excel' && 'excel'"
|
||||
v-if="data.extraFlag > -1"
|
||||
>{{ node.label }}</span
|
||||
>
|
||||
<el-tooltip
|
||||
effect="dark"
|
||||
v-else
|
||||
:content="`${t('data_set.invalid_data_source')}: ${node.label}`"
|
||||
placement="top"
|
||||
>
|
||||
<span
|
||||
:title="node.label"
|
||||
class="label-tooltip ellipsis"
|
||||
:class="data.type === 'Excel' && 'excel'"
|
||||
>{{ node.label }}</span
|
||||
>
|
||||
</el-tooltip>
|
||||
<div class="icon-more" v-if="data.weight >= 7">
|
||||
<handle-more
|
||||
icon-size="24px"
|
||||
|
Loading…
Reference in New Issue
Block a user