diff --git a/xxl-job-admin/pom.xml b/xxl-job-admin/pom.xml index 8fafc8a1..92e6f45a 100644 --- a/xxl-job-admin/pom.xml +++ b/xxl-job-admin/pom.xml @@ -141,6 +141,13 @@ ${project.parent.version} + + + com.alibaba + fastjson + 1.2.47 + + diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/IndexController.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/IndexController.java index 8dc6b754..349d3efa 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/IndexController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/IndexController.java @@ -6,18 +6,17 @@ import com.xxl.job.admin.core.util.I18nUtil; import com.xxl.job.admin.service.XxlJobService; import com.xxl.job.core.biz.model.ReturnT; import org.apache.commons.lang3.StringUtils; +import org.quartz.CronExpression; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.InitBinder; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; @@ -100,6 +99,29 @@ public class IndexController { return "help"; } + @ResponseBody + @RequestMapping("/cron-preview") + @PermessionLimit(limit=false) + public ReturnT cronPreview(HttpServletResponse response, String expression, @RequestParam(defaultValue = "5")int times){ + if (times <= 0) times = 5; + try { + CronExpression exp = new CronExpression(expression); + SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); + Date d = new Date(); + // 循环得到接下来n此的触发时间点,供验证 + String[] arr = new String[times]; + int i = 0; + while (i < times) { + d = exp.getNextValidTimeAfter(d); + arr[i] = df.format(d); + i ++; + } + return new ReturnT(arr); + } catch (ParseException e) { + return new ReturnT(500, I18nUtil.getString("jobinfo_field_cron_unvalid")); + } + } + @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl index cd9a2c96..87cd865f 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl @@ -124,7 +124,14 @@ -
+
+
+ +
+
+ +
+
@@ -292,7 +299,14 @@ process.exit(0)
-
+
+
+ +
+
+ +
+
diff --git a/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js b/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js index dbaf734e..f9da7067 100644 --- a/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js +++ b/xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js @@ -459,4 +459,39 @@ $(function() { return glueTypeTitle; } + $("body").on("click", ".cron-expression-test", function () { + var expression = $(this).closest("form").find("input[name=jobCron]").val(); + console.log("expression", expression); + if (expression.length == "") { + layer.open({ + title: I18n.system_tips, + btn: [ I18n.system_ok ], + content: ( I18n.jobinfo_field_cron_unvalid ), + icon: '2' + }); + return; + } + $.post(base_url + "/cron-preview", {expression: expression}, function(data, status) { + if (data.code == "200") { + var content = "
    " + for (i=0; i < data.content.length; i++){ + content += "
  • "+data.content[i]+"
  • "; + } + content += "
"; + layer.open({ + title: I18n.system_tips , + btn: [ I18n.system_ok ], + content: content || "error", + icon: '1' + }); + } else { + layer.open({ + title: I18n.system_tips , + btn: [ I18n.system_ok ], + content: (data.msg || I18n.jobinfo_field_cron_unvalid ), + icon: '2' + }); + } + }); + }) });