蓄电池监控管理平台数据库初始化程序
DELL
2024-12-12 690f171908a15508049251d7489f8ce519b54a8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.sql.util;
 
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
/**
 * µçÔ´¸æ¾¯Êý¾Ý¿â³õʼ»¯
 * @author DELL
 *
 */
public class Db_Power_Alarm {
    public static void init(MysqlConnPool pool) {
        createDb_Power_Alarm(pool);
        
        createPower_Alarm_Table(pool);
        
        createPower_Alarm_Cfg_Table(pool);
        
    }
    
    
    
    public static void createPower_Alarm_Cfg_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Power_Alarm_Cfg_Table + "_auto" + 
                     " INCREMENT 1" + 
                     " MINVALUE 1" + 
                     " MAXVALUE 9223372036854775807" + 
                     " START 1" + 
                     " CACHE 1;";
            //´´½¨×ÔÔöÐòÁÐ
            sql.sqlMysqlExecute(sql_str_auto);
            
            String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Power_Alarm_Cfg_Table + " "
                            + "(num bigint NOT NULL DEFAULT nextval('" + Sql_Mysql.Power_Alarm_Cfg_Table + "_auto'::regclass)," + 
                            "    alm_id integer NOT NULL DEFAULT 0," + 
                            "    alm_name character varying NOT NULL COLLATE pg_catalog.\"default\" DEFAULT ''::character varying," + 
                            "     PRIMARY KEY (num)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Power_Alarm_Cfg_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Cfg_Table + ".num IS '×ÔÔöÖ÷¼ü';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Cfg_Table + ".alm_id IS 'µçÔ´¸æ¾¯ID';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Cfg_Table + ".alm_name IS 'µçÔ´¸æ¾¯Ãû³Æ';");
            sql.sqlMysqlExecute("COMMENT ON   TABLE " + Sql_Mysql.Power_Alarm_Cfg_Table + " IS 'µçÔ´¸æ¾¯Ãû³ÆÅäÖñí';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createPower_Alarm_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Power_Alarm_Table + "_auto" + 
                     " INCREMENT 1" + 
                     " MINVALUE 1" + 
                     " MAXVALUE 9223372036854775807" + 
                     " START 1" + 
                     " CACHE 1;";
            //´´½¨×ÔÔöÐòÁÐ
            sql.sqlMysqlExecute(sql_str_auto);
            
            String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Power_Alarm_Table + " "
                            + "(num bigint NOT NULL DEFAULT nextval('" + Sql_Mysql.Power_Alarm_Table + "_auto'::regclass)," + 
                            "    power_id integer NOT NULL DEFAULT 0," + 
                            "    alm_id integer NOT NULL DEFAULT 0," + 
                            "    alm_value double precision NOT NULL DEFAULT 0," + 
                            "    alm_starttime timestamp without time zone NOT NULL DEFAULT '2000-01-01 00:00:00'::timestamp without time zone," + 
                            "    alm_endtime timestamp without time zone NOT NULL DEFAULT '2000-01-01 00:00:00'::timestamp without time zone," + 
                            "    alm_confirm_en integer NOT NULL DEFAULT 0," + 
                            "    alm_confirm_time timestamp without time zone NOT NULL DEFAULT '2000-01-01 00:00:00'::timestamp without time zone," + 
                            "    alm_level integer NOT NULL DEFAULT 1," + 
                            "     PRIMARY KEY (num)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Power_Alarm_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("CREATE INDEX IF NOT EXISTS idx_power_id ON " + Sql_Mysql.Power_Alarm_Table + " USING btree (" +
                                    " power_id" +
                                ") TABLESPACE pg_default ;");
 
            sql.sqlMysqlExecute("CREATE INDEX IF NOT EXISTS idx_alm_id ON " + Sql_Mysql.Power_Alarm_Table + " USING btree (" +
                                " alm_id " +
                                ") TABLESPACE pg_default ;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".num IS '×ÔÔöÖ÷¼ü';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".power_id IS 'µçÔ´ID';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".alm_id IS 'µçÔ´¸æ¾¯ID';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".alm_value IS '¸æ¾¯Öµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".alm_starttime IS '¸æ¾¯¿ªÊ¼Ê±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".alm_endtime IS '¸æ¾¯½áÊøÊ±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".alm_confirm_en IS '¸æ¾¯ÊÇ·ñÈ·ÈÏ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".alm_confirm_time IS '¸æ¾¯È·ÈÏʱ¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Alarm_Table + ".alm_level IS '¸æ¾¯µÈ¼¶';");
            sql.sqlMysqlExecute("COMMENT ON   TABLE " + Sql_Mysql.Power_Alarm_Table + " IS 'µçԴʵʱ¸æ¾¯±í';");
        
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createDb_Power_Alarm(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE SCHEMA IF NOT EXISTS " + Sql_Mysql.DB_POWER_ALARM + " AUTHORIZATION sysdba");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}