master
xueli.xue 9 years ago
parent 65243e7649
commit 51259d8c8e
  1. 8
      xxl-job-admin/src/main/java/com/xxl/controller/IndexController.java
  2. 30
      xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java
  3. 71
      xxl-job-admin/src/main/webapp/WEB-INF/template/job/index.ftl

@ -1,8 +1,8 @@
package com.xxl.controller; 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.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -16,8 +16,8 @@ public class IndexController {
@RequestMapping("index") @RequestMapping("index")
public String index(Model model) { public String index(Model model) {
Set<JobKey> list = DynamicSchedulerUtil.getJobKeys(); List<Map<String, Object>> jobList = DynamicSchedulerUtil.getJobList();
model.addAttribute("jobList", list); model.addAttribute("jobList", jobList);
return "job/index"; return "job/index";
} }

@ -1,6 +1,9 @@
package com.xxl.quartz; package com.xxl.quartz;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -38,21 +41,30 @@ public final class DynamicSchedulerUtil implements InitializingBean {
} }
// getJobKeys // getJobKeys
public static Set<JobKey> getJobKeys(){ public static List<Map<String, Object>> getJobList(){
List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
try { try {
String groupName = scheduler.getJobGroupNames().get(0); String groupName = scheduler.getJobGroupNames().get(0);
return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)); Set<JobKey> 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<String, Object> jobMap = new HashMap<String, Object>();
jobMap.put("TriggerKey", triggerKey);
jobMap.put("Trigger", trigger);
jobMap.put("JobDetail", jobDetail);
jobList.add(jobMap);
}
}
} catch (SchedulerException e) { } catch (SchedulerException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} return jobList;
public static void getJobDetail(String triggerKeyName){
// TriggerKey : name + group
String group = Scheduler.DEFAULT_GROUP;
TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group);
} }
// addJob 新增 // addJob 新增

@ -4,6 +4,9 @@
<title>调度中心</title> <title>调度中心</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
<!-- DataTables -->
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/datatables/dataTables.bootstrap.css">
</head> </head>
<body class="hold-transition skin-blue sidebar-mini"> <body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper"> <div class="wrapper">
@ -22,22 +25,53 @@
<li class="active">使用教程</li> <li class="active">使用教程</li>
</ol> </ol>
</section> </section>
<!-- Main content --> <!-- Main content -->
<section class="content"> <section class="content">
<div class="callout callout-info"> <div class="row">
<h4>在线任务:</h4> <div class="col-xs-12">
<#if jobList?exists && jobList?size gt 0> <div class="box">
<#list jobList as item> <div class="box-header"><h3 class="box-title">任务列表</h3></div>
<p>${item}</p> <div class="box-body">
</#list> <table id="example1" class="table table-bordered table-striped">
</#if> <thead>
</div> <tr>
<th>任务ID</th>
</section> <th>cron</th>
<!-- /.content --> <th>Job类路径</th>
<th>简介</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<#if jobList?exists && jobList?size gt 0>
<#list jobList as item>
<tr>
<td>${item['TriggerKey'].name}</td>
<td>${item['Trigger'].cronExpression}</td>
<td>${item['JobDetail'].jobClass}</td>
<td>-</td>
<td>X</td>
</tr>
</#list>
</#if>
</tbody>
<tfoot>
<tr>
<th>任务ID</th>
<th>cron</th>
<th>Job类路径</th>
<th>简介</th>
<th>操作</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
</section>
</div> </div>
<!-- /.content-wrapper -->
<!-- footer --> <!-- footer -->
<@netCommon.commonFooter /> <@netCommon.commonFooter />
@ -45,5 +79,14 @@
<@netCommon.commonControl /> <@netCommon.commonControl />
</div> </div>
<@netCommon.commonScript /> <@netCommon.commonScript />
<!-- DataTables -->
<script src="${request.contextPath}/static/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${request.contextPath}/static/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- page script -->
<script>
$(function () {
$("#example1").DataTable();
});
</script>
</body> </body>
</html> </html>

Loading…
Cancel
Save