From 25a331be1f4f5532b9bed4172e7e7f38cf0ee090 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Thu, 5 Nov 2020 21:01:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=8B=E6=AC=A1=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E9=97=B4=E4=BC=98=E5=8C=96=EF=BC=9A=E6=94=AF?= =?UTF-8?q?=E6=8C=81Cron=E3=80=81=E5=9B=BA=E5=AE=9A=E9=97=B4=E9=9A=94?= =?UTF-8?q?=E7=AD=89=E5=A4=9A=E7=A7=8D=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/JobInfoController.java | 20 ++++++++++++---- .../admin/service/impl/XxlJobServiceImpl.java | 6 ++--- .../main/resources/i18n/message_en.properties | 1 - .../resources/i18n/message_zh_CN.properties | 1 - .../resources/i18n/message_zh_TC.properties | 1 - .../resources/static/js/jobinfo.index.1.js | 23 +++++++++---------- .../static/plugins/cronGen/cronGen.js | 3 ++- .../static/plugins/cronGen/cronGen_en.js | 3 ++- 8 files changed, 33 insertions(+), 25 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java index 96c567d6..ea314b32 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java @@ -8,6 +8,7 @@ import com.xxl.job.admin.core.model.XxlJobUser; import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum; import com.xxl.job.admin.core.scheduler.MisfireStrategyEnum; import com.xxl.job.admin.core.scheduler.ScheduleTypeEnum; +import com.xxl.job.admin.core.thread.JobScheduleHelper; import com.xxl.job.admin.core.thread.JobTriggerPoolHelper; import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.util.I18nUtil; @@ -18,6 +19,8 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.enums.ExecutorBlockStrategyEnum; import com.xxl.job.core.glue.GlueTypeEnum; import com.xxl.job.core.util.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @@ -36,6 +39,7 @@ import java.util.*; @Controller @RequestMapping("/jobinfo") public class JobInfoController { + private static Logger logger = LoggerFactory.getLogger(JobInfoController.class); @Resource private XxlJobGroupDao xxlJobGroupDao; @@ -148,23 +152,29 @@ public class JobInfoController { @RequestMapping("/nextTriggerTime") @ResponseBody - public ReturnT> nextTriggerTime(String cron) { + public ReturnT> nextTriggerTime(String scheduleType, String scheduleConf) { + + XxlJobInfo paramXxlJobInfo = new XxlJobInfo(); + paramXxlJobInfo.setScheduleType(scheduleType); + paramXxlJobInfo.setScheduleConf(scheduleConf); + List result = new ArrayList<>(); try { - CronExpression cronExpression = new CronExpression(cron); Date lastTime = new Date(); for (int i = 0; i < 5; i++) { - lastTime = cronExpression.getNextValidTimeAfter(lastTime); + lastTime = JobScheduleHelper.generateNextValidTime(paramXxlJobInfo, lastTime); if (lastTime != null) { result.add(DateUtil.formatDateTime(lastTime)); } else { break; } } - } catch (ParseException e) { - return new ReturnT>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")); + } catch (Exception e) { + logger.error(e.getMessage(), e); + return new ReturnT>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) + e.getMessage()); } return new ReturnT>(result); + } } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java index 567138df..530ee41c 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java @@ -79,11 +79,11 @@ public class XxlJobServiceImpl implements XxlJobService { } if (scheduleTypeEnum == ScheduleTypeEnum.CRON) { if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) { - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") ); + return new ReturnT(ReturnT.FAIL_CODE, "Cron"+I18nUtil.getString("system_unvalid")); } } else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE/* || scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) { if (jobInfo.getScheduleConf() == null) { - return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) ); + return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")) ); } try { int fixSecond = Integer.valueOf(jobInfo.getScheduleConf()); @@ -183,7 +183,7 @@ public class XxlJobServiceImpl implements XxlJobService { } if (scheduleTypeEnum == ScheduleTypeEnum.CRON) { if (jobInfo.getScheduleConf()==null || !CronExpression.isValidExpression(jobInfo.getScheduleConf())) { - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") ); + return new ReturnT(ReturnT.FAIL_CODE, "Cron"+I18nUtil.getString("system_unvalid") ); } } else if (scheduleTypeEnum == ScheduleTypeEnum.FIX_RATE /*|| scheduleTypeEnum == ScheduleTypeEnum.FIX_DELAY*/) { if (jobInfo.getScheduleConf() == null) { diff --git a/xxl-job-admin/src/main/resources/i18n/message_en.properties b/xxl-job-admin/src/main/resources/i18n/message_en.properties index c40ea838..68f133f5 100644 --- a/xxl-job-admin/src/main/resources/i18n/message_en.properties +++ b/xxl-job-admin/src/main/resources/i18n/message_en.properties @@ -117,7 +117,6 @@ jobinfo_field_jobdesc=Job description jobinfo_field_timeout=Job timeout period jobinfo_field_gluetype=GLUE Type jobinfo_field_executorparam=Param -jobinfo_field_cron_unvalid=The Cron is illegal jobinfo_field_author=Author jobinfo_field_alarmemail=Alarm email jobinfo_field_alarmemail_placeholder=Please enter alarm mail, if there are more than one comma separated diff --git a/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties b/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties index 8ac4808a..f3b168ce 100644 --- a/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties +++ b/xxl-job-admin/src/main/resources/i18n/message_zh_CN.properties @@ -116,7 +116,6 @@ jobinfo_field_jobgroup=执行器 jobinfo_field_jobdesc=任务描述 jobinfo_field_gluetype=运行模式 jobinfo_field_executorparam=任务参数 -jobinfo_field_cron_unvalid=Cron格式非法 jobinfo_field_author=负责人 jobinfo_field_timeout=任务超时时间 jobinfo_field_alarmemail=报警邮件 diff --git a/xxl-job-admin/src/main/resources/i18n/message_zh_TC.properties b/xxl-job-admin/src/main/resources/i18n/message_zh_TC.properties index f630aa88..1761d0af 100755 --- a/xxl-job-admin/src/main/resources/i18n/message_zh_TC.properties +++ b/xxl-job-admin/src/main/resources/i18n/message_zh_TC.properties @@ -116,7 +116,6 @@ jobinfo_field_jobgroup=執行器 jobinfo_field_jobdesc=任務描述 jobinfo_field_gluetype=運行模式 jobinfo_field_executorparam=任務參數 -jobinfo_field_cron_unvalid=Cron 格式非法 jobinfo_field_author=負責人 jobinfo_field_timeout=任務超時秒數 jobinfo_field_alarmemail=告警郵件 diff --git a/xxl-job-admin/src/main/resources/static/js/jobinfo.index.1.js b/xxl-job-admin/src/main/resources/static/js/jobinfo.index.1.js index b46dfbed..b479e972 100644 --- a/xxl-job-admin/src/main/resources/static/js/jobinfo.index.1.js +++ b/xxl-job-admin/src/main/resources/static/js/jobinfo.index.1.js @@ -118,10 +118,16 @@ $(function() { start_stop_div = '
  • '+ I18n.jobinfo_opt_start +'
  • \n'; } + // job_next_time_html + var job_next_time_html = ''; + if (row.scheduleType == 'CRON' || row.scheduleType == 'FIX_RATE') { + job_next_time_html = '
  • ' + I18n.jobinfo_opt_next_time + '
  • \n'; + } + // log url var logHref = base_url +'/joblog?jobId='+ row.id; - // log url + // code url var codeBtn = ""; if ('BEAN' != row.glueType) { var codeUrl = base_url +'/jobcode?jobId='+ row.id; @@ -143,7 +149,7 @@ $(function() { '
  • '+ I18n.jobinfo_opt_run +'
  • \n' + '
  • '+ I18n.jobinfo_opt_log +'
  • \n' + '
  • ' + I18n.jobinfo_opt_registryinfo + '
  • \n' + - '
  • ' + I18n.jobinfo_opt_next_time + '
  • \n' + + job_next_time_html + '
  • \n' + codeBtn + start_stop_div + @@ -329,17 +335,16 @@ $(function() { var id = $(this).parents('ul').attr("_id"); var row = tableData['key'+id]; - var jobCron = row.jobCron; - $.ajax({ type : 'POST', url : base_url + "/jobinfo/nextTriggerTime", data : { - "cron" : jobCron + "scheduleType" : row.scheduleType, + "scheduleConf" : row.scheduleConf }, dataType : "json", success : function(data){ - + if (data.code != 200) { layer.open({ title: I18n.jobinfo_opt_next_time , @@ -585,9 +590,6 @@ $(function() { required : true, maxlength: 50 }, - jobCron : { - required : true - }, author : { required : true } @@ -596,9 +598,6 @@ $(function() { jobDesc : { required : I18n.system_please_input + I18n.jobinfo_field_jobdesc }, - jobCron : { - required : I18n.system_please_input + "Cron" - }, author : { required : I18n.system_please_input + I18n.jobinfo_field_author } diff --git a/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen.js b/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen.js index 42e4a41f..22393722 100755 --- a/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen.js +++ b/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen.js @@ -641,7 +641,8 @@ type : 'GET', url : base_url + "/jobinfo/nextTriggerTime", data : { - "cron" : inputElement.val(), + "scheduleType" : 'CRON', + "scheduleConf" : inputElement.val() }, dataType : "json", success : function(data){ diff --git a/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen_en.js b/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen_en.js index 26320527..cbf84ee3 100755 --- a/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen_en.js +++ b/xxl-job-admin/src/main/resources/static/plugins/cronGen/cronGen_en.js @@ -641,7 +641,8 @@ type : 'GET', url : base_url + "/jobinfo/nextTriggerTime", data : { - "cron" : inputElement.val(), + "scheduleType" : 'CRON', + "scheduleConf" : inputElement.val() }, dataType : "json", success : function(data){