FBS9600通信程序,带了均衡电压版本
Administrator
2021-12-27 03e9f67b82f4883395cec49b72a53ea03a4c8da6
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package com.dev.fbs9600s;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
 
import com.base.Com;
import com.dev.fbs9100.FBS9100_ComBase;
import com.dev.fbs9100.FBS9100_StatAndParam;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class FBS9600S_SocketClient_Thread_SQL {
    
    /**
     * ¸üÐÂ9600ϵͳ״̬
     * @param pool
     * @param devdata
     */
    public static void insertOrUpdateFBS9600StateByDev_id(MysqlConnPool pool, FBS9600S_SystemState systemState) {
        String sql_str_base = Sql_Mysql.FBS9100State_Table +
                  " SET dev_id = '"+ systemState.dev_id+"', "
                + " dev_ip='"+ systemState.dev_ip+"',"  
                + " dev_version='V"+ systemState.sys_version+"',"
                + " record_datetime='"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"',"
                + " dev_workstate = '"+systemState.dev_workstate+"',"
                + " dev_res_test_state = '"+systemState.dev_res_test_state+"',"
                + " dev_captest_groupvol='"+systemState.getDeviceGroupVol()+"',"
                + " dev_captest_curr='"+systemState.getDeviceTestCurr()+"',"
                + " dev_captest_onlinevol = '"+systemState.getDeviceOnlineVol()+"',"
                + " dev_temp = '"+systemState.machBoxTmp+"',"
                + " dev_commcount='"+systemState.dev_commcount+"',"
                + " dev_errcommcount='"+systemState.dev_errcommcount+"'";
                    
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        String sql_str_replace = "REPLACE INTO " + sql_str_base;
        try {
            sql.sqlMysqlExecute(sql_str_replace);
        } catch (SQLException e) {
            System.err.println("Ö´ÐРinsertOrUpdateFBS9600StateByDev_id Òì³£    at"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
            e.printStackTrace();
        } finally{
            sql.close_con();
        }
    }
    
    
    /**
     * ¸üÐÂ9600ϵͳ״̬
     * @param pool
     * @param devdata
     */
    public static void UpdateFBS9600StateByDev_id(MysqlConnPool pool, FBS9600S_SystemState systemState) {
        String sql_str_base = Sql_Mysql.FBS9100State_Table +
                  " SET dev_id = '"+ systemState.dev_id+"', "
                + " dev_ip='"+ systemState.dev_ip+"',"  
                + " dev_version='V"+ systemState.sys_version+"',"
                + " dev_workstate = '"+systemState.dev_workstate+"',"
                + " dev_res_test_state = '"+systemState.dev_res_test_state+"',"
                + " dev_captest_groupvol='"+systemState.getDeviceGroupVol()+"',"
                + " dev_captest_curr='"+systemState.getDeviceTestCurr()+"',"
                + " dev_captest_onlinevol = '"+systemState.getDeviceOnlineVol()+"',"
                + " dev_temp = '"+systemState.machBoxTmp+"',"
                + " dev_commcount='"+systemState.dev_commcount+"',"
                + " dev_errcommcount='"+systemState.dev_errcommcount+"'";
                    
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        //String sql_str_replace = "REPLACE INTO " + sql_str_base;
        if(systemState.dev_errcommcount < 5) {
            sql_str_base +=  " ,record_datetime='"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"' ";            
        }
        String sql_str_update = "UPDATE " + sql_str_base +" Where dev_id="+systemState.dev_id;
        try {
            sql.sqlMysqlExecute(sql_str_update);
        } catch (SQLException e) {
            System.err.println("Ö´ÐРinsertOrUpdateFBS9600StateByDev_id Òì³£    at"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
            e.printStackTrace();
        } finally{
            sql.close_con();
        }
    }
    
    /**
     * ¸ù¾Ý»ñÈ¡µ±Ç°É豸µÄÃüÁî
     * @param pool
     * @param dev_id
     * @return
     */
    public static FBS9600S_SystemState queryFBS9100SSysCmd(MysqlConnPool pool,int dev_id) {
        FBS9600S_SystemState state = new FBS9600S_SystemState("", dev_id);
        String sql_str = "SELECT * from db_ram_db.tb_fbs9100_state WHERE dev_id = "+dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet rs = sql.sqlMysqlQuery(sql_str);
        try {
            if(rs.next()) {
                state.dev_id = rs.getInt("dev_id");
                state.op_cmd = rs.getInt("op_cmd");
                state.dev_ip = rs.getString("dev_ip");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }        
        return state;
    }
    
    
    public static void updateFbs9100StateCmdBydev_id(MysqlConnPool con_pool, FBS9600S_SystemState sysState)
    {
        String sql_str_base = Sql_Mysql.FBS9100State_Table + " SET "
                            + "dev_id=" + sysState.dev_id + ", "
                            + "op_cmd=" + sysState.op_cmd;
        String sql_str_update = "UPDATE " + sql_str_base + " WHERE dev_id = " + sysState.dev_id;
        //String sql_str_replace = "REPLACE INTO " + sql_str_base;
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str_update);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ²éѯ9600State
     * @param con_pool
     * @param sysState
     */
    public static FBS9600S_SystemState queryFbs9600StateCmdBydev_id(MysqlConnPool con_pool, int dev_id)
    {
        FBS9600S_SystemState sys = new FBS9600S_SystemState("", dev_id);
        String sql_str = " select * from " + Sql_Mysql.FBS9600State_Table + " "
                       + " where dev_id= " + dev_id;
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str);
            if(res.next()) {                
                sys.op_cmd = res.getInt("op_cmd"); 
            }
        } catch (SQLException e) {
            //e.printStackTrace();
        } finally {
            if(null != res) {
                 try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
        return sys;
    }
    
    
    
    public static void updateFbs9600StateCmdBydev_id(MysqlConnPool con_pool, FBS9600S_SystemState sysState)
    {
        String sql_str_base = Sql_Mysql.FBS9600State_Table + " SET "
                            + "dev_id=" + sysState.dev_id + ", "
                            + "op_cmd=" + sysState.op_cmd;
        String sql_str_update = "UPDATE " + sql_str_base + " WHERE dev_id = " + sysState.dev_id;
        //String sql_str_replace = "REPLACE INTO " + sql_str_base;
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str_update);
        } catch (SQLException e) {
            //e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ²éѯ9600State
     * @param con_pool
     * @param sysState
     */
    public static FBS9600S_SystemState queryFbs9100ParamCmdBydev_id(MysqlConnPool con_pool, int dev_id)
    {
        FBS9600S_SystemState sys = new FBS9600S_SystemState("", dev_id);
        String sql_str = " select * from " + Sql_Mysql.FBS9100SetParam_Table + " "
                       + " where dev_id= " + dev_id;
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        ResultSet res = null;
        try {
            //System.out.println(sql_str);
            res = sql.sqlMysqlQuery(sql_str);
            if(res.next()) {                
                sys.op_cmd = res.getInt("op_cmd"); 
            }
        } catch (SQLException e) {
            //e.printStackTrace();
        } finally {
            if(null != res) {
                 try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
        return sys;
    }
    
    
    
    public static void updateFbs9100ParamCmdBydev_id(MysqlConnPool con_pool, FBS9600S_SystemState sysState)
    {
        String sql_str_base = Sql_Mysql.FBS9100SetParam_Table + " SET "
                            + "dev_id=" + sysState.dev_id + ", "
                            + "op_cmd=" + sysState.op_cmd;
        String sql_str_update = "UPDATE " + sql_str_base + " WHERE dev_id = " + sysState.dev_id;
        //String sql_str_replace = "REPLACE INTO " + sql_str_base;
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str_update);
        } catch (SQLException e) {
            //e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    
    /**
     * ¸ù¾Ý»ñÈ¡µ±Ç°É豸µÄÃüÁî
     * @param pool
     * @param dev_id
     * @return
     */
    public static FBS9600S_SystemState queryFBS9100SSetParam(MysqlConnPool pool,int dev_id) {
        FBS9600S_SystemState state = new FBS9600S_SystemState("", dev_id);
        String sql_str = "SELECT * from db_ram_db.tb_fbs9100_setparam WHERE dev_id = "+dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet rs = sql.sqlMysqlQuery(sql_str);
        try {
            if(rs.next()) {
                state.dev_id = rs.getInt("dev_id");
                state.op_cmd = rs.getInt("op_cmd");
                state.junHengVol = rs.getFloat("MonomerVol_Low");
                state.dev_ip = rs.getString("dev_ip");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }        
        return state;
    }
 
 
    /**
     * ÐÞ¸ÄÖ¸¶¨µÄÃüÁîÂë
     * @param pool
     * @param param
     */
    public static void updateFbs9100SetParamCmdBydev_id(MysqlConnPool pool, FBS9600S_SystemState param) {
        String sql_str_base = Sql_Mysql.FBS9100SetParam_Table + " SET "
                + "dev_id=" + param.dev_id + ", "
                + "MonomerVol_LOW=" + param.junHengVol + ", "
                + "op_cmd=" + param.op_cmd;
        String sql_str_update = "UPDATE " + sql_str_base + " WHERE dev_id = " + param.dev_id;
        //String sql_str_replace = "REPLACE INTO " + sql_str_base;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str_update);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    
    /**
     * ¸üÐÂ9600ϵͳ״̬
     * @param pool
     * @param devdata
     */
    public static void insertOrUpdateFBS9600SetParamByDev_id(MysqlConnPool pool, FBS9600S_SystemState systemState) {
        String sql_str_base = Sql_Mysql.FBS9100SetParam_Table +
                  " SET dev_id = '"+ systemState.dev_id+"', "
                + " dev_ip='"+ systemState.dev_ip+"'";    
                    
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        String sql_str_replace = "REPLACE INTO " + sql_str_base;
        try {
            sql.sqlMysqlExecute(sql_str_replace);
        } catch (SQLException e) {
            System.err.println("Ö´ÐРinsertOrUpdateFBS9600SetParamByDev_id Òì³£    at"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
            e.printStackTrace();
        } finally{
            sql.close_con();
        }
    }
    
    
    public static void main(String[] args) {
        MysqlConnPool pool = new MysqlConnPool("127.0.0.1", 3360, 5);
        FBS9600S_SystemState sys = new FBS9600S_SystemState("12.52.33.11", 960500001);
        UpdateFBS9600StateByDev_id(pool, sys);
    }
}