Administrator
2022-06-17 c5bff04a7761b7aca5dbd511a5989ebab20adb24
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
93
94
95
96
97
98
package com.power.datasave;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
import java.util.Date;
 
import com.power.mysql.MysqlConnPool;
import com.power.data.PowerData_RT;
import com.power.data.PowerData_RT_Array;
 
public class PowerRealDataSave_Thread extends Thread{
    
    public MysqlConnPool m_ConnPool;
    public PowerData_RT_Array m_AL_Data;
    Logger logger = null;
    
    public static int MinRecordTimeLong = 60;            //ÿ´Î¼Ç¼µÄ×î¶Ìʱ¼ä¼ä¸ô--60S
    public static int MaxRecordTimeLong = 366*3;        //×î´ó¼Ç¼ÀúÊ·Êý¾Ýʱ¼ä--3Äê
    
    
    public PowerRealDataSave_Thread(MysqlConnPool pool,PowerData_RT_Array data) {
        logger = LogManager.getLogger(this.getClass());
        
        m_ConnPool = pool;
        m_AL_Data = data;
    }
    
    
    public void run() {
        
        logger.info("PowerRealDataSave_Thread: Started ...");
        
        Date lastTime = new Date();
        //Ïß³ÌÆô¶¯Ç°ÐÝÃß60Ãë
        for(int i =0; i<60; i++) {
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                logger.error(e.toString(), e);
            }
        }
        logger.info("PowerRealDataSave_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;
            try {
                /**************** lijun add @ 20200906 ***************/
                //»ñȡָ¶¨ÌìÊý֮ǰµÄʱ¼ä
                Date critical = PowerDataSave_SQL.getDateBefore(nowTime, MaxRecordTimeLong);
                //ɾ³ýÐÞ¸Äʱ¼ä³¬Ê±µÄÊý¾Ý±í
                PowerDataSave_SQL.deleteHistoryData(m_ConnPool, critical);
                /**********************************************************/
                if(timelong < MinRecordTimeLong) {
                    continue;
                }
                
                boolean isRecorded = false;
                
                for(int i=0; i<m_AL_Data.getItemCount(); i++) {
                    PowerData_RT rtdata = m_AL_Data.getItem(i);
                    
                    /*
                    if(battData.getBattState() == BattStatData.BATTSTATE_NULL) {
                        continue;                //Ïû³ýδÁ¬½Ó¹ýµÄµç³Ø×é
                    }
                    */
                    isRecorded = true;
                    //¼Ç¼µ±Ç°µç³Ø×éµÄÀúʷʵʱ¼Ç¼
                    PowerDataSave_SQL.RecordPowerRealData(m_ConnPool, rtdata);                            //记录电池组的放电记录
                    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);
            }
        }
    }
    
    
 
}