蓄电池监控管理平台数据库初始化程序
1.在db_ram_db.tb_batt_rtdata表中添加'mon_LY_vol'字段用于表示单体漏液电压信息。
2.在db_ram_db.tb_fbs9100s_fod_param表中添加第5个模块的除硫参数字段信息
3.在db_ram_db.tb_fbs9100s_fod_state表中添加'BattGroupId'字段并设置成唯一索引
1个文件已添加
6个文件已修改
296 ■■■■■ 已修改文件
BattMonitor_DB_Builder/bin/com/version_inf/version_inf.txt 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/config.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/com/battdata_rt/BattData_RT_RamDB_Thread_SQL.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/com/database_util/DB_Ram_db.java 259 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/com/sql/Sql_Mysql.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/com/version_inf/version_inf.txt 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/main/main_BTS_DB_Builder.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/bin/com/version_inf/version_inf.txt
@@ -135,4 +135,7 @@
    1.在web_site数据库中新建tb_dev_restart_plan表用于设备重启计划操作
    2.在线程监控管理表中添加6度通讯线程的服务信息    
V1.50 edit at date 2020-10-16
    1.在db_ram_db.tb_batt_rtdata表中添加'mon_LY_vol'字段用于表示单体漏液电压信息。
    2.在db_ram_db.tb_fbs9100s_fod_param表中添加第5个模块的除硫参数字段信息
    3.在db_ram_db.tb_fbs9100s_fod_state表中添加'BattGroupId'字段并设置成唯一索引
BattMonitor_DB_Builder/config.xml
@@ -2,7 +2,7 @@
<root>
  <mysql_ramdb_recreate_en>false</mysql_ramdb_recreate_en>
  <mysql_server_ip>127.0.0.1</mysql_server_ip>
  <mysql_server_ip>192.168.10.221</mysql_server_ip>
  <!--SOURCE_BATTDATA_TYPE_FBSDEV = 0-->
  <!--SOURCE_BATTDATA_TYPE_SQLSERVER = 1-->
  <!--SOURCE_BATTDATA_TYPE_C_INTERFACE = 2-->
BattMonitor_DB_Builder/src/com/battdata_rt/BattData_RT_RamDB_Thread_SQL.java
@@ -54,7 +54,7 @@
                sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.BattRtData_Table 
                                + " ADD COLUMN `mon_cap` FLOAT NOT NULL DEFAULT 0;");
            }
            //添加单体容量列
            //添加均衡电流列
            res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
                    + " WHERE table_schema='db_ram_db'"
                    + " AND table_name='tb_batt_rtdata'"
@@ -63,6 +63,15 @@
                sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.BattRtData_Table 
                                + " ADD COLUMN `mon_JH_curr` FLOAT NOT NULL DEFAULT 0;");
            }
            //添加漏液电压字段
            res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
                    + " WHERE table_schema='db_ram_db'"
                    + " AND table_name='tb_batt_rtdata'"
                    + " AND column_name='mon_LY_vol'");
            if(false == res.next()) {
                sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.BattRtData_Table
                                + " ADD COLUMN `mon_LY_vol` FLOAT NOT NULL DEFAULT 0;");
            }
            ResultSet res_t = sql.sqlMysqlQuery("SELECT BattGroupId,MonCount FROM " + Sql_Mysql.BattInf_Table);
            while(res_t.next()) {
                int bg_id = res_t.getInt("BattGroupId");
BattMonitor_DB_Builder/src/com/database_util/DB_Ram_db.java
New file
@@ -0,0 +1,259 @@
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();
        }
    }
}
BattMonitor_DB_Builder/src/com/sql/Sql_Mysql.java
@@ -86,6 +86,10 @@
    public final static String TB_61850_JHState_Table = DB_RamDB +".tb_61850_jhstate";                                //61850均衡61850供电模块信息
    
    public final static String FBS9100_offlineyhplan = DB_RamDB + ".tb_fbs9100_offlineyhplan";                        //61850离线养护计划参数表
    public final static String FBS9100s_fod_state = DB_RamDB + ".tb_fbs9100s_fod_state";                            //61850除硫状态表
    public final static String FBS9100SetDLParam_Table = DB_RamDB + ".`tb_fbs9100s_fod_param`";                        //61850除硫参数表
    //--------------------------------------------------------------------------------------------//
    //--------------------------------------------------------------------------------------------//
    public final static String AppSys_Table = DB_AppSys + ".`tb_app_sys`";
@@ -201,7 +205,7 @@
        sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + DB_USER);
        sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + DB_RamDB);
        
        sqlMysqlExecute("DROP DATABASE IF EXISTS " + DB_RamDB_BATT_RT);
        //sqlMysqlExecute("DROP DATABASE IF EXISTS " + DB_RamDB_BATT_RT);
        //sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + DB_RamDB_BATT_RT);
        
        sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + WEB_Site);
BattMonitor_DB_Builder/src/com/version_inf/version_inf.txt
@@ -135,4 +135,7 @@
    1.在web_site数据库中新建tb_dev_restart_plan表用于设备重启计划操作
    2.在线程监控管理表中添加6度通讯线程的服务信息    
V1.50 edit at date 2020-10-16
    1.在db_ram_db.tb_batt_rtdata表中添加'mon_LY_vol'字段用于表示单体漏液电压信息。
    2.在db_ram_db.tb_fbs9100s_fod_param表中添加第5个模块的除硫参数字段信息
    3.在db_ram_db.tb_fbs9100s_fod_state表中添加'BattGroupId'字段并设置成唯一索引
BattMonitor_DB_Builder/src/main/main_BTS_DB_Builder.java
@@ -5,6 +5,7 @@
import com.base.Com;
import com.battdata_rt.BattData_RT_RamDB_Thread_SQL;
import com.config.AppConfig;
import com.database_util.DB_Ram_db;
import com.database_util.DB_battinf;
import com.database_util.DB_db_user;
import com.database_util.DB_web_site;
@@ -17,7 +18,7 @@
    /**************************************************************************/
    /**************************************************************************/
    public final static boolean app_debug = false;
    public final static float m_VersionNum = (float) 1.049;
    public final static float m_VersionNum = (float) 1.50;
    public final static String m_Version = "Welcome To Use BTS DB BUILDER V" + m_VersionNum + " RC_20180908";
    /**************************************************************************/
    /**************************************************************************/
@@ -61,6 +62,11 @@
        }
        /*********************************************************************************/
        boolean recreate_tb = m_AppConfig.getMysqlDB_RecreateEn();
        //初始话db_ram_db数据库
        DB_Ram_db.init(GB_MysqlConnPool, recreate_tb);
        //创建tb_batt_rtstate表格并且将电池组id的值
        BattData_RT_RamDB_Thread_SQL.createBattState_RT_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        //创建tb_batt_rtdata表格并且将电池组id的值