whyclj
2019-10-29 1c0469e45346d464e0c5672ee68f9ecd4fb6be7c
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
package com.fgkj.dao.impl;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import com.fgkj.dao.AlarmDaoFactory;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.db.DBUtil;
import com.fgkj.db.IDatabaseName;
import com.fgkj.dto.BattDischarge_plan;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.BattMap_information;
import com.fgkj.dto.Batt_Maint_Dealarm;
import com.fgkj.dto.Battalarm_data;
import com.fgkj.dto.User_inf;
 
public class BattMap_informationImpl implements BaseDAO,CallBack{
 
    public List getResults(ResultSet rs) {
        List list=new ArrayList();
        try {
            while(rs.next()){
                BattMap_information binformation=new BattMap_information();
                binformation.setNum(rs.getInt("num"));
                binformation.setStationId(rs.getString("stationId"));
                binformation.setStationName(rs.getString("stationName"));
                binformation.setAddress(rs.getString("address"));
                binformation.setLongitude(rs.getDouble("longitude"));
                binformation.setLatitude(rs.getDouble("latitude"));
                binformation.setInformation(rs.getString("information"));
                list.add(binformation);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list;
    }
    //9.1录入机房信息
    public boolean add(Object obj) {
        BattMap_information binformation=(BattMap_information) obj;
        String sql="insert into web_site.tb_battmap_information(StationId,StationName,address,longitude,latitude) values(?,?,?,?,?)";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{binformation.getStationId(),binformation.getStationName(),
            binformation.getAddress(),binformation.getLongitude(),binformation.getLatitude()});
        return bl;
    }
 
    public boolean update(Object obj) {
        BattMap_information binformation=(BattMap_information) obj;
        String sql="update web_site.tb_battmap_information set StationId=?,StationName=?,address=?,longitude=?,latitude=?,information=? where num=?";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{binformation.getStationId(),binformation.getStationName(),
            binformation.getAddress(),binformation.getLongitude(),binformation.getLatitude(),binformation.getInformation(),binformation.getNum()});
        return bl;
    }
 
