package com.database_util;
|
|
import java.sql.SQLException;
|
import java.util.Date;
|
|
import com.base.Com;
|
import com.sql.MysqlConnPool;
|
import com.sql.Sql_Mysql;
|
|
public class DB_Upspwrdev_Alarm {
|
public static void init(MysqlConnPool pool, boolean recreate) {
|
System.out.println(" db_upspwrdev_alarm init start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
|
createDB_UPSPWRDEV_ALARM(pool);
|
|
createUPSpwrdev_Alarm_Table(pool, recreate);
|
|
createUPSpwrdev_Alarm_History_Table(pool, recreate);
|
|
System.out.println(" db_upspwrdev_alarm init end at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
}
|
|
/**
|
* ´´½¨ db_upspwrdev_alarm Êý¾Ý¿â
|
* @param pool
|
*/
|
public static void createDB_UPSPWRDEV_ALARM(MysqlConnPool pool) {
|
Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
try {
|
sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_UPSPWRDEV_ALARM);
|
} catch (SQLException e) {
|
e.printStackTrace();
|
} finally {
|
sql.close_con();
|
}
|
}
|
|
|
/**
|
* ´´½¨ db_dev_testparam.tb_upspwrdev_alarm ±í
|
* @param pool
|
* @param recreate
|
*/
|
public static void createUPSpwrdev_Alarm_Table(MysqlConnPool pool, boolean recreate) {
|
String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.UPSpwrdev_Alarm_Table;
|
String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.UPSpwrdev_Alarm_Table + " (" +
|
" `num` bigint(20) NOT NULL AUTO_INCREMENT," +
|
" `record_id` bigint(20) NOT NULL DEFAULT '0'," +
|
" `power_device_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'µçÔ´id'," +
|
" `alm_type` int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯id'," +
|
" `alm_level` int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯µÈ¼¶'," +
|
" `alm_start_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '¸æ¾¯¿ªÊ¼Ê±¼ä'," +
|
" `alm_end_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '¸æ¾¯½áÊøÊ±¼ä'," +
|
" `alm_value` float NOT NULL DEFAULT '0' COMMENT '¸æ¾¯Öµ'," +
|
" `alm_is_confirmed` tinyint(1) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯ÊÇ·ñÈ·ÈÏ'," +
|
" `alm_confirmed_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '¸æ¾¯È·ÈÏʱ¼ä'," +
|
" `alm_cleared_type` int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯×´Ì¬0-ʵʱ¸æ¾¯ 1-ÀúÊ·¸æ¾¯ 2-È¡ÏûµÄ¸æ¾¯'," +
|
" PRIMARY KEY (`num`)," +
|
" KEY `index_record_id` (`record_id`)," +
|
" KEY `index_pwrdev_id` (`power_device_id`)," +
|
" KEY `index_alm_type` (`alm_type`)," +
|
" KEY `index_alm_start_time` (`alm_start_time`)," +
|
" KEY `index_alm_cleared_type` (`alm_cleared_type`)" +
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='UPSµçԴʵʱ¸æ¾¯±í';";
|
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();
|
}
|
}
|
|
/**
|
* ´´½¨ db_dev_testparam.tb_upspwrdev_alarm_history ±í
|
* @param pool
|
* @param recreate
|
*/
|
public static void createUPSpwrdev_Alarm_History_Table(MysqlConnPool pool, boolean recreate) {
|
String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.UPSpwrdev_Alarm_History_Table;
|
String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.UPSpwrdev_Alarm_History_Table + " (" +
|
" `num` bigint(20) NOT NULL AUTO_INCREMENT," +
|
" `record_id` bigint(20) NOT NULL DEFAULT '0'," +
|
" `power_device_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'µçÔ´id'," +
|
" `alm_type` int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯id'," +
|
" `alm_level` int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯µÈ¼¶'," +
|
" `alm_start_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '¸æ¾¯¿ªÊ¼Ê±¼ä'," +
|
" `alm_end_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '¸æ¾¯½áÊøÊ±¼ä'," +
|
" `alm_value` float NOT NULL DEFAULT '0' COMMENT '¸æ¾¯Öµ'," +
|
" `alm_is_confirmed` tinyint(1) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯ÊÇ·ñÈ·ÈÏ'," +
|
" `alm_confirmed_time` datetime NOT NULL DEFAULT '1982-01-01 00:00:00' COMMENT '¸æ¾¯È·ÈÏʱ¼ä'," +
|
" `alm_cleared_type` int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯×´Ì¬0-ʵʱ¸æ¾¯ 1-ÀúÊ·¸æ¾¯ 2-È¡ÏûµÄ¸æ¾¯'," +
|
" PRIMARY KEY (`num`)," +
|
" KEY `index_record_id` (`record_id`)," +
|
" KEY `index_pwrdev_id` (`power_device_id`)," +
|
" KEY `index_alm_type` (`alm_type`)," +
|
" KEY `index_alm_start_time` (`alm_start_time`)," +
|
" KEY `index_alm_cleared_type` (`alm_cleared_type`)" +
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='UPSµçÔ´ÀúÊ·¸æ¾¯±í';";
|
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();
|
}
|
}
|
|
}
|