蓄电池监控管理平台数据库初始化程序
DELL
2024-10-15 c194f0f65049346aa948e0c27e62ec936817c8e8
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
170
171
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_Dev_TestParam {
    public final static String Tb_Batt_TestParam_Table = "tb_batt_testparam_";
    
    
    
    public static void init(MysqlConnPool pool, boolean recreate) {
        System.out.println(" db_dev_testparam init start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        
        createDB_Dev_TESTPARAM(pool);
        
        createBatt_TestParam_Table(pool, recreate);            //´´½¨É豸ÀúÊ·²ÎÊý±íÓÃÓÚ´æ´¢´Î·ÅµçǰµÄ·Åµç²ÎÊý
        
    
        System.out.println(" db_dev_testparam init end at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        
    }
    
    /**
     *     ´´½¨     db_dev_testparam Êý¾Ý¿â
     * @param pool
     */
    public static void createDB_Dev_TESTPARAM(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_DEV_TESTPARAM);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    
    /**
     *     ´´½¨   `db_dev_testparam`.`tb_batt_testparam_` ±í
     * @param pool
     * @param recreate
     */
    public static void createBatt_TestParam_Table(MysqlConnPool pool, boolean recreate) {
        //System.out.println("Start:"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        String sql_str_sel = " SELECT FBSDeviceId,BattGroupId " + 
                             " FROM " + Sql_Mysql.BattInf_Table +
                             " WHERE (FLOOR(FBSDeviceId/100000)=8059) " +     //³ä·ÅµçÒ»Ìå»ú
                             " OR (FLOOR(FBSDeviceId/10000000)=91) " +         //BTS
                             " OR ((FLOOR(FBSDeviceId/100000)=6185)) ";        //61850
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        StringBuffer sql_str_head = new StringBuffer(" CREATE TABLE IF NOT EXISTS ");
        StringBuffer sql_str_body = new StringBuffer(" (" + 
                "  `num` bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  `record_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '²ÎÊý¸üÐÂʱ¼ä'," + 
                "  `BattGroupId` int(11) NOT NULL DEFAULT '1' COMMENT 'µç³Ø×éID'," + 
                "  `test_record_count` int(11) NOT NULL DEFAULT '1' COMMENT 'µç³Ø×é·Åµç´ÎÊý¶ÔÓ¦db_batt_testdata.tb_batttestdata_inf'," + 
                "  `op_cmd` int(11) NOT NULL DEFAULT '0'," + 
                "  `TestCmd` int(11) NOT NULL DEFAULT '0' COMMENT '²âÊÔÀàÐÍ'," + 
                "  `HourRate` int(11) NOT NULL DEFAULT '0' COMMENT '·ÅµçСʱÂÊ'," + 
                "  `DisCurr` float NOT NULL DEFAULT '0' COMMENT '·ÅµçµçÁ÷(A)'," + 
                "  `DisCap` float NOT NULL DEFAULT '0' COMMENT '·ÅµçÈÝÁ¿(AH)'," + 
                "  `DisTime` int(11) NOT NULL DEFAULT '0' COMMENT '·Åµçʱ³¤(·ÖÖÓ)'," + 
                "  `GroupVol_LOW` float NOT NULL DEFAULT '0' COMMENT '×é¶ËÏÂÏÞ(V)'," + 
                "  `MonomerVol_LOW` float NOT NULL DEFAULT '0' COMMENT 'µ¥ÌåÏÂÏÞ(V)'," + 
                "  `MonomerLowCount` int(11) NOT NULL DEFAULT '0' COMMENT 'µ¥ÌåÏÂÏÞÊýÁ¿'," + 
                "  `BattGroupNum` int(11) NOT NULL DEFAULT '0' COMMENT '×éºÅ'," + 
                "  `OnlineVolLowAction` int(11) NOT NULL DEFAULT '0' COMMENT 'ÔÚÏßµçѹµÍ´¦Àí'," + 
                "  `DCVolHighLimit` float NOT NULL DEFAULT '0' COMMENT 'ÉýѹÉÏÏÞ(V)'," + 
                "  `ChargeCurrSet` float NOT NULL DEFAULT '0' COMMENT '³äµçµçÁ÷(V)'," + 
                "  `MonomerTmp_High` float NOT NULL DEFAULT '0' COMMENT 'µ¥ÌåζÈÉÏÏÞ(¡æ)'," + 
                "  `AutoTestStartVol` float NOT NULL DEFAULT '0'," + 
                "  `OnLineVol_Low` float NOT NULL DEFAULT '0' COMMENT 'ÔÚÏßµçѹµÍ·§Öµ'," + 
                "  `OffLineYH_Cycle` int(11) NOT NULL DEFAULT '0' COMMENT 'ÀëÏßÑø»¤ÖÜÆÚ'," + 
                "  `OffLineYHstarttime` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT 'Ñø»¤¼Æ»®¿ªÊ¼Ê±¼ä'," + 
                "  `OffLineYHTimes` int(11) NOT NULL DEFAULT '1' COMMENT 'ÀëÏßÑø»¤Ö´ÐдÎÊý'," + 
                "  `OffLineYHOnceCycle` int(11) NOT NULL DEFAULT '1' COMMENT 'ÀëÏßÑø»¤Ã¿´ÎÖ´ÐÐÖÜÆÚ'," + 
                "  `MonCount` int(11) NOT NULL DEFAULT '0' COMMENT 'ÿ×éµ¥ÌåÊý'," + 
                "  `MonVol` float NOT NULL DEFAULT '0' COMMENT 'µ¥Ìåµçѹ'," + 
                "  `DisPower` float NOT NULL DEFAULT '0' COMMENT 'Ô¤·Å¹¦ÂÊ£¨0.1kw£©'," + 
                "  `DisPreRes` float(11,0) NOT NULL DEFAULT '0' COMMENT '·Åµç×èÖµ(m¦¸)'," + 
                "  `CharCap` int(11) NOT NULL DEFAULT '0' COMMENT '³äµçÈÝÁ¿(AH)'," + 
                "  `CharTimeLong` int(11) NOT NULL DEFAULT '0' COMMENT '³äµçʱ³¤(min)'," + 
                "  `FloatCharTimeLong` int(11) NOT NULL DEFAULT '0' COMMENT '¸¡³äʱ³¤'," + 
                "  `CharSotpCurr` float NOT NULL DEFAULT '0' COMMENT '½ØÖ¹µçÁ÷(0.1A)'," + 
                "  `MonVolHightLimit` float NOT NULL DEFAULT '0' COMMENT 'µ¥ÌåÉÏÏÞ(0.01V)'," + 
                "  `MonVolHightLimitCount` int(11) NOT NULL DEFAULT '0' COMMENT 'µ¥ÌåÉÏÏÞÊýÁ¿'," + 
                "  `CharHighTmp` float(11,0) NOT NULL DEFAULT '45' COMMENT '³äµç¹ýÎÂ'," + 
                "  `DisWaitTime` int(11) NOT NULL DEFAULT '0' COMMENT '·ÅÍê¾²ÖÃ(0-500·ÖÖÓ)'," + 
                "  `CharWaitTime` int(11) NOT NULL DEFAULT '0' COMMENT '³äÍê¾²ÖÃ(0-500·ÖÖÓ)'," + 
                "  `FlowOver_Count` int(11) NOT NULL DEFAULT '1' COMMENT 'ºãÁ÷×ܽ׶ÎÊý[1-3]'," + 
                "  `FlowOver_CharCurr_1` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷1½×¶Î³äµçµçÁ÷'," + 
                "  `FlowOver_CharCurr_2` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷2½×¶Î³äµçµçÁ÷'," + 
                "  `FlowOver_CharCurr_3` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷3½×¶Î³äµçµçÁ÷'," + 
                "  `FlowOver_CharTime_1` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷1½×¶Î³äµçʱ³¤'," + 
                "  `FlowOver_CharTime_2` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷2½×¶Î³äµçʱ³¤'," + 
                "  `FlowOver_CharTime_3` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷3½×¶Î³äµçʱ³¤'," + 
                "  `ChargeVolt` float NOT NULL DEFAULT '0' COMMENT '³äµçµçѹ(V)'," + 
                "  `C_ProtectVol1` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷±£»¤µçѹ1'," + 
                "  `C_ProtectVol2` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷±£»¤µçѹ2'," + 
                "  `C_ProtectVol3` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷±£»¤µçѹ3'," + 
                "  `C_mon_uppervol1` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷µ¥ÌåÉÏÏÞ1'," + 
                "  `C_mon_uppervol2` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷µ¥ÌåÉÏÏÞ2'," + 
                "  `C_mon_uppervol3` float NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷µ¥ÌåÉÏÏÞ3'," + 
                "  `C_mon_uppernum1` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷ÉÏÏÞ¸öÊý1'," + 
                "  `C_mon_uppernum2` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷ÉÏÏÞ¸öÊý2'," + 
                "  `C_mon_uppernum3` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷ÉÏÏÞ¸öÊý3'," + 
                "  `HV_charge_num` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ×ܽ׶ÎÊý[1~3]'," + 
                "  `HV_charge_Vol1` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î1³äµçµçѹ'," + 
                "  `HV_charge_Vol2` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î2³äµçµçѹ'," + 
                "  `HV_charge_Vol3` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î3³äµçµçѹ'," + 
                "  `HV_time1` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î1³äµçʱ¼ä'," + 
                "  `HV_time2` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î2³äµçʱ¼ä'," + 
                "  `HV_time3` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î3³äµçʱ¼ä'," + 
                "  `HV_ProtectCurr1` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î1±£»¤µçÁ÷'," + 
                "  `HV_ProtectCurr2` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î2±£»¤µçÁ÷'," + 
                "  `HV_ProtectCurr3` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î3±£»¤µçÁ÷'," + 
                "  `HV_mon_uppervol1` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î1µ¥ÌåÉÏÏÞ'," + 
                "  `HV_mon_uppervol2` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î2µ¥ÌåÉÏÏÞ'," + 
                "  `HV_mon_uppervol3` float NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î3µ¥ÌåÉÏÏÞ'," + 
                "  `HV_mon_uppernum1` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î1ÉÏÏÞ¸öÊý'," + 
                "  `HV_mon_uppernum2` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î2ÉÏÏÞ¸öÊý'," + 
                "  `HV_mon_uppernum3` int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ½×¶Î3ÉÏÏÞ¸öÊý'," + 
                "  PRIMARY KEY (`num`)," + 
                "  KEY `index_battgroupid` (`BattGroupId`) USING BTREE," + 
                "  KEY `index_test_record_count` (`test_record_count`) USING BTREE" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
        StringBuffer sql_str_buff = new StringBuffer();
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str_sel);
            while(res.next()) {
                int battgroupid = res.getInt("BattGroupId");
                sql.sqlMysqlUseDB(Sql_Mysql.DB_DEV_TESTPARAM);
                if(!sql.sqlMysqlCheckIfTableExist(Tb_Batt_TestParam_Table + battgroupid)) {
                    sql_str_buff = new StringBuffer();
                    sql_str_buff.append(sql_str_head);
                    sql_str_buff.append(Sql_Mysql.Batt_TestParam_Table + battgroupid);
                    sql_str_buff.append(sql_str_body);
                    sql.sqlMysqlExecute(sql_str_buff.toString());
                }
            }                
            //System.out.println("End:"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql_str_head = null;
            sql_str_buff = null;
            sql_str_body = null;
            if(null != res) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
    }
    
    /*public static void main(String[] args) {
        MysqlConnPool pool = new MysqlConnPool("192.168.10.79", 3360, 5);
        createBatt_TestParam_Table( pool,  false);
    }*/
}