package com.dec.fbs9100;
|
|
import java.sql.SQLException;
|
import java.util.Calendar;
|
import java.util.Date;
|
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
|
import com.base.AppConfig;
|
import com.base.Com;
|
import com.battdata_rt.BattData_RT;
|
import com.battdata_rt.BattData_RT_Array;
|
import com.battdata_rt.BattStatData;
|
|
/**
|
*
|
* @author DELL
|
*
|
*/
|
public class BattRealDataPro_Thread extends Thread{
|
public MysqlConnPool con_pool;
|
public AppConfig cfg;
|
public BattData_RT_Array data;
|
Logger logger = null;
|
|
public static int MinRecordTimeLong = 60; //ÿ´Î¼Ç¼µÄ×î¶Ìʱ¼ä¼ä¸ô
|
public static int MaxRecordTimeLong = 366; //×î´ó¼Ç¼ÀúÊ·Êý¾Ýʱ¼ä
|
|
public BattRealDataPro_Thread(MysqlConnPool con_pool, AppConfig cfg, BattData_RT_Array data) {
|
logger = LogManager.getLogger(this.getClass());
|
|
this.cfg = cfg;
|
this.con_pool = con_pool;
|
this.data = data;
|
}
|
|
|
@Override
|
public void run() {
|
logger.info("BattRealDataPro_Thread Started ...");
|
|
Date lastTime = new Date();
|
Date lastdelTime = new Date(0);
|
//Ïß³ÌÆô¶¯Ç°ÐÝÃß60Ãë //ÓÃÓÚÕç±ð»¹Î´Í¨Ñ¶ÉϵÄÉ豸
|
// for(int i =0; i<60; i++) {
|
// try {
|
// sleep(1000);
|
// } catch (InterruptedException e) {
|
// logger.error(e.toString(), e);
|
// }
|
// }
|
logger.info("BattRealDataPro_Thread Start Record......");
|
Date nowTime = null;
|
while(true) {
|
/**************** mxpopstar add @ 20200817 ***************/
|
try {
|
sleep(500);
|
} catch (InterruptedException e1) {
|
// TODO Auto-generated catch block
|
logger.error(e1.toString(), e1);
|
}
|
/**********************************************************/
|
nowTime = new Date();
|
long timelong =(nowTime.getTime()-lastTime.getTime())/1000;
|
long deltimelong = (nowTime.getTime()-lastdelTime.getTime())/1000;
|
try {
|
/**************** lijun add @ 20200906 ***************/
|
//ɾ³ýÐÞ¸Äʱ¼ä³¬Ê±µÄÊý¾Ý±í
|
if(deltimelong > 60*60*24) {
|
/**
|
* 2021-08-25 @lijun 24Сʱ¶¨ÆÚɾ³ýÖ¸¶¨ÌìÊý֮ǰµÄÀúʷʵʱ±í,¸Ã²éѯռÓÃSQL×ÊÔ´½Ï´ó£¬¼õÇáSQL²éѯ¸ºµ£
|
*/
|
//»ñȡָ¶¨ÌìÊý֮ǰµÄʱ¼ä
|
Date critical = getDateBefore(nowTime, MaxRecordTimeLong);
|
logger.error("ɾ³ý"+Com.get_DTF(critical, Com.DTF_YMDhms)+"֮ǰ´´½¨µÄµç³Ø×éÀúʷʵʱÊý¾Ý¿â±í");
|
BTS61850_Task_Thread_SQL.deleteHistoryData(con_pool, critical);
|
logger.error("ɾ³ý½áÊø¡£¡£¡£¡£¡£¡£");
|
|
lastdelTime = nowTime;
|
}
|
/**********************************************************/
|
if(timelong < MinRecordTimeLong) {
|
continue;
|
}
|
|
boolean isRecorded = false;
|
for(int i=0; i<data.getItemCount(); i++) {
|
BattData_RT battData = data.getItem(i);
|
if(battData.getBattState() == BattStatData.BATTSTATE_NULL) {
|
continue; //Ïû³ýδÁ¬½Ó¹ýµÄµç³Ø×é
|
}
|
//2021-08-09 lijun ÐÞ¸´³ÌÐòÆô¶¯Ê±Ò²»á×Ô¶¯¼Ç¼һ±ÊÊý¾ÝΪ0Êý¾Ýbug
|
if((Math.abs(nowTime.getTime()-battData.mTestData.newDataRecordTime.getTime())/1000 > 60)) {
|
continue;
|
}
|
|
isRecorded = true;
|
//¼Ç¼µ±Ç°µç³Ø×éµÄÀúʷʵʱ¼Ç¼
|
RecordBattReadDataNew(con_pool, battData); //¼Ç¼µç³Ø×éÀúʷʵʱ¼Ç¼
|
sleep(50);
|
}
|
if(isRecorded) {
|
lastTime = nowTime;
|
}
|
/**************** mxpopstar edit @ 20200817 ***************/
|
/*sleep(500);*/ //this statement is big bug, because line 59 use "continue" statement;
|
/**************** mxpopstar edit @ 20200817 ***************/
|
} catch (Exception e) {
|
logger.error(e.toString(), e);
|
}
|
}
|
}
|
|
/**
|
* ¼Ç¼µç³Ø×éÀúʷʵʱ¼Ç¼
|
* @param pool
|
* @param battData
|
*/
|
public void RecordBattReadDataNew(MysqlConnPool pool,BattData_RT battData) {
|
Date time = new Date();
|
//´´½¨Ö¸¶¨µç³Ø×éµÄµç³Ø×éµ±ÔÂÀúʷʵʱÊý¾Ý¼Ç¼±í
|
BTS61850_Task_Thread_SQL.CreateTb_BattRealDataTable(con_pool, battData.BattGroupId,time);
|
//String sql_str_delete = " DELETE FROM "+ Sql_Mysql.Tb_Batt_RealData+battData.BattGroupId +" WHERE recrod_time < DATE_SUB(NOW(),INTERVAL 1 YEAR) "; //ɾ³ý³¬¹ý1ÄêµÄ¼Ç¼
|
String sql_str = " INSERT INTO " + Sql_Mysql.Tb_Batt_RealData+battData.BattGroupId+"_"+Com.getDateTimeFormat(time, Com.DTF_YM)+"(BattGroupId,recrod_time,group_vol,online_vol,group_curr,group_tmp,batt_state,batt_test_type,batt_test_starttime,batt_test_tlong,batt_test_cap,mon_num,mon_vol,mon_tmp,mon_res,mon_ser,mon_conn_res,mon_JH_curr) VALUES" ;
|
Date dt_test_Start = new Date();
|
Date dt_record = new Date();
|
dt_test_Start.setTime(battData.getTestStartTime());
|
dt_record.setTime(battData.getTestRecordTime());
|
for(int i=0;i<battData.MonCount;i++) {
|
if(i > 0){
|
sql_str += ",";
|
}
|
sql_str+="("
|
+ battData.BattGroupId+","
|
+ "'" + Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms ) + "',"
|
+ battData.getGroupVol() +","
|
+ battData.getOnlineVol() +","
|
+ battData.getGroupCurr() +","
|
+ battData.getGroupTmp() +","
|
+ battData.getBattState() +","
|
+ battData.getBattTestType() +","
|
+ "'" + Com.getDateTimeFormat(dt_test_Start, Com.DTF_YMDhms) + "',"
|
+ battData.getTestTimeLong() +","
|
+ battData.getTestCap() +","
|
+ (i+1) +","
|
+ battData.al_MonVol.get(i).monVol +","
|
+ battData.al_MonVol.get(i).monTmp +","
|
+ battData.al_MonVol.get(i).monRes +","
|
+ battData.al_MonVol.get(i).monSer +","
|
+ battData.al_MonVol.get(i).connRes +","
|
+ battData.al_MonVol.get(i).mon_JH_curr
|
+")";
|
|
}
|
Sql_Mysql sql = new Sql_Mysql(con_pool);
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
logger.error(e.toString(), e);
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ¼Ç¼µç³Ø×éÀúʷʵʱ¼Ç¼
|
* @param pool
|
* @param battData
|
*/
|
public void RecordBattReadData(MysqlConnPool pool,BattData_RT battData) {
|
//´´½¨Ö¸¶¨µç³Ø×éµÄµç³Ø×éÀúʷʵʱÊý¾Ý¼Ç¼±í
|
FBS9100_Task_Thread_SQL.CreateTb_BattRealDataTable(con_pool, battData.BattGroupId);
|
String sql_str_delete = " DELETE FROM "+ Sql_Mysql.Tb_Batt_RealData+battData.BattGroupId +" WHERE recrod_time < DATE_SUB(NOW(),INTERVAL 1 YEAR) "; //ɾ³ý³¬¹ý1ÄêµÄ¼Ç¼
|
|
|
String sql_str = " INSERT INTO " + Sql_Mysql.Tb_Batt_RealData+battData.BattGroupId+"(BattGroupId,recrod_time,group_vol,online_vol,group_curr,group_tmp,batt_state,batt_test_type,batt_test_starttime,batt_test_tlong,batt_test_cap,mon_num,mon_vol,mon_tmp,mon_res,mon_ser,mon_conn_res,mon_JH_curr) VALUES" ;
|
Date dt_test_Start = new Date();
|
Date dt_record = new Date();
|
dt_test_Start.setTime(battData.getTestStartTime());
|
dt_record.setTime(battData.getTestRecordTime());
|
for(int i=0;i<battData.MonCount;i++) {
|
if(i > 0){
|
sql_str += ",";
|
}
|
sql_str+="("
|
+ battData.BattGroupId+","
|
+ "'" + Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms ) + "',"
|
+ battData.getGroupVol() +","
|
+ battData.getOnlineVol() +","
|
+ battData.getGroupCurr() +","
|
+ battData.getGroupTmp() +","
|
+ battData.getBattState() +","
|
+ battData.getBattTestType() +","
|
+ "'" + Com.getDateTimeFormat(dt_test_Start, Com.DTF_YMDhms) + "',"
|
+ battData.getTestTimeLong() +","
|
+ battData.getTestCap() +","
|
+ (i+1) +","
|
+ battData.al_MonVol.get(i).monVol +","
|
+ battData.al_MonVol.get(i).monTmp +","
|
+ battData.al_MonVol.get(i).monRes +","
|
+ battData.al_MonVol.get(i).monSer +","
|
+ battData.al_MonVol.get(i).connRes +","
|
+ battData.al_MonVol.get(i).mon_JH_curr
|
+")";
|
|
}
|
Sql_Mysql sql = new Sql_Mysql(con_pool);
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
sql.sqlMysqlExecute(sql_str_delete); //ɾ³ýµ±Ç°µç³Ø×éÒ»ÄêǰµÄÀúÊ·Êý¾Ý
|
} catch (SQLException e) {
|
logger.error(e.toString(), e);
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* »ñȡָ¶¨Ê±¼ä֮ǰָ¶¨ÌìÊýµÄʱ¼ä
|
* @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();
|
}
|
|
public static void main(String[] args) {
|
System.out.println(Com.getDateTimeFormat(getDateBefore(new Date(), 366), Com.DTF_YMDhms));
|
}
|
}
|