package com.power.alarm;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
import com.base.Com;
|
import com.power.mysql.MysqlConnPool;
|
|
/**
|
* ¶ÔÀúÊ·¸æ¾¯¼Ç¼½øÐÐ·Ö±í´¦Àí£¬´´½¨µÄ·Ö±íʱ¼ä³¬¹ý3ÄêµÄ¸æ¾¯¼Ç¼ɾ³ý
|
* @author LiJun
|
*
|
*/
|
public class PwrDevHistoryAlm_SubtableThread implements Runnable{
|
public static int MaxRecordAlmTimeLong = 366*3; //×î´ó¼Ç¼ÀúÊ·¸æ¾¯Ê±¼ä
|
|
private List<PwrDeviceAlarm_Data> pwrAlmDatas; //ÐèÒª·Ö±íµÄµçÔ´ÀúÊ·¸æ¾¯¼Ç¼
|
private MysqlConnPool pool;
|
private Logger logger = null;
|
|
public PwrDevHistoryAlm_SubtableThread(MysqlConnPool pool) {
|
this.pwrAlmDatas = new ArrayList<>(); //ÐèÒª·Ö±íµÄµçÔ´ÀúÊ·¸æ¾¯¼Ç¼
|
this.pool = pool;
|
this.logger = LogManager.getLogger(this);
|
}
|
|
@Override
|
public void run() {
|
logger.info(" PwrDevHistoryAlm_SubtableThread Start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) );
|
Date time = new Date(0);
|
Date lastCheck = time; //ÉÏÒ»´Î¼ì²âÀúÊ·¸æ¾¯Ê±¼ä
|
Date lastDelete = time; //ÉÏÒ»´Îɾ³ýÀúÊ·¸æ¾¯Ê±¼ä
|
|
while(true) {
|
try {
|
pwrAlmDatas.clear();
|
|
time = new Date();
|
long checkTimeLong = (time.getTime()-lastCheck.getTime())/(24*60*60*1000);
|
//System.out.println("checkTimeLong:"+checkTimeLong);
|
if(checkTimeLong >= 1) {
|
//ÿÌì¼ì²âÒ»´ÎÀúÊ·¸æ¾¯Êý¾Ý
|
PwrDevHistoryAlm_SubtableThread_SQL.queryBattHistoryAlarm(pool, pwrAlmDatas);
|
//System.err.println(pwrAlmDatas);
|
if(pwrAlmDatas.size() > 0) {
|
//¿ªÊ¼½øÐÐµç³ØÀúÊ·¸æ¾¯¼Ç¼·Ö±í
|
for(int i=0;i<pwrAlmDatas.size();i++) {
|
/*
|
if(battAlmDatas.get(i).battgroup_id != 1000022) {
|
continue;
|
}
|
*/
|
|
if(i%10==0) {
|
Thread.sleep(100);
|
}
|
//½«³¬¹ý1¸öÔµĵçÔ´¸æ¾¯¼Ç¼¼ÇÈëÀúÊ·¸æ¾¯·Ö±í
|
PwrDevHistoryAlm_SubtableThread_SQL.changePwrAlarmToHistoryTable(pool, pwrAlmDatas.get(i));
|
}
|
}
|
lastCheck = time;
|
}
|
|
|
long deleteTimeLong = (time.getTime()-lastDelete.getTime())/(24*60*60*1000);
|
//System.out.println("deleteTimeLong:"+deleteTimeLong);
|
if(deleteTimeLong >= 1) {
|
//10Ìì¼ì²âÒ»´Îɾ³ýÀúÊ·¸æ¾¯Êý¾Ý
|
Date deldate = getDateBefore(time, MaxRecordAlmTimeLong);
|
//¼ì²âÀúÊ·¸æ¾¯¼Ç¼,ɾ³ý3ÄêǰµÄ¸æ¾¯¼Ç¼·Ö±í
|
PwrDevHistoryAlm_SubtableThread_SQL.delBattAlarmData(pool, deldate);
|
|
lastDelete = time;
|
}
|
|
} catch (Exception e) {
|
logger.error(e.toString(), e);
|
} finally {
|
try {
|
Thread.sleep(10000);
|
} catch (InterruptedException e) {
|
logger.error(e.toString(), e);
|
}
|
}
|
}
|
}
|
|
/**
|
* »ñȡָ¶¨Ê±¼ä֮ǰָ¶¨ÌìÊýµÄʱ¼ä
|
* @param d Ö¸¶¨Ê±¼ä
|
* @param day Ö¸¶¨ÌìÊý
|
* @return
|
*/
|
public static Date getDateBefore(Date d,int day){
|
Calendar now =Calendar.getInstance();
|
now.setTime(d);
|
now.set(Calendar.DATE,now.get(Calendar.DATE)-day);
|
return now.getTime();
|
}
|
}
|