蓄电池监控管理平台数据库初始化程序
LiJun
2018-10-26 8bfc99d231cf771ce4b258845c15599a0570eff7
tb_battinf表中添加机房是否安装列
8个文件已修改
299 ■■■■■ 已修改文件
BattMonitor_DB_Builder/bin/.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/bin/com/dev/fbs9100/FBS9100_Task_Thread_SQL.class 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/bin/com/sql/Sql_Mysql.class 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/bin/main/main_BTS_DB_Builder.class 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/config.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/com/dev/fbs9100/FBS9100_Task_Thread_SQL.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/com/sql/Sql_Mysql.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/main/main_BTS_DB_Builder.java 237 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/bin/.gitignore
@@ -1 +1,2 @@
/com/
/main/
BattMonitor_DB_Builder/bin/com/dev/fbs9100/FBS9100_Task_Thread_SQL.class
Binary files differ
BattMonitor_DB_Builder/bin/com/sql/Sql_Mysql.class
Binary files differ
BattMonitor_DB_Builder/bin/main/main_BTS_DB_Builder.class
Binary files differ
BattMonitor_DB_Builder/config.xml
@@ -2,7 +2,7 @@
<root>
  <mysql_ramdb_recreate_en>false</mysql_ramdb_recreate_en>
  <mysql_server_ip>123.207.82.239</mysql_server_ip>
  <mysql_server_ip>127.0.0.1</mysql_server_ip>
  <!--SOURCE_BATTDATA_TYPE_FBSDEV = 0-->
  <!--SOURCE_BATTDATA_TYPE_SQLSERVER = 1-->
  <!--SOURCE_BATTDATA_TYPE_C_INTERFACE = 2-->
BattMonitor_DB_Builder/src/com/dev/fbs9100/FBS9100_Task_Thread_SQL.java
@@ -1,6 +1,9 @@
package com.dev.fbs9100;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.net.ssl.HandshakeCompletedEvent;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
@@ -54,7 +57,7 @@
                    + "`dev_station_poff_tlong` INT NOT NULL DEFAULT 0, "                //停电时长
                    + "`dev_station_poff_cnt` INT NOT NULL DEFAULT 0, "                    //停电次数
                    + "`dev_data_flowsum` BIGINT NOT NULL DEFAULT 0, "                    //机房流量
                    + "`dev_station_state` INT NOT NULL DEFAULT 0, "
                    + "`batt_online_state` INT NOT NULL DEFAULT 0, "                    //电池状态(0:闭合,1:断开)
                    
                    + " UNIQUE INDEX index_dev_id_uniq (`dev_id`), "
                    + " PRIMARY KEY (`num`) ) "
