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;
|
|
@Autowired
|
private HeiHeDataTask heiHeDataTask;
|
|
@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(heiHeDataTask,0,4000);*/
|
/*//每月刷新数据库表中天气支持城市-聚合平台,弃用
|
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();
|
}
|
}
|