From 51259d8c8e618687749ef3b3a4ced250d0ff27c8 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Tue, 1 Dec 2015 22:09:17 +0800 Subject: [PATCH] init --- .../com/xxl/controller/IndexController.java | 8 +-- .../com/xxl/quartz/DynamicSchedulerUtil.java | 30 +++++--- .../webapp/WEB-INF/template/job/index.ftl | 71 +++++++++++++++---- 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/controller/IndexController.java b/xxl-job-admin/src/main/java/com/xxl/controller/IndexController.java index c0d061ca..d7f21bdf 100644 --- a/xxl-job-admin/src/main/java/com/xxl/controller/IndexController.java +++ b/xxl-job-admin/src/main/java/com/xxl/controller/IndexController.java @@ -1,8 +1,8 @@ package com.xxl.controller; -import java.util.Set; +import java.util.List; +import java.util.Map; -import org.quartz.JobKey; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @@ -16,8 +16,8 @@ public class IndexController { @RequestMapping("index") public String index(Model model) { - Set list = DynamicSchedulerUtil.getJobKeys(); - model.addAttribute("jobList", list); + List> jobList = DynamicSchedulerUtil.getJobList(); + model.addAttribute("jobList", jobList); return "job/index"; } diff --git a/xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java b/xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java index 537ccf3b..d7d3a7b4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java @@ -1,6 +1,9 @@ package com.xxl.quartz; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -38,21 +41,30 @@ public final class DynamicSchedulerUtil implements InitializingBean { } // getJobKeys - public static Set getJobKeys(){ + public static List> getJobList(){ + List> jobList = new ArrayList>(); + try { String groupName = scheduler.getJobGroupNames().get(0); - return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)); + Set jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)); + if (jobKeys!=null && jobKeys.size()>0) { + for (JobKey jobKey : jobKeys) { + TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP); + Trigger trigger = scheduler.getTrigger(triggerKey); + JobDetail jobDetail = scheduler.getJobDetail(jobKey); + Map jobMap = new HashMap(); + jobMap.put("TriggerKey", triggerKey); + jobMap.put("Trigger", trigger); + jobMap.put("JobDetail", jobDetail); + jobList.add(jobMap); + } + } + } catch (SchedulerException e) { e.printStackTrace(); return null; } - } - - public static void getJobDetail(String triggerKeyName){ - // TriggerKey : name + group - String group = Scheduler.DEFAULT_GROUP; - TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); - + return jobList; } // addJob 新增 diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/job/index.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/job/index.ftl index 5b3b75a1..8e288d87 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/job/index.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/job/index.ftl @@ -4,6 +4,9 @@ 调度中心 <#import "/common/common.macro.ftl" as netCommon> <@netCommon.commonStyle /> + + +
@@ -22,22 +25,53 @@
  • 使用教程
  • - + -
    -
    -

    在线任务:

    - <#if jobList?exists && jobList?size gt 0> - <#list jobList as item> -

    ${item}

    - - -
    - -
    - +
    +
    +
    +
    +

    任务列表

    +
    + + + + + + + + + + + + <#if jobList?exists && jobList?size gt 0> + <#list jobList as item> + + + + + + + + + + + + + + + + + + + +
    任务IDcronJob类路径简介操作
    ${item['TriggerKey'].name}${item['Trigger'].cronExpression}${item['JobDetail'].jobClass}-X
    任务IDcronJob类路径简介操作
    +
    +
    +
    +
    +
    - <@netCommon.commonFooter /> @@ -45,5 +79,14 @@ <@netCommon.commonControl /> <@netCommon.commonScript /> + + + + +