package com.dev.fbs9009;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import com.base.Com;
|
import com.battdata_rt.BattData_RT;
|
import com.battdata_rt.BattData_RT_Array;
|
import com.sql.MysqlConnPool;
|
|
public class MyModBusPowerOffRecordThread implements Runnable{
|
public MysqlConnPool pool;
|
public BattData_RT_Array battData;
|
public List<RecordThread> threads;
|
public final static int Max_Record_Interval = 3;
|
|
public MyModBusPowerOffRecordThread(MysqlConnPool pool,BattData_RT_Array battData) {
|
this.pool = pool;
|
this.battData = battData;
|
threads = new ArrayList<RecordThread>();
|
}
|
|
@Override
|
public void run() {
|
System.out.println("MyModBusPowerOffRecordThread Start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
while(true) {
|
try {
|
for(int i =0;i<battData.getItemCount();i++) {
|
BattData_RT rt = battData.getItem(i);
|
boolean isExsist = false;
|
for(int k = 0;k<threads.size();i++) {
|
if(rt.BattGroupId == threads.get(i).battData.BattGroupId) {
|
//µ±Ç°µç³Ø×éÒÑ´æÔڼǼÏß³Ì
|
isExsist = true;
|
break;
|
}
|
}
|
if(!isExsist) {
|
RecordThread thread = new RecordThread(pool, rt);
|
threads.add(thread);
|
new Thread(thread).start();
|
}
|
}
|
Thread.sleep(1000);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
//É豸ͣµçÊý¾Ý¼Ç¼Ïß³Ì
|
class RecordThread implements Runnable{
|
public MysqlConnPool pool;
|
public BattData_RT battData; //µç³Ø×é¶ÔÏó
|
|
public int test_record_count = 0; //²âÊÔ´ÎÊý
|
public int record_num = 1; //¼Ç¼±ÊÊý
|
public int start_test_type = MyModBusCom.TestType_NULL;
|
public Date test_starttime = new Date();
|
public Date record_time = new Date();
|
public double test_cap = 0; //²âÊÔÈÝÁ¿
|
public long timelong = 0;
|
|
public RecordThread(MysqlConnPool pool,BattData_RT battData) {
|
this.pool = pool;
|
this.battData = battData;
|
}
|
|
@Override
|
public void run() {
|
//´´½¨µ±Ç°µç³Ø×éµÄ²âÊԼǼ±í¸ñ _inf±í
|
MyModBusSocketThread_SQL.createTb_ld9testdata_inf(pool);
|
//´´½¨µ±Ç°µç³Ø×éµÄ²âÊԼǼ±í¸ñ _id±í
|
MyModBusSocketThread_SQL.createTb_ld9testdata(pool,battData.BattGroupId);
|
//´´½¨µ±Ç°µç³Ø×éµÄ²âÊԼǼ±í¸ñ stop_id±í
|
MyModBusSocketThread_SQL.createTb_ld9testdatastop(pool,battData.BattGroupId);
|
|
Date last = new Date(0);
|
boolean isStartRecord = false; //ÊÇ·ñ¿ªÊ¼¼Ç¼Êý¾Ý
|
boolean isNewStart = true;
|
int now_test_type = MyModBusCom.TestType_NULL; //µ±Ç°²âÊÔÀàÐÍ
|
Date now = null;
|
boolean now_state = false;
|
while(true) {
|
try {
|
now = new Date();
|
now_state = battData.checkIFLD9State();
|
if(isStartRecord == false && now_state == true) {
|
//³õ´Î¼ì²âµ½¼à²â³ä·Åµç
|
isNewStart = true;
|
isStartRecord = true;
|
start_test_type = battData.getMyBattTestType();
|
now_test_type = start_test_type;
|
record_num = 1;
|
test_cap = 0;
|
test_starttime = new Date();
|
LD_sys_state state = MyModBusSocketThread_SQL.searchMaxTestRecordByBattGroupId(pool, battData.BattGroupId);
|
if(state == null) {
|
test_record_count = 1;
|
}else {
|
test_record_count = state.getTest_record_count()+1;
|
}
|
}
|
now_test_type = battData.getMyBattTestType();
|
if(isStartRecord && now_test_type != start_test_type) {
|
//µ±Ç°²âÊÔÀàÐͱ仯ʱ½áÊøµ±Ç°¼Ç¼
|
now_state = false;
|
}
|
if(isStartRecord && now_state == false) {
|
//³ä·Åµç½áÊøÖ±½Ó¼Ç¼µ±Ç°Êý¾Ý
|
isNewStart = true;
|
}
|
if(isStartRecord) {
|
//¼ä¸ôʱ³¤
|
long timelong = (now.getTime()-last.getTime())/1000;
|
//ÅжϼǼʱ³¤
|
if(timelong >= Max_Record_Interval || isNewStart) {
|
|
record_time = new Date();
|
timelong = (record_time.getTime()-test_starttime.getTime())/1000;
|
//¼ÆËã²âÊÔÈÝÁ¿
|
test_cap += (battData.myModBusData.getConcenState().getGroupCurr()*timelong)/3600;
|
|
//¼Ç¼Êý¾Ý
|
MyModBusSocketThread_SQL.insertOrUpdateMuilMonDataInf(pool, this); //¸üвâÊÔµÄinf±íÖеÄÊý¾Ý
|
MyModBusSocketThread_SQL.insertOrUpdateMutilMonData(pool, this); //¸üвâÊÔ_ID±íÖеÄÊý¾Ý
|
MyModBusSocketThread_SQL.insertOrUpdateMutilMonStopData(pool, this); //¸üвâÊÔStop±íÖеÄÊý¾Ý
|
|
if(!now_state) {
|
isStartRecord = false;
|
}
|
isNewStart = false;
|
record_num ++;
|
last = now;
|
}
|
}
|
Thread.sleep(1000);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
}
|
}
|