蓄电池监控管理平台数据库初始化程序
DELL
2025-03-28 5a8cd947851876593142b5175c517bfe22e28a42
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
package com.sql.util;
 
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class Db_User {
    public static void init(MysqlConnPool pool) {
        createDb_User(pool);
        
        createOperation_Log_Table(pool);
        
        createTemp_Numbers_Table(pool);
 
        createUser_Inf_Table(pool);
        
        
    } 
    
    
    public static void createDb_User(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE SCHEMA IF NOT EXISTS " + Sql_Mysql.DB_USER + " AUTHORIZATION sysdba");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    
    /**
     *     ´´½¨ db_user.operation_log Êý¾Ý¿â±í
     * @param conn
     */
    public static void createOperation_Log_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Operation_Log_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.Operation_Log_Table + " "
                    + "(num integer NOT NULL DEFAULT nextval('" + Sql_Mysql.Operation_Log_Table + "_auto'::regclass)," + 
                    "    user_id integer NOT NULL DEFAULT 1001," + 
                    "    user_name character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'lxw'::character varying," + 
                    "    type1 integer NOT NULL DEFAULT 1," + 
                    "    type2 integer NOT NULL DEFAULT 2," + 
                    "    msg character varying(1000) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'µÇ¼'::character varying," + 
                    "    detail character varying(1000) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT ''::character varying," + 
                    "    ip character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '192.168.10.1'::character varying," + 
                    "    create_time timestamp without time zone NOT NULL," + 
                    "     PRIMARY KEY (num)" + 
                    ")";
            sql.sqlMysqlExecute(sql_str);
            
            sql.sqlMysqlExecute("ALTER    TABLE " + Sql_Mysql.Operation_Log_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".num IS 'Ö÷¼ünum';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".user_id IS 'Óû§id';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".user_name IS 'Óû§Ãû';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".type1 IS 'ʼþÀàÐÍ:1-ϵͳ¼¶,2-ÒµÎñ¼¶';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".type2 IS 'ʼþÀàÐÍ:×Ó¼¶±ð';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".msg IS '»ù´¡ÐÅÏ¢';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".detail IS 'ÏêϸÐÅÏ¢';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".ip IS '²Ù×÷µÄip';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Operation_Log_Table + ".create_time IS '´´½¨Ê±¼ä';");
            
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ´´½¨ db_user.temp_numbers Êý¾Ý¿â±í
     * @param conn
     */
    public static void createTemp_Numbers_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Temp_Numbers_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.Temp_Numbers_Table + " "
                    + "(unumber integer" + 
                    ")";
            sql.sqlMysqlExecute(sql_str);
            
            
            sql.sqlMysqlExecute("ALTER    TABLE " + Sql_Mysql.Temp_Numbers_Table + " OWNER TO sysdba;");
            
            
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
 
    /**
     *     ´´½¨ db_user.user_inf Êý¾Ý¿â±í
     * @param conn
     */
    public static void createUser_Inf_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.User_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.User_Inf_Table + " "
                    + "(uid bigint NOT NULL DEFAULT nextval('" + Sql_Mysql.User_Inf_Table + "_auto'::regclass)," + 
                    "    usnid character varying(1000) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '123456'::character varying," + 
                    "    uname character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT 'lxw'::character varying," + 
                    "    udownload_role integer NOT NULL DEFAULT 0," + 
                    "    role_id character varying(32) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT '1002'::character varying," + 
                    "     PRIMARY KEY (uid)" + 
                    ")";
            sql.sqlMysqlExecute(sql_str);
            
            sql.sqlMysqlExecute("ALTER    TABLE " + Sql_Mysql.User_Inf_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.User_Inf_Table + ".uid IS 'Óû§id';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.User_Inf_Table + ".usnid IS 'rsa¼ÓÃÜÃÜÂë';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.User_Inf_Table + ".uname IS 'Óû§Ãû';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.User_Inf_Table + ".udownload_role IS 'ÏÂÔØÈ¨ÏÞ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.User_Inf_Table + ".role_id IS 'Óû§Éí·Ý£¨1001ÆÕͨÓû§£¬1002¹ÜÀíÔ±£©';");
            
            sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.User_Inf_Table + " ADD COLUMN IF NOT EXISTS role_id VARCHAR not null DEFAULT '1001';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}