lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
package com.fgkj.dao.impl.ram;
 
import java.sql.Connection;
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.LimitNumberFactory;
import com.fgkj.dao.UinfDaoFactory;
import com.fgkj.db.DBUtil;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.BattMap_information;
import com.fgkj.dto.Page;
import com.fgkj.dto.User_inf;
import com.fgkj.dto.ram.Bts_station_state;
 
public class Bts_station_stateImpl implements BaseDAO,CallBack{
 
    public List getResults(ResultSet rs) {
        // TODO Auto-generated method stub
        return null;
    }
 
    public boolean add(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
 
    public boolean update(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
 
    public boolean del(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
 
    public List searchAll() {
        // TODO Auto-generated method stub
        return null;
    }
    //查询机房实时状态
    public List serchByCondition(Object obj) {
        BattInf binf=(BattInf) obj;
        Page p=binf.getPage();
        Connection conn=DBUtil.getConn();
        String numberSql="SELECT FOUND_ROWS() number";//存放总数
        String sql="select SQL_CALC_FOUND_ROWS distinct station_id,dev_id,record_datetime,station_stat,station_poff_start_time,station_fadian_start_time" +
                   " ,station_diaozhan_start_time,station_temp,station_damp,station_dooropen_start_time,station_xuhang_start_time,station_xuhang_end_time" +
                   " ,tb_battinf.stationname,tb_battinf.stationname1,tb_battinf.stationname2,tb_battinf.stationname3,tb_battinf.stationname5 " +
                   " from db_ram_db.tb_bts_station_state,db_battinf.tb_battinf  " +
                   " where  tb_bts_station_state.dev_id=db_battinf.tb_battinf.FBSDeviceId  " +
                   " and tb_battinf.stationname1 like ? and tb_battinf.stationname2 like ? and tb_battinf.stationname3 like ?  and tb_battinf.stationname5 like ?   " +
                   " and stationid like ? and Station_install=1 " ;
                   /*"  and tb_bts_station_state.station_id in (" +
                   "  select distinct db_battinf.tb_battinf.stationid  " +
                   "  from db_battinf.tb_battinf " +
                   "  left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.stationid=db_battinf.tb_battinf.stationid " +
                   "  left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " +
                   "  left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " +
                   "  where db_user.tb_user_inf.uid=?  and tb_battinf.stationname1 like ? and tb_battinf.stationname2 like ? and tb_battinf.stationname3 like ? ) " +
                   " and stationid like ?  " ;*/
        //用户管理
        String userSql=" and StationId in(" +
                " select distinct db_user.tb_user_battgroup_baojigroup_battgroup.StationId from db_user.tb_user_battgroup_baojigroup_battgroup,db_user.tb_user_battgroup_baojigroup_usr where db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id=db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id  and db_user.tb_user_battgroup_baojigroup_usr.uId=?" +
                " ) ";
        sql+=userSql;
        if(binf.getBattGroupNum()>1){
            sql+=" and ( ";
        }  
        //掉站
        String diaozhanSql="  ((station_stat&32)>1) ";
        if((binf.getBattGroupNum()&32)>1){
            sql+=diaozhanSql;
        }
        if((binf.getBattGroupNum()&16)>1&&(binf.getBattGroupNum()>32)){
            sql+=" or ";
        }
        //开门
        String dooropenSql="  ((station_stat&16)>1) ";
        if((binf.getBattGroupNum()&16)>1){
            sql+=dooropenSql;
        }
        if((binf.getBattGroupNum()&8)>1&&(binf.getBattGroupNum()>16)){
            sql+=" or ";
        }
        //发电
        String fadianSql="  ((station_stat&8)>1) ";
        if((binf.getBattGroupNum()&8)>1){
            sql+=fadianSql;
        }
        if((binf.getBattGroupNum()&4)>1&&(binf.getBattGroupNum()>8)){
            sql+=" or ";
        }
        //续航
        String xuhangSql="  ((station_stat&4)>1) ";
        if((binf.getBattGroupNum()&4)>1){
            sql+=xuhangSql;
        }
        if((binf.getBattGroupNum()&2)>1&&(binf.getBattGroupNum()>4)){
            sql+=" or ";
        }
        //停电
        String poffSql="  ((station_stat&2)>1) ";
        if((binf.getBattGroupNum()&2)>1){
            sql+=poffSql;
        }
        
        if(binf.getBattGroupNum()>1){
            sql+=" ) ";
        }
        if(binf.getBattGroupNum()==0){
            sql+=" and station_stat<0 ";            //当没有选择想要查看的机房异常状态是筛选
        }
        //分页
        String orderSql=" limit ? ,? ";
        sql+=orderSql;
        //System.out.println(sql);
        List<Bts_station_state> list=DAOHelper.executeQueryLimit(sql, conn, new Object[]{"%"+binf.getStationName1()+"%","%"+binf.getStationName2()+"%","%"+binf.getStationName3()+"%","%"+binf.getStationName5()+"%","%"+binf.getStationId()+"%",binf.getNum(),(p.getPageCurr()-1)*p.getPageSize(),p.getPageSize()},new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Bts_station_state b=new Bts_station_state();
                        b.setStation_id(rs.getString("station_id"));
                        b.setDev_id(rs.getInt("dev_id"));
                        b.setRecord_datetime(rs.getTimestamp("record_datetime"));
                        b.setStation_stat(rs.getInt("station_stat"));
                        if(((b.getStation_stat()>>5)&1)==1){
                            b.setStation_stat_diaozhan(1);//掉站
                        }
                        if(((b.getStation_stat()>>4)&1)==1){
                            b.setStation_stat_dooropen(1);//开门
                        }
                        if(((b.getStation_stat()>>3)&1)==1){
                            b.setStation_stat_fadian(1);  //发电
                        }
                        if(((b.getStation_stat()>>2)&1)==1){
                            b.setStation_stat_xuhang(1);//续航
                        }
                        if(((b.getStation_stat()>>1)&1)==1){
                            b.setStation_stat_poff(1);    //停电
                        }
                        b.setStation_poff_start_time(rs.getTimestamp("station_poff_start_time"));
                        b.setStation_fadian_start_time(rs.getTimestamp("station_fadian_start_time"));
                        b.setStation_diaozhan_start_time(rs.getTimestamp("station_diaozhan_start_time"));
                        b.setStation_temp(rs.getFloat("station_temp"));
                        b.setStation_damp(rs.getFloat("station_damp"));
                        b.setStation_dooropen_start_time(rs.getTimestamp("station_dooropen_start_time"));
                        b.setStation_xuhang_start_time(rs.getTimestamp("station_xuhang_start_time"));
                        b.setStation_xuhang_end_time(rs.getTimestamp("station_xuhang_end_time"));
                        b.setStationName(rs.getString("stationName"));
                        b.setStationName1(rs.getString("stationName1"));
                        b.setStationName2(rs.getString("stationName2"));
                        b.setStationName3(rs.getString("stationName3"));
                        b.setStationName5(rs.getString("stationName5"));
                        Page page=new Page();
                        b.setPage(page);
                        list.add(b);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        //去掉limit条件后的总数
        int number=LimitNumberFactory.GetLimtitNumber(conn, numberSql);
        //System.out.println("number: "+number);
        if(list!=null&&list.size()>0){
            list.get(list.size()-1).getPage().setPageAll(number);
        }
        return list;
    }
    //查询当前机房停电数
    public int serchByState(Object obj) {
        User_inf uinf=(User_inf) obj;
        String sql=" select count(*) as nums from db_ram_db.tb_bts_station_state where station_stat&2>1  " +
                   "  and tb_bts_station_state.station_id  in (" +
                   "  select distinct db_battinf.tb_battinf.stationid  " +
                   "  from db_battinf.tb_battinf " +
                   "  left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.stationid=db_battinf.tb_battinf.stationid " +
                   "  left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " +
                   "  left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " +
                   "  where db_user.tb_user_inf.uid=? and  Station_install=1 ) ";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        list.add(rs.getInt("nums"));
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        int nums=0;//总数
        if(list!=null&&list.size()>0){
            nums=(Integer) list.get(list.size()-1);
        }
        return nums;
    }
    //查询当前机房掉战数
    public int serchByState_diaozhan(Object obj) {
        User_inf uinf=(User_inf) obj;
        String sql=" select count(*) as nums from db_ram_db.tb_bts_station_state where station_stat&32>1  " +
                   "  and tb_bts_station_state.station_id in (" +
                   "  select distinct db_battinf.tb_battinf.stationid  " +
                   "  from db_battinf.tb_battinf " +
                   "  left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.stationid=db_battinf.tb_battinf.stationid " +
                   "  left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " +
                   "  left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " +
                   "  where db_user.tb_user_inf.uid=? and  Station_install=1 ) ";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        list.add(rs.getInt("nums"));
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        int nums=0;//总数
        if(list!=null&&list.size()>0){
            nums=(Integer) list.get(list.size()-1);
        }
        return nums;
    }
    //查询具体某机房停电数(根据station_id )
    public int serchByStationId(Object obj) {
        BattMap_information binformation=(BattMap_information) obj;
        String sql="select count(num) as nums  from db_ram_db.tb_bts_station_state " +
                " where  station_stat&2>1  " +
                " and station_id=?  " +
                " limit 1 ";
        //System.out.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{binformation.getStationId()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        int nums=rs.getInt("nums");
                        list.add(nums);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
        int nums=0;//最后的结果
        if(list!=null&&list.size()>0){
            nums=(Integer) list.get(list.size()-1);
        }
        return nums;
    }
    //查询具体某机房掉站数(根据station_id )
    public int serchByStationId_diaozhan(Object obj) {
        BattMap_information binformation=(BattMap_information) obj;
        String sql="select count(num) as nums  from db_ram_db.tb_bts_station_state " +
                " where  station_stat&32>1   " +
                " and station_id=?  " +
                " limit 1 ";
        //System.out.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{binformation.getStationId()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        int nums=rs.getInt("nums");
                        list.add(nums);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
        int nums=0;//最后的结果
        if(list!=null&&list.size()>0){
            nums=(Integer) list.get(list.size()-1);
        }
        return nums;
    }
     
    //查询设备SD卡的实时状态
    public int serchSDCard(Object obj) {
        BattInf binf=(BattInf) obj;                                                    //station_id=?
        String sql=" select distinct station_stat from  db_ram_db.tb_bts_station_state where dev_id=? ";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(),new Object[] {binf.getFBSDeviceId()} , new CallBack() {
            
            @Override
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()) {
                        int station_stat=rs.getInt("station_stat");
                        if((station_stat&2048)>1) {
                            list.add(1);
                        }else {
                            list.add(0);
                        }
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        int station_stat=1;
        if(list!=null&&list.size()>0) {
            station_stat=(int) list.get(list.size()-1);
        }
        return station_stat;
    }
    
 
    public List serchByInfo(Object obj) {
        // TODO Auto-generated method stub
        return null;
    }
    public static void main(String[] args) {
        Bts_station_stateImpl bimpl=new Bts_station_stateImpl();
        BattInf binf=new BattInf();
        binf.setNum(1002);
        binf.setStationName1("");
        binf.setStationName2("");
        binf.setStationName3("");
        binf.setStationName5("");
        binf.setStationId("42000408");
        binf.setFBSDeviceId(910000591);
        binf.setBattGroupNum(62);
        User_inf uinf=new User_inf();
        uinf.setUId(1002);
        Page p=new Page();
        p.setPageCurr(1);
        p.setPageSize(10);
        binf.setPage(p);
        /*List<Bts_station_state> list=bimpl.serchByCondition(binf);
        for (Bts_station_state bs : list) {
            //System.out.println(bs.getStation_stat_diaozhan()+"  "+bs.getStation_stat_dooropen()+"  "+bs.getStation_stat_fadian()+"   "+bs.getStation_stat_xuhang()+"  "+bs.getStation_stat_poff());
            System.out.println(bs);
        }*/
        //System.out.println(list.size());
        //int nums=bimpl.serchByState(uinf);
        /*BattMap_information bm=new BattMap_information();
        bm.setStationId("42000570");
        int nums=bimpl.serchByStationId(bm);*/
        //int nums=bimpl.serchByState_diaozhan(uinf);
        /*BattMap_information bm=new BattMap_information();
        bm.setStationId("42000366");
        int nums=bimpl.serchByStationId_diaozhan(bm);*/
        int station_state=bimpl.serchSDCard(binf);
        System.out.println(station_state);
    }
 
    
}