lxw
2023-05-25 f3c27fb78447449a950ba73c5e72ceda64ad8a12
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
package com.whyc.listener;
 
import com.whyc.constant.YamlProperties;
import com.whyc.service.HistoryDataArchivingService;
import com.whyc.task.*;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
 
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.Timer;
 
@WebListener
public class TaskListener implements ServletContextListener {
 
    /**一月执行一次*/
    public static final Long ONE_MONTH = DateUtils.MILLIS_PER_DAY*30;
    /** 一天执行一次*/
    public static final Long ONE_DAY = DateUtils.MILLIS_PER_DAY;
 
    /**调试用*/
    //public static final Long ONE_MONTH_DEBUG = DateUtils.MILLIS_PER_SECOND*10;
 
    private Timer timer;
 
    @Autowired
    private HistoryDataArchivingTask historyDataArchivingTask;
 
    @Autowired
    private LicenseTask licenseTask;
 
    @Autowired
    private AccountLockStrategyTask accountLockStrategyTask;
 
    @Autowired
    private AccountScanTask accountScanTask;
 
    @Autowired
    private PreventTryTask preventTryTask;
 
    @Autowired
    private ProcessSurveyTask processSurveyTask;
 
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        /*Calendar instance = Calendar.getInstance();
        instance.set(Calendar.HOUR_OF_DAY,23);
        instance.set(Calendar.MINUTE,59);
        instance.set(Calendar.SECOND,59);
        Date firstDate = instance.getTime();*/
        timer = new Timer("Task定时任务",true);
        timer.schedule(processSurveyTask,0,1000);
        /*//每月刷新数据库表中天气支持城市-聚合平台,弃用
        timer.schedule(new WeatherTask(),firstDate,ONE_MONTH);*/
 
        //每日清空Application中的weather
        //timer.schedule(new ClearApplicationWeatherTask(),firstDate,ONE_DAY);
 
        //告警工单功能是否开启
        /*if(YamlProperties.alarmTaskSwitch.toUpperCase().equals("ON")) {
            //刷新告警记录生成工单,频率为1秒1次
            timer.schedule(new AlarmTask(), 1000, 1000);
 
            //告警工单自动派单,频率为1秒钟1次
            timer.schedule(new AlarmDispatchTask(), 1000, 1000);
        }*/
 
        //配置文件控制告警短信发送功能是否开启
        //告警短信发送,频率为10秒钟1次
        /*if(YamlProperties.messageSwitch.toUpperCase().equals("ON")){
            timer.schedule(new AlarmMessageTask2(),1000*10,1000*10);
        }*/
        timer.schedule(licenseTask,1000,60000);
        //账号登录失败锁定解锁相关策略,频率为2秒
        timer.schedule(accountLockStrategyTask, 1000, 2000);
        if(YamlProperties.systemType == 2) {
            //账号自动扫描策略,频率为1天
            timer.schedule(accountScanTask, 1000, ONE_DAY);
        }
        if(YamlProperties.systemType == 2 || YamlProperties.systemType == 3) {
            //防重放功能随机码清除,频率为2秒
            timer.schedule(preventTryTask, 1000, 2000);
        }
        timer.schedule(historyDataArchivingTask,0,1000*60*60*24*30L);
    }
 
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        timer.cancel();
    }
}