瀏覽代碼

调度报表优化,支持时间区间筛选;

xuxueli 7 年之前
父節點
當前提交
0e1ef7f3ed

+ 5 - 5
doc/XXL-JOB官方文档.md 查看文件

@@ -1057,6 +1057,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1057 1057
 - 9、任务注解调整为 “@JobHandler”,与任务注解统一;
1058 1058
 - 10、执行器端口支持随机生成(小于等于0时),避免端口定义冲突;
1059 1059
 - 11、任务Cron长度扩展支持至128位;
1060
+- 12、调度报表优化,支持时间区间筛选;
1060 1061
 
1061 1062
 ### TODO LIST
1062 1063
 - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;
@@ -1075,11 +1076,10 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1075 1076
 - 14、脚本任务 Shell、Python和Nodejs,如何友好获取分片参数;
1076 1077
 - 15、Bean模式任务,JobHandler自动从执行器中查询展示为下拉框,选择后自动填充任务名称等属性;
1077 1078
 - 16、任务告警邮件优化,调整为表格形式;
1078
-- 17、任务报表,支持时间筛选;
1079
-- 18、JobHandler提供 init/destroy 方法,支持自定义任务线程销毁逻辑;
1080
-- 19、cron表达式的最大长度调整,兼容复杂类型cron;
1081
-- 20、执行器回调地址/日志地址格式兼容,是否已"/"结尾均支持;
1082
-- 21、任务单机多线程:提升任务单机并行处理能力;
1079
+- 17、JobHandler提供 init/destroy 方法,支持自定义任务线程销毁逻辑;
1080
+- 18、cron表达式的最大长度调整,兼容复杂类型cron;
1081
+- 19、执行器回调地址/日志地址格式兼容,是否已"/"结尾均支持;
1082
+- 20、任务单机多线程:提升任务单机并行处理能力;
1083 1083
 
1084 1084
 
1085 1085
 ## 七、其他

+ 14 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/IndexController.java 查看文件

@@ -6,8 +6,11 @@ import com.xxl.job.admin.core.util.PropertiesUtil;
6 6
 import com.xxl.job.admin.service.XxlJobService;
7 7
 import com.xxl.job.core.biz.model.ReturnT;
8 8
 import org.apache.commons.lang.StringUtils;
9
+import org.springframework.beans.propertyeditors.CustomDateEditor;
9 10
 import org.springframework.stereotype.Controller;
10 11
 import org.springframework.ui.Model;
12
+import org.springframework.web.bind.WebDataBinder;
13
+import org.springframework.web.bind.annotation.InitBinder;
11 14
 import org.springframework.web.bind.annotation.RequestMapping;
12 15
 import org.springframework.web.bind.annotation.RequestMethod;
13 16
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
15 18
 import javax.annotation.Resource;
16 19
 import javax.servlet.http.HttpServletRequest;
17 20
 import javax.servlet.http.HttpServletResponse;
21
+import java.text.SimpleDateFormat;
22
+import java.util.Date;
18 23
 import java.util.Map;
19 24
 
