蓄电池监控管理平台数据库初始化程序
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
158
159
160
161
162
163
164
165
166
167
168
169
package com.database_util;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
 
import com.base.Com;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class DB_Ckpwrdev_Inf {
    public static void init(MysqlConnPool pool, boolean recreate) {
        System.out.println(" db_ckpwrdev_inf init start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        
        createDB_Ckpwrdev_Inf(pool);
        
 
        createBreaker_Inf_Table(pool, recreate);//´´½¨±ítb_ckpowerdev_alarm
        
        createCkpwrdev_Inf_Table(pool, recreate);//´´½¨±ítb_ckpowerdev_alarm
 
        createGateway_Inf_Table(pool, recreate);
 
        System.out.println(" db_ckpwrdev_inf init end at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
    }
    
    /**
     *     ´´½¨     db_ckpwrdev_alarm Êý¾Ý¿â
     * @param pool
     */
    public static void createDB_Ckpwrdev_Inf(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_CkpwrDev_Inf);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     * 
     * @Title: createBreaker_Inf_Table
     * @Description: ½¨±ítb_breaker_inf
     * @param pool
     * @param recreate
     * @author author
     * @date 2024Äê4ÔÂ1ÈÕ
     */
    private static void createBreaker_Inf_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Breaker_Inf_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Breaker_Inf_Table + " (" + 
                "  `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '×ÔÔöÖ÷¼ü'," + 
                "  `breaker_id` int(11) NOT NULL COMMENT '¶Ï·Æ÷id'," + 
                "  `breaker_type` varchar(255) NOT NULL COMMENT '¶Ï·Æ÷Àà±ð[1-½»Á÷΢¶Ï·Æ÷  2-Ö±Á÷΢¶Ï·Æ÷]'," + 
                "  `breaker_name` varchar(255) NOT NULL COMMENT '¿ª¹ØÃû³Æ'," + 
                "  `breaker_addr` varchar(255) NOT NULL COMMENT 'ËùÔÚλÖÃ'," + 
                "  `breaker_level` int(11) NOT NULL DEFAULT '1' COMMENT '¼«Êý[1-1P    2-2P   3-3P.....]'," + 
                "  `breaker_curr` int(11) NOT NULL DEFAULT '0' COMMENT '±£»¤µçÁ÷'," + 
                "  `gateway_id` int(255) NOT NULL DEFAULT '0' COMMENT 'ËùÔÚÍø¹Ø'," + 
                "  `node_name` varchar(255) NOT NULL DEFAULT '' COMMENT '[ÌøÕ¢]¶ÔÓ¦Êý¾Ý¿â×Ö¶ÎÃû³Æ'," + 
                "  `node_bit` int(11) NOT NULL DEFAULT '0' COMMENT '[ÌøÕ¢]µ±Ç°×Ö¶ÎÖÐʹÓõĵڼ¸Î»[0,1,2,3,...]'," + 
                "  `switch_node_name` varchar(255) NOT NULL DEFAULT '' COMMENT '¶Ï·Æ÷·ÖºÏÕ¢¶ÔÓ¦Êý¾Ý¿â×Ö¶ÎÃû³Æ'," + 
                "  `switch_node_bit` int(11) NOT NULL DEFAULT '0' COMMENT '¶Ï·Æ÷·ÖºÏÕ¢¶ÔӦλ'," + 
                "  PRIMARY KEY (`num`)," + 
                "  UNIQUE KEY `idx_breaker_id` (`breaker_id`) USING BTREE" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=37 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: createCkpwrdev_Inf_Table
     * @Description: ½¨±ítb_ckpwrdev_inf
     * @param pool
     * @param recreate
     * @author author
     * @date 2024Äê4ÔÂ1ÈÕ
     */
    private static void createCkpwrdev_Inf_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Ckpwrdev_Inf_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Ckpwrdev_Inf_Table + " (" + 
                "  `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '×ÔÔöÖ÷¼ü'," + 
                "  `power_device_id` int(11) NOT NULL DEFAULT '0' COMMENT 'µçÔ´ID'," + 
                "  `power_device_ip` varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT '²â¿ØµçÔ´ipµØÖ·'," + 
                "  `batt_moncount` int(11) NOT NULL DEFAULT '24' COMMENT 'ºËÈÝÉ豸ʹÓõ¥ÌåÊýÄ¿'," + 
                "  PRIMARY KEY (`num`)," + 
                "  UNIQUE KEY `idx_power_device_id` (`power_device_id`) USING BTREE" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='²â¿ØµçÔ´ÐÅÏ¢±í';";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        try {
            if(true == recreate) {            
                sql.sqlMysqlExecute(sql_str01);
            }
            sql.sqlMysqlExecute(sql_str02);    
            
            //ÐÂÔö×Ö¶Îpwr_dev_ip
            res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
                    + " WHERE table_schema='db_ckpwrdev_inf'"
                    + " AND table_name='tb_ckpwrdev_inf'"
                    + " AND column_name='pwr_dev_ip'");
            if(!res.next()) {
                //ÐÞ¸Ä×Ö¶Îst
                sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.Ckpwrdev_Inf_Table 
                        + " ADD column `pwr_dev_ip` varchar(64) NOT NULL DEFAULT '127.0.0.1' COMMENT '×Ͼ§61850ЭתIPµØÖ·';");
            }
            
            //ÐÂÔö×Ö¶Îzjdy_record__time
            res = sql.sqlMysqlQuery("SELECT * FROM information_schema.columns"
                    + " WHERE table_schema='db_ckpwrdev_inf'"
                    + " AND table_name='tb_ckpwrdev_inf'"
                    + " AND column_name='zjdy_record__time'");
            if(!res.next()) {
                //ÐÞ¸Ä×Ö¶Îst
                sql.sqlMysqlExecute("ALTER TABLE " + Sql_Mysql.Ckpwrdev_Inf_Table 
                        + " ADD column `zjdy_record__time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '×Ͼ§µçԴЭתÊý¾Ý¸üÐÂʱ¼ä';");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     * 
     * @Title: createGateway_Inf_Table
     * @Description: ½¨±ítb_gateway_inf
     * @param pool
     * @param recreate
     * @author author
     * @date 2024Äê4ÔÂ1ÈÕ
     */
    private static void createGateway_Inf_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Gateway_Inf_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Gateway_Inf_Table + " (" + 
                "  `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '×ÔÔöÖ÷¼ü'," + 
                "  `gateway_id` int(11) NOT NULL DEFAULT '10001' COMMENT 'Íø¹Øid'," + 
                "  `gateway_type` varchar(255) NOT NULL DEFAULT '0' COMMENT 'Íø¹ØÀà±ð[1-½»Á÷Íø¹Ø  2-Ö±Á÷Íø¹Ø]'," + 
                "  `gateway_name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Íø¹ØÃû³Æ'," + 
                "  `comm_type` varchar(255) NOT NULL DEFAULT 'RS485' COMMENT 'ͨÐÅÀàÐÍ'," + 
                "  `ip_addr` varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT 'IPµØÖ·'," + 
                "  `join_count` int(11) NOT NULL DEFAULT '0' COMMENT '½ÓÈëÉ豸ÊýÁ¿'," + 
                "  PRIMARY KEY (`num`)," + 
                "  UNIQUE KEY `idx_gateway_id` (`gateway_id`) USING BTREE" + 
                ") ENGINE=InnoDB 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();
        }
    }
}