Explorar el Código

调度报表优化:新增日志报表的存储表,三天内的任务日志会以每分钟一次的频率异步同步至报表中;任务报表仅读取报表数据,极大提升加载速度;

xuxueli hace 5 años
padre
commit
7ab75aa817

+ 2 - 1
doc/XXL-JOB官方文档.md Ver fichero

@@ -1598,7 +1598,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1598 1598
 - 20、xxl-rpc服务端线程优化,降低线程内存开销;
1599 1599
 - 21、调度中心回调API服务改为restful方式;
1600 1600
 - 22、调度中心日志删除优化,改为分页获取ID并根据ID删除的方式,避免批量删除海量日志导致死锁问题;
1601
-- 23、[ING]调度日志优化:支持设置日志保留天数,过期日志天维度记录报表,并清理;调度报表汇总实时数据和报表;
1601
+- 23、调度报表优化:新增日志报表的存储表,三天内的任务日志会以每分钟一次的频率异步同步至报表中;任务报表仅读取报表数据,极大提升加载速度;
1602
+- 24、[ing]调度日志优化:支持设置日志保留天数,过期日志天维度记录报表,并清理;调度报表汇总实时数据和报表;
1602 1603
 
1603 1604
 
1604 1605
 

+ 10 - 0
doc/db/tables_xxl_job.sql Ver fichero