    public boolean del(Object obj) {
        BattMap_information binformation=(BattMap_information) obj;
        //System.out.println(binformation);
        String sql="delete from web_site.tb_battmap_information where num=?";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{binformation.getNum()});
        return bl;
    }
   
     //9.1百度地图定位查询电池组信息
    public List searchAll() {
        String sql="select num,StationId,StationName,address,longitude,latitude,information from web_site.tb_battmap_information ";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new BattMap_informationImpl());
        return list;
    }
 
    //9.1查询未添加物理信息的机房
    public List serchNotInBattMap() {
        String sql="select distinct tb_battinf.stationid,tb_battinf.stationname from db_battinf.tb_battinf " +
                "where tb_battinf.stationid not in(select web_site.tb_battmap_information.stationid from web_site.tb_battmap_information )";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        BattInf binf=new BattInf();
                        binf.setStationId(rs.getString("StationId"));
                        binf.setStationName(rs.getString("stationName"));
                        list.add(binf);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //9.1查询未添加物理信息的机房(用户管理的)
    public List serchNotInBattMapByUid(Object obj) {
        User_inf uinf=(User_inf) obj;
        String sql="select distinct db_battinf.tb_battinf.stationname,db_battinf.tb_battinf.stationid,db_battinf.tb_battinf.fBSDeviceId " +
                  " 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 db_battinf.tb_battinf.stationid not in(select web_site.tb_battmap_information.stationid from web_site.tb_battmap_information )";
        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()){
                        BattInf binf=new BattInf();
                        binf.setStationId(rs.getString("StationId"));
                        binf.setStationName(rs.getString("stationName"));
                        binf.setFBSDeviceId(rs.getInt("fBSDeviceId"));
                        list.add(binf);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //9.1查询已经添加物理信息的机房(用户管理的)
    public List serchInBattMapByUid(Object obj) {
        User_inf uinf=(User_inf) obj;
        String sql="select distinct tb_battmap_information.num,tb_battmap_information.StationId,tb_battmap_information.StationName,address,longitude,latitude,information,db_battinf.tb_battinf.FBSDeviceId  " +
                "  from web_site.tb_battmap_information,db_battinf.tb_battinf " +
                "  where  tb_battmap_information.StationId=db_battinf.tb_battinf.StationId " +
                "  and tb_battmap_information.StationId 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=?  )";
        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()){
                        BattMap_information binformation=new BattMap_information();
                        binformation.setNum(rs.getInt("num"));
                        binformation.setStationId(rs.getString("stationId"));
                        binformation.setStationName(rs.getString("stationName"));
                        binformation.setAddress(rs.getString("address"));
                        binformation.setLongitude(rs.getDouble("longitude"));
                        binformation.setLatitude(rs.getDouble("latitude"));
                        binformation.setInformation(rs.getString("information"));
                        binformation.setFBSDeviceId(rs.getInt("fBSDeviceId"));
                        list.add(binformation);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        } );
        return list;
    }
    //9.1查询机房所在的所有省份
    public List serchStationName1(){
        String sql="  SELECT  DISTINCT substring_index(substring_index(address,'-',2),'-',1) as stationname1  FROM web_site.tb_BattMap_information  " ;
        //System.out.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        String stationname1=rs.getString("stationname1");
                        list.add(stationname1);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //9.1根据省份查询机房所在的所有城市
    public List serchStationName2(Object obj){
        BattMap_information binformation=(BattMap_information) obj;
        String sql=" SELECT  DISTINCT substring_index(substring_index(address,'-',2),'-',-1) as stationname2 FROM web_site.tb_BattMap_information" +
                " where  address  like ? " ;
        //System.out.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{"%"+binformation.getAddress()+"%"}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        String stationname2=rs.getString("stationname2");
                        list.add(stationname2);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    
    //9.1根据省份和城市查询机房所在的所有机房
    public List serchStationName(Object obj){
        BattMap_information binformation=(BattMap_information) obj;
        String sql=" SELECT DISTINCT StationName,longitude,latitude FROM web_site.tb_BattMap_information   " +
                "WHERE address  like ?   ";
        //System.out.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{"%"+binformation.getAddress()+"%"}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        BattMap_information binformation=new BattMap_information();
                        binformation.setStationName(rs.getString("stationName"));
                        binformation.setLongitude(rs.getDouble("longitude"));
                        binformation.setLatitude(rs.getDouble("latitude"));
                        list.add(binformation);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //9.1地图上根据维护区查询机房经纬度
    public List serchByInfo(Object obj) {
        BattMap_information binformation=(BattMap_information) obj;
        String sql="select num, StationId,StationName,address,longitude,latitude,information from web_site.tb_battmap_information " +
                   " where StationId=?";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{binformation.getStationId()}, new BattMap_informationImpl());
        return list;
    }
   
    public static void main(String[] args) {
        BattMap_informationImpl bimpl=new BattMap_informationImpl();
        Batt_Maint_Dealarm bmd=new Batt_Maint_Dealarm();
        Battalarm_data adata=new Battalarm_data();
        adata.setAlm_cleared_type(0);    //告警           0:选中    100:没有
        adata.setAlm_id(1);                //存在落后单体  1:选中          100:没有
        BattMap_information binformation=new BattMap_information();
        BattDischarge_plan bplan=new BattDischarge_plan();
        bplan.setDischarge_reason(3);    //存在延时:3    100 没有
        bmd.setAdata(adata);
        bmd.setBinformation(binformation);
        bmd.setBplan(bplan);
        
        List<Batt_Maint_Dealarm> list=bimpl.serchByCondition(bmd);
        for (Batt_Maint_Dealarm b : list) {
            System.out.println(b);
        }
        System.out.println(list.size());
    }
    //9.1百度地图定位根据省份查询所有该区域的机房
    public List serchByCondition(Object obj) {
        BattMap_information binformation=(BattMap_information) obj;
        String sql="select num,StationId,StationName,address,longitude,latitude,information from web_site.tb_battmap_information " +
                    " where address like ? ";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{"%"+binformation.getAddress()+"%"}, new BattMap_informationImpl());
        return list;
    }
}