@@ -237,4 +240,46 @@
            sql.close_con();
        }
    }
    /**
     *     插入在机房状态表中未添加机房状态的记录
     * @param gB_MysqlConnPool
     */
    public static void insertBTSStationState_TableOnRam(MysqlConnPool con_pool) {
        //查询没有添加机房状态的机房记录
        String sql_str1 = " SELECT DISTINCT StationId,FBSDeviceId " +
                          " FROM " + Sql_Mysql.BattInf_Table +
                          "    WHERE StationId NOT IN( " +
                          "        SELECT station_id " +
                          "        FROM  "+ Sql_Mysql.BTSStationState_Table +
                          ")";
        //添加机房状态的记录
        String sql_str2 = " INSERT INTO " + Sql_Mysql.BTSStationState_Table + "(dev_id,station_id) VALUES ";
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        ResultSet rs = null;
        try {
            rs= sql.sqlMysqlQuery(sql_str1);
            System.out.println(sql_str1);
            boolean hasInsertStation = false;;
            while(rs.next()) {
                int dev_id = rs.getInt("FBSDeviceId");
                int stationid = rs.getInt("StationId");
                if( !hasInsertStation ) {
                    sql_str2 = sql_str2 + "(" + dev_id + "," + stationid + ")";
                    hasInsertStation = true;
                }else {
                    sql_str2 = sql_str2 + ",(" + dev_id + "," + stationid + ")";
                }
            }
            if(hasInsertStation) {
                //System.out.println(sql_str2);
                sql.sqlMysqlExecute(sql_str2);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}
BattMonitor_DB_Builder/src/com/sql/Sql_Mysql.java
@@ -525,6 +525,18 @@
                        }
                        
                //---------------------------------------------------------------------------------------------//
                //-------------------------------- 2018-10-16 by lijun   (  binf表中添加   station_install->标识机房是否已经安装 )------------------------------------//
                        res = sqlMysqlQuery("SELECT * FROM information_schema.columns"
                                + " WHERE table_schema='db_battinf'"
                                + " AND table_name='tb_battinf'"
                                + " AND column_name='station_install'");
                        if(false == res.next()) {
                            sqlMysqlExecute("ALTER TABLE " + BattInf_Table
                                            + " ADD COLUMN `station_install` BOOLEAN NOT NULL DEFAULT false");
                        }
                //---------------------------------------------------------------------------------------------//
                        
                        
        //---------------------------------------------------------------------------------------------//
BattMonitor_DB_Builder/src/main/main_BTS_DB_Builder.java
@@ -1,117 +1,120 @@
package main;
import java.sql.SQLException;
import java.util.Date;
import com.base.Com;
import com.battdata_rt.BattData_RT_RamDB_Thread_SQL;
import com.config.AppConfig;
import com.dev.fbs9100.FBS9100S_DFU_SQL;
import com.dev.fbs9100.FBS9100_Task_Thread_SQL;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
public class main_BTS_DB_Builder {
    /**************************************************************************/
    /**************************************************************************/
    public final static boolean app_debug = false;
    public final static float m_VersionNum = (float) 1.001;
    public final static String m_Version = "Welcome To Use BTS DB BUILDER V" + m_VersionNum + " RC_20180908";
    /**************************************************************************/
    /**************************************************************************/
    public static final int DEF_MysqlServerFBS_Port = 3360;
    public static int MysqlServer_Port = DEF_MysqlServerFBS_Port;
    private static AppConfig m_AppConfig;
    private static MysqlConnPool GB_MysqlConnPool;
    /*********************************************************************************************/
    /*********************************************************************************************/
    public static void init(){
        /*//BasicConfigurator.configure();*/
        String ver = m_Version;
        System.out.println("/****************************************************************");
        System.out.println("*****************************************************************");
        System.out.println("****************************************************************/");
        System.out.println(ver);
        System.out.println("App Started At DateTime: " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        m_AppConfig = new AppConfig();
        System.out.println("正在连接数据库 DBserver IP:" + m_AppConfig.getMysqlServerIp() + ", port: " + MysqlServer_Port);
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 5);
        Sql_Mysql sql_ck = new Sql_Mysql(GB_MysqlConnPool.getConn());
        if(null != sql_ck.mysql_con) {
            System.out.println("成功连接数据库"
                                + " DBserver IP:" + m_AppConfig.getMysqlServerIp()
                                + ", port: " + MysqlServer_Port
                                + " @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        }
        try {
            sql_ck.checkAndCreateDB();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } finally {
            sql_ck.close_con();
        }
        /*********************************************************************************/
        boolean recreate_tb = m_AppConfig.getMysqlDB_RecreateEn();
        //创建tb_batt_rtstate表格并且将电池组id的值
        BattData_RT_RamDB_Thread_SQL.createBattState_RT_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        //创建tb_batt_rtdata表格并且将电池组id的值
        BattData_RT_RamDB_Thread_SQL.createBattData_RT_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        //创建tb_server_state表并且设置表中的值
        BattData_RT_RamDB_Thread_SQL.createServerState_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        /*********************************************************************************/
        System.out.println("Recreate RamDB Tables State Is '" + recreate_tb + "'");
        if(true == recreate_tb) {
            //创建tb_fbs9100s_state表
            FBS9100_Task_Thread_SQL.createFBS9100StateTableOnRam(GB_MysqlConnPool);
            //创建tb_fbs9100s_dcdc_data表
            FBS9100_Task_Thread_SQL.createFBS9100S_DCDC_DataTableOnRam(GB_MysqlConnPool);
            //创建tb_fbs9100s_setparam表
            FBS9100_Task_Thread_SQL.createFBS9100SetTestParamTableOnRam(GB_MysqlConnPool);
            //创建CmccPowerData表
            FBS9100_Task_Thread_SQL.createFBS9100CmccPowerDataOnRam(GB_MysqlConnPool);
            //创建tb_fbs9100S_DFU_StateTable表并向表中添加数据
            FBS9100S_DFU_SQL.createFBS9100S_DFU_TableOnRam(GB_MysqlConnPool);
            //创建BTSStationState_Table表
            FBS9100_Task_Thread_SQL.createBTSStationState_TableOnRam(GB_MysqlConnPool);
        }
        if(true == m_AppConfig.getMysqlDB_RecreateEn()) {
            m_AppConfig.setMysqlDB_RecreateEn(false);
            m_AppConfig.writeConfigToXml();
        }
        System.out.println("BTS DB BUILDER Work Done @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        //修改tb_app_sys表中的关键字,让主程序识别
        BattData_RT_RamDB_Thread_SQL.updateTb_App_Sys_AppServerTable(GB_MysqlConnPool);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        /*
        while(true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        */
    }
    public static void main(String[] args) {
        init();
    }
}
package main;
import java.sql.SQLException;
import java.util.Date;
import com.base.Com;
import com.battdata_rt.BattData_RT_RamDB_Thread_SQL;
import com.config.AppConfig;
import com.dev.fbs9100.FBS9100S_DFU_SQL;
import com.dev.fbs9100.FBS9100_Task_Thread_SQL;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
public class main_BTS_DB_Builder {
    /**************************************************************************/
    /**************************************************************************/
    public final static boolean app_debug = false;
    public final static float m_VersionNum = (float) 1.001;
    public final static String m_Version = "Welcome To Use BTS DB BUILDER V" + m_VersionNum + " RC_20180908";
    /**************************************************************************/
    /**************************************************************************/
    public static final int DEF_MysqlServerFBS_Port = 3360;
    public static int MysqlServer_Port = DEF_MysqlServerFBS_Port;
    private static AppConfig m_AppConfig;
    private static MysqlConnPool GB_MysqlConnPool;
    /*********************************************************************************************/
    /*********************************************************************************************/
    public static void init(){
        /*//BasicConfigurator.configure();*/
        String ver = m_Version;
        System.out.println("/****************************************************************");
        System.out.println("*****************************************************************");
        System.out.println("****************************************************************/");
        System.out.println(ver);
        System.out.println("App Started At DateTime: " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        m_AppConfig = new AppConfig();
        System.out.println("正在连接数据库 DBserver IP:" + m_AppConfig.getMysqlServerIp() + ", port: " + MysqlServer_Port);
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 5);
        Sql_Mysql sql_ck = new Sql_Mysql(GB_MysqlConnPool.getConn());
        if(null != sql_ck.mysql_con) {
            System.out.println("成功连接数据库"
                                + " DBserver IP:" + m_AppConfig.getMysqlServerIp()
                                + ", port: " + MysqlServer_Port
                                + " @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        }
        try {
            sql_ck.checkAndCreateDB();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } finally {
            sql_ck.close_con();
        }
        /*********************************************************************************/
        boolean recreate_tb = m_AppConfig.getMysqlDB_RecreateEn();
        //创建tb_batt_rtstate表格并且将电池组id的值
        BattData_RT_RamDB_Thread_SQL.createBattState_RT_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        //创建tb_batt_rtdata表格并且将电池组id的值
        BattData_RT_RamDB_Thread_SQL.createBattData_RT_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        //创建tb_server_state表并且设置表中的值
        BattData_RT_RamDB_Thread_SQL.createServerState_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        /*********************************************************************************/
        System.out.println("Recreate RamDB Tables State Is '" + recreate_tb + "'");
        if(true == recreate_tb) {
            //创建tb_fbs9100s_state表
            FBS9100_Task_Thread_SQL.createFBS9100StateTableOnRam(GB_MysqlConnPool);
            //创建tb_fbs9100s_dcdc_data表
            FBS9100_Task_Thread_SQL.createFBS9100S_DCDC_DataTableOnRam(GB_MysqlConnPool);
            //创建tb_fbs9100s_setparam表
            FBS9100_Task_Thread_SQL.createFBS9100SetTestParamTableOnRam(GB_MysqlConnPool);
            //创建CmccPowerData表
            FBS9100_Task_Thread_SQL.createFBS9100CmccPowerDataOnRam(GB_MysqlConnPool);
            //创建tb_fbs9100S_DFU_StateTable表并向表中添加数据
            FBS9100S_DFU_SQL.createFBS9100S_DFU_TableOnRam(GB_MysqlConnPool);
            //创建BTSStationState_Table表
            FBS9100_Task_Thread_SQL.createBTSStationState_TableOnRam(GB_MysqlConnPool);
        }
        FBS9100_Task_Thread_SQL.insertBTSStationState_TableOnRam(GB_MysqlConnPool);                    //初始化录入机房状态
        if(true == m_AppConfig.getMysqlDB_RecreateEn()) {
            m_AppConfig.setMysqlDB_RecreateEn(false);
            m_AppConfig.writeConfigToXml();
        }
        System.out.println("BTS DB BUILDER Work Done @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        //修改tb_app_sys表中的关键字,让主程序识别
        BattData_RT_RamDB_Thread_SQL.updateTb_App_Sys_AppServerTable(GB_MysqlConnPool);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        /*
        while(true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        */
    }
    public static void main(String[] args) {
        init();
    }
}