@@ -53,6 +53,16 @@ CREATE TABLE `xxl_job_log` (
53 53
   KEY `I_handle_code` (`handle_code`)
54 54
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
55 55
 
56
+CREATE TABLE `xxl_job_log_report` (
57
+  `id` int(11) NOT NULL AUTO_INCREMENT,
58
+  `trigger_day` datetime DEFAULT NULL COMMENT '调度-时间',
59
+  `running_count` int(11) NOT NULL DEFAULT '0' COMMENT '运行中-日志数量',
60
+  `suc_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行成功-日志数量',
61
+  `fail_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行失败-日志数量',
62
+  PRIMARY KEY (`id`),
63
+  UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
64
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
65
+
56 66
 CREATE TABLE `xxl_job_logglue` (
57 67
   `id` int(11) NOT NULL AUTO_INCREMENT,
58 68
   `job_id` int(11) NOT NULL COMMENT '任务,主键ID',

+ 7 - 4
xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java Ver fichero

@@ -1,10 +1,7 @@
1 1
 package com.xxl.job.admin.core.conf;
2 2
 
3 3
 import com.xxl.job.admin.core.scheduler.XxlJobScheduler;
4
-import com.xxl.job.admin.dao.XxlJobGroupDao;
5
-import com.xxl.job.admin.dao.XxlJobInfoDao;
6
-import com.xxl.job.admin.dao.XxlJobLogDao;
7
-import com.xxl.job.admin.dao.XxlJobRegistryDao;
4
+import com.xxl.job.admin.dao.*;
8 5
 import org.springframework.beans.factory.DisposableBean;
9 6
 import org.springframework.beans.factory.InitializingBean;
10 7
 import org.springframework.beans.factory.annotation.Value;
@@ -76,6 +73,8 @@ public class XxlJobAdminConfig implements InitializingBean, DisposableBean {
76 73
     @Resource
77 74
     private XxlJobGroupDao xxlJobGroupDao;
78 75
     @Resource
76
+    private XxlJobLogReportDao xxlJobLogReportDao;
77
+    @Resource
79 78
     private JavaMailSender mailSender;
80 79
     @Resource
81 80
     private DataSource dataSource;
@@ -123,6 +122,10 @@ public class XxlJobAdminConfig implements InitializingBean, DisposableBean {
123 122
         return xxlJobGroupDao;
124 123
     }
125 124
 
125
+    public XxlJobLogReportDao getXxlJobLogReportDao() {
126
+        return xxlJobLogReportDao;
127
+    }
128
+
126 129
     public JavaMailSender getMailSender() {
127 130
         return mailSender;
128 131
     }

+ 54 - 0
xxl-job-admin/src/main/java/com/xxl/job/admin/core/model/XxlJobLogReport.java Ver fichero

@@ -0,0 +1,54 @@
1
+package com.xxl.job.admin.core.model;
2
+
3
+import java.util.Date;
4
+
5
+public class XxlJobLogReport {
6
+
7
+    private int id;
8
+
9
+    private Date triggerDay;
10
+
11
+    private int runningCount;
12
+    private int sucCount;
13
+    private int failCount;
14
+
15
+    public int getId() {
16
+        return id;
17
+    }
18
+
19
+    public void setId(int id) {
20
+        this.id = id;
21
+    }
22
+
23
+    public Date getTriggerDay() {
24
+        return triggerDay;
25
+    }
26
+
27
+    public void setTriggerDay(Date triggerDay) {
28
+        this.triggerDay = triggerDay;
29
+    }
30
+
31
+    public int getRunningCount() {
32
+        return runningCount;
33
+    }
34
+
35
+    public void setRunningCount(int runningCount) {
36
+        this.runningCount = runningCount;
37
+    }
38
+
39
+    public int getSucCount() {
40
+        return sucCount;
41
+    }
42
+
43
+    public void setSucCount(int sucCount) {
44
+        this.sucCount = sucCount;
45
+    }
46
+
47
+    public int getFailCount() {
48
+        return failCount;
49
+    }
50
+
51
+    public void setFailCount(int failCount) {
52
+        this.failCount = failCount;
53
+    }
54
+}

+ 7 - 4
xxl-job-admin/src/main/java/com/xxl/job/admin/core/scheduler/XxlJobScheduler.java Ver fichero

@@ -1,10 +1,7 @@
1 1
 package com.xxl.job.admin.core.scheduler;
2 2
 
3 3
 import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
4
-import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
5
-import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
6
-import com.xxl.job.admin.core.thread.JobScheduleHelper;
7
-import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
4
+import com.xxl.job.admin.core.thread.*;
8 5
 import com.xxl.job.admin.core.util.I18nUtil;
9 6
 import com.xxl.job.core.biz.ExecutorBiz;
10 7
 import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
@@ -40,6 +37,9 @@ public class XxlJobScheduler  {
40 37
         // admin trigger pool start
41 38
         JobTriggerPoolHelper.toStart();
42 39
 
40
+        // admin log report start
41
+        JobLogReportHelper.getInstance().start();
42
+
43 43
         // start-schedule
44 44
         JobScheduleHelper.getInstance().start();
45 45
 
@@ -52,6 +52,9 @@ public class XxlJobScheduler  {
52 52
         // stop-schedule
53 53
         JobScheduleHelper.getInstance().toStop();
54 54
 
55
+        // admin log report stop
56
+        JobLogReportHelper.getInstance().toStop();
57
+
55 58
         // admin trigger pool stop
56 59
         JobTriggerPoolHelper.toStop();
57 60
 

+ 10 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java Ver fichero

@@ -85,13 +85,21 @@ public class JobFailMonitorHelper {
85 85
 							}
86 86
 						}
87 87
 
88
-						TimeUnit.SECONDS.sleep(10);
89 88
 					} catch (Exception e) {
90 89
 						if (!toStop) {
91 90
 							logger.error(">>>>>>>>>>> xxl-job, job fail monitor thread error:{}", e);
92 91
 						}
93 92
 					}
94
-				}
93
+
94
+                    try {
95
+                        TimeUnit.SECONDS.sleep(10);
96
+                    } catch (Exception e) {
97
+                        if (!toStop) {
98
+                            logger.error(e.getMessage(), e);
99
+                        }
100
+                    }
101
+
102
+                }
95 103
 
96 104
 				logger.info(">>>>>>>>>>> xxl-job, job fail monitor thread stop");
97 105
 

+ 121 - 0
xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobLogReportHelper.java Ver fichero

@@ -0,0 +1,121 @@
1
+package com.xxl.job.admin.core.thread;
2
+
3
+import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
4
+import com.xxl.job.admin.core.model.XxlJobLogReport;
5
+import org.slf4j.Logger;
6
+import org.slf4j.LoggerFactory;
7
+
8
+import java.util.Calendar;
9
+import java.util.Date;
10
+import java.util.Map;
11
+import java.util.concurrent.TimeUnit;
12
+
13
+/**
14
+ * job log report helper
15
+ *
16
+ * @author xuxueli 2019-11-22
17
+ */
18
+public class JobLogReportHelper {
19
+    private static Logger logger = LoggerFactory.getLogger(JobLogReportHelper.class);
20
+
21
+    private static JobLogReportHelper instance = new JobLogReportHelper();
22
+    public static JobLogReportHelper getInstance(){
23
+        return instance;
24
+    }
25
+
26
+
27
+    private Thread logrThread;
28
+    private volatile boolean toStop = false;
29
+    public void start(){
30
+        logrThread = new Thread(new Runnable() {
31
+
32
+            @Override
33
+            public void run() {
34
+
35
+                // monitor
36
+                while (!toStop) {
37
+                    try {
38
+
39
+                        // refresh log report in 3 days
40
+                        for (int i = 0; i < 3; i++) {
41
+
42
+                            // today
43
+                            Calendar itemDay = Calendar.getInstance();
44
+                            itemDay.add(Calendar.DAY_OF_MONTH, -i);
45
+                            itemDay.set(Calendar.HOUR_OF_DAY, 0);
46
+                            itemDay.set(Calendar.MINUTE, 0);
47
+                            itemDay.set(Calendar.SECOND, 0);
48
+                            itemDay.set(Calendar.MILLISECOND, 0);
49
+
50
+                            Date todayFrom = itemDay.getTime();
51
+
52
+                            itemDay.set(Calendar.HOUR_OF_DAY, 23);
53
+                            itemDay.set(Calendar.MINUTE, 59);
54
+                            itemDay.set(Calendar.SECOND, 59);
55
+                            itemDay.set(Calendar.MILLISECOND, 999);
56
+
57
+                            Date todayTo = itemDay.getTime();
58
+
59
+                            // refresh log-report every minute
60
+                            XxlJobLogReport xxlJobLogReport = new XxlJobLogReport();
61
+                            xxlJobLogReport.setTriggerDay(todayFrom);
62
+                            xxlJobLogReport.setRunningCount(0);
63
+                            xxlJobLogReport.setSucCount(0);
64
+                            xxlJobLogReport.setFailCount(0);
65
+
66
+                            Map<String, Object> triggerCountMap = XxlJobAdminConfig.getAdminConfig().getXxlJobLogDao().findLogReport(todayFrom, todayTo);
67
+                            if (triggerCountMap!=null && triggerCountMap.size()>0) {
68
+                                int triggerDayCount = triggerCountMap.containsKey("triggerDayCount")?Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCount"))):0;
69
+                                int triggerDayCountRunning = triggerCountMap.containsKey("triggerDayCountRunning")?Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCountRunning"))):0;
70
+                                int triggerDayCountSuc = triggerCountMap.containsKey("triggerDayCountSuc")?Integer.valueOf(String.valueOf(triggerCountMap.get("triggerDayCountSuc"))):0;
71
+                                int triggerDayCountFail = triggerDayCount - triggerDayCountRunning - triggerDayCountSuc;
72
+
73
+                                xxlJobLogReport.setRunningCount(triggerDayCountRunning);
74
+                                xxlJobLogReport.setSucCount(triggerDayCountSuc);
75
+                                xxlJobLogReport.setFailCount(triggerDayCountFail);
76
+                            }
77
+
78
+                            // do refresh
79
+                            int ret = XxlJobAdminConfig.getAdminConfig().getXxlJobLogReportDao().update(xxlJobLogReport);
80
+                            if (ret < 1) {
81
+                                XxlJobAdminConfig.getAdminConfig().getXxlJobLogReportDao().save(xxlJobLogReport);
82
+                            }
83
+                        }
84
+
85
+                    } catch (Exception e) {
86
+                        if (!toStop) {
87
+                            logger.error(">>>>>>>>>>> xxl-job, job log report thread error:{}", e);
88
+                        }
89
+                    }
90
+
91
+                    try {
92
+                        TimeUnit.MINUTES.sleep(1);
93
+                    } catch (Exception e) {
94
+                        if (!toStop) {
95
+                            logger.error(e.getMessage(), e);
96
+                        }
97
+                    }
98
+
99
+                }
100
+
101
+                logger.info(">>>>>>>>>>> xxl-job, job log report thread stop");
102
+
103
+            }
104
+        });
105
+        logrThread.setDaemon(true);
106
+        logrThread.setName("xxl-job, admin JobLogReportHelper");
107
+        logrThread.start();
108
+    }
109
+
110
+    public void toStop(){
111
+        toStop = true;
112
+        // interrupt and wait
113
+        logrThread.interrupt();
114
+        try {
115
+            logrThread.join();
116
+        } catch (InterruptedException e) {
117
+            logger.error(e.getMessage(), e);
118
+        }
119
+    }
120
+
121
+}

+ 1 - 0
xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobScheduleHelper.java Ver fichero

@@ -84,6 +84,7 @@ public class JobScheduleHelper {
84 84
                                 // time-ring jump
85 85
                                 if (nowTime > jobInfo.getTriggerNextTime() + PRE_READ_MS) {
86 86
                                     // 2.1、trigger-expire > 5s:pass && make next-trigger-time
87
+                                    logger.warn(">>>>>>>>>>> xxl-job, schedule misfire, jobId = " + jobInfo.getId());
87 88
 
88 89
                                     // fresh next
89 90
                                     refreshNextValidTime(jobInfo, new Date());

+ 2 - 4
xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java Ver fichero

@@ -41,10 +41,8 @@ public interface XxlJobLogDao {
41 41
 	
42 42
 	public int delete(@Param("jobId") int jobId);
43 43
 
44
-	public int triggerCountByHandleCode(@Param("handleCode") int handleCode);
45
-
46
-	public List<Map<String, Object>> triggerCountByDay(@Param("from") Date from,
47
-													   @Param("to") Date to);
44
+	public Map<String, Object> findLogReport(@Param("from") Date from,
45
+											 @Param("to") Date to);
48 46
 
49 47
 	public List<Long> findClearLogIds(@Param("jobGroup") int jobGroup,
50 48
 									  @Param("jobId") int jobId,

+ 26 - 0
xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogReportDao.java Ver fichero

@@ -0,0 +1,26 @@
1
+package com.xxl.job.admin.dao;
2
+
3
+import com.xxl.job.admin.core.model.XxlJobLogReport;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.util.Date;
8
+import java.util.List;
9
+
10
+/**
11
+ * job log
12
+ * @author xuxueli 2019-11-22
13
+ */
14
+@Mapper
15
+public interface XxlJobLogReportDao {
16
+
17
+	public int save(XxlJobLogReport xxlJobLogReport);
18
+
19
+	public int update(XxlJobLogReport xxlJobLogReport);
20
+
21
+	public List<XxlJobLogReport> queryLogReport(@Param("triggerDayFrom") Date triggerDayFrom,
22
+												@Param("triggerDayTo") Date triggerDayTo);
23
+
24
+	public XxlJobLogReport queryLogReportTotal();
25
+
26
+}

+ 24 - 29
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java Ver fichero

@@ -3,13 +3,11 @@ package com.xxl.job.admin.service.impl;
3 3
 import com.xxl.job.admin.core.model.XxlJobGroup;
4 4
 import com.xxl.job.admin.core.model.XxlJobInfo;
5 5
 import com.xxl.job.admin.core.cron.CronExpression;
6
+import com.xxl.job.admin.core.model.XxlJobLogReport;
6 7
 import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
7 8
 import com.xxl.job.admin.core.thread.JobScheduleHelper;
8 9
 import com.xxl.job.admin.core.util.I18nUtil;
9
-import com.xxl.job.admin.dao.XxlJobGroupDao;
10
-import com.xxl.job.admin.dao.XxlJobInfoDao;
11
-import com.xxl.job.admin.dao.XxlJobLogDao;
12
-import com.xxl.job.admin.dao.XxlJobLogGlueDao;
10
+import com.xxl.job.admin.dao.*;
13 11
 import com.xxl.job.admin.service.XxlJobService;
14 12
 import com.xxl.job.core.biz.model.ReturnT;
15 13
 import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
@@ -40,6 +38,8 @@ public class XxlJobServiceImpl implements XxlJobService {
40 38
 	public XxlJobLogDao xxlJobLogDao;
41 39
 	@Resource
42 40
 	private XxlJobLogGlueDao xxlJobLogGlueDao;
41
+	@Resource
42
+	private XxlJobLogReportDao xxlJobLogReportDao;
43 43
 	
44 44
 	@Override
45 45
 	public Map<String, Object> pageList(int start, int length, int jobGroup, int triggerStatus, String jobDesc, String executorHandler, String author) {
@@ -287,8 +287,13 @@ public class XxlJobServiceImpl implements XxlJobService {
287 287
 	public Map<String, Object> dashboardInfo() {
288 288
 
289 289
 		int jobInfoCount = xxlJobInfoDao.findAllCount();
290
-		int jobLogCount = xxlJobLogDao.triggerCountByHandleCode(-1);
291
-		int jobLogSuccessCount = xxlJobLogDao.triggerCountByHandleCode(ReturnT.SUCCESS_CODE);
290
+		int jobLogCount = 0;
291
+		int jobLogSuccessCount = 0;
292
+		XxlJobLogReport xxlJobLogReport = xxlJobLogReportDao.queryLogReportTotal();
293
+		if (xxlJobLogReport != null) {
294
+			jobLogCount = xxlJobLogReport.getRunningCount() + xxlJobLogReport.getSucCount() + xxlJobLogReport.getFailCount();
295
+			jobLogSuccessCount = xxlJobLogReport.getSucCount();
296
+		}
292 297
 
293 298
 		// executor count
294 299
 		Set<String> executorAddressSet = new HashSet<String>();
@@ -312,15 +317,8 @@ public class XxlJobServiceImpl implements XxlJobService {
312 317
 		return dashboardMap;
313 318
 	}
314 319
 
315
-	private static final String TRIGGER_CHART_DATA_CACHE = "trigger_chart_data_cache";
316 320
 	@Override
317 321
 	public ReturnT<Map<String, Object>> chartInfo(Date startDate, Date endDate) {
318
-		/*// get cache
319
-		String cacheKey = TRIGGER_CHART_DATA_CACHE + "_" + startDate.getTime() + "_" + endDate.getTime();
320
-		Map<String, Object> chartInfo = (Map<String, Object>) LocalCacheUtil.get(cacheKey);
321
-		if (chartInfo != null) {
322
-			return new ReturnT<Map<String, Object>>(chartInfo);
323
-		}*/
324 322
 
325 323
 		// process
326 324
 		List<String> triggerDayList = new ArrayList<String>();
@@ -331,14 +329,14 @@ public class XxlJobServiceImpl implements XxlJobService {
331 329
 		int triggerCountSucTotal = 0;
332 330
 		int triggerCountFailTotal = 0;
333 331
 
334
-		List<Map<String, Object>> triggerCountMapAll = xxlJobLogDao.triggerCountByDay(startDate, endDate);
335
-		if (triggerCountMapAll!=null && triggerCountMapAll.size()>0) {
336
-			for (Map<String, Object> item: triggerCountMapAll) {
337
-				String day = String.valueOf(item.get("triggerDay"));
338
-				int triggerDayCount = Integer.valueOf(String.valueOf(item.get("triggerDayCount")));
339
-				int triggerDayCountRunning = Integer.valueOf(String.valueOf(item.get("triggerDayCountRunning")));
340
-				int triggerDayCountSuc = Integer.valueOf(String.valueOf(item.get("triggerDayCountSuc")));
341
-				int triggerDayCountFail = triggerDayCount - triggerDayCountRunning - triggerDayCountSuc;
332
+		List<XxlJobLogReport> logReportList = xxlJobLogReportDao.queryLogReport(startDate, endDate);
333
+
334
+		if (logReportList!=null && logReportList.size()>0) {
335
+			for (XxlJobLogReport item: logReportList) {
336
+				String day = DateUtil.formatDate(item.getTriggerDay());
337
+				int triggerDayCountRunning = item.getRunningCount();
338
+				int triggerDayCountSuc = item.getSucCount();
339
+				int triggerDayCountFail = item.getFailCount();
342 340
 
343 341
 				triggerDayList.add(day);
344 342
 				triggerDayCountRunningList.add(triggerDayCountRunning);
@@ -350,12 +348,12 @@ public class XxlJobServiceImpl implements XxlJobService {
350 348
 				triggerCountFailTotal += triggerDayCountFail;
351 349
 			}
352 350
 		} else {
353
-            for (int i = 4; i > -1; i--) {
354
-                triggerDayList.add(DateUtil.formatDate(DateUtil.addDays(new Date(), -i)));
351
+			for (int i = -6; i <= 0; i++) {
352
+				triggerDayList.add(DateUtil.formatDate(DateUtil.addDays(new Date(), i)));
355 353
 				triggerDayCountRunningList.add(0);
356
-                triggerDayCountSucList.add(0);
357
-                triggerDayCountFailList.add(0);
358
-            }
354
+				triggerDayCountSucList.add(0);
355
+				triggerDayCountFailList.add(0);
356
+			}
359 357
 		}
360 358
 
361 359
 		Map<String, Object> result = new HashMap<String, Object>();
@@ -368,9 +366,6 @@ public class XxlJobServiceImpl implements XxlJobService {
368 366
 		result.put("triggerCountSucTotal", triggerCountSucTotal);
369 367
 		result.put("triggerCountFailTotal", triggerCountFailTotal);
370 368
 
371
-		/*// set cache
372
-		LocalCacheUtil.set(cacheKey, result, 60*1000);     // cache 60s*/
373
-
374 369
 		return new ReturnT<Map<String, Object>>(result);
375 370
 	}
376 371
 

+ 10 - 11
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml Ver fichero

@@ -164,17 +164,7 @@
164 164
 		WHERE job_id = #{jobId}
165 165
 	</delete>
166 166
 
167
-	<select id="triggerCountByHandleCode" resultType="int" >
168
-		SELECT count(1)
169
-		FROM xxl_job_log AS t
170
-		<trim prefix="WHERE" prefixOverrides="AND | OR" >
171
-			<if test="handleCode gt 0">
172
-				AND t.handle_code = #{handleCode}
173
-			</if>
174
-		</trim>
175
-	</select>
176
-
177
-    <select id="triggerCountByDay" resultType="java.util.Map" >
167
+    <!--<select id="triggerCountByDay" resultType="java.util.Map" >
178 168
 		SELECT
179 169
 			DATE_FORMAT(trigger_time,'%Y-%m-%d') triggerDay,
180 170
 			COUNT(handle_code) triggerDayCount,
@@ -184,6 +174,15 @@
184 174
 		WHERE trigger_time BETWEEN #{from} and #{to}
185 175
 		GROUP BY triggerDay
186 176
 		ORDER BY triggerDay
177
+    </select>-->
178
+
179
+    <select id="findLogReport" resultType="java.util.Map" >
180
+		SELECT
181
+			COUNT(handle_code) triggerDayCount,
182
+			SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end) as triggerDayCountRunning,
183
+			SUM(CASE WHEN handle_code = 200 then 1 else 0 end) as triggerDayCountSuc
184
+		FROM xxl_job_log
185
+		WHERE trigger_time BETWEEN #{from} and #{to}
187 186
     </select>
188 187
 
189 188
 	<select id="findClearLogIds" resultType="long" >

+ 62 - 0
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogReportMapper.xml Ver fichero

@@ -0,0 +1,62 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
3
+	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4
+<mapper namespace="com.xxl.job.admin.dao.XxlJobLogReportDao">
5
+	
6
+	<resultMap id="XxlJobLogReport" type="com.xxl.job.admin.core.model.XxlJobLogReport" >
7
+		<result column="id" property="id" />
8
+	    <result column="trigger_day" property="triggerDay" />
9
+		<result column="running_count" property="runningCount" />
10
+	    <result column="suc_count" property="sucCount" />
11
+	    <result column="fail_count" property="failCount" />
12
+	</resultMap>
13
+
14
+	<sql id="Base_Column_List">
15
+		t.id,
16
+		t.trigger_day,
17
+		t.running_count,
18
+		t.suc_count,
19
+		t.fail_count
20
+	</sql>
21
+	
22
+	<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLogReport" useGeneratedKeys="true" keyProperty="id" >
23
+		INSERT INTO xxl_job_log_report (
24
+			`trigger_day`,
25
+			`running_count`,
26
+			`suc_count`,
27
+			`fail_count`
28
+		) VALUES (
29
+			#{triggerDay},
30
+			#{runningCount},
31
+			#{sucCount},
32
+			#{failCount}
33
+		);
34
+		<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
35
+			SELECT LAST_INSERT_ID() 
36
+		</selectKey>-->
37
+	</insert>
38
+
39
+	<update id="update" >
40
+        UPDATE xxl_job_log_report
41
+        SET `running_count` = #{runningCount},
42
+        	`suc_count` = #{sucCount},
43
+        	`fail_count` = #{failCount}
44
+        WHERE `trigger_day` = #{triggerDay}
45
+    </update>
46
+
47
+	<select id="queryLogReport" resultMap="XxlJobLogReport">
48
+		SELECT <include refid="Base_Column_List" />
49
+		FROM xxl_job_log_report AS t
50
+		WHERE t.trigger_day between #{triggerDayFrom} and #{triggerDayTo}
51
+		ORDER BY t.trigger_day ASC
52
+	</select>
53
+
54
+	<select id="queryLogReportTotal" resultMap="XxlJobLogReport">
55
+		SELECT
56
+			SUM(running_count) running_count,
57
+			SUM(suc_count) suc_count,
58
+			SUM(fail_count) fail_count
59
+		FROM xxl_job_log_report AS t
60
+	</select>
61
+
62
+</mapper>

+ 0 - 4
xxl-job-admin/src/test/java/com/xxl/job/admin/dao/XxlJobLogDaoTest.java Ver fichero

@@ -9,7 +9,6 @@ import org.springframework.test.context.junit4.SpringRunner;
9 9
 import javax.annotation.Resource;
10 10
 import java.util.Date;
11 11
 import java.util.List;
12
-import java.util.Map;
13 12
 
14 13
 @RunWith(SpringRunner.class)
15 14
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -47,13 +46,10 @@ public class XxlJobLogDaoTest {
47 46
         dto = xxlJobLogDao.load(log.getId());
48 47
 
49 48
 
50
-        List<Map<String, Object>> list2 = xxlJobLogDao.triggerCountByDay(new Date(new Date().getTime() + 30*24*60*60*1000), new Date());
51
-
52 49
         List<Long> ret4 = xxlJobLogDao.findClearLogIds(1, 1, new Date(), 100, 100);
53 50
 
54 51
         int ret2 = xxlJobLogDao.delete(log.getJobId());
55 52
 
56
-        int ret3 = xxlJobLogDao.triggerCountByHandleCode(-1);
57 53
     }
58 54
 
59 55
 }

+ 4 - 4
xxl-job-core/src/main/java/com/xxl/job/core/util/DateUtil.java Ver fichero

@@ -123,10 +123,6 @@ public class DateUtil {
123 123
 
124 124
     // ---------------------- add date ----------------------
125 125
 
126
-    public static Date addDays(final Date date, final int amount) {
127
-        return add(date, Calendar.DAY_OF_MONTH, amount);
128
-    }
129
-
130 126
     public static Date addYears(final Date date, final int amount) {
131 127
         return add(date, Calendar.YEAR, amount);
132 128
     }
@@ -135,6 +131,10 @@ public class DateUtil {
135 131
         return add(date, Calendar.MONTH, amount);
136 132
     }
137 133
 
134
+    public static Date addDays(final Date date, final int amount) {
135
+        return add(date, Calendar.DAY_OF_MONTH, amount);
136
+    }
137
+
138 138
     private static Date add(final Date date, final int calendarField, final int amount) {
139 139
         if (date == null) {
140 140
             return null;