蓄电池监控管理平台数据库初始化程序
DELL
2024-12-07 1d04bea0deadc20a07599d15ee96559665ffe60a
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.sql.util;
 
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class Db_Batt {
    public static void init(MysqlConnPool pool) {
        createDb_Batt(pool);
        
        createMon_Inf_Table(pool);
        
        createMon_Plan_Table(pool);
        
        createPower_Inf_Table(pool);
        
        createSinf_Pinf_Table(pool);
        
        createStation_Inf_Table(pool);
        
    }
    
    public static void createStation_Inf_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            
            String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Station_Inf_Table + " "
                            + "(sinf_id integer NOT NULL," + 
                            "    sinf_name character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '»ú×é1'::character varying," + 
                            "    stype integer NOT NULL DEFAULT 1," + 
                            "     PRIMARY KEY (sinf_id)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Station_Inf_Table + " OWNER TO sysdba;");
        
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Station_Inf_Table + ".sinf_id IS '»ú·¿id';");
 
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Station_Inf_Table + ".sinf_name IS '»ú·¿Ãû³Æ';");
 
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Station_Inf_Table + ".stype IS '»ú·¿ÀàÐÍ';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    
    public static void createSinf_Pinf_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Sinf_Pinf_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.Sinf_Pinf_Table + " "
                            + "(num integer NOT NULL DEFAULT nextval('" + Sql_Mysql.Sinf_Pinf_Table + "db_batt.sinf_pinf_auto'::regclass)," + 
                            "    sinf_id integer NOT NULL," + 
                            "    pinf_id integer NOT NULL," + 
                            "     PRIMARY KEY (num)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Sinf_Pinf_Table + " OWNER TO sysdba;");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createPower_Inf_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Power_Inf_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_Inf_Table + " "
                            + "(power_id integer NOT NULL DEFAULT 1," + 
                            "    power_name character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'µçÔ´×é1'::character varying," + 
                            "    mon_num integer NOT NULL DEFAULT 1," + 
                            "    acvol_high_limit double precision NOT NULL DEFAULT '200'::double precision," + 
                            "    acvol_low_limit double precision NOT NULL DEFAULT '200'::double precision," + 
                            "    dcoutvol_low_limit double precision NOT NULL DEFAULT '43.2'::double precision," + 
                            "    power_ip character(32) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '127.0.0.1'::character varying," + 
                            "    dev_type integer NOT NULL DEFAULT 1," + 
                            "    binf_id integer NOT NULL DEFAULT 0," + 
                            "    binf_name character varying(32) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'µçÔ´×é1'::character varying," + 
                            "    mon_vol integer NOT NULL DEFAULT 2," + 
                            "    mon_cap integer NOT NULL DEFAULT 150," + 
                            "    mon_res double precision NOT NULL DEFAULT '0.4'::double precision," + 
                            "    load_curr double precision NOT NULL DEFAULT '0'::double precision," + 
                            "     PRIMARY KEY (power_id)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Power_Inf_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".power_id IS 'µçÔ´ID';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".power_name IS 'µçÔ´Ãû³Æ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".mon_num IS 'µç³Ø×éµ¥Ìå¸öÊý';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".acvol_high_limit IS '½»Á÷ÉÏÏÞãÐÖµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".acvol_low_limit IS '½»Á÷ÏÂÏÞãÐÖµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".dcoutvol_low_limit IS 'Ö±Á÷Êä³öµçѹÏÂÏÞãÐÖµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".power_ip IS 'µçÔ´IPµØÖ·';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".dev_type IS 'µçÔ´ÀàÐÍ[1-Ò»¶ÎÖ±Á÷µçÔ´  2-¶þ¶ÎÖ±Á÷µçÔ´  3-Èý¶ÎÖ±Á÷µçÔ´(3¶ÎÖ±Á÷µçÔ´ÎÞÐîµç³ØÊý¾Ý)]';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".binf_id IS '°ó¶¨µç³Ø×éID';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".binf_name IS 'µç³Ø×éÃû³Æ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".mon_vol IS '±ê³Æµ¥Ìåµçѹ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".mon_cap IS '±ê³ÆÈÝÁ¿';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".mon_res IS '±ê³ÆÄÚ×è';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Power_Inf_Table + ".load_curr IS '¸ºÔصçÁ÷';");
        
        
        
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createMon_Plan_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Mon_Plan_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.Mon_Plan_Table + " "
                            + "(num integer NOT NULL DEFAULT nextval('" + Sql_Mysql.Mon_Plan_Table + "_auto'::regclass)," + 
                            "    mon_id character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '2011'::character varying," + 
                            "    plan_type integer NOT NULL DEFAULT 0," + 
                            "    plan_rate double precision NOT NULL DEFAULT 0," + 
                            "    start_time timestamp without time zone NOT NULL DEFAULT '2024-01-01 00:00:00'::timestamp without time zone," + 
                            "    stop_time timestamp without time zone NOT NULL DEFAULT '2024-01-01 00:00:00'::timestamp without time zone," + 
                            "    create_time timestamp without time zone NOT NULL DEFAULT '2024-01-01 00:00:00'::timestamp without time zone," + 
                            "    create_user_id integer NOT NULL DEFAULT 1001," + 
                            "    create_user_name character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'hw'::character varying," + 
                            "    old_row character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    old_col character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    old_addres_num character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    new_row character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    new_col character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    new_addres_num character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    plan_state integer NOT NULL DEFAULT 0," + 
                            "     PRIMARY KEY (num)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Mon_Plan_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".mon_id IS 'µ¥Ìå±àºÅ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".plan_type IS '¼Æ»®ÀàÐÍ:0±¨·Ï£¬1תÔË£¬2Èë¿â£¬3³ö¿â';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".plan_rate IS '¼Æ»®½ø¶È°Ù·Ö±È';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".start_time IS '¼Æ»®¿ªÊ¼Ê±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".stop_time IS '¼Æ»®½áÊøÊ±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".create_time IS '´´½¨Ê±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".create_user_id IS '´´½¨ÈËid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".create_user_name IS '´´½¨ÈËÃû';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".old_row IS 'Ô­²ã';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".old_col IS 'Ô­ÁÐ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".old_addres_num IS 'Ô­¿âλ±àºÅ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".new_row IS 'вã';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".new_col IS 'ÐÂÁÐ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".new_addres_num IS 'пâλ±àºÅ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Plan_Table + ".plan_state IS '¼Æ»®×´Ì¬£º0δ¿ªÊ¼£¬1½øÐÐÖУ¬2Íê³É£¬3ʧ°Ü';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createMon_Inf_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Mon_Inf_Table + " "
                            + "( mon_id character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '2011'::character varying," + 
                            "    batt_type character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'ǦËá·§¿ØÐîµç³Ø'::character varying," + 
                            "    mon_vol integer NOT NULL DEFAULT 2," + 
                            "    mon_model character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'ÀíÊ¿'::character varying," + 
                            "    mon_inuse_year integer NOT NULL DEFAULT 2," + 
                            "    mon_cap double precision NOT NULL DEFAULT '300'::double precision," + 
                            "    product_time date NOT NULL DEFAULT '2024-01-01'::date," + 
                            "    mon_type character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'A'::character varying," + 
                            "    local_row character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    local_col character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    addres_num character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1'::character varying," + 
                            "    laid_up_time date NOT NULL DEFAULT '2024-01-01'::date" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Mon_Inf_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".mon_id IS 'µ¥Ìå±àºÅ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".batt_type IS 'µ¥ÌåÀàÐÍ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".mon_vol IS '±ê³Æµçѹ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".mon_model IS 'µ¥Ì寷ů';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".mon_inuse_year IS 'ʹÓÃÄêÏÞ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".mon_cap IS '±ê³ÆÈÝÁ¿';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".product_time IS '³ö³¡ÈÕÆÚ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".mon_type IS '¿âλÀàÐÍ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".local_row IS '²ã';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".local_col IS 'ÁÐ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".addres_num IS '¿âλ±àºÅ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Mon_Inf_Table + ".laid_up_time IS 'Èë¿âʱ¼ä';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createDb_Batt(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE SCHEMA IF NOT EXISTS " + Sql_Mysql.DB_BATT + " AUTHORIZATION sysdba");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}