package com.database_util;
|
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.Date;
|
|
import com.base.Com;
|
import com.sql.MysqlConnPool;
|
import com.sql.Sql_Mysql;
|
|
public class DB_Ckpwrdev_Inf {
|
public static void init(MysqlConnPool pool, boolean recreate) {
|
System.out.println(" db_ckpwrdev_inf init start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
|
createDB_Ckpwrdev_Inf(pool);
|
|
|
createBreaker_Inf_Table(pool, recreate);//´´½¨±ítb_ckpowerdev_alarm
|
|
createCkpwrdev_Inf_Table(pool, recreate);//´´½¨±ítb_ckpowerdev_alarm
|
|
createGateway_Inf_Table(pool, recreate);
|
|
System.out.println(" db_ckpwrdev_inf init end at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
}
|
|
/**
|
* ´´½¨ db_ckpwrdev_alarm Êý¾Ý¿â
|
* @param pool
|
*/
|
public static void createDB_Ckpwrdev_Inf(MysqlConnPool pool) {
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
try {
|
sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_CkpwrDev_Inf);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
/**
|
*
|
* @Title: createBreaker_Inf_Table
|
* @Description: ½¨±ítb_breaker_inf
|
* @param pool
|
* @param recreate
|
* @author author
|
* @date 2024Äê4ÔÂ1ÈÕ
|
*/
|
private static void createBreaker_Inf_Table(MysqlConnPool pool, boolean recreate) {
|
String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Breaker_Inf_Table;
|
String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Breaker_Inf_Table + " (" +
|
" `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '×ÔÔöÖ÷¼ü'," +
|
" `breaker_id` int(11) NOT NULL COMMENT '¶Ï·Æ÷id'," +
|
" `breaker_type` varchar(255) NOT NULL COMMENT '¶Ï·Æ÷Àà±ð[1-½»Á÷΢¶Ï·Æ÷ 2-Ö±Á÷΢¶Ï·Æ÷]'," +
|
" `breaker_name` varchar(255) NOT NULL COMMENT '¿ª¹ØÃû³Æ'," +
|
" `breaker_addr` varchar(255) NOT NULL COMMENT 'ËùÔÚλÖÃ'," +
|
" `breaker_level` int(11) NOT NULL DEFAULT '1' COMMENT '¼«Êý[1-1P 2-2P 3-3P.....]'," +
|
" `breaker_curr` int(11) NOT NULL DEFAULT '0' COMMENT '±£»¤µçÁ÷'," +
|
" `gateway_id` int(255) NOT NULL DEFAULT '0' COMMENT 'ËùÔÚÍø¹Ø'," +
|
" `node_name` varchar(255) NOT NULL DEFAULT '' COMMENT '[ÌøÕ¢]¶ÔÓ¦Êý¾Ý¿â×Ö¶ÎÃû³Æ'," +
|
" `node_bit` int(11) NOT NULL DEFAULT '0' COMMENT '[ÌøÕ¢]µ±Ç°×Ö¶ÎÖÐʹÓõĵڼ¸Î»[0,1,2,3,...]'," +
|
" `switch_node_name` varchar(255) NOT NULL DEFAULT '' COMMENT '¶Ï·Æ÷·ÖºÏÕ¢¶ÔÓ¦Êý¾Ý¿â×Ö¶ÎÃû³Æ'," +
|
" `switch_node_bit` int(11) NOT NULL DEFAULT '0' COMMENT '¶Ï·Æ÷·ÖºÏÕ¢¶ÔӦλ'," +
|
" PRIMARY KEY (`num`)," +
|
" UNIQUE KEY `idx_breaker_id` (`breaker_id`) USING BTREE" +
|
") ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8 COMMENT='¶Ï·Æ÷¿ª¹ØÅäÖñí';";
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
try {
|
if(true == recreate) {
|
sql.sqlMysqlExecute(sql_str01);
|
}
|
sql.sqlMysqlExecute(sql_str02);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
/**
|
*
|
* @Title: createCkpwrdev_Inf_Table
|
* @Description: ½¨±ítb_ckpwrdev_inf
|
* @param pool
|
* @param recreate
|
* @author author
|
* @date 2024Äê4ÔÂ1ÈÕ
|
*/
|
private static void createCkpwrdev_Inf_Table(MysqlConnPool pool, boolean recreate) {
|
String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Ckpwrdev_Inf_Table;
|
String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Ckpwrdev_Inf_Table + " (" +
|
" `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '×ÔÔöÖ÷¼ü'," +
|
" `power_device_id` int(11) NOT NULL DEFAULT '0' COMMENT 'µçÔ´ID'," +
|
" `power_device_ip` varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT '²â¿ØµçÔ´ipµØÖ·'," +
|
" `batt_moncount` int(11) NOT NULL DEFAULT '24' COMMENT 'ºËÈÝÉ豸ʹÓõ¥ÌåÊýÄ¿'," +
|
" PRIMARY KEY (`num`)," +
|
" UNIQUE KEY `idx_power_device_id` (`power_device_id`) USING BTREE" +
|
") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='²â¿ØµçÔ´ÐÅÏ¢±í';";
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
ResultSet res = null;
|
try {
|
if(true == recreate) {
|
sql.sqlMysqlExecute(sql_str01);
|
}
|
sql.sqlMysqlExecute(sql_str02);
|
|
//ÐÂÔö×Ö¶Îpwr_dev_ip
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ckpwrdev_inf'"
|
+ " AND table_name='tb_ckpwrdev_inf'"
|
+ " AND column_name='pwr_dev_ip'");
|
if(!res.next()) {
|
//ÐÞ¸Ä×Ö¶Îst
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.Ckpwrdev_Inf_Table
|
+ " ADD column `pwr_dev_ip` varchar(64) NOT NULL DEFAULT '127.0.0.1' COMMENT '×Ͼ§61850ÐתIPµØÖ·';");
|
}
|
|
//ÐÂÔö×Ö¶Îzjdy_record__time
|
res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
|
+ " WHERE table_schema='db_ckpwrdev_inf'"
|
+ " AND table_name='tb_ckpwrdev_inf'"
|
+ " AND column_name='zjdy_record__time'");
|
if(!res.next()) {
|
//ÐÞ¸Ä×Ö¶Îst
|
sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.Ckpwrdev_Inf_Table
|
+ " ADD column `zjdy_record__time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '×Ͼ§µçÔ´ÐתÊý¾Ý¸üÐÂʱ¼ä';");
|
}
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
/**
|
*
|
* @Title: createGateway_Inf_Table
|
* @Description: ½¨±ítb_gateway_inf
|
* @param pool
|
* @param recreate
|
* @author author
|
* @date 2024Äê4ÔÂ1ÈÕ
|
*/
|
private static void createGateway_Inf_Table(MysqlConnPool pool, boolean recreate) {
|
String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Gateway_Inf_Table;
|
String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Gateway_Inf_Table + " (" +
|
" `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '×ÔÔöÖ÷¼ü'," +
|
" `gateway_id` int(11) NOT NULL DEFAULT '10001' COMMENT 'Íø¹Øid'," +
|
" `gateway_type` varchar(255) NOT NULL DEFAULT '0' COMMENT 'Íø¹ØÀà±ð[1-½»Á÷Íø¹Ø 2-Ö±Á÷Íø¹Ø]'," +
|
" `gateway_name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Íø¹ØÃû³Æ'," +
|
" `comm_type` varchar(255) NOT NULL DEFAULT 'RS485' COMMENT 'ͨÐÅÀàÐÍ'," +
|
" `ip_addr` varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT 'IPµØÖ·'," +
|
" `join_count` int(11) NOT NULL DEFAULT '0' COMMENT '½ÓÈëÉ豸ÊýÁ¿'," +
|
" PRIMARY KEY (`num`)," +
|
" UNIQUE KEY `idx_gateway_id` (`gateway_id`) USING BTREE" +
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Íø¹ØÐÅÏ¢ÅäÖñí';";
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
try {
|
if(true == recreate) {
|
sql.sqlMysqlExecute(sql_str01);
|
}
|
sql.sqlMysqlExecute(sql_str02);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
}
|