New file |
| | |
| | | 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();
|
| | | }
|
| | | }
|
| | | }
|