package com.ruoyi.project.monitor.job.task;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ruoyi.common.constant.TrHiddenDangerCheckConstants;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.framework.web.service.JpushService;
|
import com.ruoyi.project.tr.hiddenDangerCheck.domain.HiddenDangerCheck;
|
import com.ruoyi.project.tr.hiddenDangerCheck.service.IHiddenDangerCheckService;
|
import com.ruoyi.project.tr.hiddenDangerCheckPoint.domain.HiddenDangerCheckPoint;
|
import com.ruoyi.project.tr.hiddenDangerCheckPoint.service.IHiddenDangerCheckPointService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 隐患排查定时任务调度
|
*
|
* @author ruoyi
|
*/
|
@Component("hiddenDangerCheckTask")
|
public class HiddenDangerCheckTask {
|
|
@Autowired
|
private IHiddenDangerCheckService hiddenDangerCheckService;
|
@Autowired
|
private IHiddenDangerCheckPointService hiddenDangerCheckPointService;
|
|
@Autowired
|
JpushService jpushService;
|
|
|
//此定时任务每天早上9点02分启动
|
public void rectifyTaskNoParams() {
|
System.out.println("执行隐患整改定时任务");
|
HiddenDangerCheckPoint hdcp = new HiddenDangerCheckPoint();
|
hdcp.setRectifyStatus(TrHiddenDangerCheckConstants.RECTIFY_STATUS_NOT_RECTIFY);//整改状态(待整改)
|
List<HiddenDangerCheckPoint> rectifyList = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(hdcp);
|
|
//1.隐患核查创建时间(即examineCreateTime)与 整改完成期限(即rectifyDeadlineTime) 比对
|
//2.小于一周的,提前一天提醒(即定时器执行的当前时间 与 整改完成期限 比对 小于一天)
|
//2.大于1周的,提前两天提醒(即定时器执行的当前时间 与 整改完成期限 比对 小于两天)
|
for (HiddenDangerCheckPoint rectify : rectifyList) {
|
Date rectifyDeadlineTime = rectify.getRectifyDeadlineTime();//整改完成期限
|
Date examineCreateTime = rectify.getExamineCreateTime();//隐患核查创建时间
|
Date currentDate = new Date();//当前时间
|
|
|
long nd = 1000 * 24 * 60 * 60;
|
long nh = 1000 * 60 * 60;
|
long nm = 1000 * 60;
|
// long ns = 1000;
|
// 获得两个时间的毫秒时间差异
|
Long totalTime = rectifyDeadlineTime.getTime() - examineCreateTime.getTime();//整改期限距隐患核查创建时间 的 总时间差
|
if (totalTime != null && totalTime >= 0L) {
|
Long totalDay = totalTime / nd;// 计算总时间差多少天
|
Long distanceRectifyTime = rectifyDeadlineTime.getTime() - currentDate.getTime();//整改期限距当前时间 的 时间差
|
if (distanceRectifyTime != null && distanceRectifyTime >= 0L) {
|
Long distanceRectifyDay = distanceRectifyTime / nd;// 计算整改期限距当前时间 差多少天
|
if (totalDay < 7) {
|
if (distanceRectifyDay < 1) {
|
rectifyDeadlineTimeJPush("1", rectify);//执行极光推送
|
}
|
} else {
|
if (distanceRectifyDay < 2) {
|
rectifyDeadlineTimeJPush("2", rectify);//执行极光推送
|
}
|
}
|
}
|
}
|
}
|
}
|
|
//根据整改完成期限 执行的推送任务
|
/**
|
* @param aheadDaysNumber 提前的天数
|
* @param hdcp
|
*/
|
public void rectifyDeadlineTimeJPush(String aheadDaysNumber, HiddenDangerCheckPoint hdcp) {
|
String title = "您有一项隐患待整改";
|
String content = "【隐患整改任务】您有一项隐患待整改,(隐患描述:"+hdcp.getDangerDescription()+"),隐患整改将逾期,需要在" +
|
"(" + DateUtils.parseDateToStr("yyyy-MM-dd", hdcp.getRectifyDeadlineTime())+")," +
|
"之前整改完成";
|
Map<String, String> extrasMap = new HashMap<String, String>();
|
extrasMap.put("message", "这是一个整改待处理通知");
|
extrasMap.put("methodType", "goToRectify");
|
extrasMap.put("hiddenDangerCheckPoint", JSONObject.toJSONString(hdcp));
|
|
//大文本通知栏样式
|
jpushService.sendPushByAndroidBigText(title, content, 1, content, extrasMap, hdcp.getRectifyUserId().toString());
|
}
|
|
}
|