xueli.xue 10 lat temu
rodzic
commit
51259d8c8e

+ 4 - 4
xxl-job-admin/src/main/java/com/xxl/controller/IndexController.java Wyświetl plik

@@ -1,8 +1,8 @@
1 1
 package com.xxl.controller;
2 2
 
3
-import java.util.Set;
3
+import java.util.List;
4
+import java.util.Map;
4 5
 
5
-import org.quartz.JobKey;
6 6
 import org.springframework.stereotype.Controller;
7 7
 import org.springframework.ui.Model;
8 8
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -16,8 +16,8 @@ public class IndexController {
16 16
 	
17 17
 	@RequestMapping("index")
18 18
 	public String index(Model model) {
19
-		Set<JobKey> list = DynamicSchedulerUtil.getJobKeys();
20
-		model.addAttribute("jobList", list);
19
+		List<Map<String, Object>> jobList = DynamicSchedulerUtil.getJobList();
20
+		model.addAttribute("jobList", jobList);
21 21
 		return "job/index";
22 22
 	}
23 23
 	

+ 21 - 9
xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java Wyświetl plik

@@ -1,6 +1,9 @@
1 1
 package com.xxl.quartz;
2 2
 
3
+import java.util.ArrayList;
3 4
 import java.util.Date;
5
+import java.util.HashMap;
6
+import java.util.List;
4 7
 import java.util.Map;
5 8
 import java.util.Set;
6 9
 
@@ -38,21 +41,30 @@ public final class DynamicSchedulerUtil implements InitializingBean {
38 41
     }
39 42
 	
40 43
 	// getJobKeys
41
-	public static Set<JobKey> getJobKeys(){
44
+	public static List<Map<String, Object>> getJobList(){
45
+		List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
46
+		
42 47
 		try {
43 48
 			String groupName = scheduler.getJobGroupNames().get(0);
44
-			return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
49
+			Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
50
+			if (jobKeys!=null && jobKeys.size()>0) {
51
+				for (JobKey jobKey : jobKeys) {
52
+			        TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
53
+			        Trigger trigger = scheduler.getTrigger(triggerKey);
54
+			        JobDetail jobDetail = scheduler.getJobDetail(jobKey);
55
+			        Map<String, Object> jobMap = new HashMap<String, Object>();
56
+			        jobMap.put("TriggerKey", triggerKey);
57
+			        jobMap.put("Trigger", trigger);
58
+			        jobMap.put("JobDetail", jobDetail);
59
+			        jobList.add(jobMap);
60
+				}
61
+			}
62
+			
45 63
 		} catch (SchedulerException e) {
46 64
 			e.printStackTrace();
47 65
 			return null;
48 66
 		}
49
-	}
50
-	
51
-	public static void getJobDetail(String triggerKeyName){
52
-		// TriggerKey : name + group
53
-    	String group = Scheduler.DEFAULT_GROUP;
54
-        TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group);
55
-        
67
+		return jobList;
56 68
 	}
57 69
 
58 70
 	// addJob 新增

+ 57 - 14
xxl-job-admin/src/main/webapp/WEB-INF/template/job/index.ftl Wyświetl plik

@@ -4,6 +4,9 @@
4 4
   	<title>调度中心</title>
5 5
   	<#import "/common/common.macro.ftl" as netCommon>
6 6
 	<@netCommon.commonStyle />
7
+	<!-- DataTables -->
8
+  	<link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/datatables/dataTables.bootstrap.css">
9
+  
7 10
 </head>
8 11
 <body class="hold-transition skin-blue sidebar-mini">
9 12
 <div class="wrapper">
@@ -22,22 +25,53 @@
22 25
 				<li class="active">使用教程</li>
23 26
 			</ol>
24 27
 		</section>
25
-
28
+		
26 29
 		<!-- Main content -->
27
-		<section class="content">
28
-            <div class="callout callout-info">
29
-				<h4>在线任务:</h4>
30
-				<#if jobList?exists && jobList?size gt 0>
31
-				<#list jobList as item>
32
-				<p>${item}</p>
33
-				</#list>
34
-				</#if>
35
-            </div>
36
-            
37
-		</section>
38
-		<!-- /.content -->
30
+	    <section class="content">
31
+			<div class="row">
32
+				<div class="col-xs-12">
33
+					<div class="box">
34
+			            <div class="box-header"><h3 class="box-title">任务列表</h3></div>
35
+			            <div class="box-body">
36
+			              	<table id="example1" class="table table-bordered table-striped">
37
+				                <thead>
38
+					            	<tr>
39
+					                	<th>任务ID</th>
40
+					                  	<th>cron</th>
41
+					                  	<th>Job类路径</th>
42
+					                  	<th>简介</th>
43
+					                  	<th>操作</th>
44
+					                </tr>
45
+				                </thead>
46
+				                <tbody>
47
+			                		<#if jobList?exists && jobList?size gt 0>
48
+									<#list jobList as item>
49
+									<tr>
50
+					            		<td>${item['TriggerKey'].name}</td>
51
+					                  	<td>${item['Trigger'].cronExpression}</td>
52
+					                  	<td>${item['JobDetail'].jobClass}</td>
53
+					                  	<td>-</td>
54
+					                  	<td>X</td>
55
+					                </tr>
56
+									</#list>
57
+									</#if>
58
+				                </tbody>
59
+				                <tfoot>
60
+					            	<tr>
61
+					                  	<th>任务ID</th>
62
+					                  	<th>cron</th>
63
+					                  	<th>Job类路径</th>
64
+					                  	<th>简介</th>
65
+					                  	<th>操作</th>
66
+					                </tr>
67
+				                </tfoot>
68
+							</table>
69
+						</div>
70
+					</div>
71
+				</div>
72
+			</div>
73
+	    </section>
39 74
 	</div>
40
-	<!-- /.content-wrapper -->
41 75
 	
42 76
 	<!-- footer -->
43 77
 	<@netCommon.commonFooter />
@@ -45,5 +79,14 @@
45 79
 	<@netCommon.commonControl />
46 80
 </div>
47 81
 <@netCommon.commonScript />
82
+<!-- DataTables -->
83
+<script src="${request.contextPath}/static/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
84
+<script src="${request.contextPath}/static/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
85
+<!-- page script -->
86
+<script>
87
+  $(function () {
88
+		$("#example1").DataTable();
89
+  });
90
+</script>
48 91
 </body>
49 92
 </html>