package com.donghuan.c_interface;
|
|
import java.sql.SQLException;
|
|
import com.sql.MysqlConnPool;
|
import com.sql.Sql_Mysql;
|
|
public class CInterface_Thread_SQL {
|
public static void createCInterfaceStateTableOnRam(MysqlConnPool con_pool, CInterfaceState al_state)
|
{
|
String str1 = "DROP TABLE IF EXISTS " + Sql_Mysql.CInterfaceState_Table;
|
String str2 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.CInterfaceState_Table
|
+ " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
|
+ "`BattGroupId` INT NOT NULL DEFAULT 0, "
|
+ "`ComTxCount` INT NOT NULL DEFAULT 0, "
|
+ "`ComRxCount` INT NOT NULL DEFAULT 0, "
|
+ "`ComErrCount` INT NOT NULL DEFAULT 0, "
|
+ "`ComErrType` INT NOT NULL DEFAULT 0, "
|
+ " PRIMARY KEY (`num`) ) "
|
+ " ENGINE=MEMORY DEFAULT CHARSET=utf8";
|
String str3 = "INSERT INTO " + Sql_Mysql.CInterfaceState_Table
|
+ " (BattGroupId) VALUES ";
|
for(int n=0; n<al_state.m_al_stat.size(); n++) {
|
if(n > 0) {
|
str3 += ",";
|
}
|
str3 += "(" + al_state.m_al_stat.get(n).bg_id + ")";
|
}
|
Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(str1);
|
sql.sqlMysqlExecute(str2);
|
sql.sqlMysqlExecute(str3);
|
} catch (SQLException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
|
public static void updateCInterfaceStateTableOnRam(MysqlConnPool con_pool, CInterfaceState c_state)
|
{
|
String str = "UPDATE " + Sql_Mysql.CInterfaceState_Table
|
+ " SET ComTxCount = CASE BattGroupId ";
|
for(int n=0; n<c_state.m_al_stat.size(); n++) {
|
str += " WHEN " + c_state.m_al_stat.get(n).bg_id
|
+ " THEN " + c_state.m_al_stat.get(n).tx_count;
|
}
|
str += " END, ";
|
|
str += " ComRxCount = CASE BattGroupId ";
|
for(int n=0; n<c_state.m_al_stat.size(); n++) {
|
str += " WHEN " + c_state.m_al_stat.get(n).bg_id
|
+ " THEN " + c_state.m_al_stat.get(n).rx_count;
|
}
|
str += " END, ";
|
|
str += " ComErrCount = CASE BattGroupId ";
|
for(int n=0; n<c_state.m_al_stat.size(); n++) {
|
str += " WHEN " + c_state.m_al_stat.get(n).bg_id
|
+ " THEN " + c_state.m_al_stat.get(n).com_err_count;
|
}
|
str += " END ";
|
str += " WHERE BattGroupId IN (";
|
for(int n=0; n<c_state.m_al_stat.size(); n++) {
|
if(n > 0) {
|
str += ",";
|
}
|
str += c_state.m_al_stat.get(n).bg_id;
|
}
|
str += ")";
|
|
|
Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
|
try {
|
sql.sqlMysqlExecute(str);
|
} catch (SQLException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
sql.close_con();
|
}
|
}
|