From f99865cf8d5129c3f1e513db7055b26274e2d7f0 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Fri, 28 May 2021 16:37:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E6=89=A7=E8=A1=8C=E6=97=B6=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 16 ++++++------- .../dataset/DataSetTableTaskLogService.java | 16 +++++++++++++ .../dataset/DataSetTableTaskService.java | 23 +++++++++++++++++-- .../service/dataset/ExtractDataService.java | 18 +++++++++++---- .../resources/i18n/messages_en_US.properties | 2 +- .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + frontend/src/lang/en.js | 4 ++-- frontend/src/lang/tw.js | 4 ++-- frontend/src/lang/zh.js | 4 ++-- .../src/views/dataset/data/UpdateInfo.vue | 19 +++++++-------- 11 files changed, 77 insertions(+), 31 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 2e950b79cb..14005e8ba9 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -268,18 +268,18 @@ public class DataSetTableService { e.printStackTrace(); } } else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) { - List datasetTableTaskLogs = dataSetTableTaskLogService.getByTableId(datasetTable.getId()); - if (CollectionUtils.isEmpty(datasetTableTaskLogs)) { + if (StringUtils.isEmpty(datasetTable.getSyncStatus()) || datasetTable.getSyncStatus().equalsIgnoreCase(JobStatus.Underway.name())) { map.put("status", "warnning"); map.put("msg", Translator.get("i18n_processing_data")); dataSetPreviewPage.setTotal(0); - }else if (datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Underway.name())) { - map.put("status", "warnning"); - map.put("msg", Translator.get("i18n_processing_data")); - dataSetPreviewPage.setTotal(0); - }else if (datasetTableTaskLogs.get(0).getStatus().equalsIgnoreCase(JobStatus.Error.name())) { + }else if (datasetTable.getSyncStatus().equalsIgnoreCase(JobStatus.Error.name())) { + List datasetTableTaskLogs = dataSetTableTaskLogService.getByTableId(datasetTable.getId()); map.put("status", "error"); - map.put("msg", "Failed to extract data: " + datasetTableTaskLogs.get(0).getInfo()); + if(CollectionUtils.isNotEmpty(datasetTableTaskLogs)){ + map.put("msg", "Failed to extract data: " + datasetTableTaskLogs.get(0).getInfo()); + }else { + map.put("msg", "Failed to extract data."); + } dataSetPreviewPage.setTotal(0); }else { Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource"); diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskLogService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskLogService.java index b0072fc786..b4ee6d2929 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskLogService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskLogService.java @@ -4,6 +4,7 @@ import io.dataease.base.domain.DatasetTableTaskLog; import io.dataease.base.domain.DatasetTableTaskLogExample; import io.dataease.base.mapper.DatasetTableTaskLogMapper; import io.dataease.base.mapper.ext.ExtDataSetTaskMapper; +import io.dataease.commons.constants.JobStatus; import io.dataease.dto.dataset.DataSetTaskLogDTO; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -55,4 +56,19 @@ public class DataSetTableTaskLogService { criteria.andTableIdEqualTo(datasetId); return datasetTableTaskLogMapper.selectByExampleWithBLOBs(datasetTableTaskLogExample); } + + public List select(DatasetTableTaskLog datasetTableTaskLog){ + DatasetTableTaskLogExample example = new DatasetTableTaskLogExample(); + DatasetTableTaskLogExample.Criteria criteria = example.createCriteria(); + if(StringUtils.isNotEmpty(datasetTableTaskLog.getStatus())){ + criteria.andStatusEqualTo(datasetTableTaskLog.getStatus()); + } + if(StringUtils.isNotEmpty(datasetTableTaskLog.getTableId())){ + criteria.andTableIdEqualTo(datasetTableTaskLog.getTableId()); + } + if(StringUtils.isNotEmpty(datasetTableTaskLog.getTaskId())){ + criteria.andTaskIdEqualTo(datasetTableTaskLog.getTaskId()); + } + return datasetTableTaskLogMapper.selectByExampleWithBLOBs(example); + } } diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskService.java index 85b5fa00a4..e99650b809 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableTaskService.java @@ -2,7 +2,10 @@ package io.dataease.service.dataset; import io.dataease.base.domain.DatasetTableTask; import io.dataease.base.domain.DatasetTableTaskExample; +import io.dataease.base.domain.DatasetTableTaskLog; import io.dataease.base.mapper.DatasetTableTaskMapper; +import io.dataease.commons.constants.JobStatus; +import io.dataease.commons.constants.ScheduleType; import io.dataease.controller.request.dataset.DataSetTaskRequest; import io.dataease.i18n.Translator; import io.dataease.service.ScheduleService; @@ -33,10 +36,12 @@ public class DataSetTableTaskService { @Resource @Lazy private DataSetTableService dataSetTableService; - + @Resource + private ExtractDataService extractDataService; public DatasetTableTask save(DataSetTaskRequest dataSetTaskRequest) throws Exception { - dataSetTableService.saveIncrementalConfig(dataSetTaskRequest.getDatasetTableIncrementalConfig()); DatasetTableTask datasetTableTask = dataSetTaskRequest.getDatasetTableTask(); + dataSetTableService.saveIncrementalConfig(dataSetTaskRequest.getDatasetTableIncrementalConfig()); + // check if (StringUtils.isNotEmpty(datasetTableTask.getCron())) { if (!CronExpression.isValidExpression(datasetTableTask.getCron())) { @@ -54,6 +59,20 @@ public class DataSetTableTaskService { if (StringUtils.isEmpty(datasetTableTask.getId())) { datasetTableTask.setId(UUID.randomUUID().toString()); datasetTableTask.setCreateTime(System.currentTimeMillis()); + // SIMPLE 类型,提前占位 + if(datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())){ + if(extractDataService.updateSyncStatus(dataSetTableService.get(datasetTableTask.getTableId()))){ + throw new Exception(Translator.get("i18n_sync_job_exists")); + }else { + //write log + DatasetTableTaskLog datasetTableTaskLog = new DatasetTableTaskLog(); + datasetTableTaskLog.setTableId(datasetTableTask.getTableId()); + datasetTableTaskLog.setTaskId(datasetTableTask.getId()); + datasetTableTaskLog.setStatus(JobStatus.Underway.name()); + datasetTableTaskLog.setStartTime(System.currentTimeMillis()); + dataSetTableTaskLogService.save(datasetTableTaskLog); + } + } datasetTableTaskMapper.insert(datasetTableTask); } else { datasetTableTaskMapper.updateByPrimaryKeySelective(datasetTableTask); diff --git a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java index a0d3510bc3..78a32116e8 100644 --- a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java +++ b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java @@ -3,6 +3,7 @@ package io.dataease.service.dataset; import com.google.gson.Gson; import io.dataease.base.domain.*; import io.dataease.base.mapper.DatasetTableMapper; +import io.dataease.base.mapper.DatasetTableTaskMapper; import io.dataease.base.mapper.DatasourceMapper; import io.dataease.commons.constants.JobStatus; import io.dataease.commons.constants.ScheduleType; @@ -90,13 +91,17 @@ public class ExtractDataService { @Resource private DataSetTableFieldsService dataSetTableFieldsService; @Resource + @Lazy private DataSetTableTaskLogService dataSetTableTaskLogService; @Resource + @Lazy private DataSetTableTaskService dataSetTableTaskService; @Resource private DatasourceMapper datasourceMapper; @Resource private DatasetTableMapper datasetTableMapper; + @Resource + private DatasetTableTaskMapper datasetTableTaskMapper; private static String lastUpdateTime = "${__last_update_time__}"; private static String currentUpdateTime = "${__current_update_time__}"; @@ -176,7 +181,7 @@ public class ExtractDataService { } - private synchronized boolean updateSyncStatus(DatasetTable datasetTable ){ + public synchronized boolean updateSyncStatus(DatasetTable datasetTable ){ datasetTable.setSyncStatus(JobStatus.Underway.name()); DatasetTableExample example = new DatasetTableExample(); example.createCriteria().andIdEqualTo(datasetTable.getId()).andSyncStatusEqualTo(JobStatus.Completed.name()); @@ -186,7 +191,9 @@ public class ExtractDataService { public void extractData(String datasetTableId, String taskId, String type, JobExecutionContext context) { DatasetTable datasetTable = dataSetTableService.get(datasetTableId); - if(updateSyncStatus(datasetTable)){ + DatasetTableTask datasetTableTask = datasetTableTaskMapper.selectByPrimaryKey(taskId); + boolean isSIMPLEJob = (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())); + if(updateSyncStatus(datasetTable) && !isSIMPLEJob){ LogUtil.info("Skip synchronization task for table : " + datasetTableId); return; } @@ -276,7 +283,6 @@ public class ExtractDataService { datasetTableTaskLog.setEndTime(System.currentTimeMillis()); dataSetTableTaskLogService.save(datasetTableTaskLog); } finally { - DatasetTableTask datasetTableTask = dataSetTableTaskService.get(taskId); if (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) { datasetTableTask.setRate(ScheduleType.SIMPLE_COMPLETE.toString()); dataSetTableTaskService.update(datasetTableTask); @@ -292,8 +298,10 @@ public class ExtractDataService { datasetTableTaskLog.setTableId(datasetTableId); datasetTableTaskLog.setTaskId(taskId); datasetTableTaskLog.setStatus(JobStatus.Underway.name()); - datasetTableTaskLog.setStartTime(System.currentTimeMillis()); - dataSetTableTaskLogService.save(datasetTableTaskLog); + if(CollectionUtils.isEmpty(dataSetTableTaskLogService.select(datasetTableTaskLog))){ + datasetTableTaskLog.setStartTime(System.currentTimeMillis()); + dataSetTableTaskLogService.save(datasetTableTaskLog); + } } private void extractData(DatasetTable datasetTable, String extractType) throws Exception { diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index c3d50d92fe..a89f27a5a3 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -242,4 +242,4 @@ i18n_cron_time_error=Start time can't greater then end time i18n_auth_source_be_canceled=This Auth Resource Already Be Canceled i18n_username_exists=ID is already exists i18n_ds_name_exists=Datasource name exists - +i18n_sync_job_exists=There is already a synchronization task running, please try again later diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 8ac7dde23b..5a3a318e9e 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -244,3 +244,4 @@ i18n_cron_time_error=开始时间不能大于结束时间 i18n_auth_source_be_canceled=当前资源授权权限已经被取消 i18n_username_exists=用户ID已存在 i18n_ds_name_exists=数据源名称已存在 +i18n_sync_job_exists=已经有同步任务在运行,稍后重试 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index b19c84ce96..49c3d8d98a 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -244,3 +244,4 @@ i18n_cron_time_error=開始時間不能大於結束時間 i18n_auth_source_be_canceled=當前資源授權權限已經被取消 i18n_username_exists=用戶ID已存在 i18n_ds_name_exists=數據源名稱已存在 +i18n_sync_job_exists=已經有同步任務在運行,稍後重試 diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 226822e2bb..1e00b88d08 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -732,13 +732,13 @@ export default { error: 'Error', completed: 'Completed', underway: 'underway', - task_update: 'Regular update', + task_update: 'Update Setting', update_type: 'Update Type', all_scope: 'Full update', add_scope: 'Incremental update', select_data_time: 'Select date time', execute_rate: 'Execution frequency', - execute_once: 'Only once', + execute_once: 'Execution Now', cron_config: 'Expression setting', no_limit: 'No limit', set_end_time: 'Set the end time', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 6f8cae65d9..2352f89100 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -732,13 +732,13 @@ export default { error: '錯誤', completed: '完成', underway: '執行中', - task_update: '定時更新', + task_update: '更新設置', update_type: '更新方式', all_scope: '全量更新', add_scope: '增量更新', select_data_time: '選擇日期時間', execute_rate: '執行頻率', - execute_once: '只執行一次', + execute_once: '立即執行', cron_config: '表達時設定', no_limit: '無限制', set_end_time: '設定結束時間', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 4f706be994..e206e2cb63 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -732,13 +732,13 @@ export default { error: '错误', completed: '完成', underway: '执行中', - task_update: '定时更新', + task_update: '更新设置', update_type: '更新方式', all_scope: '全量更新', add_scope: '增量更新', select_data_time: '选择日期时间', execute_rate: '执行频率', - execute_once: '只执行一次', + execute_once: '立即执行', cron_config: '表达式设定', no_limit: '无限制', set_end_time: '设定结束时间', diff --git a/frontend/src/views/dataset/data/UpdateInfo.vue b/frontend/src/views/dataset/data/UpdateInfo.vue index 3723b1cefd..19033303d8 100644 --- a/frontend/src/views/dataset/data/UpdateInfo.vue +++ b/frontend/src/views/dataset/data/UpdateInfo.vue @@ -116,14 +116,6 @@ /> - - - + - + + + +