定时任务提醒
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
59431a713e
commit
0b4b665d1b
@ -0,0 +1,25 @@
|
|||||||
|
package com.ruoyi.flyingbook.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】对象 event_log
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2023-03-15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LogCount implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Date startTime;
|
||||||
|
|
||||||
|
private Date endTime;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Integer count;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.ruoyi.quartz.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务调度日志表 sys_job_log
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class JobLogCount implements Serializable
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
|
private String jobName;
|
||||||
|
|
||||||
|
private Integer count;
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
package com.ruoyi.quartz.task;
|
||||||
|
|
||||||
|
import com.ruoyi.common.enums.EventOperateType;
|
||||||
|
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
|
||||||
|
import com.ruoyi.flyingbook.domain.LogCount;
|
||||||
|
import com.ruoyi.flyingbook.mapper.EventLogMapper;
|
||||||
|
import com.ruoyi.flyingbook.mapper.EventMapper;
|
||||||
|
import com.ruoyi.flyingbook.service.IEventLogService;
|
||||||
|
import com.ruoyi.flyingbook.service.IEventService;
|
||||||
|
import com.ruoyi.quartz.domain.JobLogCount;
|
||||||
|
import com.ruoyi.quartz.domain.SysJobLog;
|
||||||
|
import com.ruoyi.quartz.mapper.SysJobLogMapper;
|
||||||
|
import com.ruoyi.quartz.service.ISysJobService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务监控
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component("monitorJobTask")
|
||||||
|
public class MonitorJobTask {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysJobLogMapper jobLogMapper;
|
||||||
|
@Autowired
|
||||||
|
private EventLogMapper eventLogMapper;
|
||||||
|
@Autowired
|
||||||
|
private LarkRobotHelper larkRobotHelper;
|
||||||
|
|
||||||
|
@Value("${lark.robot.group}")
|
||||||
|
private String robotGroup;
|
||||||
|
|
||||||
|
public void monitor() {
|
||||||
|
log.info("scheduledRemindersTask start");
|
||||||
|
Date todayStartTime = this.getTodayStartTime();
|
||||||
|
Date endTime = new Date();
|
||||||
|
Map<String, Integer> jobLogMap = getJobLogCountMap(todayStartTime,endTime);
|
||||||
|
Map<String, Integer> eventLogCountMap = getEventLogCountMap(todayStartTime,endTime);
|
||||||
|
Map<String, String> map = this.getMap();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
Integer jobCount = jobLogMap.get(entry.getKey());
|
||||||
|
sb.append(entry.getKey()).append("\r\n");
|
||||||
|
if (jobCount != null && jobCount > 0){
|
||||||
|
Integer eventLogCount = eventLogCountMap.getOrDefault(entry.getValue(),0);
|
||||||
|
sb.append(String.format("执行成功%s条",eventLogCount));
|
||||||
|
}else {
|
||||||
|
sb.append("执行失败");
|
||||||
|
}
|
||||||
|
sb.append("\r\n");
|
||||||
|
}
|
||||||
|
larkRobotHelper.sendMessageByBot(robotGroup,sb.toString());
|
||||||
|
log.info("scheduledRemindersTask end");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Date getTodayStartTime(){
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(new Date());
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Integer> getJobLogCountMap(Date startDate,Date endDate){
|
||||||
|
SysJobLog sysJobLog = new SysJobLog();
|
||||||
|
sysJobLog.setStartTime(startDate);
|
||||||
|
sysJobLog.setStopTime(endDate);
|
||||||
|
List<JobLogCount> jobLogCounts = jobLogMapper.countJobLogByName(sysJobLog);
|
||||||
|
return jobLogCounts.stream()
|
||||||
|
.collect(Collectors.toMap(JobLogCount::getJobName, JobLogCount::getCount, (k1, k2) -> k1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Integer> getEventLogCountMap(Date startDate,Date endDate){
|
||||||
|
LogCount logCount = new LogCount();
|
||||||
|
logCount.setStartTime(startDate);
|
||||||
|
logCount.setEndTime(endDate);
|
||||||
|
List<LogCount> logCountList = eventLogMapper.countByType(logCount);
|
||||||
|
return logCountList.stream()
|
||||||
|
.collect(Collectors.toMap(LogCount::getName, LogCount::getCount, (k1, k2) -> k1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Map<String,String> getMap(){
|
||||||
|
Map<String,String> map = new HashMap<>();
|
||||||
|
map.put("邮箱信息同步到飞书-新",EventOperateType.SYNC_MAIL.getCode());
|
||||||
|
map.put("飞书定时提醒-新", EventOperateType.SCHEDULE_REMINDER.getCode());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue