From 6261dff6ccf3dacdfac9185e217b5d89d073d0d3 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 2 Aug 2021 18:09:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=A1=E9=AA=8C=E5=A2=9E=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index 45c8f6dd5f..2bb34dce5b 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -986,14 +986,15 @@ public class DataSetTableService { DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(datasetTableIncrementalConfig.getTableId()); List datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(datasetTable.getId()); datasetTableFields.sort((o1, o2) -> { - if (o1.getOriginName() == null) { + if (o1.getColumnIndex() == null) { return -1; } - if (o2.getOriginName() == null) { + if (o2.getColumnIndex() == null) { return 1; } - return o1.getOriginName().compareTo(o2.getOriginName()); + return o1.getColumnIndex().compareTo(o2.getColumnIndex()); }); + List originNameFileds = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList()); Datasource ds = datasourceMapper.selectByPrimaryKey(datasetTable.getDataSourceId()); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); @@ -1012,10 +1013,7 @@ public class DataSetTableService { }catch (Exception e){ DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage()); } - datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> { - sqlFileds.add(filed); - }); - sort(sqlFileds); + if (!originNameFileds.equals(sqlFileds)) { DataEaseException.throwException(Translator.get("i18n_sql_add_not_matching") + sqlFileds.toString()); } @@ -1025,28 +1023,20 @@ public class DataSetTableService { .replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()); datasourceRequest.setQuery(qp.wrapSql(sql)); List sqlFileds = new ArrayList<>(); - datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> { - sqlFileds.add(filed); - }); - sort(sqlFileds); + try{ + datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> { + sqlFileds.add(filed); + }); + }catch (Exception e){ + DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage()); + } + if (!originNameFileds.equals(sqlFileds)) { DataEaseException.throwException(Translator.get("i18n_sql_delete_not_matching") + sqlFileds.toString()); } } } - private void sort(List sqlFileds) { - sqlFileds.sort((o1, o2) -> { - if (o1 == null) { - return -1; - } - if (o2 == null) { - return 1; - } - return o1.compareTo(o2); - }); - } - private void checkName(DatasetTable datasetTable) { // if (StringUtils.isEmpty(datasetTable.getId()) && StringUtils.equalsIgnoreCase("db", datasetTable.getType())) { // return;