蓄电池监控管理平台数据库初始化程序
DELL
2025-04-14 e96689d1c771081cba6a65a3330c19c701e088f8
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
package com.sql.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_Work {
    public static void init(MysqlConnPool pool) {
        System.out.println("Db_Work init Start " + Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms));
        
        createDb_Work(pool);
        
        createWorksheet_Link_Table(pool);
        
        createWorksheet_Main_Table(pool);
 
        System.out.println("Db_Work init End " + Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms));
    } 
    
    
    public static void createDb_Work(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE SCHEMA IF NOT EXISTS " + Sql_Mysql.DB_WORK + " AUTHORIZATION sysdba");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    
    /**
     *     ´´½¨ db_work.worksheet_link Êý¾Ý¿â±í
     * @param conn
     */
    public static void createWorksheet_Link_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Worksheet_Link_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.Worksheet_Link_Table + " "
                    + "(id integer NOT NULL DEFAULT nextval('" + Sql_Mysql.Worksheet_Link_Table + "_auto'::regclass)," + 
                    "    main_id integer," + 
                    "    parent_id integer," + 
                    "    deal_user_id integer," + 
                    "    deal_type integer," + 
                    "    deal_desc character varying(255) COLLATE pg_catalog.\"default\" DEFAULT NULL::character varying," + 
                    "    deal_reason character varying(255) COLLATE pg_catalog.\"default\" DEFAULT NULL::character varying," + 
                    "    link_file character varying(255) COLLATE pg_catalog.\"default\" DEFAULT NULL::character varying," + 
                    "    link_status integer," + 
                    "    enable_archive integer," + 
                    "    create_time timestamp without time zone NOT NULL," + 
                    "    deal_time timestamp without time zone NOT NULL," + 
                    "     PRIMARY KEY (id)" + 
                    ")";
            sql.sqlMysqlExecute(sql_str);
            
            sql.sqlMysqlExecute("ALTER    TABLE " + Sql_Mysql.Worksheet_Link_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".id IS 'Ö÷¼üid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".main_id IS 'Ö÷±íid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".parent_id IS '¸¸½Úµãid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".deal_user_id IS '´¦ÀíÈËid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".deal_type IS '´¦ÀíÀàÐÍ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".deal_desc IS '´¦ÀíÃèÊö';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".deal_reason IS '´¦ÀíÒâ¼û';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".link_file IS '½Úµã¸½¼þµÄÎļþ·¾¶';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".link_status IS '½Úµã״̬';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".enable_archive IS 'ÄÜ·ñ¹éµµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".create_time IS '½Úµã´´½¨Ê±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Link_Table + ".deal_time IS '½Úµã´¦Àíʱ¼ä';");
                
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
 
    
    /**
     *     ´´½¨ db_work.worksheet_main Êý¾Ý¿â±í
     * @param conn
     */
    public static void createWorksheet_Main_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Worksheet_Main_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.Worksheet_Main_Table + " "
                    + "(id integer NOT NULL DEFAULT nextval('" + Sql_Mysql.Worksheet_Main_Table + "_auto'::regclass)," + 
                    "    title character varying(255) NOT NULL COLLATE pg_catalog.\"default\"," + 
                    "    description character varying(255) COLLATE pg_catalog.\"default\" DEFAULT NULL::character varying," + 
                    "    file character varying(255) COLLATE pg_catalog.\"default\" DEFAULT NULL::character varying," + 
                    "    create_user_id integer NOT NULL," + 
                    "    begin_time timestamp without time zone NOT NULL," + 
                    "    end_time timestamp without time zone NOT NULL," + 
                    "    level integer," + 
                    "    status integer," + 
                    "    end_reason integer," + 
                    "    type integer," + 
                    "     PRIMARY KEY (id)" + 
                    ")";
            sql.sqlMysqlExecute(sql_str);
            
            sql.sqlMysqlExecute("ALTER    TABLE " + Sql_Mysql.Worksheet_Main_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".id IS 'Ö÷¼üid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".title IS '¹¤µ¥±êÌâ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".description IS 'ÈÎÎñÃèÊö';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".create_user_id IS '¹¤µ¥´´½¨ÈËid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".begin_time IS '¹¤µ¥¿ªÊ¼Ê±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".end_time IS '¹¤µ¥½áÊøÊ±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".level IS '¹¤µ¥¼¶±ð';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".status IS '¹¤µ¥×´Ì¬';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".end_reason IS '¹¤µ¥½áÊøÒâ¼û';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Worksheet_Main_Table + ".type IS '¹¤µ¥ÀàÐÍ';");
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}