蓄电池监控管理平台数据库初始化程序
Administrator
2021-08-17 8db779331bf6cdeacaa95d61ac1c38cc3635791c
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package com.database_util;
 
import java.sql.ResultSet;
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class DB_App_Sys {
 
    public static void init(MysqlConnPool pool, boolean recreate) {
        createDB_AppSys(pool);
        
        createPage_Param_Table(pool, recreate);
        
        createFbsdev_Statechange_Inf_Table(pool, recreate);
        
        createDashboard_Module_Chart_Table(pool, recreate);
        
        createDashboard_Module_Table(pool, recreate);
        
        createDashboard_Chart_Type_Table(pool, recreate);
        
        createApp_Sys_Table(pool, recreate);
        
        createApp_Bts_Comm_Task_Table(pool, recreate);
        
        createApp_Bts_Battgroup_Table(pool, recreate);
        
        createMenu_Table(pool, recreate);
        
    }
    
    /**
     *     ´´½¨     db_app_sys Êý¾Ý¿â
     * @param pool
     */
    public static void createDB_AppSys(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_AppSys);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ´´½¨ tb_page_param ±í
     * @param pool
     * @param recreate
     */
    public static void createPage_Param_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Page_Param_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Page_Param_Table + " (" + 
                "  id int(11) NOT NULL AUTO_INCREMENT," + 
                "  param varchar(30) DEFAULT NULL COMMENT '¾ßÌå²ÎÊý'," + 
                "  status int(1) DEFAULT NULL COMMENT '²ÎÊýÊÇ·ñÒ³ÃæÏÔʾ'," + 
                "  categoryId int(1) DEFAULT NULL COMMENT '²ÎÊý·ÖÀà,ÀàÄ¿1,ÀàÄ¿2'," + 
                "  PRIMARY KEY (id) USING BTREE" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;";
        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();
        }
    }
    
    /**
     *     ´´½¨ tb_fbsdev_statechange_inf ±í
     * @param pool
     * @param recreate
     */
    public static void createFbsdev_Statechange_Inf_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Fbsdev_Statechange_Inf_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Fbsdev_Statechange_Inf_Table + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  dev_id int(11) NOT NULL DEFAULT '0'," + 
                "  rec_time datetime NOT NULL DEFAULT '1980-01-01 00:00:00'," + 
                "  last_stat int(11) NOT NULL DEFAULT '0'," + 
                "  now_stat int(11) NOT NULL DEFAULT '0'," + 
                "  state_change_reason int(11) NOT NULL DEFAULT '0'," + 
                "  dev_alarm int(11) NOT NULL DEFAULT '0'," + 
                "  eve_type int(11) NOT NULL DEFAULT '0'," + 
                "  module_num int(11) NOT NULL DEFAULT '0'," + 
                "  PRIMARY KEY (num)," + 
                "  KEY index_dev_id (dev_id)" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
        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();
        }
    }
    
    
    /**
     *     ´´½¨ tb_dashboard_module_chart ±í
     * @param pool
     * @param recreate
     */
    public static void createDashboard_Module_Chart_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Dashboard_Module_Chart_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Dashboard_Module_Chart_Table + " (" + 
                "  id int(11) NOT NULL AUTO_INCREMENT," + 
                "  module_id int(11) NOT NULL DEFAULT '0' COMMENT 'Ä£¿éid'," + 
                "  title varchar(255) NOT NULL DEFAULT ''," + 
                "  label varchar(20) NOT NULL DEFAULT ''," + 
                "  type_id int(11) NOT NULL DEFAULT '1' COMMENT 'ͼ±êÀàÐÍ:1.ºáÏòÖù״ͼ;2.ÊúÏòÖù״ͼ;3.ÕÛÏßͼ;4.±ýͼ'," + 
                "  page_id int(11) NOT NULL DEFAULT '1' COMMENT 'Ò³Ãæid'," + 
                "  PRIMARY KEY (id) USING BTREE" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;";
        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();
        }
    }
    
    /**
     *     ´´½¨ tb_dashboard_module ±í
     * @param pool
     * @param recreate
     */
    public static void createDashboard_Module_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Dashboard_Module_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Dashboard_Module_Table + " (" + 
                "  id int(11) NOT NULL AUTO_INCREMENT," + 
                "  x int(11) DEFAULT NULL DEFAULT '1' COMMENT 'x×ø±ê'," + 
                "  y int(11) DEFAULT NULL DEFAULT '0' COMMENT 'y×ø±ê'," + 
                "  w int(11) DEFAULT NULL DEFAULT '0' COMMENT '¿í¶È'," + 
                "  h int(11) DEFAULT NULL DEFAULT '0' COMMENT '¸ß¶È'," + 
                "  module_id int(11) DEFAULT '0' COMMENT 'Ä£¿éId'," + 
                "  title varchar(255) DEFAULT '' COMMENT 'Ä£¿é±êÌâ'," + 
                "  label varchar(255) DEFAULT '' COMMENT 'Ó¢ÎÄ'," + 
                "  type varchar(20) DEFAULT '' COMMENT 'ͼ±êÀàÐÍ:1.ºáÏòÖù״ͼ;2.ÊúÏòÖù״ͼ;3.ÕÛÏßͼ;4.±ýͼ'," + 
                "  page_id int(11) DEFAULT '0' COMMENT 'Ò³ÃæId'," + 
                "  user_id int(11) DEFAULT '0' COMMENT 'ËùÊôÓû§'," + 
                "  PRIMARY KEY (id) USING BTREE" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        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();
        }
    }
    
    /**
     *     ´´½¨ tb_dashboard_chart_type ±í
     * @param pool
     * @param recreate
     */
    public static void createDashboard_Chart_Type_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Dashboard_Chart_Type_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Dashboard_Chart_Type_Table + " (" + 
                "  id int(11) NOT NULL AUTO_INCREMENT," + 
                "  type_id int(11) DEFAULT '1'," + 
                "  type_name varchar(20) DEFAULT ''," + 
                "  PRIMARY KEY (id) USING BTREE" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;";
        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();
        }
    }
    
    /**
     *     ´´½¨ tb_app_sys ±í
     * @param pool
     * @param recreate
     */
    public static void createApp_Sys_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.App_Sys_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.App_Sys_Table + " (" + 
                "  num int(11) NOT NULL AUTO_INCREMENT," + 
                "  SqlDB_Version float NOT NULL DEFAULT '1'," + 
                "  SqlDB_BackUpTime datetime NOT NULL DEFAULT '2000-01-01 00:00:00'," + 
                "  SqlDB_BackUpManual_EN tinyint(1) NOT NULL DEFAULT '0'," + 
                "  AppServer_Reinit_BattGroupData_EN tinyint(1) NOT NULL DEFAULT '0'," + 
                "  AppServer_Reinit_BattGroupData_LD9_EN tinyint(1) NOT NULL DEFAULT '0'," + 
                "  AppServer_Reinit_BattGroupData_A059_EN tinyint(1) NOT NULL DEFAULT '0'," + 
                "  AppServer_Reinit_Config_EN tinyint(1) NOT NULL DEFAULT '0'," + 
                "  AppServer_Version float NOT NULL DEFAULT '1'," + 
                "  AppClient_Version float NOT NULL DEFAULT '1'," + 
                "  AppName varchar(50) NOT NULL DEFAULT '0'," + 
                "  PRIMARY KEY (num)" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        try {
            if(true == recreate) {            
                sql.sqlMysqlExecute(sql_str01);
            }
            sql.sqlMysqlExecute(sql_str02);    
            //Ìí¼Ó³ä·ÅµçÒ»Ìå»úÐîµç³Ø×é¼Èë״̬
            res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
                    + " WHERE table_schema='db_app_sys'"
                    + " AND table_name='tb_app_sys'"
                    + " AND column_name='AppServer_Reinit_BattGroupData_A059_EN'");
            if(false == res.next()) {
                sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.App_Sys_Table 
                                + " ADD COLUMN AppServer_Reinit_BattGroupData_A059_EN tinyint(1) NOT NULL DEFAULT '0';");
            }
            
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ´´½¨ tb_app_bts_comm_task ±í
     * @param pool
     * @param recreate
     */
    public static void createApp_Bts_Comm_Task_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.App_Bts_Comm_Task_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.App_Bts_Comm_Task_Table + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  thread_id bigint(20) NOT NULL DEFAULT '0'," + 
                "  dev_id bigint(20) NOT NULL DEFAULT '0'," + 
                "  dev_mcu_uid varchar(48) NOT NULL DEFAULT 'null'," + 
                "  battgroup_cnt int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_id1 int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_index1 int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_id2 int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_index2 int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_id3 int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_index3 int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_id4 int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_index4 int(11) NOT NULL DEFAULT '0'," + 
                "  connet_time varchar(20) NOT NULL DEFAULT '1980-01-01 01:01:00'," + 
                "  dev_comm_runtime varchar(20) NOT NULL DEFAULT '1980-01-01 01:01:00'," + 
                "  break_type int(11) NOT NULL DEFAULT '0'," + 
                "  PRIMARY KEY (num)," + 
                "  KEY index_dev_id_uniq (dev_id)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        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();
        }
    }
    
    /**
     *     ´´½¨ tb_app_bts_battgroup ±í
     * @param pool
     * @param recreate
     */
    public static void createApp_Bts_Battgroup_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.App_Bts_Battgroup_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.App_Bts_Battgroup_Table + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  dev_id bigint(20) NOT NULL DEFAULT '0'," + 
                "  battgroup_id int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_index int(11) NOT NULL DEFAULT '-1'," + 
                "  battgroup_mon_cnt int(11) NOT NULL DEFAULT '0'," + 
                "  battgroup_float_vol float NOT NULL DEFAULT '0'," + 
                "  battgroup_float_curr float NOT NULL DEFAULT '0'," + 
                "  battgroup_register_code varchar(48) NOT NULL DEFAULT 'null'," + 
                "  PRIMARY KEY (num)" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;";
        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();
        }
    }
    
    /**
     *     ´´½¨ tb_menu ±í
     * @param pool
     * @param recreate
     */
    public static void createMenu_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Menu_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Menu_Table + " (" + 
                "  `id` int(11) NOT NULL," + 
                "  `label` varchar(50) DEFAULT NULL COMMENT 'ÖÐÎÄÃû³Æ'," + 
                "  `name` varchar(100) DEFAULT NULL COMMENT 'Ãû³Æ'," + 
                "  `src` varchar(100) DEFAULT NULL COMMENT '·¾¶'," + 
                "  `icon` varchar(100) DEFAULT NULL COMMENT 'ͼ±ê'," + 
                "  `closable` tinyint(4) DEFAULT NULL COMMENT 'ÊÇ·ñ¿É¹Ø±Õ'," + 
                "  `enableduse` tinyint(4) DEFAULT NULL COMMENT 'ÊÇ·ñÆôÓÃ'," + 
                "  `permitName` varchar(100) DEFAULT NULL COMMENT 'ȨÏÞ'," + 
                "  `level` tinyint(4) DEFAULT NULL COMMENT '²Ëµ¥µÈ¼¶'," + 
                "  `ord` tinyint(4) DEFAULT NULL COMMENT 'ÅÅÐò'," + 
                "  `menuId` int(11) DEFAULT NULL COMMENT 'Éϼ¶²Ëµ¥id'," + 
                "  PRIMARY KEY (`id`)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        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();
        }
    }
}