From cbc46be67c8008c64e27004df54ec126a6ca712e Mon Sep 17 00:00:00 2001 From: junjie Date: Wed, 1 Dec 2021 11:45:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=95=B0=E6=8D=AE=E9=9B=86):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E9=9B=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 81 +++++++++++-------- .../resources/i18n/messages_en_US.properties | 3 +- .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 3 +- 4 files changed, 51 insertions(+), 37 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 85bba76a30..40c15f1b63 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -7,6 +7,7 @@ import io.dataease.base.mapper.*; import io.dataease.base.mapper.ext.ExtDataSetGroupMapper; import io.dataease.base.mapper.ext.ExtDataSetTableMapper; import io.dataease.base.mapper.ext.UtilMapper; +import io.dataease.commons.constants.DatasourceTypes; import io.dataease.commons.constants.JobStatus; import io.dataease.commons.constants.ScheduleType; import io.dataease.commons.constants.TaskStatus; @@ -15,16 +16,16 @@ import io.dataease.commons.utils.*; import io.dataease.controller.request.dataset.DataSetGroupRequest; import io.dataease.controller.request.dataset.DataSetTableRequest; import io.dataease.controller.request.dataset.DataSetTaskRequest; -import io.dataease.controller.response.DataSetDetail; -import io.dataease.commons.constants.DatasourceTypes; -import io.dataease.dto.datasource.TableFiled; -import io.dataease.provider.datasource.DatasourceProvider; -import io.dataease.provider.datasource.JdbcProvider; -import io.dataease.provider.ProviderFactory; import io.dataease.controller.request.datasource.DatasourceRequest; +import io.dataease.controller.response.DataSetDetail; import io.dataease.dto.dataset.*; +import io.dataease.dto.datasource.TableFiled; import io.dataease.exception.DataEaseException; import io.dataease.i18n.Translator; +import io.dataease.plugins.loader.ClassloaderResponsity; +import io.dataease.provider.ProviderFactory; +import io.dataease.provider.datasource.DatasourceProvider; +import io.dataease.provider.datasource.JdbcProvider; import io.dataease.provider.query.DDLProvider; import io.dataease.provider.query.QueryProvider; import org.apache.commons.collections4.CollectionUtils; @@ -39,6 +40,8 @@ import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -93,6 +96,8 @@ public class DataSetTableService { @Value("${upload.file.path}") private String path; + private static Logger logger = LoggerFactory.getLogger(ClassloaderResponsity.class); + public void batchInsert(List datasetTable) throws Exception { for (DataSetTableRequest table : datasetTable) { save(table); @@ -469,8 +474,8 @@ public class DataSetTableService { datasourceRequest.setPageable(true); data.addAll(datasourceProvider.getData(datasourceRequest)); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } try { @@ -478,8 +483,8 @@ public class DataSetTableService { datasourceRequest.setPageable(false); dataSetPreviewPage.setTotal(datasourceProvider.getData(datasourceRequest).size()); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } } else { // check doris table @@ -497,15 +502,15 @@ public class DataSetTableService { try { data.addAll(jdbcProvider.getData(datasourceRequest)); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } try { datasourceRequest.setQuery(qp.createQueryTableWithLimit(table, fields, Integer.valueOf(dataSetTableRequest.getRow()), false, ds)); dataSetPreviewPage.setTotal(jdbcProvider.getData(datasourceRequest).size()); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } } @@ -532,16 +537,16 @@ public class DataSetTableService { datasourceRequest.setPageable(true); data.addAll(datasourceProvider.getData(datasourceRequest)); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } try { datasourceRequest.setPageable(false); datasourceRequest.setQuery(qp.createQuerySqlWithLimit(sql, fields, Integer.valueOf(dataSetTableRequest.getRow()), false)); dataSetPreviewPage.setTotal(datasourceProvider.getData(datasourceRequest).size()); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } } else { // check doris table @@ -559,15 +564,15 @@ public class DataSetTableService { try { data.addAll(jdbcProvider.getData(datasourceRequest)); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } try { datasourceRequest.setQuery(qp.createQueryTableWithLimit(table, fields, Integer.valueOf(dataSetTableRequest.getRow()), false, ds)); dataSetPreviewPage.setTotal(jdbcProvider.getData(datasourceRequest).size()); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } } } else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) { @@ -586,15 +591,15 @@ public class DataSetTableService { try { data.addAll(jdbcProvider.getData(datasourceRequest)); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } try { datasourceRequest.setQuery(qp.createQueryTableWithLimit(table, fields, Integer.valueOf(dataSetTableRequest.getRow()), false, ds)); dataSetPreviewPage.setTotal(jdbcProvider.getData(datasourceRequest).size()); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } } else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) { if (datasetTable.getMode() == 0) { @@ -609,7 +614,13 @@ public class DataSetTableService { DataTableInfoDTO dt = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class); List list = dataSetTableUnionService.listByTableId(dt.getList().get(0).getTableId()); - String sql = getCustomSQLDatasource(dt, list, ds); + String sql = ""; + try { + sql = getCustomSQLDatasource(dt, list, ds); + } catch (Exception e) { + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); + } QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); datasourceRequest.setQuery(qp.createQuerySQLWithPage(sql, fields, page, pageSize, realSize, false)); map.put("sql", datasourceRequest.getQuery()); @@ -622,16 +633,16 @@ public class DataSetTableService { datasourceRequest.setPageable(true); data.addAll(datasourceProvider.getData(datasourceRequest)); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } try { datasourceRequest.setPageable(false); datasourceRequest.setQuery(qp.createQuerySqlWithLimit(sql, fields, Integer.valueOf(dataSetTableRequest.getRow()), false)); dataSetPreviewPage.setTotal(datasourceProvider.getData(datasourceRequest).size()); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } } else { Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource"); @@ -645,16 +656,16 @@ public class DataSetTableService { try { data.addAll(jdbcProvider.getData(datasourceRequest)); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } try { datasourceRequest.setQuery(qp.createQueryTableWithLimit(table, fields, Integer.valueOf(dataSetTableRequest.getRow()), false, ds)); dataSetPreviewPage.setTotal(jdbcProvider.getData(datasourceRequest).size()); } catch (Exception e) { - e.printStackTrace(); - DEException.throwException(e.getMessage()); + logger.error(e.getMessage()); + DEException.throwException(Translator.get("i18n_ds_error")); } } } diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 1ef2d89426..ab583bd2b4 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -288,4 +288,5 @@ i18n_Stopped=END i18n_Exec=Running i18n_no_trigger=The current setting does not trigger task generation. i18n_dataset_field_delete=Union field deleted,please set again and redo. -i18n_es_limit=Elasticsearch version cannot be less than 6.3 \ No newline at end of file +i18n_es_limit=Elasticsearch version cannot be less than 6.3 +i18n_ds_error=Preview fail:Execute SQL error。Cause field、table、dataset changed,please check \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 7c51906b79..6bafb1da79 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -288,3 +288,4 @@ i18n_Exec=运行中 i18n_no_trigger=当前设置没有触发任务生成 i18n_dataset_field_delete=该自定义数据集有关联字段被删除,请重新确认关联关系并重做该数据集 i18n_es_limit=Elasticsearch 版本不能小于6.3 +i18n_ds_error=预览数据错误:执行SQL失败。可能因相关字段、表、数据集等元素发生变更,请检查 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 8e0c9b58dc..4c40206670 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -290,4 +290,5 @@ i18n_Stopped=執行結束 i18n_Exec=運行中 i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任務生成. i18n_dataset_field_delete=該自定義數據集有關聯字段被刪除,請重新確認關聯關系並重做該數據集 -i18n_es_limit=Elasticsearch 版本不能小於6.3 \ No newline at end of file +i18n_es_limit=Elasticsearch 版本不能小於6.3 +i18n_ds_error=預覽數據錯誤:執行SQL失敗。可能因相關字段、表、數據集等元素發生變更,請檢查 \ No newline at end of file