package com.battdata_rt; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import com.base.Com; import com.dec.fbs9100.BattResStorePro_Thread; import com.dec.fbs9100.FBS9100_batt_testparam; import com.dec.fbs9100.MysqlConnPool; import com.dec.fbs9100.Sql_Mysql; public class BattData_RT_SQL { public static void get_MonData_From_BattData_RT_RamDB_Table(MysqlConnPool conn_pool, BattData_RT bd_rt) { Sql_Mysql sql = new Sql_Mysql(conn_pool); try { String sql_str = "SELECT mon_num,mon_vol,mon_tmp,mon_res,mon_ser,mon_conn_res FROM " + Sql_Mysql.BattRtData_Table + " WHERE BattGroupId=" + bd_rt.BattGroupId + " ORDER BY mon_num ASC"; //System.out.println(sql_str); ResultSet res = sql.sqlMysqlQuery(sql_str); try { while(res.next()) { int mon_index = res.getInt("mon_num"); if(mon_index > 0) { mon_index -= 1; } if(mon_index < bd_rt.al_MonVol.size()) { bd_rt.al_MonVol.get(mon_index).monVol = res.getFloat("mon_vol"); bd_rt.al_MonVol.get(mon_index).monTmp = res.getFloat("mon_tmp"); bd_rt.al_MonVol.get(mon_index).monRes = res.getFloat("mon_res"); bd_rt.al_MonVol.get(mon_index).monSer = res.getFloat("mon_ser"); bd_rt.al_MonVol.get(mon_index).connRes = res.getFloat("mon_conn_res"); } } } catch (Exception e) { sql.logger.error("get_MonData_From_BattData_RT_RamDB_Table():" + e.toString(), e); } res.close(); } catch (SQLException e) { // TODO Auto-generated catch block sql.logger.error(e.toString(), e); } finally { sql.close_con(); } } /************************************************************************************************/ /** * ������������tb_batt_rtdata����������������������������bd_al�����������������������������������������id������mon_num �� * @param conn_pool * @param bd_al */ public static void createBattData_RT_RamDB_Table(MysqlConnPool conn_pool, int bg_id, int batt_cnt) { String tb_name = "`db_ram_batt_rt`.`tb_batt_rtdata_" + bg_id + "`"; String sql_str0 = "DELETE FROM " + tb_name + " WHERE " + tb_name + ".num>0"; String sql_str1 = "CREATE TABLE IF NOT EXISTS " + tb_name + " " + "( `num` BIGINT NOT NULL AUTO_INCREMENT, " + "`BattGroupId` INT NOT NULL DEFAULT 0, " + "`rec_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', " + "`mon_num` INT NOT NULL DEFAULT 0, " + "`mon_vol` FLOAT NOT NULL DEFAULT 0, " + "`mon_tmp` FLOAT NOT NULL DEFAULT 0, " + "`mon_res` FLOAT NOT NULL DEFAULT 0, " + "`mon_ser` FLOAT NOT NULL DEFAULT 0, " + "`mon_conn_res` FLOAT NOT NULL DEFAULT 0, " + "`mon_cap` FLOAT NOT NULL DEFAULT 0, " + "`batt_count` INT NOT NULL DEFAULT 0, " + "`online_vol` FLOAT NOT NULL DEFAULT 0, " + "`group_vol` FLOAT NOT NULL DEFAULT 0, " + "`group_tmp` FLOAT NOT NULL DEFAULT 0, " + "`group_curr` FLOAT NOT NULL DEFAULT 0, " + "`batt_state` INT NOT NULL DEFAULT 0, " + "`batt_test_type` INT NOT NULL DEFAULT 0, " + "`batt_test_starttime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', " + "`batt_test_recordtime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', " + "`batt_test_tlong` INT NOT NULL DEFAULT 0, " + "`batt_test_cap` FLOAT NOT NULL DEFAULT 0, " + "`batt_real_cap` FLOAT NOT NULL DEFAULT 0, " + "`batt_rest_cap` FLOAT NOT NULL DEFAULT 0, " + "`batt_rest_power1_time` INT NOT NULL DEFAULT 0, " + "`batt_rest_power2_time` INT NOT NULL DEFAULT 0, " + "INDEX index_BattGroupId (`BattGroupId`), " + "PRIMARY KEY (`num`)) " + "ENGINE=MEMORY DEFAULT CHARSET=utf8;"; String sql_str2 = "INSERT INTO " + tb_name + " " + "(BattGroupId," + "mon_num)" + " VALUES "; int cnt = 0; for(int mc=0; mc 0) { sql_str2 += ","; } sql_str2 += "(" + bg_id + "," + (mc+1) + ")"; cnt++; } Sql_Mysql sql = new Sql_Mysql(conn_pool); try { sql.sqlMysqlExecute(sql_str1); ResultSet res_t = sql.sqlMysqlQuery("SELECT COUNT(*) FROM " + tb_name); if(res_t.next()) { int cnt_row = res_t.getInt(1); if(cnt_row != batt_cnt) { sql.sqlMysqlExecute(sql_str0); sql.sqlMysqlExecute(sql_str2); } } else { sql.sqlMysqlExecute(sql_str2); } } catch (SQLException e) { sql.logger.error("createBattData_RT_RamDB_Table():" + e.toString(), e); } finally { sql.close_con(); } } /************************************************************************************************/ public static BattData_RT selectRT_BttInf_Table(MysqlConnPool conn_pool,BattData_RT bd_rt){ Sql_Mysql sql = new Sql_Mysql(conn_pool); ResultSet res = null; String sql_str = "SELECT * FROM " + Sql_Mysql.BattInf_Table + " WHERE " + " FBSDeviceId= " + bd_rt.FBSDeviceId; res = sql.sqlMysqlQuery(sql_str); try { while(res.next()) { bd_rt.FBSDeviceIp = res.getString("FBSDeviceIp"); bd_rt.FBSDeviceIp_WG = res.getString("FBSDeviceIp_WG"); bd_rt.FBSDeviceIp_YM = res.getString("FBSDeviceIp_YM"); } } catch (SQLException e) { // TODO Auto-generated catch block sql.logger.error("selectRT_BttInf_Table():" + e.toString(), e); } finally { sql.close_con(); } return bd_rt; } /************************************************************************************************/ public static void updateBattState_RT_RamDB_Table(MysqlConnPool conn_pool, BattData_RT bd_rt) { Sql_Mysql sql = new Sql_Mysql(conn_pool); try { Date dt_test_Start = new Date(); Date dt_record = new Date(); dt_test_Start.setTime(bd_rt.getTestStartTime()); dt_record.setTime(bd_rt.getTestRecordTime()); //System.out.println("bd_rt.getBattRestCap():"+bd_rt.getBattRestCap()); String sql_str = "UPDATE " + Sql_Mysql.BattRtState_Table + " SET " + " rec_datetime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "'," + " batt_count=" + bd_rt.MonCount + "," + " online_vol=" + bd_rt.getOnlineVol() + "," + " group_vol=" + bd_rt.getGroupVol() + "," + " group_tmp=" + bd_rt.getGroupTmp() + "," + " group_curr=" + bd_rt.getGroupCurr() + "," + " batt_state=" + bd_rt.getBattState() + "," + " batt_test_type=" + bd_rt.getBattTestType() + "," + " batt_test_starttime='" + Com.getDateTimeFormat(dt_test_Start, Com.DTF_YMDhms) + "'," + " batt_test_recordtime='" + Com.getDateTimeFormat(dt_record, Com.DTF_YMDhms) + "'," + " batt_test_tlong=" + bd_rt.getTestTimeLong() + "," + " batt_test_cap=" + bd_rt.getTestCap() + "," + " batt_real_cap=" + bd_rt.getBattRealCap() + "," + " batt_rest_cap=" + bd_rt.getBattRestCap() + "," + " batt_rest_power1_time=" + bd_rt.getBattRestTime() + " WHERE BattGroupId=" + bd_rt.BattGroupId; //System.out.println(sql_str); sql.sqlMysqlExecute(sql_str); } catch (SQLException e) { // TODO Auto-generated catch block sql.logger.error("updateBattState_RT_RamDB_Table():" + e.toString(), e); } finally { sql.close_con(); } } /************************************************************************************************/ /** * ������������tb_batt_rtdata�������������������������� * @param conn_pool * @param bd_al */ public static void updateBattData_RT_RamDB_Table(MysqlConnPool conn_pool, BattData_RT bd_rt) { Sql_Mysql sql = new Sql_Mysql(conn_pool); try { String sql_str = "UPDATE " + Sql_Mysql.BattRtData_Table + " SET " + " rec_datetime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "'"; float tmp_dt = 0; String sql_str_vol = " "; for(int n=0; n 1) { sql_str_vol = ", mon_vol = CASE mon_num " + sql_str_vol + " ELSE mon_vol END "; } String sql_str_tmp = " "; for(int n=0; n 1) { sql_str_tmp = ", mon_tmp = CASE mon_num " + sql_str_tmp + " ELSE mon_tmp END "; } String sql_str_res = " "; for(int n=0; n 1) { sql_str_res = ", mon_res = CASE mon_num " + sql_str_res + " ELSE mon_res END "; } String sql_str_ser = " "; for(int n=0; n 1) { sql_str_ser = ", mon_ser = CASE mon_num " + sql_str_ser + " ELSE mon_ser END "; } String sql_str_JH = " "; for(int n=0; n 1) { sql_str_JH = ", mon_JH_curr = CASE mon_num " + sql_str_JH + " ELSE mon_JH_curr END "; } String sql_str_rest_cap = " "; for(int n=0; n 1) { sql_str_rest_cap = ", mon_rest_cap = CASE mon_num " + sql_str_rest_cap + " ELSE mon_rest_cap END "; } String sql_str_2 = sql_str_vol + sql_str_tmp + sql_str_res + sql_str_ser + sql_str_JH + sql_str_rest_cap; if(sql_str_2.trim().length() > 1) { sql_str_2 += " WHERE BattGroupId=" + bd_rt.BattGroupId; /* + " AND mon_num IN ("; for(int n=0; n 0) { sql_str_2 += ","; } sql_str_2 += (n+1); } sql_str_2 += ")"; */ } else { sql_str_2 = " WHERE BattGroupId=" + bd_rt.BattGroupId; } //2021-08-09 更新当前蓄电池数据更新时间 bd_rt.mTestData.updateNewDataRCTime(new Date()); sql_str += sql_str_2; //System.out.println(bd_rt.MonCount); //System.out.println(sql_str); sql.sqlMysqlExecute(sql_str); } catch (SQLException e) { // TODO Auto-generated catch block sql.logger.error("updateBattData_RT_RamDB_Table():" + e.toString(), e); } finally { sql.close_con(); } } /************************************************************************************************/ /** * ������������������������������������������������������������� * @param tb_name * @return */ public static String getCreateBattTestDataStr(String tb_name) { String sql_str = "CREATE TABLE IF NOT EXISTS " + tb_name + " " + "( `num` BIGINT NOT NULL AUTO_INCREMENT, " + "`BattGroupId` INT NOT NULL DEFAULT 0, " + "`test_record_count` INT NOT NULL DEFAULT 0, " + "`test_type` INT NOT NULL DEFAULT 0, " + "`data_new` BOOLEAN NOT NULL DEFAULT false, " + "`data_available` BOOLEAN NOT NULL DEFAULT false, " + "`record_num` INT NOT NULL DEFAULT 0, " + "`test_starttime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', " + "`record_time` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', " + "`test_timelong` INT NOT NULL DEFAULT 0, " + "`online_vol` FLOAT NOT NULL DEFAULT 0, " + "`group_vol` FLOAT NOT NULL DEFAULT 0, " + "`test_curr` FLOAT NOT NULL DEFAULT 0, " + "`test_cap` FLOAT NOT NULL DEFAULT 0, " + "`mon_num` INT NOT NULL DEFAULT 0, " + "`mon_vol` FLOAT NOT NULL DEFAULT 0, " + "`mon_tmp` FLOAT NOT NULL DEFAULT 0, " + "INDEX index_test_record_count (`test_record_count`), " + "PRIMARY KEY (`num`));"; return sql_str; } /** * ������tb_batttestdata_id������������������������������������������������� * @param rt_data * @return */ public static String getInsertBattTestDataStr(BattData_RT rt_data) { int mon_count = rt_data.MonCount; BattStatData tmp_test_data = rt_data.mTestData.clone(); String sql_str = "INSERT INTO tb_BattTestData_" + rt_data.BattGroupId + " " + "(BattGroupId, " + "test_record_count, " + "test_type, " + "data_new, " + "data_available, " + "record_num, " + "test_starttime, " + "record_time, " + "test_timelong, " + "online_vol, " + "group_vol, " + "test_curr, " + "test_cap, " + "mon_num, " + "mon_vol, " + "mon_tmp)" + " VALUES "; String sql_str_data = ""; for(int n=0; n0) && (false == rt_data.is_al_MonVol_History_New(n)) && (tmp_test_data.recordNum > 2)) continue; */ if(n > 0) sql_str_data += ", "; sql_str_data += "("+ rt_data.BattGroupId + ", " + tmp_test_data.testRecordCount + ", " + tmp_test_data.battTestType_For_DataSave + ", " + true + ", " + true + ", " + (tmp_test_data.recordNum + 1) + ", " + "'" + Com.getDateTimeFormat(tmp_test_data.startTestTime, Com.DTF_YMDhms) + "', " + "'" + Com.getDateTimeFormat(tmp_test_data.recordTime, Com.DTF_YMDhms) + "', " + rt_data.getTestTimeLong() + ", " + tmp_test_data.onlineVol + ", " + tmp_test_data.groupVol + ", " + tmp_test_data.testCurr + ", " + tmp_test_data.testCap + ", " + (n+1) + ", " + rt_data.get_al_MonVol_History(n) + ", " + rt_data.al_MonVol.get(n).monTmp + ")"; } //System.out.println(sql_str + sql_str_data); return (sql_str + sql_str_data); } /** * ������tb_batttestdatastop_id������������������������������������������������������������� * @param rt_data * @return */ public static ArrayList getInsertOrUpdateBattTestDataStopStr(BattData_RT rt_data) { ArrayList al_sql_str = new ArrayList(); int mon_count = rt_data.MonCount; BattStatData tmp_test_data = rt_data.mTestData.clone(); ArrayList tmp_mon_vol = rt_data.al_MonVol_History; rt_data.makeMaxMinMonVol(tmp_mon_vol); if(false == rt_data.MysqlDataResInfTable_Exist) { String sql_str = "INSERT INTO " + "tb_BattTestDataStop_" + rt_data.BattGroupId + " (BattGroupId, " + "test_record_count, " + "test_type, " + "data_new, " + "data_available, " + "record_num, " + "test_starttime, " + "record_time, " + "test_timelong, " //+ "online_vol, " + "group_vol, " + "test_curr, " + "test_cap, " + "mon_num, " + "mon_vol)" + " VALUES "; for(int n=0; n 0) sql_str += ", "; sql_str += "("+ rt_data.BattGroupId + ", " + tmp_test_data.testRecordCount + ", " + tmp_test_data.battTestType_For_DataSave + ", " + true + ", " + true + ", " + (tmp_test_data.recordNum + 1) + ", " + "'" + Com.getDateTimeFormat(tmp_test_data.startTestTime, Com.DTF_YMDhms) + "', " + "'" + Com.getDateTimeFormat(tmp_test_data.recordTime, Com.DTF_YMDhms) + "', " + tmp_test_data.testTimeLong + ", " //+ tmp_test_data.onlineVol + ", " + tmp_test_data.groupVol + ", " + tmp_test_data.testCurr + ", " + tmp_test_data.testCap + ", " + (n+1) + ", " + tmp_mon_vol.get(n).monVol + ")"; } al_sql_str.add(sql_str); } else { String sql_str = "UPDATE " + "tb_BattTestDataStop_" + rt_data.BattGroupId + " SET " + " data_new=" + true + ", " + "data_available=" + true + ", " + "record_num=" + (tmp_test_data.recordNum + 1) + ", " + "record_time='" + Com.getDateTimeFormat(tmp_test_data.recordTime, Com.DTF_YMDhms) + "', " + "test_timelong=" + tmp_test_data.testTimeLong + ", " //+ "online_vol=" + tmp_test_data.onlineVol + ", " + "group_vol=" + tmp_test_data.groupVol + ", " + "test_curr=" + tmp_test_data.testCurrAbsMax + ", " + "test_cap=" + tmp_test_data.testCap + " " + " WHERE " + " BattGroupId=" + rt_data.BattGroupId + " AND " + " test_record_count=" + tmp_test_data.testRecordCount; al_sql_str.add(sql_str); String temp_str = ""; sql_str = "UPDATE " + "tb_BattTestDataStop_" + rt_data.BattGroupId + " SET " + " mon_vol = CASE mon_num"; for(int n=0; n0) && (false == rt_data.is_al_MonVol_History_New(n)) && (tmp_test_data.recordNum > 2)) continue; if(n > 0) { temp_str += ","; } temp_str += (n+1); sql_str += " WHEN " + (n+1) + " THEN " + rt_data.get_al_MonVol_History(n); } sql_str += " END WHERE mon_num IN (" + temp_str + ")" + " AND BattGroupId=" + rt_data.BattGroupId + " AND " + " test_record_count=" + tmp_test_data.testRecordCount; al_sql_str.add(sql_str); } return al_sql_str; } /** * ������tb_batttestdata_inf������������������������������������������������������������� * @param rt_data * @return */ public static String getInsertOrUpdateBattTestDataInfStr(BattData_RT rt_data, int test_stoptype_t) { String sql_str = " "; BattStatData tmp_test_data = rt_data.mTestData.clone(); tmp_test_data.test_stoptype = test_stoptype_t; if(false == rt_data.MysqlRecordInf_Exist) { sql_str = "INSERT INTO " + Sql_Mysql.BattTestDataInf_Table + " (BattGroupId, " + "test_record_count, " + "test_type, " + "record_time_interval, " + "data_new, " + "data_available, " + "record_num, " + "test_starttime, " + "test_starttype, " + "record_time, " + "test_timelong, " + "test_stoptype, " + "group_vol, " + "test_curr, " + "test_cap, " + "max_monnum, " + "max_monvol, " + "min_monnum, " + "min_monvol) " + " VALUES " + "("+ rt_data.BattGroupId + ", " + tmp_test_data.testRecordCount + ", " + tmp_test_data.battTestType_For_DataSave + ", " + rt_data.mSaveDataTimeInterval + ", " + true + ", " + true + ", " + (tmp_test_data.recordNum + 1) + ", " + "'" + Com.getDateTimeFormat(tmp_test_data.startTestTime, Com.DTF_YMDhms) + "', " + tmp_test_data.testLoaderType + ", " + "'" + Com.getDateTimeFormat(tmp_test_data.recordTime, Com.DTF_YMDhms) + "', " + tmp_test_data.testTimeLong + ", " + tmp_test_data.test_stoptype + ", " + tmp_test_data.groupVol + ", " + tmp_test_data.testCurr + ", " + tmp_test_data.testCap + ", " + rt_data.mMaxMonNum + ", " + rt_data.mMaxMonVol + ", " + rt_data.mMinMonNum + ", " + rt_data.mMinMonVol + ") "; } else { sql_str = "UPDATE " + Sql_Mysql.BattTestDataInf_Table + " SET " + "test_type=" + tmp_test_data.battTestType_For_DataSave + ", " + "record_time_interval=" + rt_data.mSaveDataTimeInterval + ", " + "data_new=" + true + ", " + "data_available=" + true + ", " + "record_num=" + (tmp_test_data.recordNum + 1) + ", " + "test_starttime='" + Com.getDateTimeFormat(tmp_test_data.startTestTime, Com.DTF_YMDhms) + "', " + "test_starttype=" + tmp_test_data.testLoaderType + ", " + "record_time='" + Com.getDateTimeFormat(tmp_test_data.recordTime, Com.DTF_YMDhms) + "', " + "test_timelong=" + tmp_test_data.testTimeLong + ", " + "test_stoptype=" + tmp_test_data.test_stoptype + ", " + "group_vol=" + tmp_test_data.groupVol + ", " + "test_curr=" + tmp_test_data.testCurrAbsMax + ", " + "test_cap=" + tmp_test_data.testCap + ", " + "max_monnum=" + rt_data.mMaxMonNum + ", " + "max_monvol=" + rt_data.mMaxMonVol + ", " + "min_monnum=" + rt_data.mMinMonNum + ", " + "min_monvol=" + rt_data.mMinMonVol + " " + " WHERE " + " BattGroupId=" + rt_data.BattGroupId + " AND " + " test_record_count=" + tmp_test_data.testRecordCount; } //System.out.println(sql_str); return sql_str; } /** * * @lijun 2021-08-16向tb_batttestdata_inf表中添加数据或者更新数据 * @param rt_data * @return */ public static String getInsertOrUpdateBattTestDataInfStr(MysqlConnPool pool,BattData_RT rt_data, int test_stoptype_t) { String sql_str = " "; BattStatData tmp_test_data = rt_data.mTestData.clone(); tmp_test_data.test_stoptype = test_stoptype_t; if(false == rt_data.MysqlRecordInf_Exist) { sql_str = "INSERT INTO " + Sql_Mysql.BattTestDataInf_Table + " (BattGroupId, " + "test_record_count, " + "test_type, " + "record_time_interval, " + "data_new, " + "data_available, " + "record_num, " + "test_starttime, " + "test_starttype, " + "record_time, " + "test_timelong, " + "test_stoptype, " + "group_vol, " + "test_curr, " + "test_cap, " + "max_monnum, " + "max_monvol, " + "min_monnum, " + "min_monvol) " + " VALUES " + "("+ rt_data.BattGroupId + ", " + tmp_test_data.testRecordCount + ", " + tmp_test_data.battTestType_For_DataSave + ", " + rt_data.mSaveDataTimeInterval + ", " + true + ", " + true + ", " + (tmp_test_data.recordNum + 1) + ", " + "'" + Com.getDateTimeFormat(tmp_test_data.startTestTime, Com.DTF_YMDhms) + "', " + tmp_test_data.testLoaderType + ", " + "'" + Com.getDateTimeFormat(tmp_test_data.recordTime, Com.DTF_YMDhms) + "', " + tmp_test_data.testTimeLong + ", " + tmp_test_data.test_stoptype + ", " + tmp_test_data.groupVol + ", " + tmp_test_data.testCurr + ", " + tmp_test_data.testCap + ", " + rt_data.mMaxMonNum + ", " + rt_data.mMaxMonVol + ", " + rt_data.mMinMonNum + ", " + rt_data.mMinMonVol + ") "; /** * 2021-08-17 @lijun 向插入batttestdata_inf表中插入历史数据时记录当前电池组的内阻数据 * */ BattResStorePro_Thread.insertMonDataToResTable(pool, rt_data, tmp_test_data.startTestTime, BattStatData.BATTDATA_RES); /** * 2023-02-09 @lijun 记录放电之前设置的放电参数 * */ recordTestParam(pool,rt_data); } else { sql_str = "UPDATE " + Sql_Mysql.BattTestDataInf_Table + " SET " + "test_type=" + tmp_test_data.battTestType_For_DataSave + ", " + "record_time_interval=" + rt_data.mSaveDataTimeInterval + ", " + "data_new=" + true + ", " + "data_available=" + true + ", " + "record_num=" + (tmp_test_data.recordNum + 1) + ", " + "test_starttime='" + Com.getDateTimeFormat(tmp_test_data.startTestTime, Com.DTF_YMDhms) + "', " + "test_starttype=" + tmp_test_data.testLoaderType + ", " + "record_time='" + Com.getDateTimeFormat(tmp_test_data.recordTime, Com.DTF_YMDhms) + "', " + "test_timelong=" + tmp_test_data.testTimeLong + ", " + "test_stoptype=" + tmp_test_data.test_stoptype + ", " + "group_vol=" + tmp_test_data.groupVol + ", " + "test_curr=" + tmp_test_data.testCurrAbsMax + ", " + "test_cap=" + tmp_test_data.testCap + ", " + "max_monnum=" + rt_data.mMaxMonNum + ", " + "max_monvol=" + rt_data.mMaxMonVol + ", " + "min_monnum=" + rt_data.mMinMonNum + ", " + "min_monvol=" + rt_data.mMinMonVol + " " + " WHERE " + " BattGroupId=" + rt_data.BattGroupId + " AND " + " test_record_count=" + tmp_test_data.testRecordCount; } return sql_str; } /** * 插入记录放电数据之前的放电参数 * @param pool * @param rt_data */ private static void recordTestParam(MysqlConnPool pool, BattData_RT rt_data) { String sql_str_sel = " SELECT * " + " FROM " + Sql_Mysql.Batt_TestParam_Table + rt_data.BattGroupId + " WHERE BattGroupId = " + rt_data.BattGroupId + " AND test_record_count = " + rt_data.mTestData.testRecordCount; ResultSet res = null; String sql_str = ""; Sql_Mysql sql = new Sql_Mysql(pool); FBS9100_batt_testparam param = rt_data.mTestData.test_param; if(null != param) { try { res = sql.sqlMysqlQuery(sql_str_sel); if(null != res && res.next()) { //更新当前参数 sql_str = " UPDATE " + Sql_Mysql.Batt_TestParam_Table + rt_data.BattGroupId + " SET op_cmd = " + param.op_cmd + ",TestCmd = " + param.TestCmd + ",record_time = '" + Com.getDateTimeFormat(param.record_time, Com.DTF_YMDhms) + "'" + ",HourRate = " + param.HourRate + ",DisCurr = " + param.DisCurr + ",DisCap = " + param.DisCap + ",DisTime = " + param.DisTime + ",GroupVol_LOW = " + param.GroupVol_LOW + ",MonomerVol_LOW = " + param.MonomerVol_LOW + ",MonomerLowCount = " + param.MonomerLowCount + ",BattGroupNum = " + param.BattGroupNum + ",OnlineVolLowAction = " + param.OnlineVolLowAction + ",DCVolHighLimit = " + param.DCVolHighLimit + ",ChargeCurrSet = " + param.ChargeCurrSet + ",MonomerTmp_High = " + param.MonomerTmp_High + ",AutoTestStartVol = " + param.AutoTestStartVol + ",OnLineVol_Low = " + param.OnLineVol_Low + ",OffLineYH_Cycle = " + param.OffLineYH_Cycle + ",OffLineYHstarttime = '" + Com.getDateTimeFormat(param.OffLineYHstarttime, Com.DTF_YMDhms) + "'"+ ",OffLineYHTimes = " + param.OffLineYHTimes + ",OffLineYHOnceCycle = " + param.OffLineYHOnceCycle + ",MonCount = " + param.MonCount + ",MonVol = " + param.MonVol + ",DisPower = " + param.DisPower + ",DisPreRes = " + param.DisPreRes + ",CharCap = " + param.CharCap + ",CharTimeLong = " + param.CharTimeLong + ",FloatCharTimeLong = " + param.FloatCharTimeLong + ",CharSotpCurr = " + param.CharSotpCurr + ",MonVolHightLimit = " + param.MonVolHightLimit + ",MonVolHightLimitCount = " + param.MonVolHightLimitCount + ",CharHighTmp = " + param.CharHighTmp + ",DisWaitTime = " + param.DisWaitTime + ",CharWaitTime = " + param.CharWaitTime + ",FlowOver_Count = " + param.FlowOver_Count + ",FlowOver_CharCurr_1 = " + param.FlowOver_CharCurr_1 + ",FlowOver_CharCurr_2 = " + param.FlowOver_CharCurr_2 + ",FlowOver_CharCurr_3 = " + param.FlowOver_CharCurr_3 + ",FlowOver_CharTime_1 = " + param.FlowOver_CharTime_1 + ",FlowOver_CharTime_2 = " + param.FlowOver_CharTime_2 + ",FlowOver_CharTime_3 = " + param.FlowOver_CharTime_3 + ",ChargeVolt = " + param.ChargeVolt + ",C_ProtectVol1 = " + param.C_ProtectVol1 + ",C_ProtectVol2 = " + param.C_ProtectVol2 + ",C_ProtectVol3 = " + param.C_ProtectVol3 + ",C_mon_uppervol1 = " + param.C_mon_uppervol1 + ",C_mon_uppervol2 = " + param.C_mon_uppervol2 + ",C_mon_uppervol3 = " + param.C_mon_uppervol3 + ",C_mon_uppernum1 = " + param.C_mon_uppernum1 + ",C_mon_uppernum2 = " + param.C_mon_uppernum2 + ",C_mon_uppernum3 = " + param.C_mon_uppernum3 + ",HV_charge_num = " + param.HV_charge_num + ",HV_charge_Vol1 = " + param.HV_charge_Vol1 + ",HV_charge_Vol2 = " + param.HV_charge_Vol2 + ",HV_charge_Vol3 = " + param.HV_charge_Vol3 + ",HV_time1 = " + param.HV_time1 + ",HV_time2 = " + param.HV_time2 + ",HV_time3 = " + param.HV_time3 + ",HV_ProtectCurr1 = " + param.HV_ProtectCurr1 + ",HV_ProtectCurr2 = " + param.HV_ProtectCurr2 + ",HV_ProtectCurr3 = " + param.HV_ProtectCurr3 + ",HV_mon_uppervol1 = " + param.HV_mon_uppervol1 + ",HV_mon_uppervol2 = " + param.HV_mon_uppervol2 + ",HV_mon_uppervol3 = " + param.HV_mon_uppervol3 + ",HV_mon_uppernum1 = " + param.HV_mon_uppernum1 + ",HV_mon_uppernum2 = " + param.HV_mon_uppernum2 + ",HV_mon_uppernum3 = " + param.HV_mon_uppernum3 + " WHERE BattGroupId = " + rt_data.BattGroupId + " AND test_record_count = " + rt_data.mTestData.testRecordCount; }else{ //插入当前参数 sql_str = "INSERT INTO " + Sql_Mysql.Batt_TestParam_Table + rt_data.BattGroupId + "(record_time,BattGroupId,test_record_count,op_cmd,TestCmd,HourRate,DisCurr,DisCap,DisTime,GroupVol_LOW,MonomerVol_LOW,MonomerLowCount,BattGroupNum,OnlineVolLowAction,DCVolHighLimit,ChargeCurrSet,MonomerTmp_High,AutoTestStartVol,OnLineVol_Low,OffLineYH_Cycle,OffLineYHstarttime,OffLineYHTimes,OffLineYHOnceCycle,MonCount,MonVol,DisPower,DisPreRes,CharCap,CharTimeLong,FloatCharTimeLong,CharSotpCurr,MonVolHightLimit,MonVolHightLimitCount,CharHighTmp,DisWaitTime,CharWaitTime,FlowOver_Count,FlowOver_CharCurr_1,FlowOver_CharCurr_2,FlowOver_CharCurr_3,FlowOver_CharTime_1,FlowOver_CharTime_2,FlowOver_CharTime_3,ChargeVolt,C_ProtectVol1,C_ProtectVol2,C_ProtectVol3,C_mon_uppervol1,C_mon_uppervol2,C_mon_uppervol3,C_mon_uppernum1,C_mon_uppernum2,C_mon_uppernum3,HV_charge_num,HV_charge_Vol1,HV_charge_Vol2,HV_charge_Vol3,HV_time1,HV_time2,HV_time3,HV_ProtectCurr1,HV_ProtectCurr2,HV_ProtectCurr3,HV_mon_uppervol1,HV_mon_uppervol2,HV_mon_uppervol3,HV_mon_uppernum1,HV_mon_uppernum2,HV_mon_uppernum3) " + "VALUES(" + "'" + Com.getDateTimeFormat(param.record_time, Com.DTF_YMDhms) + "'," + rt_data.BattGroupId + "," + rt_data.mTestData.testRecordCount + "," + param.op_cmd + "," + param.TestCmd + "," + param.HourRate + "," + param.DisCurr + "," + param.DisCap + "," + param.DisTime + "," + param.GroupVol_LOW + "," + param.MonomerVol_LOW + "," + param.MonomerLowCount + "," + param.BattGroupNum + "," + param.OnlineVolLowAction + "," + param.DCVolHighLimit + "," + param.ChargeCurrSet + "," + param.MonomerTmp_High + "," + param.AutoTestStartVol + "," + param.OnLineVol_Low + "," + param.OffLineYH_Cycle + "," + "'" + Com.getDateTimeFormat(param.OffLineYHstarttime, Com.DTF_YMDhms) + "'," + param.OffLineYHTimes + "," + param.OffLineYHOnceCycle + "," + param.MonCount + "," + param.MonVol + "," + param.DisPower + "," + param.DisPreRes + "," + param.CharCap + "," + param.CharTimeLong + "," + param.FloatCharTimeLong + "," + param.CharSotpCurr + "," + param.MonVolHightLimit + "," + param.MonVolHightLimitCount + "," + param.CharHighTmp + "," + param.DisWaitTime + "," + param.CharWaitTime + "," + param.FlowOver_Count + "," + param.FlowOver_CharCurr_1 + "," + param.FlowOver_CharCurr_2 + "," + param.FlowOver_CharCurr_3 + "," + param.FlowOver_CharTime_1 + "," + param.FlowOver_CharTime_2 + "," + param.FlowOver_CharTime_3 + "," + param.ChargeVolt + "," + param.C_ProtectVol1 + "," + param.C_ProtectVol2 + "," + param.C_ProtectVol3 + "," + param.C_mon_uppervol1 + "," + param.C_mon_uppervol2 + "," + param.C_mon_uppervol3 + "," + param.C_mon_uppernum1 + "," + param.C_mon_uppernum2 + "," + param.C_mon_uppernum3 + "," + param.HV_charge_num + "," + param.HV_charge_Vol1 + "," + param.HV_charge_Vol2 + "," + param.HV_charge_Vol3 + "," + param.HV_time1 + "," + param.HV_time2 + "," + param.HV_time3 + "," + param.HV_ProtectCurr1 + "," + param.HV_ProtectCurr2 + "," + param.HV_ProtectCurr3 + "," + param.HV_mon_uppervol1 + "," + param.HV_mon_uppervol2 + "," + param.HV_mon_uppervol3 + "," + param.HV_mon_uppernum1 + "," + param.HV_mon_uppernum2 + "," + param.HV_mon_uppernum3 + ");"; } //System.out.println(sql_str); sql.sqlMysqlExecute(sql_str); } catch (Exception e) { e.printStackTrace(); } finally { if(null != res) { try { res.close(); } catch (SQLException e) { sql.logger.error("BattData_RT_SQL.recordTestParam():" + e.toString(), e); } } sql.close_con(); } } } /** * ��������������������rt_data����������������������������������������tb_batttestdata_id,tb_testdatastop_id,tb_batttestdata_inf��������������������������SQL��������������� * @param rt_data * @return */ public static ArrayList getDeleteBattTestDataStr(BattData_RT rt_data) { ArrayList al_str = new ArrayList(); BattStatData tmp_test_data = rt_data.mTestData.clone(); String sql_str = "DELETE FROM tb_BattTestData_" + rt_data.BattGroupId + " WHERE test_record_count=" + tmp_test_data.testRecordCount; al_str.add(sql_str); sql_str = "DELETE FROM tb_BattTestDataStop_" + rt_data.BattGroupId + " WHERE test_record_count=" + tmp_test_data.testRecordCount; al_str.add(sql_str); sql_str = "DELETE FROM " + Sql_Mysql.BattTestDataInf_Table + " WHERE " + " BattGroupId=" + rt_data.BattGroupId + " AND " + " test_record_count=" + tmp_test_data.testRecordCount; al_str.add(sql_str); return al_str; } /************************************************************************************************/ public static void queryBattState_From_RT_Table(MysqlConnPool conn_pool, BattData_RT bd_rt) { Sql_Mysql sql = new Sql_Mysql(conn_pool); try { String sql_str = "SELECT * FROM " + Sql_Mysql.BattRtState_Table + " WHERE BattGroupId=" + bd_rt.BattGroupId; //System.out.println(sql_str); ResultSet rs_t = sql.sqlMysqlQuery(sql_str); if(rs_t.next()) { bd_rt.mTestData.battTestState = rs_t.getByte("batt_test_type"); if((BattStatData.BATTDATA_DISCHARGE == bd_rt.mTestData.battTestState) || (BattStatData.BATTDATA_CHARGE == bd_rt.mTestData.battTestState)) { bd_rt.mTestData.battTestType_For_DataSave = bd_rt.mTestData.battTestState; bd_rt.mTestData.testLoaderType = rs_t.getByte("test_loadertype"); bd_rt.mTestData.recordNum = rs_t.getInt("test_recordnum"); bd_rt.mTestData.onlineVol = rs_t.getFloat("online_vol"); bd_rt.mTestData.groupVol = rs_t.getFloat("group_vol"); bd_rt.mTestData.groupTmp = rs_t.getFloat("group_tmp"); bd_rt.mTestData.testCurr = rs_t.getFloat("group_curr"); bd_rt.mTestData.TestCurr_RT = bd_rt.mTestData.testCurr; bd_rt.mTestData.battState = rs_t.getByte("batt_state"); bd_rt.mTestData.startTestTime.setTime(rs_t.getTimestamp("batt_test_starttime").getTime()); bd_rt.mTestData.recordTime.setTime(rs_t.getTimestamp("batt_test_recordtime").getTime()); bd_rt.mTestData.testTimeLong = rs_t.getInt("batt_test_tlong"); bd_rt.mTestData.testCap = rs_t.getFloat("batt_test_cap"); bd_rt.mTestData.battRealCap = rs_t.getFloat("batt_real_cap"); bd_rt.mTestData.battRestCap = rs_t.getFloat("batt_rest_cap"); bd_rt.mTestData.battRestTime = rs_t.getInt("batt_rest_power1_time"); } } } catch (SQLException e) { // TODO Auto-generated catch block sql.logger.error("queryBattState_From_RT_Table():" + e.toString(), e); } finally { sql.close_con(); } } /************************************************************************************************/ /************************************************************************************************/ public static int queryTestRecordCountMax_From_tb_batttestdata_inf(MysqlConnPool conn_pool, int bg_id) { int rec_count = 0; Sql_Mysql sql = new Sql_Mysql(conn_pool); try { String sql_str = "SELECT MAX(test_record_count) FROM " + Sql_Mysql.BattTestDataInf_Table + " WHERE BattGroupId=" + bg_id; //System.out.println(sql_str); ResultSet rs_t = sql.sqlMysqlQuery(sql_str); if(rs_t.next()) { rec_count = rs_t.getInt(1); } } catch (SQLException e) { // TODO Auto-generated catch block sql.logger.error("queryTestRecordCountMax_From_tb_batttestdata_inf():" + e.toString(), e); } finally { sql.close_con(); } return rec_count; } /************************************************************************************************/ /************************************************************************************************/ public static void checkTbFbs9100StateIntegrity(MysqlConnPool conn_pool, long dev_id_t) { Sql_Mysql sql = new Sql_Mysql(conn_pool); try { boolean recreate_data_tag = false; //-----------------------Sql_Mysql.FBS9100State_Table-------------------------// String sql_str = "SELECT dev_id FROM " + Sql_Mysql.FBS9100State_Table + " WHERE dev_id=" + dev_id_t; ResultSet res = sql.sqlMysqlQuery(sql_str); if(false == res.next()) { recreate_data_tag = true; } if(true == recreate_data_tag) { sql_str = "INSERT INTO " + Sql_Mysql.FBS9100State_Table + " (dev_id) VALUES (" + dev_id_t + ")"; sql.logger.debug("BattData_RT_SQL.checkTbFbs9100StateIntegrity(): " + sql_str); sql.sqlMysqlExecute(sql_str); } else { sql.logger.debug("BattData_RT_SQL.checkTbFbs9100StateIntegrity(): " + Sql_Mysql.FBS9100State_Table + ".dev_id:" + dev_id_t + " is exist"); } } catch (SQLException e) { sql.logger.error("BattData_RT_SQL.checkTbFbs9100StateIntegrity():" + e.toString(), e); } finally { sql.close_con(); } } /************************************************************************************************/ public static void checkTbBattDataIntegrity(MysqlConnPool conn_pool, int bg_id, int batt_cnt_t) { Sql_Mysql sql = new Sql_Mysql(conn_pool); try { boolean recreate_data_tag = false; //------------------------Sql_Mysql.BattRtState_Table-------------------------// String sql_str = "SELECT BattGroupId FROM " + Sql_Mysql.BattRtState_Table + " WHERE BattGroupId=" + bg_id; ResultSet res = sql.sqlMysqlQuery(sql_str); if(false == res.next()) { recreate_data_tag = true; } if(true == recreate_data_tag) { sql_str = "INSERT INTO " + Sql_Mysql.BattRtState_Table + " (BattGroupId) VALUES (" + bg_id + ")"; sql.logger.debug("BattData_RT_SQL.checkTbBattDataIntegrity(): " + sql_str); sql.sqlMysqlExecute(sql_str); } else { sql.logger.debug("BattData_RT_SQL.checkTbBattDataIntegrity(): " + Sql_Mysql.BattRtState_Table + ".dev_id:" + bg_id + " is exist"); } //----------------------------------------------------------------------------// recreate_data_tag = false; //------------------------Sql_Mysql.BattRtData_Table--------------------------// sql_str = "SELECT COUNT(mon_num) FROM " + Sql_Mysql.BattRtData_Table + " WHERE BattGroupId=" + bg_id; res = sql.sqlMysqlQuery(sql_str); int len = 0; if(res.next()) { len = res.getInt(1); if((len<1) || (len != batt_cnt_t)) { recreate_data_tag = true; } } if(false == recreate_data_tag) { sql_str = "SELECT mon_num FROM " + Sql_Mysql.BattRtData_Table + " WHERE BattGroupId=" + bg_id + " ORDER BY mon_num ASC"; res = sql.sqlMysqlQuery(sql_str); int index_num = 1; while(res.next()) { if(res.getInt(1) != index_num) { recreate_data_tag = true; break; } else { index_num += 1; continue; } } } if(true == recreate_data_tag) { sql_str = "DELETE FROM " + Sql_Mysql.BattRtData_Table + " WHERE BattGroupId=" + bg_id; sql.logger.debug("BattData_RT_SQL.checkTbBattDataIntegrity(): " + sql_str); sql.sqlMysqlExecute(sql_str); int batt_cnt = batt_cnt_t; if(batt_cnt > 500) { batt_cnt = 500; } if(batt_cnt > 0) { sql_str = "INSERT INTO " + Sql_Mysql.BattRtData_Table + " (BattGroupId, mon_num) + VALUES "; for(int n=0; n 1) { sql_str_vol = ", monvol_alm = CASE mon_num " + sql_str_vol + " ELSE monvol_alm END "; } String sql_str_tmp = " "; for(int n=0; n 1) { sql_str_tmp = ", montmp_alm = CASE mon_num " + sql_str_tmp + " ELSE montmp_alm END "; } String sql_str_res = " "; for(int n=0; n 1) { sql_str_res = ", monres_alm = CASE mon_num " + sql_str_res + " ELSE monres_alm END "; } String sql_str_cap = " "; for(int n=0; n 1) { sql_str_cap = ", monrestcap_alm = CASE mon_num " + sql_str_cap + " ELSE monrestcap_alm END "; } String sql_str_2 = sql_str_vol + sql_str_tmp + sql_str_res + sql_str_cap ; if(sql_str_2.trim().length() > 1) { sql_str_2 += " WHERE BattGroupId=" + bd_rt.BattGroupId; /* + " AND mon_num IN ("; for(int n=0; n 0) { sql_str_2 += ","; } sql_str_2 += (n+1); } sql_str_2 += ")"; */ } else { sql_str_2 = " WHERE BattGroupId=" + bd_rt.BattGroupId; } sql_str += sql_str_2; //System.out.println(bd_rt.MonCount); //System.out.println(sql_str); sql.sqlMysqlExecute(sql_str); } catch (SQLException e) { // TODO Auto-generated catch block sql.logger.error("updateBattAlarm_RT_RamDB_Table():" + e.toString(), e); } finally { sql.close_con(); } } /************************************************************************************************/ }