| | |
| | | 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);
|
| | | }
|
| | | }
|