package com.dev.fbs9009;
|
|
import java.sql.Connection;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Date;
|
|
import com.base.Com;
|
import com.battdata_rt.BattData_RT;
|
import com.dev.fbs9009.MyModBusPowerOffRecordThread.RecordThread;
|
import com.dev.fbs9009.MyModBusRecordDataThread2.RecordDataThread;
|
import com.sql.MysqlConnPool;
|
import com.sql.Sql_Mysql;
|
|
import main.main_MonitorServer_FBS9009S;
|
|
public class MyModBusSocketThread_SQL {
|
|
/**
|
* ²åÈëÈí¼þ·þÎñÐÅÏ¢
|
* @param conn_pool
|
*/
|
public static void insertServerStateInfoToProcess(MysqlConnPool conn_pool) {
|
String sql_select_str = "SELECT * FROM web_site.tb_process_survey WHERE ProcessId = 11012";
|
|
String sql_insert_str = "INSERT INTO " + Sql_Mysql.Tb_ProcessSurvey +
|
"(ProcessId,ProcessName,ProcessTime,Process_starttime,ServerFlag,ServerName,ProcessVersion,note,OutTime) " +
|
"VALUES (11012,'BMS_LD-9_DEV','"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"',1,'BMS_LD-9_DEV','"+String.format("V%1.3f", main_MonitorServer_FBS9009S.m_VersionNum)+"','9¶ÈÉ豸ͨѶÏß³Ì',300)";
|
|
ResultSet rs = null;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
rs = sql.sqlMysqlQuery(sql_select_str);
|
try {
|
if(!rs.next()) {
|
sql.sqlMysqlExecute(sql_insert_str); //²åÈë9¶ÈÏß³ÌÐÅÏ¢
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
if(rs != null) {
|
rs.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
|
}
|
|
//¸üе±Ç°Ïß³ÌµÄÆô¶¯Ê±¼äÒÔ¼°Èí¼þ³ÌÐòµÄ°æ±¾ºÅ
|
public static boolean updateServerStartInfTo_RamDB_Table(MysqlConnPool conn_pool, double ver)
|
{
|
boolean res = false;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlUseDB("web_site");
|
if(true == sql.sqlMysqlCheckIfTableExist("tb_process_survey")) {
|
String sql_str_1 = "UPDATE " + "tb_process_survey" + " SET "
|
+ " Process_starttime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "', "
|
+ " ProcessVersion='" + String.format("V%1.3f", ver) + "' "
|
+ " WHERE Processid = 11012";
|
sql.sqlMysqlExecute(sql_str_1);
|
res = true;
|
}
|
} catch (SQLException e) {
|
res = false;
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
|
return res;
|
}
|
|
//¸üе±Ç°Ï̵߳ÄÔËÐÐʱ¼ä
|
public static boolean updateServerTimeTo_RamDB_Table(MysqlConnPool conn_pool)
|
{
|
boolean res = false;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlUseDB("web_site");
|
if(true == sql.sqlMysqlCheckIfTableExist("tb_process_survey")) {
|
String sql_str_1 = " UPDATE " + "tb_process_survey" + " SET "
|
+ " ProcessTime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "'"
|
+ " WHERE Processid = 11012";
|
sql.sqlMysqlExecute(sql_str_1);
|
res = true;
|
}
|
} catch (SQLException e) {
|
res = false;
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
|
return res;
|
}
|
|
//´´½¨tb_LD9_state±í
|
public static void createLD9_state(MysqlConnPool conn_pool){
|
//String sql_str1 = "DROP TABLE IF EXISTS "+Sql_Mysql.LD9_State_Table;
|
String sql_str2 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.LD9_State_Table + " "
|
+ "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
|
+ "`dev_id` INT NOT NULL DEFAULT 401900001, "
|
+ "`dev_ip` varchar(20) NOT NULL DEFAULT '127.0.0.1', "
|
+ "`dev_version` VARCHAR(64) NOT NULL DEFAULT 'v1.01.01',"
|
+ "`sys_state` INT NOT NULL DEFAULT 0, "
|
+ "`sys_online_vol` float NOT NULL DEFAULT 0.01, "
|
+ "`sys_group_vol` FLOAT NOT NULL DEFAULT 0.01, "
|
+ "`sys_now_battnum` int NOT NULL DEFAULT 1, "
|
+ "`sys_now_battstate` int NOT NULL DEFAULT 1, "
|
+ "`sys_now_battvol` FLOAT NOT NULL DEFAULT 0.01, "
|
+ "`sys_now_battcurr` float NOT NULL DEFAULT 0.01, "
|
+ "`sys_now_battcap` float NOT NULL DEFAULT 0.01, "
|
+ "`sys_now_testtime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
|
+ "`sys_next_battnum` int NOT NULL DEFAULT 1, "
|
+ "`sys_next_battstate` int NOT NULL DEFAULT 1, "
|
+ "`sys_next_battvol` FLOAT NOT NULL DEFAULT 0.01, "
|
+ "`sys_next_battcurr` float NOT NULL DEFAULT 0.01, "
|
+ "`sys_next_battcap` float NOT NULL DEFAULT 0.01, "
|
+ "`sys_next_testtime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
|
+ "`sys_tmp` float NOT NULL DEFAULT 0.1, "
|
+ "`sys_stop_reason` INT NOT NULL DEFAULT 1, "
|
+ "`dev_commcount` int not null DEFAULT 0, "
|
+ "`dev_errcommcount` int not null DEFAULT 0, "
|
+ "`timelong` int not null DEFAULT 0, " //²âÊÔʱ³¤
|
+ "UNIQUE INDEX index_dev_id (`dev_id`), " //Ìí¼ÓΨһË÷Òý
|
+ "PRIMARY KEY (`num`)) "
|
+ "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
//sql.sqlMysqlExecute(sql_str1);
|
sql.sqlMysqlExecute(sql_str2);
|
|
ResultSet res = null;
|
//Ìí¼Óµ¥Ìåµçѹ¸ß¸æ¾¯ÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_state'"
|
+ " AND column_name='monvol_hightalarm'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_State_Table
|
+ " ADD COLUMN `monvol_hightalarm` int(11) NOT NULL DEFAULT '0';");
|
}
|
//Ìí¼Óµ¥ÌåµçѹµÍ¸æ¾¯ÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_state'"
|
+ " AND column_name='monvol_loweralarm'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_State_Table
|
+ " ADD COLUMN `monvol_loweralarm` int(11) NOT NULL DEFAULT '0';");
|
}
|
//Ìí¼ÓÈÝÁ¿¸æ¾¯ÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_state'"
|
+ " AND column_name='moncap_alarm'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_State_Table
|
+ " ADD COLUMN `moncap_alarm` int(11) NOT NULL DEFAULT '0';");
|
}
|
|
//Ìí¼Óζȸ澯ÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_state'"
|
+ " AND column_name='montmp_alarm'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_State_Table
|
+ " ADD COLUMN `montmp_alarm` int(11) NOT NULL DEFAULT '0';");
|
}
|
|
//Ìí¼ÓÄÚ×è¸æ¾¯ÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_state'"
|
+ " AND column_name='monres_alarm'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_State_Table
|
+ " ADD COLUMN `monres_alarm` int(11) NOT NULL DEFAULT '0';");
|
}
|
|
//Ìí¼Ó¼Ç¼ʱ¼äÁÐ,Ϊ·½±ã¼Ç¼É豸µÄͨѶ¹ÊÕϸ澯
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db' "
|
+ " AND table_name='tb_LD9_state' "
|
+ " AND column_name='record_datetime' ");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_State_Table
|
+ " ADD COLUMN `record_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00' AFTER `dev_ip`;");
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
//´´½¨tb_LD9_setparam±í
|
public static void createLD9_setparam(MysqlConnPool conn_pool){
|
String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.LD9_Setparam_Table + " "
|
+ "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
|
+ "`dev_id` INT NOT NULL DEFAULT 401900001, "
|
+ "`op_cmd` int not null DEFAULT 0, "
|
+ "`param_teststart_batt_num` INT NOT NULL DEFAULT 0, "
|
+ "`param_cap` int NOT NULL DEFAULT 1, "
|
+ "`param_discharge_curr` FLOAT NOT NULL DEFAULT 0.001, "
|
+ "`param_mon_curr_high` float NOT NULL DEFAULT 0.001, "
|
+ "`param_charge_curr` float NOT NULL DEFAULT 0.001, "
|
+ "`param_mon_curr_low` FLOAT NOT NULL DEFAULT 0.001, "
|
+ "`param_online_vol` float NOT NULL DEFAULT 0.01, "
|
+ "`param_charge_curr_low` float NOT NULL DEFAULT 0.001, "
|
+ "`param_charge_cap_low` float NOT NULL DEFAULT 0.1, "
|
+ "`param_online_vol_recover` int NOT NULL DEFAULT 0.01, "
|
+ "`param_module_address` int NOT NULL DEFAULT 1, "
|
+ "`param_junheng_model` INT NOT NULL DEFAULT 0, " //¾ùºâ¹¦ÄÜ
|
+ " UNIQUE INDEX index_dev_id (`dev_id`), "
|
+ "PRIMARY KEY (`num`)) "
|
+ "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
ResultSet res = null;
|
//Ìí¼ÓÈÝÁ¿ÏÂÏÞÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_setparam'"
|
+ " AND column_name='param_cap_low'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_Setparam_Table
|
+ " ADD COLUMN `param_cap_low` float NOT NULL DEFAULT '0';");
|
}
|
|
//Ìí¼ÓÊý¾ÝÀ´Ô´ÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_setparam'"
|
+ " AND column_name='param_datasource'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_Setparam_Table
|
+ " ADD COLUMN `param_datasource` int NOT NULL DEFAULT '0';");
|
}
|
|
//Ìí¼ÓÄÚ×è²âÊÔϵÊýÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_setparam'"
|
+ " AND column_name='param_res_args'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_Setparam_Table
|
+ " ADD COLUMN `param_res_args` int NOT NULL DEFAULT '0';");
|
}
|
|
//Ìí¼ÓÈÝÁ¿ÏÂÏÞÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_setparam'"
|
+ " AND column_name='param_tmp_high'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_Setparam_Table
|
+ " ADD COLUMN `param_tmp_high` float NOT NULL DEFAULT '0';");
|
}
|
|
//Ìí¼ÓÈÝÁ¿ÏÂÏÞÁÐ
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_LD9_setparam'"
|
+ " AND column_name='param_res_high'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.LD9_Setparam_Table
|
+ " ADD COLUMN `param_res_high` float NOT NULL DEFAULT '0';");
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
//´´½¨db_ld9_testdataÊý¾Ý¿â
|
public static void createDb_ld9_testdata(MysqlConnPool conn_pool){
|
String sql_str = "CREATE DATABASE if not exists "+Sql_Mysql.DB_LD9_TESTDATA;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
//´´½¨tb_ld9testdata_inf±í
|
public static void createTb_ld9testdata_inf(MysqlConnPool conn_pool){
|
String sql_str1 = "CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_LD9_TESTDATA;
|
String sql_str2 = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.TB_Ld9testdata_inf
|
+ "("
|
+ "`num` bigint(20) NOT NULL AUTO_INCREMENT,"
|
+ "`BattGroupId` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_record_count` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_record_count_ex` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_type` int(11) NOT NULL DEFAULT '0',"
|
+ "`record_time_interval` int(11) NOT NULL DEFAULT '0',"
|
+ "`record_num` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_starttime` datetime NOT NULL DEFAULT '1982-01-01 00:00:00',"
|
+ "`test_starttime_ex` 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(11) NOT NULL DEFAULT '0',"
|
+ "`test_stoptype` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_stopreason` int(11) 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(11) NOT NULL DEFAULT '0',"
|
+ "`mon_vol` float NOT NULL DEFAULT '0',"
|
+ "`max_monnum` int(11) NOT NULL DEFAULT '1',"
|
+ "`max_monvol` float NOT NULL DEFAULT '12.5',"
|
+ "`min_monnum` int(11) NOT NULL DEFAULT '1',"
|
+ "`min_monvol` float NOT NULL DEFAULT '12',"
|
+ "PRIMARY KEY (`num`),"
|
+ "KEY `index_battgroup_id` (`BattGroupId`),"
|
+ "KEY `index_test_record_count` (`test_record_count`),"
|
+ "KEY `index_test_starttime` (`test_starttime`)"
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(sql_str1);
|
sql.sqlMysqlExecute(sql_str2);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ´´½¨LD_9É豸ÖÐµÄµç³Ø×éµÄ·Åµç¼Ç¼±í(Èç¹û²»´æÔÚÔò´´½¨)
|
* @param conn_pool
|
* @param BattgroupId
|
*/
|
public static void createTb_ld9testdata(MysqlConnPool conn_pool,int BattgroupId){
|
String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.TB_Ld9testdata+BattgroupId
|
+ "("
|
+ "`num` bigint(20) NOT NULL AUTO_INCREMENT,"
|
+ "`BattGroupId` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_record_count` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_type` int(11) NOT NULL DEFAULT '0',"
|
+ "`record_num` int(11) 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(11) 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(11) NOT NULL DEFAULT '0',"
|
+ "`mon_vol` float NOT NULL DEFAULT '0',"
|
+ "`mon_tmp` float NOT NULL DEFAULT '0',"
|
+ "`test_monnum` int(11) NOT NULL DEFAULT '1'," //±»²âµç³Ø×éµ¥ÌåºÅ
|
+ "PRIMARY KEY (`num`),"
|
+ "KEY `index_test_record_count` (`test_record_count`)"
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ´´½¨tb_ld9testdatastop_id±í(Èç¹û²»´æÔÚÔò´´½¨)
|
* @param conn_pool
|
* @param BattgroupId
|
*/
|
public static void createTb_ld9testdatastop(MysqlConnPool conn_pool,int BattgroupId){
|
String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.TB_Ld9testdatastop+BattgroupId
|
+ "("
|
+ "`num` bigint(20) NOT NULL AUTO_INCREMENT,"
|
+ "`BattGroupId` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_record_count` int(11) NOT NULL DEFAULT '0',"
|
+ "`test_type` int(11) NOT NULL DEFAULT '0',"
|
+ "`record_num` int(11) 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(11) 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(11) NOT NULL DEFAULT '0',"
|
+ "`mon_vol` float NOT NULL DEFAULT '0',"
|
+ "`mon_tmp` float NOT NULL DEFAULT '0',"
|
+ "`test_monnum` int(11) NOT NULL DEFAULT '1'," //±»²âµç³Ø×éµ¥ÌåºÅ
|
+ "`max_monvol` float NOT NULL DEFAULT '13',"
|
+ "`min_monvol` float NOT NULL DEFAULT '12',"
|
+ "`test_stopreason` int(11) NOT NULL DEFAULT '0',"
|
+ "PRIMARY KEY (`num`),"
|
+ "KEY `index_test_record_count` (`test_record_count`)"
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
/**
|
* ¸ù¾Ýbd_al¸üÐÂtb_batt_rtstate±í
|
* @param conn_pool
|
* @param bd_al
|
*/
|
public static void updateBattState_RT_RamDB_Table(MysqlConnPool conn_pool,MyModBusData devinfo)
|
{
|
int BattGroupId = devinfo.getBattgroupid();
|
LD_sys_state ld_sys = devinfo.getDischageSysState();
|
//LD_batt_states batt_state = devinfo.getLd_batt_states();
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try
|
{
|
String sql_str = "UPDATE " + Sql_Mysql.BattRtState_Table
|
+ " SET "
|
+ " rec_datetime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "',";
|
|
sql_str += " online_vol = CASE BattGroupId ";
|
sql_str += " WHEN " +BattGroupId + " THEN " +ld_sys.getSys_online_vol();
|
|
sql_str += " END, " + " group_vol = CASE BattGroupId ";
|
sql_str += " WHEN " +BattGroupId + " THEN " + devinfo.getTotalGroupVol();
|
|
sql_str += " END, " + " group_tmp = CASE BattGroupId ";
|
sql_str += " WHEN " + BattGroupId + " THEN " + ld_sys.getSys_tmp();
|
|
sql_str += " END, " + " group_curr = CASE BattGroupId ";
|
sql_str += " WHEN " +BattGroupId + " THEN " + ld_sys.getBattTestCurr();
|
|
sql_str += " END, " + " batt_state = CASE BattGroupId ";
|
sql_str += " WHEN " +BattGroupId + " THEN " + ld_sys.getNowBattType();
|
|
sql_str += " END, " + " batt_test_type = CASE BattGroupId ";
|
sql_str += " WHEN " + BattGroupId + " THEN " +ld_sys.getNowBattType();
|
|
sql_str += " END, " + " batt_test_starttime = CASE BattGroupId ";
|
//System.out.println(devinfo.getTest_starttime());
|
Date dt = ld_sys.getTest_starttime();
|
sql_str += " WHEN " + BattGroupId + " THEN '" + Com.getDateTimeFormat(dt, Com.DTF_YMDhms) + "'";
|
|
|
sql_str += " END, " + " batt_test_recordtime = CASE BattGroupId ";
|
Calendar now = Calendar.getInstance();
|
//String batt_test_recordtime=now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH) + 1)+"-"+now.get(Calendar.DAY_OF_MONTH)+" "+ld_sys.getSys_next_testtime_hour()+":"+ld_sys.getSys_next_testtime_minute()+":"+ld_sys.getSys_next_testtime_second();
|
String batt_test_recordtime = Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms);
|
sql_str += " WHEN " + BattGroupId + " THEN '" + batt_test_recordtime+ "'";
|
|
|
sql_str += " END, " + " batt_test_tlong = CASE BattGroupId ";
|
//for(int n=0; n<bd_al.size(); n++) {
|
// BattData_RT brt = bd_al.get(n);
|
sql_str += " WHEN " + BattGroupId + " THEN " + ld_sys.getTest_timelong();
|
//}
|
|
sql_str += " END, " + " batt_test_cap = CASE BattGroupId ";
|
sql_str += " WHEN " + BattGroupId + " THEN " +ld_sys.getBattTestCap(); //ÏÔʾ·ÅµçʱµÄ²âÊÔÈÝÁ¿
|
|
|
/*sql_str += " END, " + " batt_real_cap = CASE BattGroupId ";
|
sql_str += " WHEN " + BattGroupId + " THEN " + getBattRealCap();
|
*/
|
/*
|
sql_str += " END, " + " batt_rest_cap = CASE BattGroupId ";
|
sql_str += " WHEN " + brt.BattGroupId + " THEN " + brt.getBattRestCap();
|
*/
|
/*
|
sql_str += " END, " + " batt_rest_power1_time = CASE BattGroupId ";
|
for(int n=0; n<bd_al.size(); n++) {
|
BattData_RT brt = bd_al.get(n);
|
sql_str += " WHEN " + brt.BattGroupId + " THEN " + brt.getBattRestTime();
|
}*/
|
|
sql_str += " END WHERE BattGroupId IN (";
|
sql_str += BattGroupId;
|
|
sql_str += ")";
|
//System.out.println(sql_str);
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
/**
|
* ¸üÐÂtb_batt_rtdata±íÖеÄÊý¾Ý
|
* @param conn_pool
|
* @param bd_al
|
*/
|
public static void updateBattData_RT_RamDB_Table(MysqlConnPool conn_pool,int BattGroupId , LD_batt_states ld_batts,int index)
|
{
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
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<ld_batts.getLd_batts().length; n++) {
|
tmp_dt = (float) ld_batts.getLd_batts()[n].getBatt_vol();
|
sql_str_vol += " WHEN " + (9*index+n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
if(sql_str_vol.trim().length() > 1) {
|
sql_str_vol = ", mon_vol = CASE mon_num " + sql_str_vol + " ELSE mon_vol END ";
|
}
|
|
String sql_str_mon_cap = " ";
|
for(int n=0; n<ld_batts.getLd_batts().length; n++) {
|
tmp_dt = (float) ld_batts.getLd_batts()[n].getBatt_cap();
|
sql_str_mon_cap += " WHEN " + (9*index+n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
if(sql_str_mon_cap.trim().length() > 1) {
|
sql_str_mon_cap = ", mon_cap = CASE mon_num " + sql_str_mon_cap + " ELSE mon_cap END ";
|
}
|
|
/*String sql_str_tmp = " ";
|
for(int n=0; n<brt.MonCount; n++) {
|
tmp_dt = brt.al_MonVol.get(n).monTmp;
|
if(brt.al_MonVol_RtOld.get(n).monTmp != tmp_dt) {
|
brt.al_MonVol_RtOld.get(n).monTmp = tmp_dt;
|
sql_str_tmp += " WHEN " + (n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
}
|
if(sql_str_tmp.trim().length() > 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<brt.MonCount; n++) {
|
tmp_dt = brt.al_MonVol.get(n).monRes;
|
if(brt.al_MonVol_RtOld.get(n).monRes != tmp_dt) {
|
brt.al_MonVol_RtOld.get(n).monRes = tmp_dt;
|
sql_str_res += " WHEN " + (n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
}
|
if(sql_str_res.trim().length() > 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<brt.MonCount; n++) {
|
tmp_dt = brt.al_MonVol.get(n).monSer;
|
if(brt.al_MonVol_RtOld.get(n).monSer != tmp_dt) {
|
brt.al_MonVol_RtOld.get(n).monSer = tmp_dt;
|
sql_str_ser += " WHEN " + (n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
}
|
if(sql_str_ser.trim().length() > 1) {
|
sql_str_ser = ", mon_ser = CASE mon_num " + sql_str_ser + " ELSE mon_ser END ";
|
}*/
|
|
String sql_str_2 = sql_str_vol+sql_str_mon_cap ;
|
if(sql_str_2.trim().length() > 1) {
|
sql_str_2 += " WHERE BattGroupId=" + BattGroupId;
|
} else {
|
sql_str_2 = " WHERE BattGroupId=" + BattGroupId;
|
}
|
|
sql_str += sql_str_2;
|
//System.out.println(sql_str);
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ¸üÐÂtb_batt_rtdata±íÖе¥ÌåζÈÄÚ×èµÄÊý¾Ý
|
* @param conn_pool
|
* @param bd_al
|
*/
|
public static void updateBattMonData_RT_RamDB_Table(MysqlConnPool conn_pool,int BattGroupId , LD_batt_states ld_batts,int index)
|
{
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try
|
{
|
String sql_str = "UPDATE " + Sql_Mysql.BattRtData_Table
|
+ " SET "
|
+ " rec_datetime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "'";
|
|
double tmp_dt = 0;
|
String sql_str_vol = " ";
|
|
for(int n=0; n<ld_batts.mon_tmps.length; n++) {
|
tmp_dt = ld_batts.mon_tmps[n];
|
sql_str_vol += " WHEN " + (9*index+n+1) + " THEN " + String.format("%1.1f", tmp_dt);
|
}
|
if(sql_str_vol.trim().length() > 1) {
|
sql_str_vol = ", mon_tmp = CASE mon_num " + sql_str_vol + " ELSE mon_tmp END ";
|
}
|
|
String sql_str_mon_cap = " ";
|
for(int n=0; n<ld_batts.mon_ress.length; n++) {
|
tmp_dt = ld_batts.mon_ress[n];
|
sql_str_mon_cap += " WHEN " + (9*index+n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
if(sql_str_mon_cap.trim().length() > 1) {
|
sql_str_mon_cap = ", mon_res = CASE mon_num " + sql_str_mon_cap + " ELSE mon_res END ";
|
}
|
|
/*String sql_str_tmp = " ";
|
for(int n=0; n<brt.MonCount; n++) {
|
tmp_dt = brt.al_MonVol.get(n).monTmp;
|
if(brt.al_MonVol_RtOld.get(n).monTmp != tmp_dt) {
|
brt.al_MonVol_RtOld.get(n).monTmp = tmp_dt;
|
sql_str_tmp += " WHEN " + (n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
}
|
if(sql_str_tmp.trim().length() > 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<brt.MonCount; n++) {
|
tmp_dt = brt.al_MonVol.get(n).monRes;
|
if(brt.al_MonVol_RtOld.get(n).monRes != tmp_dt) {
|
brt.al_MonVol_RtOld.get(n).monRes = tmp_dt;
|
sql_str_res += " WHEN " + (n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
}
|
if(sql_str_res.trim().length() > 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<brt.MonCount; n++) {
|
tmp_dt = brt.al_MonVol.get(n).monSer;
|
if(brt.al_MonVol_RtOld.get(n).monSer != tmp_dt) {
|
brt.al_MonVol_RtOld.get(n).monSer = tmp_dt;
|
sql_str_ser += " WHEN " + (n+1) + " THEN " + String.format("%1.3f", tmp_dt);
|
}
|
}
|
if(sql_str_ser.trim().length() > 1) {
|
sql_str_ser = ", mon_ser = CASE mon_num " + sql_str_ser + " ELSE mon_ser END ";
|
}*/
|
|
String sql_str_2 = sql_str_vol+sql_str_mon_cap ;
|
if(sql_str_2.trim().length() > 1) {
|
sql_str_2 += " WHERE BattGroupId=" + BattGroupId;
|
} else {
|
sql_str_2 = " WHERE BattGroupId=" + BattGroupId;
|
}
|
|
sql_str += sql_str_2;
|
//System.out.println(sql_str);
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ²éѯµ±Ç°µç³Ø×éÖÐ×î´óµÄtest_record_count
|
* @return
|
*/
|
public static int searchMaxTestReCord(MysqlConnPool conn_pool,int BattGroupId){
|
int testRecordCount = 1;
|
String sql_str = "SELECT MAX(test_record_count)as test_record_count"
|
+ " FROM "+Sql_Mysql.TB_Ld9testdata_inf
|
+ " WHERE BattGroupId = "+BattGroupId
|
+ " FOR UPDATE ";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
ResultSet rs = null;
|
try {
|
rs = sql.sqlMysqlQuery(sql_str);
|
if(rs.next()){
|
testRecordCount = rs.getInt("test_record_count");
|
}
|
if(testRecordCount<1){
|
testRecordCount = 1;
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
if(rs != null){
|
try {
|
rs.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
sql.close_con();
|
}
|
return testRecordCount;
|
}
|
|
/**
|
* ²éѯµç³Ø×鵱ǰµÄ×î´ó²âÊԵıÊÊýÒÔ¼°Ê±¼ä
|
* @param conn_pool
|
* @param BattGroupId
|
* @return
|
*/
|
public static LD_sys_state searchMaxTestRecordByBattGroupId(MysqlConnPool conn_pool,int BattGroupId) {
|
String sql_str = "SELECT MAX(test_record_count)as test_record_count,record_time " +
|
" FROM " + Sql_Mysql.TB_Ld9testdata_inf +
|
" WHERE BattGroupId = "+BattGroupId+" AND test_record_count = ( " +
|
" SELECT MAX(test_record_count)as test_record_count " +
|
" FROM " + Sql_Mysql.TB_Ld9testdata_inf +
|
" WHERE BattGroupId = " + BattGroupId +
|
" ) ";
|
LD_sys_state sys_state = null;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
ResultSet res = sql.sqlMysqlQuery(sql_str);
|
try {
|
while(res.next()) {
|
if(res.getString("record_time") !=null) {
|
sys_state = new LD_sys_state();
|
sys_state.setRecord_historytime(res.getTimestamp("record_time"));
|
sys_state.setTest_record_count(res.getInt("test_record_count"));
|
}
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
if(res != null) {
|
try {
|
res.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
sql.close_con();
|
}
|
return sys_state;
|
}
|
|
/**
|
* ²éѯµ±Ç°µç³Ø×éÖвâÊÔµ½µÄ×î´óµÄµ¥Ìå±àºÅ
|
* @return
|
*/
|
public static int searchMaxMonNum(MysqlConnPool conn_pool,int BattGroupId,int testrecordcount){
|
int mon_num = 1;
|
String sql_str = "SELECT MAX(mon_num)as mon_num"
|
+ " FROM "+Sql_Mysql.TB_Ld9testdata+BattGroupId
|
+ " WHERE BattGroupId = " + BattGroupId
|
+ " AND test_record_count = " + testrecordcount
|
+ " FOR UPDATE ";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
ResultSet rs = null;
|
try {
|
rs = sql.sqlMysqlQuery(sql_str);
|
if(rs.next()){
|
mon_num = rs.getInt("mon_num");
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
if(rs != null){
|
try {
|
rs.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
sql.close_con();
|
}
|
return mon_num;
|
}
|
|
/**
|
* ²éѯµ±Ç°µ¥ÌåÔÚ×îºóÒ»´Î²âÊÔ¹ý³ÌÖÐÊÇ·ñ²âÊÔ¹ý
|
* @return
|
*/
|
public static boolean searchMonHasDischarge(MysqlConnPool conn_pool,int BattGroupId,int test_record_count,int mon_num) {
|
boolean flag = false;
|
String sql_str = " SELECT record_num from " + Sql_Mysql.TB_Ld9testdata+BattGroupId +
|
" WHERE BattGroupId = " + BattGroupId +
|
" AND test_record_count = " + test_record_count +
|
" AND mon_num = " + mon_num;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
ResultSet res = sql.sqlMysqlQuery(sql_str);
|
try {
|
if(res.next()) {
|
flag = true;
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
if(res != null) {
|
try {
|
res.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
sql.close_con();
|
}
|
return flag;
|
}
|
|
/**
|
* ¼Ç¼µç³Ø×éµÄ·Åµç²âÊÔ inf
|
*/
|
public static void insertOrUpdate(MysqlConnPool conn_pool,BattData_RT battdata,int dev_index){
|
LD_sys_state sys_state = battdata.myModBusData.getLd_sys()[dev_index];
|
String sql_str1 =
|
" SELECT battgroupid FROM "+Sql_Mysql.TB_Ld9testdata_inf+""
|
+ " WHERE battgroupid="+battdata.BattGroupId+" AND "
|
+ " test_record_count = "+sys_state.getTest_record_count();
|
|
int test_monnum = sys_state.getTest_mon_num() + 9*dev_index;
|
String sql_str2 = " INSERT INTO "+Sql_Mysql.TB_Ld9testdata_inf+"("
|
+ " BattGroupId,test_record_count,test_record_count_ex,"
|
+ " test_type,record_num,test_starttime,record_time,"
|
+ " test_timelong,test_stopreason,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,max_monnum,max_monvol,min_monnum,min_monvol)"
|
+ " values("+battdata.BattGroupId+","+
|
sys_state.getTest_record_count()+","+
|
(sys_state.getTest_record_count()+1)+","+
|
MyModBusCom.TestType_HERONG_DISCHARGE+","+
|
sys_state.getRecord_num()+","+
|
"'"+Com.getDateTimeFormat(sys_state.getTest_starttime(), Com.DTF_YMDhms)+"',"+
|
"'"+Com.getDateTimeFormat(sys_state.getRecord_historytime(),Com.DTF_YMDhms)+"',"+
|
sys_state.getTest_timelong()+","+
|
sys_state.getSys_stop_reason()+","+
|
battdata.myModBusData.getTotalGroupVol()+","+
|
sys_state.getNowTestCurr()+","+
|
sys_state.getNowTestCap()+","+
|
test_monnum+","+
|
sys_state.getNowMonVol()+","+
|
battdata.myModBusData.getLd_batt_states()[dev_index].getMax_mon_num()+","+
|
battdata.myModBusData.getLd_batt_states()[dev_index].getMax_mon_vol()+","+
|
battdata.myModBusData.getLd_batt_states()[dev_index].getMin_mon_num()+","+
|
battdata.myModBusData.getLd_batt_states()[dev_index].getMin_mon_vol()+
|
")";
|
int stopreason = battdata.myModBusData.getLd_batt_states()[dev_index].getLd_batts()[sys_state.getTest_mon_num()-1]!=null?battdata.myModBusData.getLd_batt_states()[dev_index].getLd_batts()[sys_state.getTest_mon_num()-1].getStop_reason():1;
|
String sql_str3 = " UPDATE "+Sql_Mysql.TB_Ld9testdata_inf+" "
|
+ " SET record_num="+sys_state.getRecord_num()+","
|
+ " record_time='"+Com.getDateTimeFormat(sys_state.getRecord_historytime(), Com.DTF_YMDhms)+"',"
|
+ " test_timelong="+sys_state.getTest_timelong()+","
|
+ " test_stopreason="+stopreason+","
|
+ " group_vol="+battdata.myModBusData.getTotalGroupVol()+","
|
+ " test_curr="+sys_state.getNowTestCurr()+","
|
+ " test_cap="+sys_state.getNowTestCap()+","
|
+ " mon_vol="+sys_state.getNowMonVol()+","
|
+ " max_monnum="+battdata.myModBusData.getLd_batt_states()[dev_index].getMax_mon_num()+","
|
+ " max_monvol="+battdata.myModBusData.getLd_batt_states()[dev_index].getMax_mon_vol()+","
|
+ " min_monnum="+battdata.myModBusData.getLd_batt_states()[dev_index].getMin_mon_num()+","
|
+ " min_monvol="+battdata.myModBusData.getLd_batt_states()[dev_index].getMin_mon_vol()
|
+ " where BattGroupId = "+ battdata.BattGroupId
|
//+ " AND mon_num="+battdata.myModBusData.getLd_sys().getNowTestMonNum()
|
+" AND test_record_count="+sys_state.getTest_record_count();
|
ResultSet rs = null;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
rs = sql.sqlMysqlQuery(sql_str1);
|
if(rs.next()){
|
//System.out.println("Ö´ÐиüÐÂÓï¾ä");
|
sql.sqlMysqlExecute(sql_str3);
|
}else{
|
//System.out.println("Ö´ÐвåÈëÓï¾ä");
|
//battdata.record_num = 1;
|
//System.out.println(sql_str2);
|
sql.sqlMysqlExecute(sql_str2);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
try {
|
if(rs != null){
|
rs.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
|
}
|
|
/**
|
* ¼Ç¼LD9¶à×éµç³Ø×éµÄ·Åµç²âÊÔ inf
|
*/
|
public static void insertOrUpdateMuilMonDataInf(MysqlConnPool conn_pool,RecordThread thread){
|
BattData_RT battdata = thread.battData;
|
|
String sql_str1 =
|
" SELECT battgroupid FROM "+Sql_Mysql.TB_Ld9testdata_inf+""
|
+ " WHERE battgroupid="+battdata.BattGroupId+" AND "
|
+ " test_record_count = "+thread.test_record_count;
|
|
String sql_str2 = " INSERT INTO "+Sql_Mysql.TB_Ld9testdata_inf+"("
|
+ " BattGroupId,test_record_count,test_record_count_ex,"
|
+ " test_type,record_num,test_starttime,record_time,"
|
+ " test_timelong,test_stopreason,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,max_monnum,max_monvol,min_monnum,min_monvol)"
|
+ " values("+battdata.BattGroupId+","+
|
thread.test_record_count+","+
|
(thread.test_record_count+1)+","+
|
thread.start_test_type+","+
|
thread.record_num+","+
|
"'"+Com.getDateTimeFormat(thread.test_starttime, Com.DTF_YMDhms)+"',"+
|
"'"+Com.getDateTimeFormat(thread.record_time,Com.DTF_YMDhms)+"',"+
|
thread.timelong+","+
|
0+","+
|
battdata.myModBusData.getTotalGroupVol()+","+
|
battdata.myModBusData.getConcenState().getGroupCurr()+","+
|
thread.test_cap+","+
|
1+","+
|
battdata.myModBusData.getBattVolByIndex(0)+","+
|
battdata.myModBusData.getMaxBattVolNum()+","+
|
battdata.myModBusData.getMaxBattVol()+","+
|
battdata.myModBusData.getMinBattVolNum()+","+
|
battdata.myModBusData.getMinBattVol()+
|
")";
|
int stopreason = 0;
|
String sql_str3 = " UPDATE "+Sql_Mysql.TB_Ld9testdata_inf+" "
|
+ " SET record_num="+thread.record_num+","
|
+ " record_time='"+Com.getDateTimeFormat(thread.record_time, Com.DTF_YMDhms)+"',"
|
+ " test_timelong="+thread.timelong+","
|
+ " test_stopreason="+stopreason+","
|
+ " group_vol="+battdata.myModBusData.getTotalGroupVol()+","
|
+ " test_curr="+battdata.myModBusData.getConcenState().getGroupCurr()+","
|
+ " test_cap="+thread.test_cap+","
|
+ " mon_vol="+battdata.myModBusData.getBattVolByIndex(1)+","
|
+ " max_monnum="+battdata.myModBusData.getMaxBattVolNum()+","
|
+ " max_monvol="+battdata.myModBusData.getMaxBattVol()+","
|
+ " min_monnum="+battdata.myModBusData.getMinBattVolNum()+","
|
+ " min_monvol="+battdata.myModBusData.getMinBattVol()
|
+ " where BattGroupId = "+ battdata.BattGroupId
|
//+ " AND mon_num="+battdata.myModBusData.getLd_sys().getNowTestMonNum()
|
+" AND test_record_count="+thread.test_record_count;
|
ResultSet rs = null;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
rs = sql.sqlMysqlQuery(sql_str1);
|
if(rs.next()){
|
//System.out.println("Ö´ÐиüÐÂÓï¾ä");
|
sql.sqlMysqlExecute(sql_str3);
|
}else{
|
//System.out.println("Ö´ÐвåÈëÓï¾ä");
|
//battdata.record_num = 1;
|
//System.out.println(sql_str2);
|
sql.sqlMysqlExecute(sql_str2);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
try {
|
if(rs != null){
|
rs.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
|
}
|
|
|
/**
|
* ¼Ç¼µç³Ø×éµÄ·Åµç²âÊÔ_battgroupid ±íÖеÄÀúÊ·Êý¾Ý
|
*/
|
public static void insertOrUpdateMonData(MysqlConnPool conn_pool,BattData_RT battdata,int dev_index){
|
//long testlong = (battdata.myModBusData.getRecordhistorytime().getTime() - battdata.myModBusData.getTest_starttime().getTime())/1000;
|
String base_sql_str = " INSERT INTO "+Sql_Mysql.TB_Ld9testdata+battdata.BattGroupId+"("
|
+ " BattGroupId,test_record_count,test_type,"
|
+ " record_num,test_starttime,record_time,"
|
+ " test_timelong,online_vol,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,test_monnum)"
|
+ " values";
|
String body_sql_str = "";
|
LD_sys_state sys_state = battdata.myModBusData.getLd_sys()[dev_index];
|
LD_batt_states batt_state = battdata.myModBusData.getLd_batt_states()[dev_index];
|
int mon_num = sys_state.getTest_mon_num() + dev_index*9;
|
String record_date = Com.getDateTimeFormat(sys_state.getRecord_historytime(),Com.DTF_YMDhms);
|
//for(int i=0;i<battdata.MonCount;){
|
body_sql_str += "("+battdata.BattGroupId+","+
|
sys_state.getTest_record_count()+","+
|
MyModBusCom.TestType_HERONG_DISCHARGE+","+
|
sys_state.getRecord_num()+","+
|
"'"+Com.getDateTimeFormat(sys_state.getTest_starttime(), Com.DTF_YMDhms)+"',"+
|
"'"+record_date+"',"+
|
sys_state.getTest_timelong()+","+
|
sys_state.getSys_online_vol()+","+
|
battdata.myModBusData.getTotalGroupVol()+","+
|
batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_curr()+","+
|
batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_cap()+","+
|
(mon_num)+","+
|
batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_vol()+","+
|
mon_num+
|
")";
|
/*i++;
|
if(i == battdata.myModBusData.getLd_batt_states().getLd_batts().length && i==battdata.MonCount){
|
body_sql_str += ";";
|
}else{
|
body_sql_str += ",";
|
}
|
}*/
|
String sql_str = base_sql_str+body_sql_str;
|
System.out.println(sql_str);
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
if(body_sql_str.length() > 0){
|
//System.out.println("Ö´ÐвåÈëÓï¾ä¼Ç¼Õû×éµç³Ø×éµÄ·ÅµçÐÅÏ¢");
|
sql.sqlMysqlExecute(sql_str);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ¼Ç¼¶à¸öµ¥Ìåµç³Ø×éµÄ·Åµç²âÊÔ_battgroupid ±íÖеÄÀúÊ·Êý¾Ý[Í£µç·ÅµçºÍÍ£µç³äµç]
|
*/
|
public static void insertOrUpdateMutilMonData(MysqlConnPool conn_pool,RecordThread thread){
|
BattData_RT battdata = thread.battData;
|
long timelong = (thread.record_time.getTime() - thread.test_starttime.getTime())/1000;
|
String base_sql_str = " INSERT INTO "+Sql_Mysql.TB_Ld9testdata+battdata.BattGroupId+"("
|
+ " BattGroupId,test_record_count,test_type,"
|
+ " record_num,test_starttime,record_time,"
|
+ " test_timelong,online_vol,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,test_monnum)"
|
+ " values ";
|
String body_sql_str = "";
|
for(int i=0;i<battdata.MonCount;i++){
|
if(i>0) {
|
body_sql_str += ",";
|
}
|
body_sql_str += "("+battdata.BattGroupId+","+
|
thread.test_record_count+","+
|
thread.start_test_type+","+
|
thread.record_num+","+
|
"'"+Com.getDateTimeFormat(thread.test_starttime, Com.DTF_YMDhms)+"',"+
|
"'"+Com.getDateTimeFormat(thread.record_time, Com.DTF_YMDhms)+"',"+
|
timelong+","+
|
battdata.myModBusData.getLd_sys()[0].getSys_online_vol()+","+
|
battdata.myModBusData.getTotalGroupVol()+","+
|
battdata.myModBusData.getConcenState().getGroupCurr()+","+
|
thread.test_cap+","+
|
(i+1)+","+
|
battdata.myModBusData.getBattVolByIndex(i)+","+
|
(i+1)+
|
")";
|
}
|
String sql_str = base_sql_str+body_sql_str;
|
//System.out.println(sql_str);
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
if(body_sql_str.length() > 0){
|
//System.out.println("Ö´ÐвåÈëÓï¾ä¼Ç¼Õû×éµç³Ø×éµÄ·ÅµçÐÅÏ¢");
|
sql.sqlMysqlExecute(sql_str);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ¼Ç¼µç³Ø×éµÄ·Åµç²âÊÔstop_battgroupid ±íÖеÄÀúÊ·Êý¾Ý
|
*/
|
public static void insertOrUpdateMonStopData(MysqlConnPool conn_pool,BattData_RT battdata,int dev_index){
|
LD_sys_state sys_state = battdata.myModBusData.getLd_sys()[dev_index];
|
LD_batt_states batt_state = battdata.myModBusData.getLd_batt_states()[dev_index];
|
String sql_str1 =
|
" SELECT battgroupid FROM "+Sql_Mysql.TB_Ld9testdatastop+battdata.BattGroupId
|
+ " WHERE battgroupid="+battdata.BattGroupId+" AND "
|
+ " test_record_count = "+sys_state.getTest_record_count()+" AND mon_num="+(sys_state.getTest_mon_num()+dev_index*9);
|
long testlong = sys_state.getTest_timelong();
|
|
ResultSet rs = null;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
//int mon_num = battdata.myModBusData.getLd_sys().getNowTestMonNum();
|
//System.out.println(battdata.myModBusData.getLd_batt_states().getLd_batts());
|
//System.out.println("·Åµçµ¥Ìå:"+battdata.test_monnum+"\tÍ£Ö¹ÔÒò:"+battdata.myModBusData.getLd_batt_states().getLd_batts()[battdata.test_monnum-1].getStop_reason());
|
try {
|
rs = sql.sqlMysqlQuery(sql_str1);
|
if(rs.next()){
|
//System.out.println("Ö´ÐиüÐÂÓï¾ä");
|
ArrayList<String> al_sql_strs = new ArrayList<>();
|
//for(int i = 0;i<battdata.MonCount || i<battdata.myModBusData.getLd_batt_states().getLd_batts().length;i++){
|
String sql_str3 = " UPDATE "+Sql_Mysql.TB_Ld9testdatastop+battdata.BattGroupId+" "
|
+ " SET record_num="+sys_state.getRecord_num()+","
|
+ " record_time='"+Com.getDateTimeFormat(sys_state.getRecord_historytime(), Com.DTF_YMDhms)+"',"
|
+ " test_timelong="+testlong+","
|
+ " online_vol="+sys_state.getSys_online_vol()+","
|
+ " group_vol="+battdata.myModBusData.getTotalGroupVol()+","
|
+ " test_curr="+batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_curr()+","
|
+ " test_cap="+batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_cap()+","
|
+ " mon_vol="+batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_vol()+", "
|
+ " max_monvol ="+batt_state.getMax_mon_vol()+","
|
+ " min_monvol ="+batt_state.getMin_mon_vol()+","
|
+ " test_stopreason="+batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getStop_reason()
|
+ " where BattGroupId = "+ battdata.BattGroupId
|
+ " AND mon_num=" + (dev_index*9+sys_state.getTest_mon_num())
|
+ " AND test_record_count="+sys_state.getTest_record_count();
|
al_sql_strs.add(sql_str3);
|
//}
|
//System.out.println(al_sql_strs);
|
sql.makeManualCommit(al_sql_strs);
|
}else{
|
String base_sql_str2 = " INSERT INTO "+Sql_Mysql.TB_Ld9testdatastop+battdata.BattGroupId+"("
|
+ " BattGroupId,test_record_count,"
|
+ " test_type,record_num,test_starttime,record_time,"
|
+ " test_timelong,online_vol,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,test_monnum,max_monvol,min_monvol,test_stopreason)"
|
+ " values";
|
String body_sql_str2 = "";
|
//for(int i = 0;i<battdata.MonCount && i<battdata.myModBusData.getLd_batt_states().getLd_batts().length;){
|
body_sql_str2 += "("+battdata.BattGroupId+","+
|
sys_state.getTest_record_count()+","+
|
MyModBusCom.TestType_HERONG_DISCHARGE+","+
|
sys_state.getRecord_num()+","+
|
"'"+Com.getDateTimeFormat(sys_state.getTest_starttime(), Com.DTF_YMDhms)+"',"+
|
"'"+Com.getDateTimeFormat(sys_state.getRecord_historytime(),Com.DTF_YMDhms)+"',"+
|
sys_state.getTest_timelong()+","+
|
sys_state.getSys_online_vol()+","+
|
battdata.myModBusData.getTotalGroupVol()+","+
|
batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_curr()+","+
|
batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_cap()+","+
|
(sys_state.getTest_mon_num() + dev_index*9)+","+
|
batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getBatt_vol()+","+
|
(sys_state.getTest_mon_num() + dev_index*9)+","+
|
batt_state.getMax_mon_vol()+","+
|
batt_state.getMin_mon_vol()+","+
|
batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getStop_reason()+
|
")";
|
/*i++;
|
if(i<battdata.MonCount && i<battdata.myModBusData.getLd_batt_states().getLd_batts().length){
|
body_sql_str2 += ",";
|
}else{
|
body_sql_str2 += ";";
|
}*/
|
//}
|
//System.out.println(base_sql_str2 + body_sql_str2);
|
sql.sqlMysqlExecute(base_sql_str2 + body_sql_str2);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
try {
|
if(rs != null){
|
rs.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ¼Ç¼¶à¸öµç³Ø×éµ¥ÌåµÄ·Åµç²âÊÔstop_battgroupid ±íÖеÄÀúÊ·Êý¾Ý
|
*/
|
public static void insertOrUpdateMutilMonStopData(MysqlConnPool conn_pool,RecordThread thread){
|
BattData_RT battdata = thread.battData;
|
String sql_str1 =
|
" SELECT battgroupid FROM "+Sql_Mysql.TB_Ld9testdatastop+battdata.BattGroupId
|
+ " WHERE battgroupid="+battdata.BattGroupId+" AND "
|
+ " test_record_count = "+thread.test_record_count;
|
long testlong = (thread.record_time.getTime()-thread.test_starttime.getTime())/1000;
|
|
ResultSet rs = null;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
rs = sql.sqlMysqlQuery(sql_str1);
|
if(rs.next()){
|
//System.out.println("Ö´ÐиüÐÂÓï¾ä");
|
ArrayList<String> al_sql_strs = new ArrayList<>();
|
for(int i = 0;i<battdata.MonCount && i<battdata.myModBusData.getDev_count()*9;i++){
|
String sql_str3 = " UPDATE "+Sql_Mysql.TB_Ld9testdatastop+battdata.BattGroupId+" "
|
+ " SET record_num="+thread.record_num+","
|
+ " record_time='"+Com.getDateTimeFormat(thread.record_time, Com.DTF_YMDhms)+"',"
|
+ " test_timelong="+testlong+","
|
+ " online_vol="+battdata.myModBusData.getLd_sys()[0].getSys_online_vol()+","
|
+ " group_vol="+battdata.myModBusData.getTotalGroupVol()+","
|
+ " test_curr="+battdata.myModBusData.getConcenState().getGroupCurr()+","
|
+ " test_cap="+thread.test_cap+","
|
+ " mon_vol="+battdata.myModBusData.getBattVolByIndex(i)+", "
|
+ " max_monvol ="+battdata.myModBusData.getMaxBattVol()+","
|
+ " min_monvol ="+battdata.myModBusData.getMinBattVol()+","
|
+ " test_stopreason="+0
|
+ " where BattGroupId = "+ battdata.BattGroupId
|
+ " AND mon_num=" + (i+1)
|
+ " AND test_record_count="+thread.test_record_count;
|
al_sql_strs.add(sql_str3);
|
}
|
//System.out.println(al_sql_strs);
|
sql.makeManualCommit(al_sql_strs);
|
}else{
|
String base_sql_str2 = " INSERT INTO "+Sql_Mysql.TB_Ld9testdatastop+battdata.BattGroupId+"("
|
+ " BattGroupId,test_record_count,"
|
+ " test_type,record_num,test_starttime,record_time,"
|
+ " test_timelong,online_vol,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,test_monnum,max_monvol,min_monvol,test_stopreason)"
|
+ " values";
|
String body_sql_str2 = "";
|
for(int i = 0;i<battdata.MonCount && i<battdata.myModBusData.getDev_count()*9;i++){
|
if(i>0) {
|
body_sql_str2 += ",";
|
}
|
body_sql_str2 += "("+battdata.BattGroupId+","+
|
thread.test_record_count+","+
|
thread.start_test_type+","+
|
thread.record_num+","+
|
"'"+Com.getDateTimeFormat(thread.test_starttime, Com.DTF_YMDhms)+"',"+
|
"'"+Com.getDateTimeFormat(thread.record_time,Com.DTF_YMDhms)+"',"+
|
testlong+","+
|
battdata.myModBusData.getLd_sys()[0].getSys_online_vol()+","+
|
battdata.myModBusData.getTotalGroupVol()+","+
|
battdata.myModBusData.getConcenState().getGroupCurr()+","+
|
thread.test_cap+","+
|
(i+1)+","+
|
battdata.myModBusData.getBattVolByIndex(i)+","+
|
(i+1)+","+
|
battdata.myModBusData.getMaxBattVol()+","+
|
battdata.myModBusData.getMinBattVol()+","+
|
0+
|
")";
|
}
|
//System.out.println(base_sql_str2 + body_sql_str2);
|
sql.sqlMysqlExecute(base_sql_str2 + body_sql_str2);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
try {
|
if(rs != null){
|
rs.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ÐÞ¸Ästop±íÖеķŵçÍ£Ö¹ÔÒò
|
*/
|
public static void updateStopReason(MysqlConnPool conn_pool,BattData_RT battdata,int dev_index){
|
LD_batt_states batt_state = battdata.myModBusData.getLd_batt_states()[dev_index];
|
LD_sys_state sys_state = battdata.myModBusData.getLd_sys()[dev_index];
|
String sql_str = " UPDATE "+Sql_Mysql.TB_Ld9testdatastop+battdata.BattGroupId+" "
|
+ " SET test_stopreason="+batt_state.getLd_batts()[sys_state.getTest_mon_num()-1].getStop_reason()
|
+ " where BattGroupId = "+ battdata.BattGroupId
|
+ " AND mon_num=" + (sys_state.getTest_mon_num() + dev_index*9)
|
+ " AND test_record_count="+sys_state.getTest_record_count();
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ɾ³ý»¹Î´²âÊÔÍê³ÉµÄÀúÊ·Êý¾Ý
|
* @param mysql_pool
|
* @param myModBusData
|
*/
|
public static void deleteHistoryData(MysqlConnPool mysql_pool, MyModBusData myModBusData,int dev_index) {
|
LD_sys_state sys_state = myModBusData.getLd_sys()[dev_index];
|
int test_monnum = sys_state.getTest_mon_num() + dev_index*9;
|
String sql_str1 = "DELETE from "+Sql_Mysql.TB_Ld9testdata+myModBusData.getBattgroupid()
|
+ " WHERE test_monnum="+test_monnum
|
+ " AND test_record_count = "+ sys_state.getTest_record_count();
|
String sql_str2 = "DELETE from "+Sql_Mysql.TB_Ld9testdatastop+myModBusData.getBattgroupid()
|
+ " WHERE test_monnum="+test_monnum
|
+ " AND test_record_count = " + sys_state.getTest_record_count();
|
ArrayList<String> sql_strs = new ArrayList<>();
|
sql_strs.add(sql_str1);
|
sql_strs.add(sql_str2);
|
System.out.println("ɾ³ýÀúÊ··ÅµçÊý¾Ý"+myModBusData.getBattgroupid()+"===mon_num:"+test_monnum);
|
//System.out.println(sql_str2);
|
Sql_Mysql sql = new Sql_Mysql(mysql_pool.getConn());
|
try {
|
sql.makeManualCommit(sql_strs);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}finally{
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ¸ù¾ÝÉ豸idÐÞ¸Ä tb_ld9_setparam ±íÖеÄÃüÁî
|
*/
|
public static void UpdateLd9CmdByDev_id(MysqlConnPool conn_pool,MyModBusData modData){
|
String sql_str_base = Sql_Mysql.LD9_Setparam_Table +
|
" SET dev_id = "+ modData.getDev_id() + ","+
|
" op_cmd = "+ modData.getLd_param().getOp_cmd();
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
String sql_str_replace = "UPDATE " + sql_str_base+" WHERE dev_id="+modData.getDev_id();
|
try {
|
sql.sqlMysqlExecute(sql_str_replace);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ¸ù¾ÝÉ豸idÌí¼Ó»òÐÞ¸Ä tb_ld9_state ±íÖеÄÊý¾Ý
|
*/
|
public static void insertOrUpdateLd9StateByDev_id(MysqlConnPool conn_pool,MyModBusData modData){
|
LD_sys_state sys_state = modData.getDischageSysState();
|
String sql_str_base = Sql_Mysql.LD9_State_Table +
|
" SET dev_id = '"+modData.getDev_id()+"', "
|
+ " dev_ip='"+modData.getDev_ip()+"',"
|
+ " record_datetime ='"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"'," //¸üмǼʱ¼ä
|
+ " dev_version='"+modData.getLd_version().getDev_version()+"',"
|
+ " sys_state = '"+sys_state.getSys_state()+"',"
|
+ " sys_online_vol='"+sys_state.getSys_online_vol()+"',"
|
+ " sys_group_vol='"+modData.getTotalGroupVol()+"',"
|
+ " sys_now_battnum='"+sys_state.getSys_now_battnum()+"',"
|
+ " sys_now_battstate='"+sys_state.getSys_now_battstate()+"',"
|
+ " sys_now_battvol='"+sys_state.getSys_now_battvol()+"',"
|
+ " sys_now_battcurr='"+sys_state.getSys_now_battcurr()+"',"
|
+ " sys_now_battcap='"+sys_state.getSys_now_battcap()+"',"
|
+ " sys_now_testtime='"+sys_state.getSys_now_testtime()+"',"
|
+ " sys_next_battnum='"+sys_state.getSys_now_battnum()+"',"
|
+ " sys_next_battstate='"+sys_state.getSys_next_battstate()+"',"
|
+ " sys_next_battvol='"+sys_state.getSys_next_battvol()+"',"
|
+ " sys_next_battcurr='"+sys_state.getSys_next_battcurr()+"',"
|
+ " sys_next_battcap='"+sys_state.getSys_next_battcap()+"',"
|
+ " sys_next_testtime='"+sys_state.getSys_next_testtime()+"',"
|
+ " sys_tmp='"+sys_state.getSys_tmp()+"',"
|
+ " sys_stop_reason='"+sys_state.getSys_stop_reason()+"',"
|
+ " timelong='" + sys_state.getTest_timelong()+"',"
|
+ " dev_commcount='"+modData.getComent_totalcount()+"',"
|
+ " dev_errcommcount='"+modData.getComent_errorcount()+"',"
|
+ " monvol_hightalarm="+sys_state.getMon_vol_hight_alarm()+","
|
+ " monvol_loweralarm="+sys_state.getMon_vol_lower_alarm()+","
|
+ " moncap_alarm="+sys_state.getMon_cap_alarm();
|
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
String sql_str_replace = "REPLACE INTO " + sql_str_base;
|
try {
|
sql.sqlMysqlExecute(sql_str_replace);
|
} catch (SQLException e) {
|
System.err.println("Ö´ÐÐ insertOrUpdateLd9StateByDev_id Òì³£ at"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
e.printStackTrace();
|
} finally{
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ¸ù¾ÝÉ豸id¸üлòÕßÌí¼ÓÉ豸µÄ·ÅµçÊý¾ÝÐÅÏ¢
|
* @param conn_pool
|
* @param modData
|
*/
|
public static void insertOrUpdateLd9_setParamByDev_id(MysqlConnPool conn_pool,MyModBusData modData){
|
String sql_str_base = Sql_Mysql.LD9_Setparam_Table +
|
" SET dev_id = '"+modData.getDev_id()+"',"
|
+ " op_cmd='"+modData.getLd_param().getOp_cmd()+"',"
|
+ " param_teststart_batt_num='"+modData.getLd_param().getParam_teststart_batt_num()+"',"
|
+ " param_cap='"+modData.getLd_param().getParam_cap()+"',"
|
+ " param_discharge_curr='"+modData.getLd_param().getParam_discharge_curr()+"',"
|
+ " param_mon_curr_high='"+modData.getLd_param().getParam_mon_curr_high()+"',"
|
+ " param_charge_curr='"+modData.getLd_param().getParam_charge_curr()+"',"
|
+ " param_mon_curr_low='"+modData.getLd_param().getParam_mon_curr_low()+"',"
|
+ " param_online_vol='"+modData.getLd_param().getParam_online_vol()+"',"
|
+ " param_charge_curr_low='"+modData.getLd_param().getParam_charge_curr_low()+"',"
|
+ " param_charge_cap_low='"+modData.getLd_param().getParam_charge_cap_low()+"',"
|
+ " param_online_vol_recover='"+modData.getLd_param().getParam_online_vol_recover()+"',"
|
+ " param_module_address='"+modData.getLd_param().getParam_module_address()+"',"
|
+ " param_junheng_model='"+modData.getLd_param().getParam_junheng_model()+"',"
|
+ " param_cap_low = " + modData.getLd_param().getParam_cap_low() +","
|
+ " param_datasource = " + modData.getLd_param().getParam_datasource()+","
|
+ " param_res_args = " + modData.getLd_param().getParam_res_args()+","
|
+ " param_tmp_high = " + modData.getLd_param().getParam_tmp_high() +","
|
+ " param_res_high = " + modData.getLd_param().getParam_res_high();
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
String sql_str_replace = " REPLACE INTO " + sql_str_base;
|
try {
|
//System.out.println(sql_str_replace);
|
sql.sqlMysqlExecute(sql_str_replace);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ¼à²âÊý¾Ý¿âÖеIJÎÊý±íÊÇ·ñ·¢Éú±ä»¯ -> ¼à²âÊÇ·ñÐèÒªÆô¶¯²âÊÔ,Í£Ö¹²âÊÔ,»ñÈ¡²ÎÊý,ÉèÖòÎÊýµÈÃüÁî
|
* @param mysql_pool
|
* @param devinfo
|
*/
|
public static void searchLd9_setParamByDev_id(MysqlConnPool conn_pool, MyModBusData devinfo) throws SQLException {
|
String sql_str = "SELECT dev_id,op_cmd,param_teststart_batt_num,param_cap,param_discharge_curr,param_mon_curr_high, "
|
+ " param_charge_curr,param_mon_curr_low,param_online_vol,param_charge_curr_low,param_charge_cap_low, "
|
+ " param_online_vol_recover,param_module_address,param_junheng_model,param_cap_low,param_datasource,param_res_args,param_tmp_high,param_res_high "
|
+ " FROM db_ram_db.tb_ld9_setparam "
|
+ " WHERE dev_id = " + devinfo.getDev_id();
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
ResultSet rs = null;
|
try {
|
rs = sql.sqlMysqlQuery(sql_str);
|
if(rs.next()){
|
LD_param param = devinfo.getLd_param();
|
if(param != null){
|
param.setOp_cmd(rs.getInt("op_cmd"));
|
param.setParam_teststart_batt_num(rs.getInt("param_teststart_batt_num"));
|
param.setParam_cap(rs.getInt("param_cap"));
|
param.setParam_discharge_curr(rs.getDouble("param_discharge_curr"));
|
param.setParam_mon_curr_high(rs.getDouble("param_mon_curr_high"));
|
param.setParam_charge_curr(rs.getDouble("param_charge_curr"));
|
param.setParam_mon_curr_low(rs.getDouble("param_mon_curr_low"));
|
param.setParam_online_vol(rs.getDouble("param_online_vol"));
|
param.setParam_charge_curr_low(rs.getDouble("param_charge_curr_low"));
|
param.setParam_charge_cap_low(rs.getDouble("param_charge_cap_low"));
|
param.setParam_online_vol_recover(rs.getDouble("param_online_vol_recover"));
|
param.setParam_module_address(rs.getInt("param_module_address"));
|
param.setParam_junheng_model(rs.getInt("param_junheng_model"));
|
param.setParam_cap_low(rs.getFloat("param_cap_low"));
|
param.setParam_datasource(rs.getInt("param_datasource"));
|
param.setParam_res_args(rs.getInt("param_res_args"));
|
param.setParam_tmp_high(rs.getInt("param_tmp_high"));
|
param.setParam_res_high(rs.getFloat("param_res_high"));
|
}
|
}
|
}catch (Exception e) {
|
e.printStackTrace();
|
} finally{
|
try {
|
if(rs != null){
|
rs.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
}
|
|
/**
|
* Ìí¼Ó»òÕ߸üÐÂtestdata_inf±íÖеÄÊý¾Ý
|
* @param mysql_pool
|
* @param ld9BattState
|
*/
|
public static void insertOrUpdateMonInfo(MysqlConnPool mysql_pool, BattStateData ld9BattState) {
|
String sql_str1 =
|
" SELECT battgroupid FROM "+Sql_Mysql.TB_Ld9testdata_inf+""
|
+ " WHERE battgroupid="+ld9BattState.getBattGroupId()+" AND "
|
+ " test_record_count = "+ld9BattState.getTest_record_count()+" AND mon_num="+ld9BattState.getTest_mon_num();
|
long testlong = (new Date().getTime() - ld9BattState.getTest_starttime().getTime())/1000;
|
String sql_str2 = " INSERT INTO "+Sql_Mysql.TB_Ld9testdata_inf+"("
|
+ " BattGroupId,test_record_count,test_record_count_ex,"
|
+ " test_type,record_num,test_starttime,record_time,"
|
+ " test_timelong,test_stopreason,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,max_monnum,max_monvol,min_monnum,min_monvol)"
|
+ " values("+ld9BattState.getBattGroupId()+","+
|
ld9BattState.getTest_record_count()+","+
|
(ld9BattState.getTest_record_count()+1)+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_states()+","+
|
ld9BattState.getRecord_num()+","+
|
"'"+Com.getDateTimeFormat(ld9BattState.getTest_starttime(), Com.DTF_YMDhms)+"',"+
|
"'"+Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms)+"',"+
|
testlong+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getStop_reason()+","+
|
ld9BattState.getGroupvol()+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_curr()+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_cap()+","+
|
ld9BattState.getTest_mon_num()+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_vol()+","+
|
ld9BattState.getMaxmon_num()+","+
|
ld9BattState.getMaxmon_vol()+","+
|
ld9BattState.getMinmon_num()+","+
|
ld9BattState.getMinmon_vol()+","+
|
")";
|
String sql_str3 = " UPDATE "+Sql_Mysql.TB_Ld9testdata_inf+" "
|
+ " SET record_num="+ld9BattState.getTest_record_count()+","
|
+ " record_time='"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"',"
|
+ " test_timelong="+testlong+","
|
+ " test_stopreason="+ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getStop_reason()+","
|
+ " group_vol="+ld9BattState.getGroupvol()+","
|
+ " test_curr="+ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_curr()+","
|
+ " test_cap="+ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1)+","
|
+ " mon_vol="+ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_vol()+","
|
+ " max_monnum="+ld9BattState.getMaxmon_num()+","
|
+ " max_monvol="+ld9BattState.getMaxmon_vol()+","
|
+ " min_monnum="+ld9BattState.getMinmon_num()+","
|
+ " min_monvol="+ld9BattState.getMinmon_vol()
|
+ " where BattGroupId = "+ ld9BattState.getBattGroupId()
|
+ " AND mon_num="+ld9BattState.getTest_mon_num()
|
+" AND test_record_count="+ld9BattState.getTest_record_count();
|
ResultSet rs = null;
|
Sql_Mysql sql = new Sql_Mysql(mysql_pool.getConn());
|
try {
|
rs = sql.sqlMysqlQuery(sql_str1);
|
if(rs.next()){
|
//System.out.println("Ö´ÐиüÐÂÓï¾ä");
|
sql.sqlMysqlExecute(sql_str3);
|
}else{
|
//System.out.println("Ö´ÐвåÈëÓï¾ä");
|
ld9BattState.setRecord_num(1);
|
sql.sqlMysqlExecute(sql_str2);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
try {
|
if(rs != null){
|
rs.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
|
}
|
|
/**
|
* Ìí¼Ó»ò¸üÐÂµç³ØºËÈݲâÊÔÖеÄÕû¸öµç³Ø×éµÄ·ÅµçÐÅÏ¢
|
* @param mysql_pool
|
* @param ld9BattState
|
*/
|
public static void insertOrUpdateMonData(MysqlConnPool mysql_pool, BattStateData ld9BattState) {
|
Date nowtime = new Date();
|
long testlong = (nowtime.getTime() - ld9BattState.getTest_starttime().getTime())/1000;
|
String base_sql_str = " INSERT INTO "+Sql_Mysql.TB_Ld9testdata+ld9BattState.getBattGroupId()+"("
|
+ " BattGroupId,test_record_count,test_type,"
|
+ " record_num,test_starttime,record_time,"
|
+ " test_timelong,online_vol,group_vol,test_curr,"
|
+ " test_cap,mon_num,mon_vol,test_monnum)"
|
+ " values+";
|
String body_sql_str = "";
|
String record_date = Com.getDateTimeFormat(nowtime,Com.DTF_YMDhms);
|
for(int i=0;i<ld9BattState.getMon_info().size() && i<ld9BattState.getMon_count();){
|
body_sql_str += "("+ld9BattState.getBattGroupId()+","+
|
ld9BattState.getTest_record_count()+","+
|
MyModBusCom.BATT_DISCHARGE+","+
|
ld9BattState.getRecord_num()+","+
|
"'"+Com.getDateTimeFormat(ld9BattState.getTest_starttime(), Com.DTF_YMDhms)+"',"+
|
"'"+record_date+"',"+
|
testlong+","+
|
ld9BattState.getOnlinevol()+","+
|
ld9BattState.getGroupvol()+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_curr()+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_cap()+","+
|
(i+1)+","+
|
ld9BattState.getMon_info().get(ld9BattState.getTest_mon_num()-1).getMon_vol()+","+
|
ld9BattState.getTest_mon_num()+
|
")";
|
i++;
|
if(i == ld9BattState.getMon_info().size() && i==ld9BattState.getMon_count()){
|
body_sql_str += ";";
|
}else{
|
body_sql_str += ",";
|
}
|
}
|
String sql_str = base_sql_str+body_sql_str;
|
Sql_Mysql sql = new Sql_Mysql(mysql_pool.getConn());
|
try {
|
if(body_sql_str.length() > 0){
|
System.out.println("Ö´ÐвåÈëÓï¾ä¼Ç¼Õû×éµç³Ø×éµÄ·ÅµçÐÅÏ¢");
|
sql.sqlMysqlExecute(sql_str);
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally{
|
sql.close_con();
|
}
|
|
}
|
|
/**
|
* ´´½¨9¶È»ã¼¯Æ÷״̬±í
|
* @param conn_pool
|
*/
|
public static void createConcentratStateTable(MysqlConnPool conn_pool) {
|
String sql_str = "CREATE TABLE IF NOT EXISTS "+ Sql_Mysql.LD9_ConcentratorState_Table +" (" +
|
" `num` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," +
|
" `dev_id` int(11) NOT NULL DEFAULT '0' COMMENT 'É豸id'," +
|
" `record_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¼Ç¼ʱ¼ä'," +
|
" `systemVersion` varchar(255) NOT NULL DEFAULT '' COMMENT 'ϵͳ°æ±¾'," +
|
" `systemState` int(11) NOT NULL DEFAULT '0' COMMENT 'ϵͳ״̬'," +
|
" `groupVol` float NOT NULL DEFAULT '0' COMMENT '×é¶Ëµçѹ'," +
|
" `groupCurr` float NOT NULL DEFAULT '0' COMMENT '×é¶ËµçÁ÷'," +
|
" `battState` int(11) NOT NULL DEFAULT '0' COMMENT 'µç³Ø×´Ì¬'," +
|
" `currDirection` int(11) NOT NULL DEFAULT '0' COMMENT 'µçÁ÷·½Ïò'," +
|
" `rippleCurrAvg` float NOT NULL DEFAULT '0' COMMENT 'ÎÆ²¨µçÁ÷¾ùÖµ'," +
|
" `rippleCurrTop` float NOT NULL DEFAULT '0' COMMENT 'ÎÆ²¨µçÁ÷·åÖµ'," +
|
" `resTestCount` int(11) NOT NULL DEFAULT '0' COMMENT 'ÄÚ×è²âÊÔ´ÎÊý'," +
|
" `resTestMethod` int(11) NOT NULL DEFAULT '0' COMMENT 'ÄÚ×è²âÊÔ·½·¨'," +
|
" PRIMARY KEY (`num`)," +
|
" UNIQUE KEY `unique_dev_id` (`dev_id`)" +
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ²åÈë»ò¸üл㼯Æ÷״̬
|
* @param conn_pool
|
* @param state
|
* @param dev_id
|
*/
|
public static void insertOrUpdateConcentratState(MysqlConnPool conn_pool,ConcentratorState state,int dev_id) {
|
String sql_str_base = Sql_Mysql.LD9_ConcentratorState_Table
|
+ " SET "
|
+ "dev_id=" + dev_id + ", "
|
+ "record_time='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "', "
|
+ "systemVersion=" + state.getSystemVersion() + ", "
|
+ "systemState=" + state.getSystemState() + ", "
|
+ "groupVol=" + state.getGroupVol() + ", "
|
+ "groupCurr=" + state.getGroupCurr() + ","
|
+ "battState=" + state.getBattState() + ", "
|
+ "currDirection=" + state.getCurrDirection() + ", "
|
+ "rippleCurrAvg=" + state.getRippleCurrAvg() + ", "
|
+ "rippleCurrTop=" + state.getRippleCurrTop() + ","
|
+ "resTestCount=" + state.getResTestCount() + ", "
|
+ "resTestMethod=" + state.getResTestMethod() ;
|
|
String sql_str_replace = "REPLACE INTO " + sql_str_base;
|
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
//System.out.println(sql_str_replace);
|
sql.sqlMysqlExecute(sql_str_replace);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ´´½¨9¶È»ã¼¯Æ÷²ÎÊý±í
|
* @param conn_pool
|
*/
|
public static void createConcentratParamTable(MysqlConnPool conn_pool) {
|
String sql_str = "CREATE TABLE IF NOT EXISTS " +Sql_Mysql.LD9_ConcentratorParam_Table+ " (" +
|
" `num` int(11) NOT NULL AUTO_INCREMENT," +
|
" `dev_id` int(11) NOT NULL DEFAULT '0' COMMENT 'É豸id'," +
|
" `op_cmd` int(11) NOT NULL DEFAULT '0' COMMENT 'ÃüÁî¿ØÖÆ×Ö¶Î'," +
|
" `addr` int(11) NOT NULL DEFAULT '0' COMMENT '»ã¼¯Æ÷µØÖ·£¨0-2555£©'," +
|
" `firthMonCount` int(11) NOT NULL DEFAULT '0' COMMENT 'µÚһ·µ¥Ìå¸öÊý'," +
|
" `secondMonCount` int(11) NOT NULL DEFAULT '0' COMMENT 'µÚ¶þ·µ¥Ìå¸öÊý'," +
|
" `thirdMonCount` int(11) NOT NULL DEFAULT '0' COMMENT 'µÚÈý·µ¥Ìå¸öÊý'," +
|
" `fourthMonCount` int(11) NOT NULL DEFAULT '0' COMMENT 'µÚËÄ·µ¥Ìå¸öÊý'," +
|
" `fifthMonCount` int(11) NOT NULL DEFAULT '0' COMMENT 'µÚÎå·µ¥Ìå¸öÊý'," +
|
" `currRange` int(11) NOT NULL DEFAULT '0' COMMENT 'µçÁ÷ǯÁ¿³Ì'," +
|
" `floatCurrLimit` float NOT NULL DEFAULT '0' COMMENT '¸¡³äµçÁ÷ÃÅÏÞ'," +
|
" `rippleCurrLimit` float NOT NULL DEFAULT '0' COMMENT 'ÎÆ²¨µçÁ÷·§Öµ'," +
|
" `autoTestCycle` int(11) NOT NULL DEFAULT '1' COMMENT '×Ô¶¯²âÊÔÖÜÆÚ'," +
|
" `resTestType` int(11) NOT NULL DEFAULT '0' COMMENT 'ÄÚ×è²âÊÔ·½·¨'," +
|
" `dischargeType` int(11) NOT NULL DEFAULT '0' COMMENT '·Åµçģʽ'," +
|
" `battCapStd` int(11) NOT NULL DEFAULT '0' COMMENT '±ê³ÆÈÝÁ¿'," +
|
" `backup1` int(11) NOT NULL DEFAULT '0' COMMENT '±¸ÓÃ1'," +
|
" `backup2` int(11) NOT NULL DEFAULT '0' COMMENT '±¸ÓÃ2'," +
|
" `backup3` int(11) NOT NULL DEFAULT '0' COMMENT '±¸ÓÃ3'," +
|
" `backup4` int(11) NOT NULL DEFAULT '0' COMMENT '±¸ÓÃ4'," +
|
" PRIMARY KEY (`num`)," +
|
" UNIQUE KEY `unique_dev_id` (`dev_id`)" +
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
|
try {
|
sql.sqlMysqlExecute(sql_str);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ²éѯ»ã¼¯Æ÷²ÎÊýÒÔ¼°¿ØÖÆÖ¸Áî
|
* @param conn_pool
|
* @param dev_id
|
* @param param
|
*/
|
public static ConcentratorParam queryConcentratParam(MysqlConnPool conn_pool,int dev_id) {
|
ConcentratorParam param = new ConcentratorParam();
|
String sql_str = "SELECT * FROM " + Sql_Mysql.LD9_ConcentratorParam_Table + " WHERE dev_id = " + dev_id;
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
|
ResultSet res = sql.sqlMysqlQuery(sql_str);
|
try {
|
while(res.next()) {
|
param.setOp_cmd(res.getInt("op_cmd"));
|
param.setAddr(res.getInt("addr"));
|
param.setFirthMonCount(res.getInt("firthMonCount"));
|
param.setSecondMonCount(res.getInt("secondMonCount"));
|
param.setThirdMonCount(res.getInt("thirdMonCount"));
|
param.setFourthMonCount(res.getInt("fourthMonCount"));
|
param.setFifthMonCount(res.getInt("fifthMonCount"));
|
param.setCurrRange(res.getInt("currRange"));
|
param.setFloatCurrLimit(res.getDouble("floatCurrLimit"));
|
param.setRippleCurrLimit(res.getDouble("rippleCurrLimit"));
|
param.setAutoTestCycle(res.getInt("autoTestCycle"));
|
param.setResTestType(res.getInt("resTestType"));
|
param.setDischargeType(res.getInt("dischargeType"));
|
param.setBattCapStd(res.getInt("battCapStd"));
|
param.setBackup1(res.getInt("backup1"));
|
param.setBackup1(res.getInt("backup2"));
|
param.setBackup1(res.getInt("backup3"));
|
param.setBackup1(res.getInt("backup4"));
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
if(res != null) {
|
res.close();
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
return param;
|
}
|
|
/**
|
* ÐÞ¸ÄÊý¾Ý¿âÖл㼯Æ÷µÄ²ÎÊý
|
* @param conn_pool
|
* @param dev_id
|
* @param param
|
*/
|
public static void updateConcentratParam(MysqlConnPool conn_pool,int dev_id,ConcentratorParam param) {
|
String sql_str_base = Sql_Mysql.LD9_ConcentratorParam_Table
|
+ " SET "
|
+ "dev_id=" + dev_id + ", "
|
+ "op_cmd=" + param.getOp_cmd() + ", "
|
+ "addr=" + param.getAddr() + ", "
|
+ "firthMonCount=" + param.getFirthMonCount() + ", "
|
+ "secondMonCount=" + param.getSecondMonCount() + ", "
|
+ "thirdMonCount=" + param.getThirdMonCount() + ","
|
+ "fourthMonCount=" + param.getFourthMonCount() + ", "
|
+ "fifthMonCount=" + param.getFifthMonCount() + ", "
|
+ "currRange=" + param.getCurrRange() + ", "
|
+ "floatCurrLimit=" + param.getFloatCurrLimit() + ","
|
+ "rippleCurrLimit=" + param.getRippleCurrLimit() + ", "
|
+ "autoTestCycle=" + param.getAutoTestCycle() + ", "
|
+ "resTestType=" + param.getResTestType() + ", "
|
+ "dischargeType=" + param.getDischargeType() + ", "
|
+ "battCapStd=" + param.getBattCapStd() + ", "
|
+ "backup1=" + param.getBackup1() + ", "
|
+ "backup2=" + param.getBackup1() + ", "
|
+ "backup3=" + param.getBackup1() + ", "
|
+ "backup4=" + param.getBackup1()
|
;
|
|
String sql_str_replace = "REPLACE INTO " + sql_str_base;
|
|
Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
try {
|
//System.out.println(sql_str_replace);
|
sql.sqlMysqlExecute(sql_str_replace);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ¸ù¾ÝÖ¸¶¨µÄÉ豸id Ð޸ıí tb_fbs9100_setparam ÖеÄop_cmdÖµ
|
*/
|
public static void updateConcentratParamCmdBydev_id(MysqlConnPool con_pool, ConcentratorParam param,int dev_id)
|
{
|
String sql_str_base = Sql_Mysql.LD9_ConcentratorParam_Table + " SET "
|
+ "dev_id=" + dev_id + ", "
|
+ "op_cmd=" + param.getOp_cmd() + " "
|
//+ "TestCmd=" + param.m_FBS_DiscParam.test_cmd
|
+ " where dev_id = " + dev_id;
|
String sql_str_update = "UPDATE " + sql_str_base;
|
//String sql_str_replace = "REPLACE INTO " + sql_str_base;
|
Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
|
try {
|
//System.out.println(sql_str_update);
|
sql.sqlMysqlExecute(sql_str_update);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ¸ù¾Ýtb_bts_gprs_state±í¸üÐÂal_paramÊý×é
|
* @param con_pool
|
* @param al_param
|
*/
|
public static int queryBTSGPRSCmdBydev_id(MysqlConnPool mysql_pool, int dev_id) {
|
int cmd_t = 0;
|
String sql_str = "SELECT op_cmd FROM " + Sql_Mysql.BTSGPRSState_Table + " where dev_id = " + dev_id;
|
Sql_Mysql sql = new Sql_Mysql(mysql_pool.getConn());
|
ResultSet res = sql.sqlMysqlQuery(sql_str);
|
try {
|
if(res.next()) {
|
if(dev_id > 0) {
|
cmd_t = res.getInt("op_cmd");
|
}
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
|
return cmd_t;
|
}
|
|
/**
|
* »ñÈ¡µ±Ç°Êý¾ÝÃüÁî
|
* @param mysql_pool
|
* @param dev_id
|
* @return
|
*/
|
public static String queryBTSGPRS_ATCmd_Bydev_id(MysqlConnPool mysql_pool, int dev_id) {
|
String cmd_at = "";
|
String sql_str = "SELECT AT_cmd FROM " + Sql_Mysql.BTSGPRSState_Table + " where dev_id = " + dev_id;
|
Sql_Mysql sql = new Sql_Mysql(mysql_pool.getConn());
|
ResultSet res = sql.sqlMysqlQuery(sql_str);
|
try {
|
if(res.next()) {
|
if(dev_id > 0) {
|
cmd_at = res.getString("AT_cmd").trim();
|
}
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
|
return cmd_at;
|
}
|
|
/**
|
* ¸ù¾Ý Ö¸¶¨¶ÔÏóµÄÉ豸idÐÞ¸Ätb_bts_gprs_state±íÖÐÖ¸¶¨É豸µÄÐÅÏ¢
|
* @param con_pool
|
* @param al_param
|
*/
|
public static void updateBTSGPRSSateBydev_id(MysqlConnPool con_pool, int dev_id, int op_cmd_ack,
|
String val)
|
{
|
if(op_cmd_ack == MyModBusCom.CMD_ReadGPRSCSQAck)
|
{
|
String tmp_val = "null";
|
if(null != val) {
|
if((val.length() > 6) && (val.contains("usr.cn"))) {
|
tmp_val = val;
|
}
|
}
|
String sql_str_base = Sql_Mysql.BTSGPRSState_Table
|
+ " SET "
|
+ "dev_id=" + dev_id + ", "
|
+ "op_cmd=" + op_cmd_ack + ", "
|
+ "ack_inf='" + tmp_val + "'"
|
+ " WHERE dev_id = " + dev_id;
|
String sql_str_update = "UPDATE " + sql_str_base;
|
Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
|
try {
|
//System.out.println(sql_str_replace);
|
sql.sqlMysqlExecute(sql_str_update);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
}
|
|
/**
|
* ²éѯµ±Ç°µç³Ø×éÔÚ×îºóÒ»´Î·ÅµçÊý¾ÝÖÐÊÇ·ñ´æÔÚ
|
* @param mysql_pool
|
* @param recordDataThread
|
* @param test_record_count
|
* @return true - ´æÔÚ flase - ²»´æÔÚ
|
*/
|
public static boolean searchDeviceHasDischarge(MysqlConnPool mysql_pool, RecordDataThread thread,
|
int test_record_count) {
|
boolean flag = false;
|
String sql_str = " SELECT * FROM " + Sql_Mysql.TB_Ld9testdata + thread.getBattData().BattGroupId +
|
" where mon_num >= "+thread.test_monnum+" AND mon_num <= " + (thread.dev_index+1)*9 +
|
" AND test_record_count = " + test_record_count;
|
Sql_Mysql sql = new Sql_Mysql(mysql_pool.getConn());
|
ResultSet res = sql.sqlMysqlQuery(sql_str);
|
try {
|
if(res.next()) {
|
flag = true;
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
if(res != null) {
|
try {
|
res.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
sql.close_con();
|
}
|
return flag;
|
}
|
|
public static void main(String[] args) {
|
MysqlConnPool conn_pool=new MysqlConnPool("192.168.0.34", 3360, 10);
|
LD_sys_state ld_sys=new LD_sys_state();
|
|
}
|
|
|
}
|