双重预防项目-国泰新华二开定制版
SZH
2022-08-20 f9f0687195e0fe349185437d22c495d74c8d4a20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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());
    }
 
}