蓄电池监控管理平台数据库初始化程序
DELL
2024-09-25 36deaf5ab0fc4390aba3a9407ff82984a0feee11
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
package com.database_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_Ied_Scout {
    public static void init(MysqlConnPool pool, boolean recreate) {
        System.out.println(" db_ied_scout init start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        
        createDB_IED_SCOUT(pool);
        
        createConnect_Inf_Table(pool, recreate);        //´´½¨IED Scout ÅäÖÃÐÅÏ¢±í
 
        createIed_NodeState_Table(pool, recreate);        //´´½¨IED Scout ÊµÊ±×´Ì¬ÐÅÏ¢±í
        
        System.out.println(" db_ied_scout init end at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
    }
    
    /**
     *     ´´½¨     db_ied_scout Êý¾Ý¿â
     * @param pool
     */
    public static void createDB_IED_SCOUT(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_IED_SCOUT);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ´´½¨ tb_connect_inf ±í
     * @param pool
     * @param recreate
     */
    public static void createConnect_Inf_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Connect_Inf_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Connect_Inf_Table + " (" + 
                "  `num` bigint(20) NOT NULL COMMENT 'Ö÷¼ü'," + 
                "  `target_ip` varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT 'Ä¿±êIPµØÖ·'," + 
                "  `target_port` int(11) NOT NULL DEFAULT '102' COMMENT 'Ä¿µÄ¶Ë¿ÚºÅ'," + 
                "  `target_icd` varchar(255) NOT NULL DEFAULT '' COMMENT 'Ä¿µÄÉ豸icdÎļþ·¾¶'," + 
                "  `conn_st` int(11) NOT NULL DEFAULT '0' COMMENT 'Á¬½Ó״̬0-ĬÈÏ  1-¿ªÊ¼Á¬½Ó[ƽ̨ÉèÖÃ]  2-Á¬½ÓÖР  3-Á¬½Ó³É¹¦  4-Á¬½Óʧ°Ü'," + 
                "  `fail_reasion` int(11) NOT NULL DEFAULT '0' COMMENT 'ʧ°ÜÔ­Òò£º0-ÎÞ  1-ICDÎļþ²»´æÔÚ  2-ICDÎļþ²»Æ¥Åä'," + 
                "  `comm_num` bigint(20) NOT NULL DEFAULT '0' COMMENT 'ͨÐżÆÊý'," + 
                "  `error_num` bigint(20) NOT NULL DEFAULT '0' COMMENT 'ͨÐÅ´íÎó¼ÆÊý'," + 
                "  PRIMARY KEY (`num`)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='IED_Scout Á¬½ÓÅäÖÃÐÅÏ¢±í';";
        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();
        }
    }
    
    /**
     *     ´´½¨ tb_ied_nodestate ±í
     * @param pool
     * @param recreate
     */
    public static void createIed_NodeState_Table(MysqlConnPool pool, boolean recreate) {
        String sql_str01 = " DROP TABLE IF EXISTS "+Sql_Mysql.Ied_NodeState_Table;
        String sql_str02 = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Ied_NodeState_Table + " (" + 
                " `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '×ÔÔöÖ÷¼ü'," + 
                "  `node_path` varchar(255) CHARACTER SET gbk NOT NULL DEFAULT '' COMMENT '½Úµã·¾¶'," + 
                "  `node_name` varchar(255) CHARACTER SET gbk NOT NULL DEFAULT '' COMMENT '½ÚµãÖÐÎÄÃû³Æ'," + 
                "  `node_value` float NOT NULL DEFAULT '0' COMMENT '½ÚµãÖµ'," + 
                "  PRIMARY KEY (`num`)," + 
                "  UNIQUE KEY `index_node_path` (`node_path`) USING BTREE" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='IED Scout ÊµÊ±×´Ì¬ÐÅÏ¢±í';";
        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();
        }
    }
}