1、修改 监测数据删除 的bug
This commit is contained in:
@@ -211,7 +211,7 @@ public class BaseConfig extends JFinalConfig{
|
|||||||
timer.schedule(new DetectDataFileReadTask(timer), 2000);
|
timer.schedule(new DetectDataFileReadTask(timer), 2000);
|
||||||
logger.info("文件定时读取任务启动");
|
logger.info("文件定时读取任务启动");
|
||||||
Timer clearTableTimer=new Timer();
|
Timer clearTableTimer=new Timer();
|
||||||
clearTableTimer.schedule(new LogTimerTask(clearTableTimer), new Date());
|
clearTableTimer.scheduleAtFixedRate(new LogTimerTask(), 1000L, 24*60*60*1000);//每天执行一次删除7天之前的数据
|
||||||
logger.info("监测数据定时清理任务启动");
|
logger.info("监测数据定时清理任务启动");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,67 +4,50 @@ import java.util.Arrays;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.jfinal.kit.PropKit;
|
import com.jfinal.kit.PropKit;
|
||||||
import com.jfinal.plugin.activerecord.Db;
|
import com.jfinal.plugin.activerecord.Db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时器 定时清除日志表中的数据
|
* 定时器 定时清除日志表中的数据
|
||||||
|
*
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LogTimerTask extends TimerTask {
|
public class LogTimerTask extends TimerTask {
|
||||||
private Timer timer;
|
private Logger logger = Logger.getLogger(LogTimerTask.class);
|
||||||
private Logger logger=Logger.getLogger(LogTimerTask.class);
|
|
||||||
public LogTimerTask(Timer timer){
|
public LogTimerTask() {
|
||||||
this.timer = timer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int date = 7;//默认七天
|
|
||||||
try {
|
try {
|
||||||
PropKit.use("config.properties");
|
PropKit.use("config.properties");
|
||||||
date=Integer.parseInt(PropKit.get("delete_logtime"));
|
int date = PropKit.getInt("delete_logtime",7);
|
||||||
} catch (Exception e) {
|
String[] clearTables = PropKit.get("detect_info_clear").split(",");
|
||||||
logger.info("获取时间配置失败!使用默认时间:"+date);
|
logger.info("clearTables-->" + Arrays.toString(clearTables));
|
||||||
}
|
Calendar calendar = new GregorianCalendar();
|
||||||
|
|
||||||
try {
|
|
||||||
String[] clearTables=PropKit.get("detect_info_clear").split(",");
|
|
||||||
logger.info("clearTables-->"+Arrays.toString(clearTables));
|
|
||||||
Calendar calendar=new GregorianCalendar();
|
|
||||||
calendar.setTime(new Date());
|
calendar.setTime(new Date());
|
||||||
calendar.add(calendar.DATE, -date);
|
calendar.add(calendar.DATE, -date);
|
||||||
for(String table:clearTables){
|
for (String table : clearTables) {
|
||||||
if(table.startsWith("_")){
|
if (table.startsWith("_")) {
|
||||||
if(table.equals("_nmsc")){
|
if (table.equals("_nmsc")) {
|
||||||
table="delect_info"+table;
|
table = "delect_info" + table;
|
||||||
}else{
|
} else {
|
||||||
table="detect_info"+table;
|
table = "detect_info" + table;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
String sql="delete from "+table+" where DATA_CHECK_TIME_DIGITAL<?";
|
String sql = "delete from " + table + " where DATA_CHECK_TIME_DIGITAL<?";
|
||||||
logger.debug("监测表清理sql-->"+sql+calendar.getTime().getTime());
|
logger.debug("监测表清理sql-->" + sql + calendar.getTime().getTime());
|
||||||
|
Db.update(sql, calendar.getTime().getTime());
|
||||||
Db.update(sql,calendar.getTime().getTime());
|
logger.info("清理表:" + table + "完成");
|
||||||
logger.info("清理表:"+table+"完成");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
restart(date);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("监测表清理失败!",e);
|
logger.error("监测表清理失败!", e);
|
||||||
restart(date);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//定时删除日志 一周清除一次一周前的日志 可修改配置文件来设定日志保存天数
|
|
||||||
public void restart(int day){
|
|
||||||
timer.schedule(new LogTimerTask(timer), day*24*3600*1000);
|
|
||||||
logger.info("数据清除任务重启完成!");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user