1
81041
2019-06-20 ab3c4acf83f54f8449ca8664c4a2bb79bd30f297
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package com.fgkj.dao.impl.ram;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.UinfDaoFactory;
import com.fgkj.db.DBUtil;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.User_log;
import com.fgkj.dto.ram.Fbs9100s_dfu_state;
import com.fgkj.services.User_logService;
 
public class Fbs9100s_dfu_stateImpl implements BaseDAO,CallBack{
 
    public List getResults(ResultSet rs) {
        // TODO Auto-generated method stub
        return null;
    }
    //升级插入
    public boolean add(Object obj) {
        Fbs9100s_dfu_state dfu=(Fbs9100s_dfu_state) obj;
        String sql=" REPLACE into db_ram_db.tb_fbs9100s_dfu_state (dev_id,dfu_file,dfu_wr_stat,dfu_data_blocknum,dfu_file_len) values (?,?,?,?,?)";
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{dfu.getDev_id(),dfu.getDfu_file(),dfu.getDfu_wr_stat(),dfu.getDfu_data_blocknum(),dfu.getDfu_file_len()});
        return bl;
    }
    //批量升级插入(所有属性传到stationName中,文件大小的值放在num中)
    public boolean addPro(Object obj) {
        BattInf binf=(BattInf) obj;
        String sql=" REPLACE into db_ram_db.tb_fbs9100s_dfu_state(dev_id,dfu_wr_stat,dfu_data_blocknum) " +
                " SELECT  DISTINCT fBSDeviceId,1,1 FROM db_battinf.tb_battinf " +
                " where fBSDeviceId not in(select DISTINCT dev_id from db_ram_db.tb_fbs9100s_dfu_state where dfu_en=true)  ";
        //条件
        String sql0=" and stationid=? "; //具体机房
        String sql1=" and stationname1=? ";//省
        String sql2=" and stationname2=? ";//市
        String sql5=" and stationname5=? ";//区县
        switch (binf.getNum()) {
        case 0:
            sql+=sql0;
            break;
        case 1:
            sql+=sql1;
            break;
        case 2:
            sql+=sql2;
            break;
        case 5:
            sql+=sql5;
             break;
        default:
            return false;
        }
        //System.out.println(sql);
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{binf.getStationName()});
        return bl;
    }
    //表格显示批量插入的机房信息
    public List serchInserStation(Object obj){
        BattInf binf=(BattInf) obj; 
        String sql="SELECT  DISTINCT fBSDeviceId,fBSDeviceName,stationId,stationname,stationname1,stationname2,stationname3,stationname5 " +
                ",db_ram_db.tb_fbs9100_state.dev_id,db_ram_db.tb_fbs9100_state.dev_version" +
                " from db_battinf.tb_battinf,db_ram_db.tb_fbs9100_state " +
                " where db_battinf.tb_battinf.fBSDeviceId=db_ram_db.tb_fbs9100_state.dev_id " +
                " and db_battinf.tb_battinf.station_install=1 " +
                " and ";
        //条件
        String sql0="  stationid=? "; //具体机房
        String sql1="  stationname1=? ";//省
        String sql2="  stationname2=? ";//市
        String sql5="  stationname5=? ";//区县
        switch (binf.getNum()) {
        case 0:
            sql+=sql0;
            break;
        case 1:
            sql+=sql1;
            break;
        case 2:
            sql+=sql2;
            break;
        case 5:
            sql+=sql5;
             break;
        default:
            return null;
        }
        String endSql="  order by fBSDeviceId ";
        sql+=endSql;
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{binf.getStationName()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        BattInf binf=new BattInf();
                        binf.setFBSDeviceId(rs.getInt("fBSDeviceId"));
                        binf.setStationName(rs.getString("stationName"));
                        binf.setStationName1(rs.getString("stationName1"));
                        binf.setStationName2(rs.getString("stationName2"));
                        binf.setStationName3(rs.getString("stationName3"));
                        binf.setStationName5(rs.getString("stationName5"));
                        binf.setStationId(rs.getString("stationId"));
                        binf.setFBSDeviceName(rs.getString("fBSDeviceName"));
                        binf.setStationIp(rs.getString("dev_version"));
                        list.add(binf);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //批量升级前验证升级的设备必须处于在线监测状态(9100state的workstate为0)
    public List judgeStation(Object obj){
        List<Integer> list=(List<Integer>) obj;
        String sql=" select distinct dev_id,db_battinf.tb_battinf.stationname,db_battinf.tb_battinf.stationname3 from db_ram_db.tb_fbs9100_state,db_battinf.tb_battinf  " +
                " where db_ram_db.tb_fbs9100_state.dev_id=db_battinf.tb_battinf.fBSDeviceId  and dev_workstate=0 and dev_id in(";
        String devSql="";
        Object[] object=new Object[list.size()];
        //System.out.println(list.size());
        if(list!=null&&list.size()>0){
            for (int i = 0; i <list.size(); i++) {
                if(i==(list.size()-1)){
                    devSql+="?)";
                }else{
                    devSql+="?,";
                }
                object[i]=list.get(i);
            }
        }
        sql+=devSql;
        String endSql="  order by dev_id";
        sql+=endSql;
        List listAll=DAOHelper.executeQuery(sql, DBUtil.getConn(), object, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        BattInf binf=new BattInf();
                        binf.setFBSDeviceId(rs.getInt("dev_id"));
                        binf.setStationName(rs.getString("stationName"));
                        binf.setStationName3(rs.getString("stationName3"));
                        list.add(binf);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return listAll;
    }
    //升级确认
    public boolean update(Object obj) {
        Fbs9100s_dfu_state dfu=(Fbs9100s_dfu_state) obj;
        String sql="update db_ram_db.tb_fbs9100s_dfu_state set dfu_en=true,dfu_wr_stat=1, dfu_data_blocknum=1 where dev_id=?";
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{dfu.getDev_id()});
        return bl;
    }
    //批量升级确认
    public boolean updatePro(Object obj) {
        List<Fbs9100s_dfu_state> list=(List<Fbs9100s_dfu_state>) obj;
        List<User_log> listU=new ArrayList<User_log>();//存放user_log
        ArrayList sql_str=new ArrayList();
        if(list!=null&&list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                Fbs9100s_dfu_state dfu=list.get(i);
                String sql="update db_ram_db.tb_fbs9100s_dfu_state set dfu_en=true,dfu_wr_stat=1, dfu_data_blocknum=1,dfu_file='"+dfu.getDfu_file()+"'  where dev_id="+dfu.getDev_id();
                sql_str.add(sql);
                {
                    String msg="升级"+dfu.getDev_id()+"设备";
                    User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg);
                    listU.add(ulog);
                 }
            }
        }
        boolean bl=DAOHelper.makeManualCommit(DBUtil.getConn(), sql_str);
        (new User_logService()).addPro(listU);//将用户的操作记录下来
        return bl;
    }
    public boolean del(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    //查询出所有处于升级的设备
    public List searchAll() {
        String sql=" select distinct db_ram_db.tb_fbs9100s_dfu_state.dev_id,db_battinf.tb_battinf.stationname,db_battinf.tb_battinf.stationId,db_battinf.tb_battinf.fBSDeviceName " +
                ",sysVersion_new,softVersion_new,sysVersion_dev,softVersion_dev,dfu_file,dfu_en,dfu_wr_stat,dfu_data_blocknum,dfu_data_blocklen,dfu_file_len " +
                ",db_ram_db.tb_fbs9100_state.dev_version" +
                " from  db_ram_db.tb_fbs9100s_dfu_state,db_battinf.tb_battinf,db_ram_db.tb_fbs9100_state " +
                " where db_ram_db.tb_fbs9100s_dfu_state.dev_id=db_battinf.tb_battinf.fBSDeviceId  " +
                " and db_ram_db.tb_fbs9100s_dfu_state.dev_id=db_ram_db.tb_fbs9100_state.dev_id " +
                " and dfu_en=1";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null , new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Fbs9100s_dfu_state dfu=new Fbs9100s_dfu_state();
                        dfu.setDev_id(rs.getInt("dev_id"));
                        dfu.setSysVersion_new(rs.getInt("sysVersion_new"));
                        dfu.setSoftVersion_new(rs.getInt("softVersion_new"));
                        dfu.setSysVersion_dev(rs.getInt("sysVersion_dev"));
                        dfu.setSoftVersion_dev(rs.getInt("softVersion_dev"));
                        dfu.setDfu_file(rs.getString("dfu_file"));
                        dfu.setDfu_en(rs.getInt("dfu_en"));
                        dfu.setDfu_wr_stat(rs.getInt("dfu_wr_stat"));
                        dfu.setDfu_data_blocknum(rs.getInt("dfu_data_blocknum"));
                        dfu.setDfu_file_len(rs.getInt("dfu_file_len"));
                        dfu.setDfu_data_blocklen(rs.getInt("dfu_data_blocklen"));
                        dfu.setStationName(rs.getString("stationName"));
                        dfu.setStationId(rs.getString("stationId"));
                        dfu.setfBSDeviceName(rs.getString("fBSDeviceName"));
                        dfu.setNote(rs.getString("dev_version"));
                        list.add(dfu);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //升级界面实时刷新
    public List serchByCondition(Object obj) {
        List<Integer> list=(List<Integer>) obj;
        String sql=" select * from db_ram_db.tb_fbs9100s_dfu_state  " +
                " where dev_id in(";
        String devSql="";
        Object[] object=new Object[list.size()];
        //System.out.println(list.size());
        if(list!=null&&list.size()>0){
            for (int i = 0; i <list.size(); i++) {
                if(i==(list.size()-1)){
                    devSql+="?)";
                }else{
                    devSql+="?,";
                }
                object[i]=list.get(i);
            }
        }
        sql+=devSql;
        String endSql="  order by dev_id";
        sql+=endSql;
        //System.out.println(sql);
        List listAll=DAOHelper.executeQuery(sql, DBUtil.getConn(), object, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Fbs9100s_dfu_state dfu=new Fbs9100s_dfu_state();
                        dfu.setDev_id(rs.getInt("dev_id"));
                        dfu.setSysVersion_new(rs.getInt("sysVersion_new"));
                        dfu.setSoftVersion_new(rs.getInt("softVersion_new"));
                        dfu.setSysVersion_dev(rs.getInt("sysVersion_dev"));
                        dfu.setSoftVersion_dev(rs.getInt("softVersion_dev"));
                        dfu.setDfu_file(rs.getString("dfu_file"));
                        dfu.setDfu_en(rs.getInt("dfu_en"));
                        dfu.setDfu_wr_stat(rs.getInt("dfu_wr_stat"));
                        dfu.setDfu_data_blocknum(rs.getInt("dfu_data_blocknum"));
                        dfu.setDfu_file_len(rs.getInt("dfu_file_len"));
                        dfu.setDfu_data_blocklen(rs.getInt("dfu_data_blocklen"));
                        list.add(dfu);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return listAll;
    }
   
    public List serchByInfo(Object obj) {
        return null;
    }
    public static void main(String[] args) {
    Fbs9100s_dfu_stateImpl fimpl=new Fbs9100s_dfu_stateImpl();
    List list=new ArrayList();
    list.add(910000001);
    /*list.add(910000577);
    list.add(910000534);*/
    BattInf binf=new BattInf();
    binf.setNum(1);
    binf.setStationName("广西省");
    
    /*List<Fbs9100s_dfu_state> listAll=fimpl.serchByCondition(list);
    for (Fbs9100s_dfu_state dfu : listAll) {
        System.out.println(dfu);
    }*/
    /*List<BattInf> listAll=fimpl.judgeStation(list);
    for (BattInf binf : listAll) {
        System.out.println(binf.getStationName3()+" "+binf.getFBSDeviceId());
    }*/
    
    /*boolean bl=fimpl.addPro(binf);
    System.out.println(bl);*/
    /*List<BattInf> listAll=fimpl.serchInserStation(binf);
    for (BattInf b : listAll) {
        System.out.println(b.getStationName3()+" "+b.getFBSDeviceId());
    }
    System.out.println(listAll.size());*/
    /*List<Fbs9100s_dfu_state> listAll=fimpl.searchAll();
    for (Fbs9100s_dfu_state dfu : listAll) {
        System.out.println(dfu);
    }*/
    List<Fbs9100s_dfu_state> listAll=fimpl.searchAll();
    for (Fbs9100s_dfu_state dfu : listAll) {
        System.out.println(dfu);
    }
    System.out.println(listAll.size());
}
}