20 25
 /**
@@ -38,8 +43,8 @@ public class IndexController {
38 43
 
39 44
     @RequestMapping("/triggerChartDate")
40 45
 	@ResponseBody
41
-	public ReturnT<Map<String, Object>> triggerChartDate() {
42
-        ReturnT<Map<String, Object>> triggerChartDate = xxlJobService.triggerChartDate();
46
+	public ReturnT<Map<String, Object>> triggerChartDate(Date startDate, Date endDate) {
47
+        ReturnT<Map<String, Object>> triggerChartDate = xxlJobService.triggerChartDate(startDate, endDate);
43 48
         return triggerChartDate;
44 49
     }
45 50
 	
@@ -91,5 +96,12 @@ public class IndexController {
91 96
 
92 97
 		return "help";
93 98
 	}
99
+
100
+	@InitBinder
101
+	public void initBinder(WebDataBinder binder) {
102
+		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
103
+		dateFormat.setLenient(false);
104
+		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
105
+	}
94 106
 	
95 107
 }

+ 2 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/service/XxlJobService.java 查看文件

@@ -4,6 +4,7 @@ package com.xxl.job.admin.service;
4 4
 import com.xxl.job.admin.core.model.XxlJobInfo;
5 5
 import com.xxl.job.core.biz.model.ReturnT;
6 6
 
7
+import java.util.Date;
7 8
 import java.util.Map;
8 9
 
9 10
 /**
@@ -29,6 +30,6 @@ public interface XxlJobService {
29 30
 
30 31
 	public Map<String,Object> dashboardInfo();
31 32
 
32
-	public ReturnT<Map<String,Object>> triggerChartDate();
33
+	public ReturnT<Map<String,Object>> triggerChartDate(Date startDate, Date endDate);
33 34
 
34 35
 }

+ 3 - 6
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java 查看文件

@@ -310,18 +310,15 @@ public class XxlJobServiceImpl implements XxlJobService {
310 310
 	}
311 311
 
312 312
 	@Override
313
-	public ReturnT<Map<String, Object>> triggerChartDate() {
314
-		Date from = DateUtils.addDays(new Date(), -30);
315
-		Date to = new Date();
316
-
313
+	public ReturnT<Map<String, Object>> triggerChartDate(Date startDate, Date endDate) {
317 314
 		List<String> triggerDayList = new ArrayList<String>();
318 315
 		List<Integer> triggerDayCountSucList = new ArrayList<Integer>();
319 316
 		List<Integer> triggerDayCountFailList = new ArrayList<Integer>();
320 317
 		int triggerCountSucTotal = 0;
321 318
 		int triggerCountFailTotal = 0;
322 319
 
323
-		List<Map<String, Object>> triggerCountMapAll = xxlJobLogDao.triggerCountByDay(from, to, -1);
324
-		List<Map<String, Object>> triggerCountMapSuc = xxlJobLogDao.triggerCountByDay(from, to, ReturnT.SUCCESS_CODE);
320
+		List<Map<String, Object>> triggerCountMapAll = xxlJobLogDao.triggerCountByDay(startDate, endDate, -1);
321
+		List<Map<String, Object>> triggerCountMapSuc = xxlJobLogDao.triggerCountByDay(startDate, endDate, ReturnT.SUCCESS_CODE);
325 322
 		if (CollectionUtils.isNotEmpty(triggerCountMapAll)) {
326 323
 			for (Map<String, Object> item: triggerCountMapAll) {
327 324
 				String day = String.valueOf(item.get("triggerDay"));

+ 21 - 7
xxl-job-admin/src/main/webapp/WEB-INF/template/index.ftl 查看文件

@@ -4,6 +4,8 @@
4 4
   	<title>任务调度中心</title>
5 5
   	<#import "/common/common.macro.ftl" as netCommon>
6 6
 	<@netCommon.commonStyle />
7
+    <!-- daterangepicker -->
8
+    <link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/daterangepicker/daterangepicker.css">
7 9
 </head>
8 10
 <body class="hold-transition skin-blue sidebar-mini <#if cookieMap?exists && "off" == cookieMap["xxljob_adminlte_settings"].value >sidebar-collapse</#if> ">
9 11
 <div class="wrapper">
@@ -43,7 +45,7 @@
43 45
                             <div class="progress">
44 46
                                 <div class="progress-bar" style="width: 100%"></div>
45 47
                             </div>
46
-                            <span class="progress-description">系统中配置的任务数量</span>
48
+                            <span class="progress-description">调度中心运行的任务数量</span>
47 49
                         </div>
48 50
                     </div>
49 51
                 </div>
@@ -82,7 +84,7 @@
82 84
                             <div class="progress">
83 85
                                 <div class="progress-bar" style="width: 100%"></div>
84 86
                             </div>
85
-                            <span class="progress-description">心跳检测成功的执行器机器数量</span>
87
+                            <span class="progress-description">调度中心注册发现的执行器机器数量</span>
86 88
                         </div>
87 89
                     </div>
88 90
                 </div>
@@ -94,8 +96,20 @@
94 96
                 <div class="col-md-12">
95 97
                     <div class="box">
96 98
                         <div class="box-header with-border">
97
-                            <h3 class="box-title">调度报表(一月之内)</h3>
99
+                            <h3 class="box-title">调度报表</h3>
98 100
                             <#--<input type="text" class="form-control" id="filterTime" readonly >-->
101
+
102
+                            <!-- tools box -->
103
+                            <div class="pull-right box-tools">
104
+                                <button type="button" class="btn btn-primary btn-sm daterange pull-right" data-toggle="tooltip" id="filterTime" >
105
+                                    <i class="fa fa-calendar"></i>
106
+                                </button>
107
+                                <#--<button type="button" class="btn btn-primary btn-sm pull-right" data-widget="collapse" data-toggle="tooltip" title="" style="margin-right: 5px;" data-original-title="Collapse">
108
+                                    <i class="fa fa-minus"></i>
109
+                                </button>-->
110
+                            </div>
111
+                            <!-- /. tools -->
112
+
99 113
                         </div>
100 114
                         <div class="box-body">
101 115
                             <div class="row">
@@ -113,7 +127,6 @@
113 127
                 </div>
114 128
             </div>
115 129
 
116
-
117 130
 		</section>
118 131
 		<!-- /.content -->
119 132
 	</div>
@@ -123,10 +136,11 @@
123 136
 	<@netCommon.commonFooter />
124 137
 </div>
125 138
 <@netCommon.commonScript />
126
-<#--<script src="${request.contextPath}/static/adminlte/plugins/daterangepicker/moment.min.js"></script>
127
-<script src="${request.contextPath}/static/adminlte/plugins/daterangepicker/daterangepicker.js"></script>-->
139
+<!-- daterangepicker -->
140
+<script src="${request.contextPath}/static/adminlte/plugins/daterangepicker/moment.min.js"></script>
141
+<script src="${request.contextPath}/static/adminlte/plugins/daterangepicker/daterangepicker.js"></script>
142
+<#-- echarts -->
128 143
 <script src="${request.contextPath}/static/plugins/echarts/echarts.common.min.js"></script>
129 144
 <script src="${request.contextPath}/static/js/index.js"></script>
130
-
131 145
 </body>
132 146
 </html>

+ 64 - 53
xxl-job-admin/src/main/webapp/static/js/index.js 查看文件

@@ -5,29 +5,74 @@
5 5
 
6 6
 $(function () {
7 7
 
8
+    // 过滤时间
9
+    var _startDate = moment().subtract(1, 'months');
10
+    var _endDate = moment();
11
+    $('#filterTime').daterangepicker({
12
+        autoApply:false,
13
+        singleDatePicker:false,
14
+        showDropdowns:false,        // 是否显示年月选择条件
15
+        timePicker: true, 			// 是否显示小时和分钟选择条件
16
+        timePickerIncrement: 10, 	// 时间的增量,单位为分钟
17
+        timePicker24Hour : true,
18
+        opens : 'left', //日期选择框的弹出位置
19
+        ranges: {
20
+            //'最近1小时': [moment().subtract(1, 'hours'), moment()],
21
+            '今日': [moment().startOf('day'), moment().endOf('day')],
22
+            '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
23
+            '最近7日': [moment().subtract(7, 'days'), moment()],
24
+            '最近30日': [moment().subtract(1, 'months'), moment()],
25
+            '本月': [moment().startOf('month'), moment().endOf('month')],
26
+            '上个月': [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')]
27
+        },
28
+        locale : {
29
+            format: 'YYYY-MM-DD HH:mm:ss',
30
+            separator : ' - ',
31
+            customRangeLabel : '自定义',
32
+            applyLabel : '确定',
33
+            cancelLabel : '取消',
34
+            fromLabel : '起始时间',
35
+            toLabel : '结束时间',
36
+            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
37
+            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
38
+            firstDay : 1
39
+        },
40
+        startDate:_startDate,
41
+        endDate: _endDate
42
+    }, function (start, end, label) {
43
+        freshChartDate(start, end);
44
+    });
45
+    freshChartDate(_startDate, _endDate);
46
+
8 47
     /**
48
+     * 刷新报表
9 49
      *
50
+     * @param startDate
51
+     * @param endDate
10 52
      */
