蓄电池监控管理平台数据库初始化程序
LiJun
2018-11-16 a47761ab730e6219bd8caedb11249b9a1554e07a
添加电池参数表
7个文件已修改
760 ■■■■■ 已修改文件
BattMonitor_DB_Builder/bin/.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/bin/com/battdata_rt/BattData_RT_RamDB_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/src/com/battdata_rt/BattData_RT_RamDB_Thread_SQL.java 708 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/com/sql/Sql_Mysql.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/src/main/main_BTS_DB_Builder.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BattMonitor_DB_Builder/bin/.gitignore
@@ -1 +1,2 @@
/com/
/main/
BattMonitor_DB_Builder/bin/com/battdata_rt/BattData_RT_RamDB_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/src/com/battdata_rt/BattData_RT_RamDB_Thread_SQL.java
@@ -1,318 +1,390 @@
package com.battdata_rt;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import main.main_BTS_DB_Builder;
import com.base.Com;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
public class BattData_RT_RamDB_Thread_SQL {
    /**
     * 创建tb_batt_rtdata表并且根据集合bd_al,向表中添加电池组id和mon_num 值
     * @param conn_pool
     * @param bd_al
     */
    public static void createBattData_RT_RamDB_Table(MysqlConnPool conn_pool, boolean recreate)
    {
        String sql_str0 = "DROP TABLE IF EXISTS " + Sql_Mysql.BattRtData_Table + "; ";
        String sql_str1 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BattRtData_Table + " "
                        + "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                        + "`rec_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`mon_num` INT NOT NULL DEFAULT 0, "
                        + "`mon_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_tmp` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_res` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_ser` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_conn_res` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_JH_curr` FLOAT NOT NULL DEFAULT 0, "
                        + "INDEX index_BattGroupId (`BattGroupId`), "
                        + "PRIMARY KEY (`num`)) "
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate) {
                sql.sqlMysqlExecute(sql_str0);                    //删除tb_batt_rtdata
                sql.sqlMysqlExecute(sql_str1);                    //不存在  tb_batt_rtdata表的时候重新建表
            } else {
                //sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.BattRtData_Table);        //删除tb_batt_rtdata
            }
            ResultSet res_t = sql.sqlMysqlQuery("SELECT BattGroupId,MonCount FROM " + Sql_Mysql.BattInf_Table);
            while(res_t.next()) {
                int bg_id = res_t.getInt("BattGroupId");
                int mon_cnt = res_t.getInt("MonCount");
                if(mon_cnt > 0){
                    int max_monnum = seachBattMaxMonNum(conn_pool,bg_id);            //当前电池组在 tb_batt_rtdata 表中的最大单体个数
                    if(mon_cnt > max_monnum){
                        //需要从max_monnum开始添加单体记录
                        String sql_str2 = "INSERT INTO " + Sql_Mysql.BattRtData_Table + "(BattGroupId, mon_num)" + " VALUES ";
                        boolean isStart = true;
                        for(int mc = max_monnum; mc < mon_cnt; mc++) {
                            if(isStart) {
                                isStart = false;
                            }else{
                                sql_str2 += ",";
                            }
                            sql_str2 += "(" + bg_id + "," + (mc+1) + ")";
                        }
                        System.out.println("电池组"+bg_id+"从单体"+(max_monnum+1)+"开始在tb_batt_rtdata表中添加单体数据  at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
                        sql.sqlMysqlExecute(sql_str2);
                    }else if(mon_cnt < max_monnum){
                        //删除当前电池组中超过单体个数的数据
                        String sql_str2 = " DELETE FROM " + Sql_Mysql.BattRtData_Table + " WHERE  BattGroupId = " +bg_id+ " AND mon_num > "+mon_cnt;
                        sql.sqlMysqlExecute(sql_str2);
                        System.out.println("电池组"+bg_id+"从单体"+(mon_cnt+1)+"开始删除tb_batt_rtdata单体数据 at "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     * 查询当前电池组在    tb_batt_rtdata  表中最大单体数
     * @param conn_pool
     * @param battGroupId
     * @return
     */
    public static int seachBattMaxMonNum(MysqlConnPool conn_pool,int battGroupId){
        int maxMonNum = 0;
        String sql_str = " SELECT MAX(mon_num) as maxmon_num "
                + " FROM " + Sql_Mysql.BattRtData_Table
                + " WHERE BattGroupId = " + battGroupId;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        //System.out.println(sql_str);
        ResultSet rs = sql.sqlMysqlQuery(sql_str);
        try {
            if(rs.next()){
                maxMonNum = rs.getInt("maxmon_num");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
            sql.close_con();
        }
        return maxMonNum;
    }
    /************************************************************************************************/
    /************************************************************************************************/
    /************************************************************************************************/
    /************************************************************************************************/
    /**
     * 创建tb_batt_rtstate数据库表,并且将bd_al数组中的BattGroupId数据插入到表中
     * @param conn_pool
     * @param bd_al
     */
    public static void createBattState_RT_RamDB_Table(MysqlConnPool conn_pool, boolean recreate)
    {
        String sql_str0 = "DROP TABLE IF EXISTS " + Sql_Mysql.BattRtState_Table + "; ";
        String sql_str1 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BattRtState_Table + " "
                        + "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                        + "`batt_count` INT NOT NULL DEFAULT 0, "
                        + "`rec_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`online_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`group_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`group_tmp` FLOAT NOT NULL DEFAULT 0, "
                        + "`group_curr` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_state` INT NOT NULL DEFAULT 0, "
                        + "`batt_test_type` INT NOT NULL DEFAULT 0, "
                        + "`batt_test_starttime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`batt_test_recordtime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`batt_test_tlong` INT NOT NULL DEFAULT 0, "
                        + "`batt_test_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_real_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_rest_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_rest_power1_time` INT NOT NULL DEFAULT 0, "
                        + "`batt_rest_power2_time` INT NOT NULL DEFAULT 0, "
                        + "INDEX index_BattGroupId (`BattGroupId`), "
                        + "PRIMARY KEY (`num`)) "
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        String sql_str2 = "INSERT INTO " + Sql_Mysql.BattRtState_Table + "(BattGroupId)"
                            + " SELECT BattGroupId FROM " + Sql_Mysql.BattInf_Table;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate) {
                sql.sqlMysqlExecute(sql_str0);
                sql.sqlMysqlExecute(sql_str1);
            } else {
                sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.BattRtState_Table);
            }
            sql.sqlMysqlExecute(sql_str2);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /************************************************************************************************/
    /************************************************************************************************/
    /**
     * 建tb_server_state表并设置值
     * @param conn_pool
     */
    public static void createServerState_RamDB_Table(MysqlConnPool conn_pool, boolean recreate)
    {
        String sql_str0 = "DROP TABLE IF EXISTS " + Sql_Mysql.ServerState_Table + "; ";
        String sql_str1 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.ServerState_Table + " "
                        + "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`server_version` FLOAT NOT NULL DEFAULT 0, "
                        + "`server_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`max_mem` BIGINT NOT NULL DEFAULT 0, "
                        + "`total_mem` BIGINT NOT NULL DEFAULT 0, "
                        + "`free_men` BIGINT NOT NULL DEFAULT 0, "
                        + "`total_disc_space` BIGINT NOT NULL DEFAULT 0, "
                        + "`free_disc_space` BIGINT NOT NULL DEFAULT 0, "
                        + "`db_conn_max` INT NOT NULL DEFAULT 0, "
                        + "`db_conn_count` INT NOT NULL DEFAULT 0, "
                        + "PRIMARY KEY (`num`)) "
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        String sql_str2 = "INSERT INTO " + Sql_Mysql.ServerState_Table
                        + "(server_version) VALUES (" + main_BTS_DB_Builder.m_VersionNum + ")";
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate) {
                sql.sqlMysqlExecute(sql_str0);
                sql.sqlMysqlExecute(sql_str1);
            } else {
                sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.ServerState_Table);
            }
            sql.sqlMysqlExecute(sql_str2);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     * 更新tb_server_state表中的值
     * @param conn_pool
     */
    public static void updateServerState_RamDB_Table(MysqlConnPool conn_pool)
    {
        Runtime rt = Runtime.getRuntime();
        String path = System.getProperty("user.dir");
        File diskPartition = new File(path.substring(0, path.indexOf(":")+1));
        long totalCapacity = diskPartition.getTotalSpace() / (1024*1024);
        long usablePatitionSpace = diskPartition.getUsableSpace() / (1024*1024);
        int conn_max = 0;
        int conn_count = 0;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            ResultSet res = sql.sqlMysqlQuery("show variables like 'max_connections'");
            if(res.next()) {
                conn_max = res.getInt(2);
            }
            res = sql.sqlMysqlQuery("show status like 'Threads_connected'");
            if(res.next()) {
                conn_count = res.getInt(2);
            }
            String sql_str = "UPDATE " + Sql_Mysql.ServerState_Table
                    + " SET "
                    + "server_datetime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "',"
                    + "max_mem=" + rt.maxMemory() + ","
                    + "total_mem=" + rt.totalMemory() + ","
                    + "free_men=" + rt.freeMemory() + ","
                    + "total_disc_space=" + totalCapacity + ","
                    + "free_disc_space=" + usablePatitionSpace + ","
                    + "db_conn_max=" + conn_max + ","
                    + "db_conn_count=" + conn_count;
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlUseDB("web_site");
            if(true == sql.sqlMysqlCheckIfTableExist("tb_process_survey")) {
                String sql_str_1 = "UPDATE " + "tb_process_survey" + " SET "
                                    + " ProcessTime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "' "
                                    + " WHERE ProcessId=11001";
                sql.sqlMysqlExecute(sql_str_1);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /************************************************************************************************/
    public static boolean updateServerStartInfTo_RamDB_Table(MysqlConnPool conn_pool, double ver)
    {
        boolean res = false;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            sql.sqlMysqlUseDB(Sql_Mysql.WEB_Site);
            if(true == sql.sqlMysqlCheckIfTableExist("tb_process_survey")) {
                String sql_str_1 = "UPDATE " + "tb_process_survey" + " SET "
                                    + " Process_starttime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "', "
                                    + " ProcessVersion='" + String.format("V%1.3f", ver) + "' "
                                    + " WHERE ProcessId=11001";
                //System.out.println(sql_str_1);
                sql.sqlMysqlExecute(sql_str_1);
                res = true;
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            res = false;
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
        return res;
    }
    /************************************************************************************************/
    /************************************************************************************************/
    /**
     * 让主程序重新导入单体数据关键字改成true
     * @param conn_pool
     */
    public static void updateTb_App_Sys_AppServerTable(MysqlConnPool conn_pool)
    {
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            sql.sqlMysqlUseDB(Sql_Mysql.DB_AppSys);
            if(true == sql.sqlMysqlCheckIfTableExist(Sql_Mysql.TB_AppSys)) {
                //System.out.println("修改数据库中的是否重载数据");
                String sql_str_1 = "UPDATE " + Sql_Mysql.AppSys_Table + " SET "
                                    + " AppServer_Reinit_BattGroupData_EN = 1";
                sql.sqlMysqlExecute(sql_str_1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}
package com.battdata_rt;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import main.main_BTS_DB_Builder;
import com.base.Com;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
public class BattData_RT_RamDB_Thread_SQL {
    /**
     * 创建tb_batt_rtdata表并且根据集合bd_al,向表中添加电池组id和mon_num 值
     * @param conn_pool
     * @param bd_al
     */
    public static void createBattData_RT_RamDB_Table(MysqlConnPool conn_pool, boolean recreate)
    {
        String sql_str0 = "DROP TABLE IF EXISTS " + Sql_Mysql.BattRtData_Table + "; ";
        String sql_str1 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BattRtData_Table + " "
                        + "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                        + "`rec_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`mon_num` INT NOT NULL DEFAULT 0, "
                        + "`mon_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_tmp` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_res` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_ser` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_conn_res` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_JH_curr` FLOAT NOT NULL DEFAULT 0, "
                        + "INDEX index_BattGroupId (`BattGroupId`), "
                        + "PRIMARY KEY (`num`)) "
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate) {
                sql.sqlMysqlExecute(sql_str0);                    //删除tb_batt_rtdata
                sql.sqlMysqlExecute(sql_str1);                    //不存在  tb_batt_rtdata表的时候重新建表
            } else {
                //sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.BattRtData_Table);        //删除tb_batt_rtdata
            }
            ResultSet res_t = sql.sqlMysqlQuery("SELECT BattGroupId,MonCount FROM " + Sql_Mysql.BattInf_Table);
            while(res_t.next()) {
                int bg_id = res_t.getInt("BattGroupId");
                int mon_cnt = res_t.getInt("MonCount");
                if(mon_cnt > 0){
                    int max_monnum = seachBattMaxMonNum(conn_pool,bg_id);            //当前电池组在 tb_batt_rtdata 表中的最大单体个数
                    if(mon_cnt > max_monnum){
                        //需要从max_monnum开始添加单体记录
                        String sql_str2 = "INSERT INTO " + Sql_Mysql.BattRtData_Table + "(BattGroupId, mon_num)" + " VALUES ";
                        boolean isStart = true;
                        for(int mc = max_monnum; mc < mon_cnt; mc++) {
                            if(isStart) {
                                isStart = false;
                            }else{
                                sql_str2 += ",";
                            }
                            sql_str2 += "(" + bg_id + "," + (mc+1) + ")";
                        }
                        System.out.println("电池组"+bg_id+"从单体"+(max_monnum+1)+"开始在tb_batt_rtdata表中添加单体数据  at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
                        sql.sqlMysqlExecute(sql_str2);
                    }else if(mon_cnt < max_monnum){
                        //删除当前电池组中超过单体个数的数据
                        String sql_str2 = " DELETE FROM " + Sql_Mysql.BattRtData_Table + " WHERE  BattGroupId = " +bg_id+ " AND mon_num > "+mon_cnt;
                        sql.sqlMysqlExecute(sql_str2);
                        System.out.println("电池组"+bg_id+"从单体"+(mon_cnt+1)+"开始删除tb_batt_rtdata单体数据 at "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     * 查询当前电池组在    tb_batt_rtdata  表中最大单体数
     * @param conn_pool
     * @param battGroupId
     * @return
     */
    public static int seachBattMaxMonNum(MysqlConnPool conn_pool,int battGroupId){
        int maxMonNum = 0;
        String sql_str = " SELECT MAX(mon_num) as maxmon_num "
                + " FROM " + Sql_Mysql.BattRtData_Table
                + " WHERE BattGroupId = " + battGroupId;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        //System.out.println(sql_str);
        ResultSet rs = sql.sqlMysqlQuery(sql_str);
        try {
            if(rs.next()){
                maxMonNum = rs.getInt("maxmon_num");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
            sql.close_con();
        }
        return maxMonNum;
    }
    /************************************************************************************************/
    /************************************************************************************************/
    /************************************************************************************************/
    /************************************************************************************************/
    /**
     * 创建tb_batt_rtstate数据库表,并且将bd_al数组中的BattGroupId数据插入到表中
     * @param conn_pool
     * @param bd_al
     */
    public static void createBattState_RT_RamDB_Table(MysqlConnPool conn_pool, boolean recreate)
    {
        String sql_str0 = "DROP TABLE IF EXISTS " + Sql_Mysql.BattRtState_Table + "; ";
        String sql_str1 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BattRtState_Table + " "
                        + "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                        + "`batt_count` INT NOT NULL DEFAULT 0, "
                        + "`rec_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`online_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`group_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`group_tmp` FLOAT NOT NULL DEFAULT 0, "
                        + "`group_curr` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_state` INT NOT NULL DEFAULT 0, "
                        + "`batt_test_type` INT NOT NULL DEFAULT 0, "
                        + "`batt_test_starttime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`batt_test_recordtime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`batt_test_tlong` INT NOT NULL DEFAULT 0, "
                        + "`batt_test_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_real_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_rest_cap` FLOAT NOT NULL DEFAULT 0, "
                        + "`batt_rest_power1_time` INT NOT NULL DEFAULT 0, "
                        + "`batt_rest_power2_time` INT NOT NULL DEFAULT 0, "
                        + "INDEX index_BattGroupId (`BattGroupId`), "
                        + "PRIMARY KEY (`num`)) "
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        String sql_str2 = "INSERT INTO " + Sql_Mysql.BattRtState_Table + "(BattGroupId)"
                            + " SELECT BattGroupId FROM " + Sql_Mysql.BattInf_Table;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate) {
                sql.sqlMysqlExecute(sql_str0);
                sql.sqlMysqlExecute(sql_str1);
            } else {
                sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.BattRtState_Table);
            }
            sql.sqlMysqlExecute(sql_str2);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /************************************************************************************************/
    /************************************************************************************************/
    /**
     * 建tb_server_state表并设置值
     * @param conn_pool
     */
    public static void createServerState_RamDB_Table(MysqlConnPool conn_pool, boolean recreate)
    {
        String sql_str0 = "DROP TABLE IF EXISTS " + Sql_Mysql.ServerState_Table + "; ";
        String sql_str1 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.ServerState_Table + " "
                        + "( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`server_version` FLOAT NOT NULL DEFAULT 0, "
                        + "`server_datetime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`max_mem` BIGINT NOT NULL DEFAULT 0, "
                        + "`total_mem` BIGINT NOT NULL DEFAULT 0, "
                        + "`free_men` BIGINT NOT NULL DEFAULT 0, "
                        + "`total_disc_space` BIGINT NOT NULL DEFAULT 0, "
                        + "`free_disc_space` BIGINT NOT NULL DEFAULT 0, "
                        + "`db_conn_max` INT NOT NULL DEFAULT 0, "
                        + "`db_conn_count` INT NOT NULL DEFAULT 0, "
                        + "PRIMARY KEY (`num`)) "
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        String sql_str2 = "INSERT INTO " + Sql_Mysql.ServerState_Table
                        + "(server_version) VALUES (" + main_BTS_DB_Builder.m_VersionNum + ")";
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate) {
                sql.sqlMysqlExecute(sql_str0);
                sql.sqlMysqlExecute(sql_str1);
            } else {
                sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.ServerState_Table);
            }
            sql.sqlMysqlExecute(sql_str2);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     * 更新tb_server_state表中的值
     * @param conn_pool
     */
    public static void updateServerState_RamDB_Table(MysqlConnPool conn_pool)
    {
        Runtime rt = Runtime.getRuntime();
        String path = System.getProperty("user.dir");
        File diskPartition = new File(path.substring(0, path.indexOf(":")+1));
        long totalCapacity = diskPartition.getTotalSpace() / (1024*1024);
        long usablePatitionSpace = diskPartition.getUsableSpace() / (1024*1024);
        int conn_max = 0;
        int conn_count = 0;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            ResultSet res = sql.sqlMysqlQuery("show variables like 'max_connections'");
            if(res.next()) {
                conn_max = res.getInt(2);
            }
            res = sql.sqlMysqlQuery("show status like 'Threads_connected'");
            if(res.next()) {
                conn_count = res.getInt(2);
            }
            String sql_str = "UPDATE " + Sql_Mysql.ServerState_Table
                    + " SET "
                    + "server_datetime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "',"
                    + "max_mem=" + rt.maxMemory() + ","
                    + "total_mem=" + rt.totalMemory() + ","
                    + "free_men=" + rt.freeMemory() + ","
                    + "total_disc_space=" + totalCapacity + ","
                    + "free_disc_space=" + usablePatitionSpace + ","
                    + "db_conn_max=" + conn_max + ","
                    + "db_conn_count=" + conn_count;
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlUseDB("web_site");
            if(true == sql.sqlMysqlCheckIfTableExist("tb_process_survey")) {
                String sql_str_1 = "UPDATE " + "tb_process_survey" + " SET "
                                    + " ProcessTime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "' "
                                    + " WHERE ProcessId=11001";
                sql.sqlMysqlExecute(sql_str_1);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /************************************************************************************************/
    public static boolean updateServerStartInfTo_RamDB_Table(MysqlConnPool conn_pool, double ver)
    {
        boolean res = false;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            sql.sqlMysqlUseDB(Sql_Mysql.WEB_Site);
            if(true == sql.sqlMysqlCheckIfTableExist("tb_process_survey")) {
                String sql_str_1 = "UPDATE " + "tb_process_survey" + " SET "
                                    + " Process_starttime='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "', "
                                    + " ProcessVersion='" + String.format("V%1.3f", ver) + "' "
                                    + " WHERE ProcessId=11001";
                //System.out.println(sql_str_1);
                sql.sqlMysqlExecute(sql_str_1);
                res = true;
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            res = false;
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
        return res;
    }
    /************************************************************************************************/
    /************************************************************************************************/
    /**
     * 让主程序重新导入单体数据关键字改成true
     * @param conn_pool
     */
    public static void updateTb_App_Sys_AppServerTable(MysqlConnPool conn_pool)
    {
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            sql.sqlMysqlUseDB(Sql_Mysql.DB_AppSys);
            if(true == sql.sqlMysqlCheckIfTableExist(Sql_Mysql.TB_AppSys)) {
                //System.out.println("修改数据库中的是否重载数据");
                String sql_str_1 = "UPDATE " + Sql_Mysql.AppSys_Table + " SET "
                                    + " AppServer_Reinit_BattGroupData_EN = 1";
                sql.sqlMysqlExecute(sql_str_1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     *    创建GPRS状态表
     * @param conn_pool
     * @param recreate_tb
     */
    public static void createBTSGPRSState_Table(MysqlConnPool conn_pool, boolean recreate_tb) {
        String str1 = "DROP TABLE IF EXISTS "+Sql_Mysql.BTSGPRSState_Table;
        String str2 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BTSGPRSState_Table
                + " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                + "`dev_id` BIGINT NOT NULL DEFAULT 0, "
                + "`op_cmd` INT NOT NULL DEFAULT 0, "
                + "`AT_cmd` varchar(20) NOT NULL DEFAULT '', "
                + "`ack_inf` varchar(50) NOT NULL DEFAULT '', "
                + " UNIQUE INDEX index_dev_id_uniq (`dev_id`), "
                + " PRIMARY KEY (`num`) ) "
                + " ENGINE=InnoDB DEFAULT CHARSET=utf8";
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate_tb) {
                sql.sqlMysqlExecute(str1);
            }else{
                //sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.BTSGPRSState_Table);
            }
            sql.sqlMysqlExecute(str2);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     *     创建电池参数表
     */
    public static void createBattParam_Table(MysqlConnPool conn_pool, boolean recreate_tb) {
        String str1 = "DROP TABLE IF EXISTS "+Sql_Mysql.FBS9100BattParam_Table;
        String str2 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.FBS9100BattParam_Table
            + " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
            + "`dev_ip` varchar(20) NOT NULL DEFAULT '127.0.0.0', "
            + "`dev_id` BIGINT NOT NULL DEFAULT 0, "
            + "`op_cmd` INT NOT NULL DEFAULT 0, "
            + "`STD_CAP` INT NOT NULL DEFAULT 0, "
            + "`STD_RES` INT NOT NULL DEFAULT 0, "
            + "`BattGroupCount` INT NOT NULL DEFAULT 0, "
            + "`EachGroupBattCount` INT NOT NULL DEFAULT 0, "
            + "`MonomerVol` FLOAT NOT NULL DEFAULT 0, "
            + "`GroupVol` FLOAT NOT NULL DEFAULT 0, "
            + "`BattTemp` FLOAT NOT NULL DEFAULT 0, "
            + "`FloatChargeVol` FLOAT NOT NULL DEFAULT 0, "
            + "`FloatChargeCurr` FLOAT NOT NULL DEFAULT 0, "
            + "`OnlineVolLow` FLOAT NOT NULL DEFAULT 0, "
            + "`GroupConnType` INT NOT NULL DEFAULT 0, "
            + " UNIQUE INDEX index_dev_id_uniq (`dev_id`), "
            + " PRIMARY KEY (`num`) ) "
            + " ENGINE=MEMORY DEFAULT CHARSET=utf8";
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            if(true == recreate_tb) {
                sql.sqlMysqlExecute(str1);
            }
            sql.sqlMysqlExecute(str2);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    public static void main(String[] args) {
        MysqlConnPool conn_pool = new MysqlConnPool("123.207.82.239",3360,5);
        createBattParam_Table(conn_pool,false);
    }
}
BattMonitor_DB_Builder/src/com/sql/Sql_Mysql.java
@@ -77,7 +77,11 @@
    
    public final static String BTSStationState_Table = DB_RamDB + ".`tb_bts_station_state`";                        //机房状态表
    
    public final static String FBS9100SysParam_Table = DB_RamDB + ".`tb_fbs9100_sysparam`";                            //
    public final static String FBS9100SysParam_Table = DB_RamDB + ".`tb_fbs9100_sysparam`";                            //系统参数表
    public final static String BTSGPRSState_Table = DB_RamDB + ".`tb_bts_gprs_state`";                                //gprs 信息表
    public final static String FBS9100BattParam_Table = DB_RamDB + ".`tb_fbs9100_battparam`";                        //电池组参数表
    //--------------------------------------------------------------------------------------------//
    //--------------------------------------------------------------------------------------------//
    public final static String AppSys_Table = DB_AppSys + ".`tb_app_sys`";
@@ -244,21 +248,31 @@
                        + "ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        
        String table_2_1 = "CREATE TABLE IF NOT EXISTS "+DEVERRORRECORD_Table+" (" + 
                "  `num` int(11) NOT NULL AUTO_INCREMENT," +
                "  `stationid` varchar(64) NOT NULL DEFAULT '42000001'," +
                "  `record_time` datetime NOT NULL DEFAULT '2018-01-01 00:00:00'," +
                "  `error_descript` longtext NOT NULL," +
                "  `uid` int(11) NOT NULL DEFAULT '1002'," +
                "  `error_en` int(11) NOT NULL DEFAULT '0'," +
                "  `note` varchar(64) NOT NULL DEFAULT ''," +
                "  `picture_one` blob," +
                "  `picture_two` blob," +
                "  `picture_three` blob," +
                "  `picture_four` blob," +
                "  `picture_num` int(11) NOT NULL DEFAULT '0'," +
                "  PRIMARY KEY (`num`)," +
                "  KEY `stationid_index` (`stationid`)" +
                ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;";
                        "  `num` int(11) NOT NULL AUTO_INCREMENT," +
                        "  `stationid` varchar(64) NOT NULL DEFAULT '42000001'," +
                        "  `record_time` datetime NOT NULL DEFAULT '2018-01-01 00:00:00'," +
                        "  `error_descript` longtext NOT NULL," +
                        "  `uid` int(11) NOT NULL DEFAULT '1002'," +
                        "  `uname` varchar(64) NOT NULL DEFAULT ''," +
                        "  `error_en` int(11) NOT NULL DEFAULT '0'," +
                        "  `error_dispose` longtext NOT NULL," +
                        "  `note` varchar(64) NOT NULL DEFAULT ''," +
                        "  `picture_one` longblob," +
                        "  `picture_two` longblob," +
                        "  `picture_three` longblob," +
                        "  `picture_four` longblob," +
                        "  `picture_num` int(11) NOT NULL DEFAULT '0'," +
                        "  `solve_picture_one` longblob," +
                        "  `solve_picture_two` longblob," +
                        "  `solve_picture_three` longblob," +
                        "  `solve_picture_four` longblob," +
                        "  `solve_picture_num` int(11) NOT NULL DEFAULT '0'," +
                        "  `solve_uid` int(11) NOT NULL DEFAULT '1002'," +
                        "  `solve_uname` varchar(64) NOT NULL DEFAULT ''," +
                        "  `solve_record_time` datetime NOT NULL DEFAULT '2018-01-01 00:00:00'," +
                        "  PRIMARY KEY (`num`)," +
                        "  KEY `stationid_index` (`stationid`)" +
                        ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        
        String table_3 = "CREATE TABLE IF NOT EXISTS " + BattMainInf_Table
                        + " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
BattMonitor_DB_Builder/src/main/main_BTS_DB_Builder.java
@@ -66,6 +66,11 @@
        //创建tb_server_state表并且设置表中的值
        BattData_RT_RamDB_Thread_SQL.createServerState_RamDB_Table(GB_MysqlConnPool, recreate_tb);
        
        //创建tb_bts_gprs_state表
        BattData_RT_RamDB_Thread_SQL.createBTSGPRSState_Table(GB_MysqlConnPool, recreate_tb);
        //创建tb_fbs9100_battparam表
        BattData_RT_RamDB_Thread_SQL.createBattParam_Table(GB_MysqlConnPool, recreate_tb);
        
        /*********************************************************************************/
        System.out.println("Recreate RamDB Tables State Is '" + recreate_tb + "'");