蓄电池监控管理平台数据库初始化程序
DELL
2024-04-01 e14cf75ccba4797d388492252e168994a5bc46fc
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
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_User {
    public static void init(MysqlConnPool pool, boolean recreate) {
        System.out.println(" db_user init start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        
        createDB_User(pool);
        
 
        createOperation_Log_Table(pool, recreate);//´´½¨±ítb_ckpowerdev_alarm
 
        createUser_Inf_Table(pool, recreate);//´´½¨±ítb_ckpowerdev_alarm
 
        createTemp_Numbers_Table(pool, recreate);//´´½¨±ítb_ckpowerdev_alarm
        
 
        System.out.println(" db_user init end at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
    }
    
    /**
     *     ´´½¨     db_user Êý¾Ý¿â
     * @param pool
     */
    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();
        }
    }
    
    /**
     * 
     * @Title: createOperation_Log_Table
     * @Description: ½¨±ítb_operation_log
     * @param pool
     * @param recreate
     * @author author
     * @date 2024Äê4ÔÂ1ÈÕ
     */
    private 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 AUTO_INCREMENT=1468 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();
        }
    }
    /**
     * 
     * @Title: createUser_Inf_Table
     * @Description: ½¨±ítb_user_inf
     * @param pool
     * @param recreate
     * @author author
     * @date 2024Äê4ÔÂ1ÈÕ
     */
    private 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(255) NOT NULL DEFAULT '0' COMMENT 'Óû§ÃÜÂë'," + 
                "  `udownload_role` int(16) NOT NULL DEFAULT '0' COMMENT 'ÏÂÔØÈ¨ÏÞ'," + 
                "  PRIMARY KEY (`uid`)" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=1012 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();
        }
    }
    /**
     * 
     * @Title: createTemp_Numbers_Table
     * @Description: ½¨±ítemp_numbers
     * @param pool
     * @param recreate
     * @author author
     * @date 2024Äê4ÔÂ1ÈÕ
     */
    private 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();
        }
    }
    
}