蓄电池监控管理平台数据库初始化程序
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
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_Alarm {
 
    public static void init(MysqlConnPool pool) {
        System.out.println("Db_Alarm init Start " + Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms));
        
        createDb_Alarm(pool);
        
        createBatt_Alarm_Table(pool);
        
        System.out.println("Db_Alarm init End " + Com.getDateTimeFormat(new Date(),Com.DTF_YMDhms));
    } 
    
    
    public static void createDb_Alarm(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE SCHEMA IF NOT EXISTS " + Sql_Mysql.DB_ALARM + " AUTHORIZATION sysdba");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
    /**
     * ´´½¨ batt_alarm Êý¾Ý¿â±í
     * @param conn
     */
    public static void createBatt_Alarm_Table(MysqlConnPool pool)
    {
        
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            String sql_str_auto = "CREATE SEQUENCE IF NOT EXISTS " + Sql_Mysql.Batt_Alarm_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.Batt_Alarm_Table + " "
                            + "(num integer NOT NULL DEFAULT nextval('" + Sql_Mysql.Batt_Alarm_Table + "_auto'::regclass)," + 
                            "    binf_id integer NOT NULL DEFAULT 1," + 
                            "    alm_start_time timestamp without time zone NOT NULL DEFAULT '2000-01-01 00:00:00'::timestamp without time zone," + 
                            "    mon_num integer NOT NULL DEFAULT 0," + 
                            "    alm_id integer NOT NULL DEFAULT 0," + 
                            "    alm_level integer NOT NULL DEFAULT 0," + 
                            "    alm_value double precision NOT NULL DEFAULT '0'::double precision," + 
                            "    alm_confirm integer NOT NULL DEFAULT 0," + 
                            "    alm_confirm_time timestamp without time zone NOT NULL DEFAULT '2000-01-01 00:00:00'::timestamp without time zone," + 
                            "    alm_type integer NOT NULL DEFAULT 1," + 
                            "     PRIMARY KEY (num)" + 
                            ")";
            sql.sqlMysqlExecute(sql_str);
            sql.sqlMysqlExecute("ALTER  TABLE " + Sql_Mysql.Batt_Alarm_Table + " OWNER TO sysdba;");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".binf_id IS 'µç³Ø×éid';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".alm_start_time IS '¸æ¾¯¿ªÊ¼Ê±¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".mon_num IS '¸æ¾¯µ¥Ìå±àºÅ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".alm_id IS '¸æ¾¯ÀàÐÍ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".alm_level IS '¸æ¾¯µÈ¼¶';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".alm_value IS '¸æ¾¯Öµ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".alm_confirm IS 'È·ÈÏ';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".alm_confirm_time IS 'È·ÈÏʱ¼ä';");
            sql.sqlMysqlExecute("COMMENT ON COLUMN " + Sql_Mysql.Batt_Alarm_Table + ".alm_type IS '¸æ¾¯ÀàÐÍ[1-ÉÏÏ޸澯 2-ÏÂÏ޸澯]';");
            sql.sqlMysqlExecute("COMMENT ON   TABLE " + Sql_Mysql.Batt_Alarm_Table + " IS 'µç³ØÊµÊ±¸æ¾¯';");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    
}