DELL
2025-03-02 27cfc60fb7cb7c689e318c488f768619ede1e22e
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package com.dev_concentrator.data;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
 
import com.battmonitor.base.Com;
import com.battmonitor.data.BattData_RT;
import com.battmonitor.data.BattData_RT_Array;
import com.battmonitor.data.MonVolData;
import com.battmonitor.sql.MysqlConnPool;
import com.battmonitor.sql.Sql_Mysql;
 
public class FBS9800_SocketThread_SQL {
    
    /**
     *    ²åÈëĬÈÏÊý¾Ý
     * @param pool
     * @param param
     */
    public static void insertFBS9100SetParam_Table(MysqlConnPool pool,FBS9800_SetParam param) {
        String sql_str_sel = " SELECT * FROM " + Sql_Mysql.FBS9100SetParam_Table + " where dev_id = " + param.dev_id;
        String sql_str_ins = " INSERT INTO " + Sql_Mysql.FBS9100SetParam_Table + "(dev_id) values("+param.dev_id+")";
        String sql_str_upd = " UPDATE " + Sql_Mysql.FBS9100SetParam_Table + " SET op_cmd = 0 WHERE dev_id =  "+param.dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str_sel);
            if(!res.next()) {
                sql.sqlMysqlExecute(sql_str_ins);
            }else {
                sql.sqlMysqlExecute(sql_str_upd);
            }
        } catch (Exception e) {
            sql.logger.error(e.toString(), e);
        } finally {
            if(null != res) {
                try {
                    res.close();
                } catch (SQLException e) {
                    sql.logger.error(e.toString(), e);
                }
            }
            sql.close_con();
        }
    }
    
    /**
     *    ²éѯ¶ÔÓ¦µÄ²ÎÊý
     * @param pool
     * @param param
     */
    public static void queryFBS9100SetParam_Table(MysqlConnPool pool,FBS9800_SetParam param) {
        String sql_str_sel = " SELECT * FROM " + Sql_Mysql.FBS9100SetParam_Table + " where dev_id = " + param.dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str_sel);
            if(res.next()) {
                param.setOp_cmd(res.getInt("op_cmd"));
                param.setBattGroupNum(res.getInt("battGroupNum"));
                param.setTestCmd(res.getInt("testCmd"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != res) {
                try {
                    res.close();
                } catch (SQLException e) {
                    sql.logger.error(e.toString(), e);
                }
            }
            sql.close_con();
        }
    }
    
    /**
     *     ¸üл㼯¿ØÖÆ×´Ì¬
     * @param pool
     * @param param
     */
    public static void updateFBS9100SetParam_Table(MysqlConnPool pool,FBS9800_SetParam param) {
        String sql_str_upd = " UPDATE " + Sql_Mysql.FBS9100SetParam_Table + " SET op_cmd = "+param.getOp_cmd()+" where dev_id = " + param.dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str_upd);
        } catch (Exception e) {
            sql.logger.error(e.toString(), e);
        } finally {
            sql.close_con();
        }
    }
    
    public static BattData_RT_Array queryDeviceFromDataBase(MysqlConnPool pool,int dev_id) {
        BattData_RT_Array  dataArray = null;
        String sql_str1 = " SELECT DISTINCT " + 
                            " FBSDeviceId,FBSDeviceIp,BattGroupName6," + 
                            " BattGroupNum,BattFloatCurrent,FloatVolLevel,MonVolStd " + 
                            " FROM " + Sql_Mysql.BattInf_Table +
                            " WHERE FBSDeviceId = " + dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        res = sql.sqlMysqlQuery(sql_str1);
        try {
            if(res.next()) {
                dataArray = new BattData_RT_Array();
                
                String sql_str2 = "SELECT * " + 
                        " FROM " + Sql_Mysql.BattInf_Table + 
                        " WHERE FBSDeviceId = " + dev_id +
                        " ORDER BY GroupIndexInFBSDevice ";
                
                res = sql.sqlMysqlQuery(sql_str2);
                while(res.next()) {
                    BattData_RT battData = new BattData_RT();
                    battData.setM_Conn_Pool(pool);
                    battData.FBSDeviceId = res.getInt("FBSDeviceId");
                    battData.BattGroupId = res.getInt("BattGroupId");
                    battData.BattGroupNum = res.getInt("BattGroupNum");
                    battData.StationId = res.getInt("StationId");
                    battData.MonStdVol = res.getFloat("MonVolStd");
                    battData.MonStdCap = res.getFloat("MonCapStd");
                    battData.MonCount = res.getInt("MonCount");
                    battData.GroupIndexInFBSDevice = res.getInt("GroupIndexInFBSDevice");
                    if(battData.MonCount >0) {
                        for(int i = 0;i<battData.MonCount;i++) {
                            battData.al_MonVol.add(new MonVolData());
                            battData.al_MonVol_RtOld.add(new MonVolData());
                            battData.al_MonVol_History.add(new MonVolData());
                            
                        }
                    }
                    
                    dataArray.addItem(battData);
                }
            }
        } catch (SQLException e) {
            sql.logger.error(e.toString(), e);
        } finally {
            if(res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    sql.logger.error(e.toString(), e);
                }
            }
            sql.close_con();
        }
        return dataArray;
    }
    
    
    /**
     *     ¸ù¾ÝÉ豸id¸üР tb_fbs9100_state ±í
     * @param con_pool
     * @param v_data
     * @param dev_id
     */
    public static void insertOrupdateFbs9100StateByDev_Id(MysqlConnPool con_pool, FBS9800_SysState sysState)
    {
        
        String sql_str_query = "SELECT * FROM db_ram_db.tb_fbs9100_state WHERE dev_id = "+sysState.getDev_id();
        String sql_str_base = Sql_Mysql.FBS9100State_Table 
                        + " SET "
                        + "dev_id=" + sysState.getDev_id() + ", "
                        + "dev_version='V" + sysState.sysversion + "', "
                        + "dev_workstate=" + sysState.getSysstate() + ", "
                        + "dev_restest_count=" + sysState.dev_restest_count + ", "
                        + "dev_res_test_state=" + sysState.dev_res_test_state + ", "
                        + "dev_ip='" + sysState.getDev_ip() + "', "
                        + "record_datetime="
                        + "'" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "',"
                        + "dev_commcount=" + sysState.getDev_commcount() + ", "
                        + "dev_errcommcount=" + sysState.getDev_errcommcount();
                        
        
        //String sql_str_replace = "REPLACE INTO " + sql_str_base;
        String sql_str_update = " UPDATE " + sql_str_base + " WHERE dev_id = "+sysState.getDev_id();
        String sql_str_insert = " INSERT INTO "+Sql_Mysql.FBS9100State_Table 
                                +"(dev_id,dev_ip,record_datetime,dev_commcount,dev_errcommcount) "
                                + "VALUES("+sysState.getDev_id()+",'"+sysState.getDev_ip()+"','"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"',"+sysState.getDev_commcount()+","+sysState.getDev_errcommcount()+"); ";
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        ResultSet res = sql.sqlMysqlQuery(sql_str_query);
        try {
            if(res != null && res.next()) {
                //¸üÐÂÊý¾Ý
                sql.sqlMysqlExecute(sql_str_update);
            }else {
                //²åÈëÊý¾Ý
                sql.sqlMysqlExecute(sql_str_insert);
            }
            //System.out.println(sql_str);
        } catch (SQLException e) {
            sql.logger.error(e.toString(), e);
        } finally {
            if(res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    sql.logger.error(e.toString(), e);
                }
            }
            sql.close_con();
        }
    }
    
    //²åÈë»ò¸üÐÂFBSÉ豸״̬(½öÊÊÓÃÓÚMYSQL)
    public static void insertOrUpdateFBS9600StateByDevId(MysqlConnPool con_pool, FBS9800_SysState sysState) {
        String sql_str = "INSERT INTO " +Sql_Mysql.FBS9100State_Table 
                + " (dev_id,dev_ip,record_datetime,dev_commcount,dev_errcommcount) " 
                + " VALUES ("+sysState.getDev_id()+",'"+sysState.getDev_ip()+"','"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"',"+sysState.getDev_commcount()+","+sysState.getDev_errcommcount()+") "
                + " ON DUPLICATE KEY UPDATE dev_id=values(dev_id),dev_ip=values(dev_ip),record_datetime=values(record_datetime),dev_commcount = values(dev_commcount),dev_errcommcount = values(dev_errcommcount)";
        //System.out.println(sql_str);
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            sql.logger.error(e.toString(), e);
        } finally {
            sql.close_con();
        }
    }
    
    
    //²é¿´µ±Ç°Êý¾Ý¿âÖÐÊÇ·ñ´æÔÚµ±Ç°³ÌÐòµÄ½ø³Ì£¬²¢½øÐгõʼ»¯
    public static void initConcentratorThreadSQL(MysqlConnPool conn_pool) {
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        //Ìí¼ÓFBS»ã¼¯Æ÷ͨѶ½ø³Ì¼Ç¼
        ResultSet res = sql.sqlMysqlQuery("SELECT * FROM "+ Sql_Mysql.ProcessSurvey_Table + " WHERE ProcessId = 11030");
        try {
            if(false == res.next()) {
                sql.sqlMysqlExecute("INSERT INTO " + Sql_Mysql.ProcessSurvey_Table + "(ProcessId,ProcessName,ProcessTime,Process_starttime,ServerName,ServerFlag,ProcessVersion,note,OutTime) VALUES ('11030', 'BMS_FBS9800_DISPLAY',         '1970-01-01 00:00:00', '1970-01-01 00:00:00', 'BMS_FBS9800_DISPLAY', '2', 'v1.101', 'FBS9800»ã¼¯Æ÷ÏÔʾÆÁͨѶÏß³Ì', '300');");
            }
        } catch (SQLException e) {
            sql.logger.error(e.toString(), e);
        } finally {
            if(res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    sql.logger.error(e.toString(), e);
                }
            }
            sql.close_con();
        }
    }
    
    //¸üÐÂÏß³Ì¼à¿ØµÄÆô¶¯Ê±¼ä
    public static void updateConcentratorThread_StartTime(MysqlConnPool conn_pool,String version){
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            sql.sqlMysqlUseDB(Sql_Mysql.WEB_Site);
            String sql_str = "UPDATE tb_process_survey "
                    + "SET Process_starttime = '"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"'"
                    + ",ProcessVersion = '"+version+"'"
                    + " WHERE processid = 11030 ";
            //System.out.println(sql_str);
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            sql.logger.error(e.toString(), e);
        } finally {
            sql.close_con();
        }
    }
    
    //¸üл㼯Æ÷ͨѶÏ̵߳Äʱ¼ä´Á
    public static void updateConcentratorThread_Time(MysqlConnPool conn_pool){
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            sql.sqlMysqlUseDB(Sql_Mysql.WEB_Site);
            String sql_str = "UPDATE tb_process_survey SET ProcessTime = '"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)
                        + "' WHERE processid = 11030";
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            sql.logger.error(e.toString(), e);
        } finally {
            sql.close_con();
        }        
    }
    
    /*public static void main(String[] args) {
        Concentrator_SysState sys = new Concentrator_SysState();
        sys.setDev_id(960500001);
        MysqlConnPool pool = new MysqlConnPool("127.0.0.1", 3360, 10);
        insertOrUpdateFBS9600StateByDevId(pool, sys);
    }*/
}