11
-    $.ajax({
12
-        type : 'POST',
13
-        url : base_url + '/triggerChartDate',
14
-        data : {        },
15
-        dataType : "json",
16
-        success : function(data){
17
-            if (data.code == 200) {
18
-                lineChartInit(data)
19
-                pieChartInit(data);
20
-            } else {
21
-                layer.open({
22
-                    title: '系统提示',
23
-                    content: (data.msg || '调度报表数据加载异常'),
24
-                    icon: '2'
25
-                });
53
+    function freshChartDate(startDate, endDate) {
54
+        $.ajax({
55
+            type : 'POST',
56
+            url : base_url + '/triggerChartDate',
57
+            data : {
58
+                'startDate':startDate.format('YYYY-MM-DD HH:mm:ss'),
59
+                'endDate':endDate.format('YYYY-MM-DD HH:mm:ss')
60
+            },
61
+            dataType : "json",
62
+            success : function(data){
63
+                if (data.code == 200) {
64
+                    lineChartInit(data)
65
+                    pieChartInit(data);
66
+                } else {
67
+                    layer.open({
68
+                        title: '系统提示',
69
+                        content: (data.msg || '调度报表数据加载异常'),
70
+                        icon: '2'
71
+                    });
72
+                }
26 73
             }
27
-        }
28
-    });
29
-
30
-
74
+        });
75
+    }
31 76
 
32 77
     /**
33 78
      * 折线图
@@ -151,38 +196,4 @@ $(function () {
151 196
         pieChart.setOption(option);
152 197
     }
153 198
 
154
-    // 过滤时间
155
-    /*$('#filterTime').daterangepicker({
156
-        autoApply:false,
157
-        singleDatePicker:false,
158
-        showDropdowns:false,        // 是否显示年月选择条件
159
-        timePicker: true, 			// 是否显示小时和分钟选择条件
160
-        timePickerIncrement: 10, 	// 时间的增量,单位为分钟
161
-        timePicker24Hour : true,
162
-        opens : 'left', //日期选择框的弹出位置
163
-        ranges: {
164
-            '最近1小时': [moment().subtract(1, 'hours'), moment()],
165
-            '今日': [moment().startOf('day'), moment().endOf('day')],
166
-            '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
167
-            '最近7日': [moment().subtract(6, 'days'), moment()],
168
-            '最近30日': [moment().subtract(29, 'days'), moment()],
169
-            '本月': [moment().startOf('month'), moment().endOf('month')],
170
-            '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
171
-        },
172
-        locale : {
173
-            format: 'YYYY-MM-DD HH:mm:ss',
174
-            separator : ' - ',
175
-            customRangeLabel : '自定义',
176
-            applyLabel : '确定',
177
-            cancelLabel : '取消',
178
-            fromLabel : '起始时间',
179
-            toLabel : '结束时间',
180
-            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
181
-            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
182
-            firstDay : 1,
183
-            startDate: moment().startOf('day'),
184
-            endDate: moment().endOf('day')
185
-        }
186
-    });*/
187
-
188 199
 });