蓄电池监控管理平台数据库初始化程序
DELL
2024-11-05 578a33144c0435f7479535e540a7e60622e4b232
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
package com.database_util;
 
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class DB_User {
    
    public static void init(MysqlConnPool pool, boolean recreate) {
        //´´½¨Êý¾Ý¿â
        createDB_User(pool);
        
        createBaoJiGroup_Table(pool, recreate);
 
        createBattGroup_BaoJiGroup_Table(pool, recreate);
        
        createBattGroup_Usr_Table(pool, recreate);
        
        createOperation_Log_Table(pool, recreate);
        
        createUser_Inf_Table(pool, recreate);
        
        createTemp_Numbers_Table(pool, recreate);
    }
    
    /**
     *    ´´½¨ tb_baojigroup
     * @param pool
     * @param recreate
     */
    public static void createBaoJiGroup_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.BaoJiGroup_Table;
        String sql_str02 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BaoJiGroup_Table + " (" + 
                "  `num` int(20) NOT NULL AUTO_INCREMENT," + 
                "  `baoji_group_id` int(20) DEFAULT '0'," + 
                "  `baoji_group_name` varchar(200) NOT NULL DEFAULT '0'," + 
                "  PRIMARY KEY (`num`)" + 
                ") 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_battgroup_baojigroup
     * @param pool
     * @param recreate
     */
    public static void createBattGroup_BaoJiGroup_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.BattGroup_BaoJiGroup_Table;
        String sql_str02 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BattGroup_BaoJiGroup_Table + " (" + 
                "  `num` bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  `baoji_group_id` int(11) NOT NULL DEFAULT '0'," + 
                "  `dev_id` int(11) NOT NULL DEFAULT '0'," + 
                "  PRIMARY KEY (`num`)," + 
                "  KEY `index_group_id` (`baoji_group_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_battgroup_usr
     * @param pool
     * @param recreate
     */
    public static void createBattGroup_Usr_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.BattGroup_Usr_Table;
        String sql_str02 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.BattGroup_Usr_Table + " (" + 
                "  `num` bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  `baoji_group_id` int(11) NOT NULL DEFAULT '0'," + 
                "  `uid` int(11) NOT NULL DEFAULT '0'," + 
                "  PRIMARY KEY (`num`)," + 
                "  KEY `index_group_id` (`baoji_group_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_operation_log
     * @param pool
     * @param recreate
     */
    public static void createOperation_Log_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Operation_Log_Table;
        String sql_str02 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Operation_Log_Table + " (" + 
                "  `id` int(11) NOT NULL AUTO_INCREMENT," + 
                "  `user_id` int(11) DEFAULT NULL," + 
                "  `user_name` varchar(45) DEFAULT NULL," + 
                "  `type1` int(11) DEFAULT NULL COMMENT 'ʼþÀàÐÍ:1-ϵͳ¼¶,2-ÒµÎñ¼¶'," + 
                "  `type2` int(11) DEFAULT NULL COMMENT 'ʼþÀàÐÍ:×Ó¼¶±ð'," + 
                "  `msg` varchar(45) DEFAULT NULL COMMENT '»ù´¡ÐÅÏ¢'," + 
                "  `detail` varchar(21000) DEFAULT NULL COMMENT 'ÏêϸÐÅÏ¢'," + 
                "  `ip` varchar(45) DEFAULT NULL COMMENT '²Ù×÷µÄip'," + 
                "  `create_time` datetime DEFAULT NULL," + 
                "  PRIMARY KEY (`id`)" + 
                ") 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();
        }
    }
    
    /**
     *    ´´½¨ tb_user_inf
     * @param pool
     * @param recreate
     */
    public static void createUser_Inf_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.User_Inf_Table;
        String sql_str02 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.User_Inf_Table + " (" + 
                "  `uid` int(11) NOT NULL AUTO_INCREMENT," + 
                "  `uname` varchar(64) NOT NULL DEFAULT '0' COMMENT 'Óû§Ãû×Ö'," + 
                "  `usnid` varchar(1000) NOT NULL DEFAULT '0' COMMENT 'Óû§ÃÜÂë'," + 
                "  `udownload_role` int(16) NOT NULL DEFAULT '0' COMMENT 'ÏÂÔØÈ¨ÏÞ'," + 
                "  PRIMARY KEY (`uid`)" + 
                ") 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();
        }
    }
    
    /**
     *    ´´½¨ temp_numbers
     * @param pool
     * @param recreate
     */
    public static void createTemp_Numbers_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Temp_Numbers_Table;
        String sql_str02 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Temp_Numbers_Table + " (" + 
                "  `unumber` int(11) DEFAULT NULL" + 
                ") 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();
        }
    }
    
    
    
    public static void createDB_User(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_USER);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}