蓄电池监控管理平台数据库初始化程序
DELL
2024-12-12 690f171908a15508049251d7489f8ce519b54a8f
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
package com.sql.util;
 
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class Db_Param {
    public static void init(MysqlConnPool pool) {
        createDb_Param(pool);
        
        createBattAlarm_Param_Table(pool);
        
        createPowerAlarm_param_Table(pool);
    }
    
    public static void createPowerAlarm_param_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.PowerAlarm_param_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.PowerAlarm_param_Table + " "
                            + "(num bigint NOT NULL DEFAULT nextval('" + Sql_Mysql.PowerAlarm_param_Table + "_auto'::regclass)," + 
                            "    alm_id integer NOT NULL DEFAULT 1," + 
                            "    alm_level integer NOT NULL DEFAULT 1," + 
                            "    alm_en integer NOT NULL DEFAULT 1," + 
                            "     PRIMARY KEY (num)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.PowerAlarm_param_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.PowerAlarm_param_Table + ".num IS '×ÔÔöÖ÷¼ü';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.PowerAlarm_param_Table + ".alm_id IS 'µçÔ´¸æ¾¯ID';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.PowerAlarm_param_Table + ".alm_level IS '¸æ¾¯µÈ¼¶';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.PowerAlarm_param_Table + ".alm_en IS '¸æ¾¯Ê¹ÄÜ[0-½ûÓà 1-ÆôÓÃ]';");
            sql.sqlMysqlExecute("COMMENT ON   TABLE " + Sql_Mysql.PowerAlarm_param_Table + " IS 'µçÔ´¸æ¾¯²ÎÊý±í';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createBattAlarm_Param_Table(MysqlConnPool pool)
    {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.BattAlarm_Param_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.BattAlarm_Param_Table + " "
                            + "(num integer NOT NULL DEFAULT nextval('" + Sql_Mysql.BattAlarm_Param_Table + "_auto'::regclass)," + 
                            "    alm_id integer NOT NULL DEFAULT 0," + 
                            "    alm_name character varying(50) NOT NULL COLLATE pg_catalog.\"default\" DEFAULT ' '::character varying," + 
                            "    alm_high_coe double precision NOT NULL DEFAULT '0'::double precision," + 
                            "    alm_low_coe double precision NOT NULL DEFAULT '0'::double precision," + 
                            "    alm_high_level integer NOT NULL DEFAULT 0," + 
                            "    alm_low_level integer NOT NULL DEFAULT 0," + 
                            "    alm_high_en integer NOT NULL DEFAULT 0," + 
                            "    alm_low_en integer NOT NULL DEFAULT 0," + 
                            "     PRIMARY KEY (num)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.BattAlarm_Param_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_id IS '¸æ¾¯id';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_name IS '¸æ¾¯Ãû³Æ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_high_coe IS 'ÉÏÏ޸澯ãÐÖµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_low_coe IS 'ÏÂÏ޸澯ãÐÖµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_high_level IS 'ÉÏÏ޸澯µÈ¼¶';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_low_level IS 'ÏÂÏ޸澯µÈ¼¶';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_high_en IS 'ÉÏÏ޸澯ʹÄÜ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.BattAlarm_Param_Table + ".alm_low_en IS 'ÏÂÏ޸澯ʹÄÜ';");
            sql.sqlMysqlExecute("COMMENT ON   TABLE " + Sql_Mysql.BattAlarm_Param_Table + " IS 'µç³Ø¸æ¾¯²ÎÊý±í';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    public static void createDb_Param(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE SCHEMA IF NOT EXISTS " + Sql_Mysql.DB_PARAM + " AUTHORIZATION sysdba");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}