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.datasource.dao.auto.entity.CoreDatasource;
|
||||||
import io.dataease.exception.DEException;
|
import io.dataease.exception.DEException;
|
||||||
import io.dataease.extensions.datasource.dto.DatasetTableDTO;
|
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.DatasourceRequest;
|
||||||
import io.dataease.extensions.datasource.dto.TableField;
|
import io.dataease.extensions.datasource.dto.TableField;
|
||||||
import io.dataease.utils.AuthUtils;
|
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<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 {
|
public static List<DatasetTableDTO> getTables(DatasourceRequest datasourceRequest) throws DEException {
|
||||||
List<DatasetTableDTO> tableDescs = new ArrayList<>();
|
List<DatasetTableDTO> tableDescs = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
@ -404,7 +404,7 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
List<String> tables = ExcelUtils.getTables(datasourceRequest).stream().map(DatasetTableDTO::getTableName).collect(Collectors.toList());
|
List<String> tables = ExcelUtils.getTables(datasourceRequest).stream().map(DatasetTableDTO::getTableName).collect(Collectors.toList());
|
||||||
if (dataSourceDTO.getEditType() == 0) {
|
if (dataSourceDTO.getEditType() == 0) {
|
||||||
toCreateTables = tables;
|
toCreateTables = tables;
|
||||||
toDeleteTables = sourceTables;
|
toDeleteTables = sourceTables.stream().filter(s -> tables.contains(s)).collect(Collectors.toList());
|
||||||
for (String deleteTable : toDeleteTables) {
|
for (String deleteTable : toDeleteTables) {
|
||||||
try {
|
try {
|
||||||
datasourceSyncManage.dropEngineTable(deleteTable);
|
datasourceSyncManage.dropEngineTable(deleteTable);
|
||||||
@ -422,6 +422,7 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
}
|
}
|
||||||
datasourceSyncManage.extractExcelData(requestDatasource, "all_scope");
|
datasourceSyncManage.extractExcelData(requestDatasource, "all_scope");
|
||||||
dataSourceManage.checkName(dataSourceDTO);
|
dataSourceManage.checkName(dataSourceDTO);
|
||||||
|
ExcelUtils.mergeSheets(requestDatasource, sourceData);
|
||||||
dataSourceManage.innerEdit(requestDatasource);
|
dataSourceManage.innerEdit(requestDatasource);
|
||||||
} else {
|
} else {
|
||||||
datasourceSyncManage.extractExcelData(requestDatasource, "add_scope");
|
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 {
|
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();
|
ExcelUtils excelUtils = new ExcelUtils();
|
||||||
ExcelFileData excelFileData = excelUtils.excelSaveAndParse(file);
|
ExcelFileData excelFileData = excelUtils.excelSaveAndParse(file);
|
||||||
if (editType == 1 || editType == 0) { //按照excel sheet 名称匹配
|
if (Objects.equals(editType, append)) { //按照excel sheet 名称匹配,替换:0;追加:1
|
||||||
CoreDatasource coreDatasource = datasourceMapper.selectById(datasourceId);
|
|
||||||
if (coreDatasource != null) {
|
if (coreDatasource != null) {
|
||||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||||
datasourceRequest.setDatasource(transDTO(coreDatasource));
|
datasourceRequest.setDatasource(transDTO(coreDatasource));
|
||||||
@ -757,7 +762,6 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
oldTableFields.sort((o1, o2) -> {
|
oldTableFields.sort((o1, o2) -> {
|
||||||
return o1.getName().compareTo(o2.getName());
|
return o1.getName().compareTo(o2.getName());
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isEqual(newTableFields, oldTableFields)) {
|
if (isEqual(newTableFields, oldTableFields)) {
|
||||||
sheet.setDeTableName(datasetTableDTO.getTableName());
|
sheet.setDeTableName(datasetTableDTO.getTableName());
|
||||||
excelSheetDataList.add(sheet);
|
excelSheetDataList.add(sheet);
|
||||||
@ -770,8 +774,21 @@ public class DatasourceServer implements DatasourceApi {
|
|||||||
}
|
}
|
||||||
excelFileData.setSheets(excelSheetDataList);
|
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 (ExcelSheetData sheet : excelFileData.getSheets()) {
|
||||||
for (int i = 0; i < sheet.getFields().size() - 1; i++) {
|
for (int i = 0; i < sheet.getFields().size() - 1; i++) {
|
||||||
for (int j = i + 1; j < sheet.getFields().size(); j++) {
|
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())) {
|
if (!Arrays.asList("API", "Excel", "folder").contains(coreDatasource.getType())) {
|
||||||
calciteProvider.updateDsPoolAfterCheckStatus(datasourceDTO);
|
calciteProvider.updateDsPoolAfterCheckStatus(datasourceDTO);
|
||||||
}
|
}
|
||||||
|
} catch (DEException e) {
|
||||||
|
datasourceDTO.setStatus("Error");
|
||||||
|
DEException.throwException(e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
coreDatasource.setStatus("Error");
|
datasourceDTO.setStatus("Error");
|
||||||
DEException.throwException(e.getMessage());
|
DEException.throwException(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
coreDatasource.setStatus(datasourceDTO.getStatus());
|
coreDatasource.setStatus(datasourceDTO.getStatus());
|
||||||
|
@ -380,7 +380,6 @@ const initSearch = () => {
|
|||||||
state.filterTable = tableData.value.filter(ele =>
|
state.filterTable = tableData.value.filter(ele =>
|
||||||
ele.tableName.toLowerCase().includes(nickName.value.toLowerCase())
|
ele.tableName.toLowerCase().includes(nickName.value.toLowerCase())
|
||||||
)
|
)
|
||||||
console.log(tableData.value)
|
|
||||||
state.paginationConfig.total = state.filterTable.length
|
state.paginationConfig.total = state.filterTable.length
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,7 +866,6 @@ const operation = (cmd: string, data: Tree, nodeType: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleClick = (tabName: TabPaneName) => {
|
const handleClick = (tabName: TabPaneName) => {
|
||||||
console.log(tabName)
|
|
||||||
switch (tabName) {
|
switch (tabName) {
|
||||||
case 'config':
|
case 'config':
|
||||||
listDatasourceTables({ datasourceId: nodeInfo.id }).then(res => {
|
listDatasourceTables({ datasourceId: nodeInfo.id }).then(res => {
|
||||||
@ -1091,8 +1089,22 @@ const getMenuList = (val: boolean) => {
|
|||||||
:title="node.label"
|
:title="node.label"
|
||||||
class="label-tooltip ellipsis"
|
class="label-tooltip ellipsis"
|
||||||
:class="data.type === 'Excel' && 'excel'"
|
:class="data.type === 'Excel' && 'excel'"
|
||||||
|
v-if="data.extraFlag > -1"
|
||||||
>{{ node.label }}</span
|
>{{ 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">
|
<div class="icon-more" v-if="data.weight >= 7">
|
||||||
<handle-more
|
<handle-more
|
||||||
icon-size="24px"
|
icon-size="24px"
|
||||||
|
Loading…
Reference in New Issue
Block a user