diff --git a/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java b/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java index fe2dbc8da8..d84b3e0cc4 100644 --- a/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java +++ b/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java @@ -49,7 +49,7 @@ public class DatasourceController { } @PostMapping("/delete/{datasourceID}") - public void deleteDatasource(@PathVariable(value = "datasourceID") String datasourceID) { + public void deleteDatasource(@PathVariable(value = "datasourceID") String datasourceID) throws Exception { datasourceService.deleteDatasource(datasourceID); } diff --git a/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java index 8a2eee16a5..a8351668fd 100644 --- a/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java +++ b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java @@ -76,7 +76,13 @@ public class DatasourceService { return extDataSourceMapper.query(gridExample); } - public void deleteDatasource(String datasourceId) { + public void deleteDatasource(String datasourceId) throws Exception { + DatasetTableExample example = new DatasetTableExample(); + example.createCriteria().andDataSourceIdEqualTo(datasourceId); + List datasetTables = datasetTableMapper.selectByExample(example); + if(CollectionUtils.isNotEmpty(datasetTables)){ + throw new Exception(datasetTables.size() + Translator.get("i18n_datasource_not_allow_delete_msg")); + } datasourceMapper.deleteByPrimaryKey(datasourceId); } diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 0a378bdf4d..b2334f10f8 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -245,4 +245,5 @@ i18n_ds_name_exists=Datasource name exists i18n_sync_job_exists=There is already a synchronization task running, please try again later i18n_datasource_check_fail=Invalid,please check config i18n_not_find_user=Can not find user. -i18n_sql_not_empty=SQL can not be empty. \ No newline at end of file +i18n_sql_not_empty=SQL can not be empty. +i18n_datasource_not_allow_delete_msg= datasets are using this data source and cannot be deleted \ 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 46259d26ec..ae5e27a5e6 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -247,4 +247,5 @@ i18n_ds_name_exists=数据源名称已存在 i18n_sync_job_exists=已经有同步任务在运行,稍后重试 i18n_datasource_check_fail=校验失败,请检查配置信息 i18n_not_find_user=未找到用户 -i18n_sql_not_empty=SQL 不能为空 \ No newline at end of file +i18n_sql_not_empty=SQL 不能为空 +i18n_datasource_not_allow_delete_msg= 个数据集正在使用此数据源,无法删除 \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index fd650136bf..6e9048d929 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -247,4 +247,5 @@ i18n_ds_name_exists=數據源名稱已存在 i18n_sync_job_exists=已經有同步任務在運行,稍後重試 i18n_datasource_check_fail=校驗失敗,請檢查配置信息 i18n_not_find_user=未找到用戶 -i18n_sql_not_empty=SQL 不能為空 \ No newline at end of file +i18n_sql_not_empty=SQL 不能為空 +i18n_datasource_not_allow_delete_msg= 個數據集正在使用此數據源,無法刪除 \ No newline at end of file