package com.database_util;
|
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
|
import com.sql.MysqlConnPool;
|
import com.sql.Sql_Mysql;
|
|
public class DB_Ram_db {
|
|
public static void init(MysqlConnPool pool, boolean recreate) {
|
createFBS9100s_fod_state(pool,recreate); //´´½¨³ýÁò״̬±ítb_fbs9100s_fod_state
|
|
createFBS9100SetDLParam_Table(pool,recreate); //´´½¨³ýÁò²ÎÊý±í
|
}
|
|
|
/**
|
* ´´½¨ web_site Êý¾Ý¿â
|
* @param pool
|
*/
|
public static void createDb_Ram_Db(MysqlConnPool pool) {
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
try {
|
sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_RamDB);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ´´½¨³ýÁò״̬±í
|
* @param pool
|
* @param recreate
|
*/
|
public static void createFBS9100s_fod_state(MysqlConnPool pool, boolean recreate) {
|
String sql_str1 = " DROP TABLE IF EXISTS " + Sql_Mysql.FBS9100s_fod_state;
|
String sql_str2 = "CREATE TABLE IF NOT EXISTS "+ Sql_Mysql.FBS9100s_fod_state +" (" +
|
" num int(11) NOT NULL AUTO_INCREMENT," +
|
" dev_id int(11) NOT NULL DEFAULT '0' COMMENT 'É豸id'," +
|
" BattGroupId int(11) NOT NULL DEFAULT '0' COMMENT 'µç³Ø×éid'," +
|
" record_time datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '¼Ç¼ʱ¼ä'," +
|
" RestTime_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ê£ÓàÌìÊý(×é1)'," +
|
" WorkState_one int(11) NOT NULL DEFAULT '0' COMMENT '¹¤×÷ģʽ(×é1)'," +
|
" VGroupVol_one double NOT NULL DEFAULT '0' COMMENT '×é¶Ëµçѹ(×é1)'," +
|
" VpeakVol_one double NOT NULL DEFAULT '0' COMMENT '·åÖµµçѹ(×é1)'," +
|
" RestTime_two int(11) NOT NULL DEFAULT '0' COMMENT 'Ê£ÓàÌìÊý(×é2)'," +
|
" WorkState_two int(11) NOT NULL DEFAULT '0' COMMENT '¹¤×÷ģʽ(×é2)'," +
|
" VGroupVol_two double NOT NULL DEFAULT '0' COMMENT '×é¶Ëµçѹ(×é2)'," +
|
" VpeakVol_two double NOT NULL DEFAULT '0' COMMENT '·åÖµµçѹ(×é2)'," +
|
" RestTime_three int(11) NOT NULL DEFAULT '0' COMMENT 'Ê£ÓàÌìÊý(×é3)'," +
|
" WorkState_three int(11) NOT NULL DEFAULT '0' COMMENT '¹¤×÷ģʽ(×é3)'," +
|
" VGroupVol_three double NOT NULL DEFAULT '0' COMMENT '×é¶Ëµçѹ(×é3)'," +
|
" VpeakVol_three double NOT NULL DEFAULT '0' COMMENT '·åÖµµçѹ(×é3)'," +
|
" RestTime_four int(11) NOT NULL DEFAULT '0' COMMENT 'Ê£ÓàÌìÊý(×é4)'," +
|
" WorkState_four int(11) NOT NULL DEFAULT '0' COMMENT '¹¤×÷ģʽ(×é4)'," +
|
" VGroupVol_four double NOT NULL DEFAULT '0' COMMENT '×é¶Ëµçѹ(×é4)'," +
|
" VpeakVol_four double NOT NULL DEFAULT '0' COMMENT '·åÖµµçѹ(×é4)'," +
|
" RestTime_five int(11) NOT NULL DEFAULT '0' COMMENT 'Ê£Óàʱ¼ä(×é5)'," +
|
" WorkState_five int(11) NOT NULL DEFAULT '0' COMMENT '³ýÁò5״̬(×é5)'," +
|
" VGroupVol_five int(11) NOT NULL DEFAULT '0' COMMENT '×é¶Ëµçѹ(×é5)'," +
|
" VpeakVol_five int(11) NOT NULL DEFAULT '0' COMMENT '·åÖµµçѹ(×é5)'," +
|
" PRIMARY KEY (num)," +
|
" UNIQUE KEY unique_battgroupid (BattGroupId) USING BTREE" +
|
") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
ResultSet res = null;
|
try {
|
if(recreate) {
|
sql.sqlMysqlExecute(sql_str1);
|
}
|
sql.sqlMysqlExecute(sql_str2);
|
|
//ÒÆ³ý֮ǰµÄÒÔÉ豸id·Ö×éµÄÉ豸idΨһË÷Òý
|
res = sql.sqlMysqlQuery("show INDEX FROM "+Sql_Mysql.FBS9100s_fod_state+" WHERE KEY_name = 'unique_dev_id'");
|
if(res.next()) {
|
sql.sqlMysqlExecute("alter table "+Sql_Mysql.FBS9100s_fod_state+" drop index unique_dev_id;");
|
}
|
|
//Ìí¼ÓÊ£Óàʱ¼ä(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_state'"
|
+ " AND column_name='RestTime_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100s_fod_state
|
+ " ADD COLUMN RestTime_five int(11) NOT NULL DEFAULT '0' COMMENT 'Ê£Óàʱ¼ä(×é5)'");
|
}
|
//Ìí¼Ó³ýÁò״̬(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_state'"
|
+ " AND column_name='WorkState_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100s_fod_state
|
+ " ADD COLUMN WorkState_five int(11) NOT NULL DEFAULT '0' COMMENT '³ýÁò5״̬(×é5)'");
|
}
|
//Ìí¼Ó×é¶Ëµçѹ(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_state'"
|
+ " AND column_name='VGroupVol_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100s_fod_state
|
+ " ADD COLUMN VGroupVol_five int(11) NOT NULL DEFAULT '0' COMMENT '×é¶Ëµçѹ(×é5)'");
|
}
|
//Ìí¼Ó·åÖµµçѹ(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_state'"
|
+ " AND column_name='VpeakVol_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100s_fod_state
|
+ " ADD COLUMN VpeakVol_five int(11) NOT NULL DEFAULT '0' COMMENT '·åÖµµçѹ(×é5)'");
|
}
|
//Ìí¼Óµç³Ø×éid×Ö¶Î
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_state'"
|
+ " AND column_name='BattGroupId'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100s_fod_state
|
+ " ADD COLUMN BattGroupId int(11) NOT NULL DEFAULT '0' COMMENT 'µç³Ø×éid' AFTER dev_id");
|
}
|
//Ìí¼Óµç³Ø×éidΪΨһË÷Òý
|
res = sql.sqlMysqlQuery("show INDEX FROM "+Sql_Mysql.FBS9100s_fod_state+" WHERE KEY_name = 'unique_BattGroupId'");
|
if(!res.next()) {
|
//Ìí¼ÓΨһË÷ÒýǰÏÈɾ³ý±íÖмǼ
|
sql.sqlMysqlExecute("DELETE FROM "+Sql_Mysql.FBS9100s_fod_state+" WHERE num>0");
|
sql.sqlMysqlExecute("alter table "+Sql_Mysql.FBS9100s_fod_state+" add UNIQUE `unique_BattGroupId`(`BattGroupId`);");
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != res) {
|
try {
|
res.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
sql.close_con();
|
}
|
}
|
|
/**
|
* ´´½¨³ýÁò״̬±í
|
* @param pool
|
* @param recreate
|
*/
|
public static void createFBS9100SetDLParam_Table(MysqlConnPool pool, boolean recreate) {
|
String sql_str1 = " DROP TABLE IF EXISTS " + Sql_Mysql.FBS9100SetDLParam_Table;
|
String sql_str2 = "CREATE TABLE IF NOT EXISTS "+ Sql_Mysql.FBS9100SetDLParam_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'," +
|
" test_cmd int(11) NOT NULL DEFAULT '0'," +
|
" GroupNum int(11) NOT NULL DEFAULT '0' COMMENT 'Ä£¿é±àºÅ'," +
|
" BattGroupNum int(11) NOT NULL DEFAULT '0' COMMENT 'µç³Ø×éºÅ'," +
|
" STDCap_one int(11) NOT NULL DEFAULT '0' COMMENT '×é1±ê³ÆÈÝÁ¿'," +
|
" FloatVol_one double NOT NULL DEFAULT '0' COMMENT '×é1¸¡³äµçѹ'," +
|
" Strength_one double NOT NULL DEFAULT '0' COMMENT '×é1³ýÁòÇ¿¶È'," +
|
" YHStrength_one double NOT NULL DEFAULT '0' COMMENT '×é1Ñø»¤Ç¿¶È'," +
|
" TimeLong_one int(11) NOT NULL DEFAULT '0' COMMENT '×é1³ýÁòÌìÊý'," +
|
" STDCap_two int(11) NOT NULL DEFAULT '0' COMMENT '×é2±ê³ÆÈÝÁ¿'," +
|
" FloatVol_two double NOT NULL DEFAULT '0' COMMENT '×é2¸¡³äµçѹ'," +
|
" Strength_two double NOT NULL DEFAULT '0' COMMENT '×é2³ýÁòÇ¿¶È'," +
|
" YHStrength_two double NOT NULL DEFAULT '0' COMMENT '×é2Ñø»¤Ç¿¶È'," +
|
" TimeLong_two int(11) NOT NULL DEFAULT '0' COMMENT '×é2³ýÁòÌìÊý'," +
|
" STDCap_three int(11) NOT NULL DEFAULT '0' COMMENT '×é3±ê³ÆÈÝÁ¿'," +
|
" FloatVol_three double NOT NULL DEFAULT '0' COMMENT '×é3¸¡³äµçѹ'," +
|
" Strength_three double NOT NULL DEFAULT '0' COMMENT '×é3³ýÁòÇ¿¶È'," +
|
" YHStrength_three double NOT NULL DEFAULT '0' COMMENT '×é3Ñø»¤Ç¿¶È'," +
|
" TimeLong_three int(11) NOT NULL DEFAULT '0' COMMENT '×é3³ýÁòÌìÊý'," +
|
" STDCap_four int(11) NOT NULL DEFAULT '0' COMMENT '×é4±ê³ÆÈÝÁ¿'," +
|
" FloatVol_four double NOT NULL DEFAULT '0' COMMENT '×é4¸¡³äµçѹ'," +
|
" Strength_four double NOT NULL DEFAULT '0' COMMENT '×é4³ýÁòÇ¿¶È'," +
|
" YHStrength_four double NOT NULL DEFAULT '0' COMMENT '×é4Ñø»¤Ç¿¶È'," +
|
" TimeLong_four int(11) NOT NULL DEFAULT '0' COMMENT '×é4³ýÁòÌìÊý'," +
|
" PRIMARY KEY (num)," +
|
" UNIQUE KEY unique_dev_id (dev_id)" +
|
") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
ResultSet res = null;
|
try {
|
if(recreate) {
|
sql.sqlMysqlExecute(sql_str1);
|
}
|
sql.sqlMysqlExecute(sql_str2);
|
//Ìí¼Óµç³Ø×é±àºÅ×Ö¶Î
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_param'"
|
+ " AND column_name='BattGroupNum'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100SetDLParam_Table
|
+ " ADD COLUMN BattGroupNum int(11) NOT NULL DEFAULT '0' COMMENT 'µç³Ø×é×éºÅ'");
|
}
|
//Ìí¼Ó±ê³ÆÈÝÁ¿(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_param'"
|
+ " AND column_name='STDCap_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100SetDLParam_Table
|
+ " ADD COLUMN STDCap_five int(11) NOT NULL DEFAULT '0' COMMENT '×é5±ê³ÆÈÝÁ¿'");
|
}
|
//Ìí¼Ó¸¡³äµçѹ(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_param'"
|
+ " AND column_name='FloatVol_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100SetDLParam_Table
|
+ " ADD COLUMN FloatVol_five double NOT NULL DEFAULT '0' COMMENT '×é5¸¡³äµçѹ'");
|
}
|
//Ìí¼Ó³ýÁòÇ¿¶È(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_param'"
|
+ " AND column_name='Strength_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100SetDLParam_Table
|
+ " ADD COLUMN Strength_five double NOT NULL DEFAULT '0' COMMENT '×é5³ýÁòÇ¿¶È'");
|
}
|
//Ìí¼ÓÑø»¤Ç¿¶È(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_param'"
|
+ " AND column_name='YHStrength_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100SetDLParam_Table
|
+ " ADD COLUMN YHStrength_five double NOT NULL DEFAULT '0' COMMENT '×é5Ñø»¤Ç¿¶È'");
|
}
|
//Ìí¼ÓÊ£Óàʱ¼ä(×é5)
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ram_db'"
|
+ " AND table_name='tb_fbs9100s_fod_param'"
|
+ " AND column_name='TimeLong_five'");
|
if(false == res.next()) {
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.FBS9100SetDLParam_Table
|
+ " ADD COLUMN TimeLong_five int(11) NOT NULL DEFAULT '0' COMMENT '×é5³ýÁòÌìÊý'");
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
if(null != res) {
|
try {
|
res.close();
|
} catch (SQLException e) {
|
e.printStackTrace();
|
}
|
}
|
sql.close_con();
|
}
|
}
|
}
|