81041
2018-12-11 5c9ff4d11524b55914d8edf7f1ca776c6e0cb62e
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
package com.fgkj.dao.impl;
 
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.BattinfGroupFactory;
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.Battinf_apply;
import com.fgkj.dto.Page;
import com.fgkj.dto.User_inf;
import com.fgkj.dto.User_log;
import com.fgkj.services.User_logService;
 
public class Battinf_applyImpl implements BaseDAO,CallBack{
 
    public List getResults(ResultSet rs) {
        // TODO Auto-generated method stub
        return null;
    }
    //添加申请
    public boolean add(Object obj) {
        List<Battinf_apply> list=(List<Battinf_apply>) obj;
        List<User_log> listU=new ArrayList<User_log>();//存放user_log
        ArrayList<String> sql_str=new ArrayList();
        //获取当前最大的stationid和battgroupid
        int maxs=BattinfGroupFactory.searchStationId();
        int maxb=BattinfGroupFactory.searchMaxBattgroupId();
        if(list!=null && list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                Battinf_apply bapply=list.get(i);
                /*int uid=((User_inf)ActionUtil.getUser()).getUId();
                bapply.setApply_uid(uid);*/
                BattInf binf=bapply.getBinf();
                //验证新添加的机房是否存在
                List listS=(new BattInfImpl()).judgeBatt(binf);
                if(listS!=null&&listS.size()>0){
                    binf.setStationId((String) listS.get(listS.size()-1));
                }else{
                    binf.setStationId(String.valueOf(maxs));
                }
                binf.setBattGroupId(maxb);
                String sql = "insert into db_battinf.tb_battinf_apply(" +
                        "apply_uid,apply_date,StationId,StationName,StationName1,StationName2,StationName3,StationName4,StationName5,StationIp,FBSDeviceId,FbsDeviceIp,FbsDeviceIp_YM,FbsDeviceIp_WG,"
                        + "FBSDeviceName,GroupIndexInFBSDevice,battgroupId,BattGroupNum,BattGroupName,FloatVolLevel,OfflineVolLevel,BattFloatCurrent" +
                        ",MonCount,MonCapStd,monVolStd,monResStd,MonSerStd,MonVolLowToAvg,BattProducer,BattModel,BattProductDate,BattInUseDate,Load_curr,install_user,DisCurrMax,station_phone" +
                        ") values("+bapply.getApply_uid()+",'"+DAOHelper.sdf.format(bapply.getApply_date())+"','"+binf.getStationId()+"','"+binf.getStationName()+"','"+binf.getStationName1()+"','"+binf.getStationName2()+"','"+binf.getStationName3()+"','"+binf.getStationName4()+"','"+binf.getStationName5()+
                        "','"+binf.getStationIp()+"',"+binf.getFBSDeviceId()+",'"+binf.getFbsDeviceIp()+"','"+binf.getFbsDeviceIp_YM()+"','"+binf.getFbsDeviceIp_WG()+"','"+binf.getFBSDeviceName()+"',"+binf.getGroupIndexInFBSDevice()+
                        ","+binf.getBattGroupId()+","+binf.getBattGroupNum()+",'"+binf.getBattGroupName()+"',"+binf.getFloatVolLevel()+","+binf.getOfflineVolLevel()+","+binf.getBattFloatCurrent()+
                        ","+binf.getMonCount()+","+binf.getMonCapStd()+","+binf.getMonVolStd()+","+binf.getMonResStd()+","+binf.getMonSerStd()+","+binf.getMonVolLowToAvg()+
                        ",'"+binf.getBattProducer()+"','"+binf.getBattModel()+"','"+DAOHelper.sdf.format(binf.getBattProductDate())+"','"+DAOHelper.sdf.format(binf.getBattInUseDate())+"',"+binf.getLoad_curr()+",'"+binf.getInstall_user()+"',"+binf.getDisCurrMax()+",'"+binf.getStation_phone()+"')";
                
                if(binf.getStationId().equals(maxs)){
                    maxs++;
                }
                maxb++;
                sql_str.add(sql);
                /*{
                    String msg=((User_inf)ActionUtil.getUser()).getUId()+"申请添加"+binf.getStationName()+"机房"+binf.getBattGroupId()+"电池组的信息";
                    User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg);
                    listU.add(ulog);
                 }*/
            }
        }
        Boolean bl=false;
        boolean en=BattinfGroupFactory.backup_battinf();
        if(en){
            bl=DAOHelper.makeManualCommit(DBUtil.getConn(), sql_str);
        }else{
            return false;
        }
        //(new User_logService()).addPro(listU);//将用户的操作记录下来
        
        return bl;
    }
    //确认申请(多条)
    public boolean update(Object obj) {
        List<Battinf_apply> list=(List<Battinf_apply>) obj;
        List<User_log> listU=new ArrayList<User_log>();//存放user_log
        ArrayList<String> sql_str=new ArrayList();
        if(list!=null&&list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                Battinf_apply bapply=list.get(i);
                bapply.setConfrim_uid(((User_inf)ActionUtil.getUser()).getUId());
                BattInf binf=bapply.getBinf();
                binf.setStation_install(1);
                String sql_update_apply=" update db_battinf.tb_battinf_apply set confrim_uid="+bapply.getConfrim_uid()+",apply_en=1 where num="+bapply.getNum();
                sql_str.add(sql_update_apply);
                String sql_insert_binf="insert into db_battinf.tb_battinf(" +
                        "StationId,StationName,StationName1,StationName2,StationName3,StationName4,StationName5,StationIp,FBSDeviceId,FbsDeviceIp,FbsDeviceIp_YM,FbsDeviceIp_WG,"
                        + "FBSDeviceName,GroupIndexInFBSDevice,battgroupId,BattGroupNum,BattGroupName,FloatVolLevel,OfflineVolLevel,BattFloatCurrent" +
                        ",MonCount,MonCapStd,monVolStd,monResStd,MonSerStd,MonVolLowToAvg,BattProducer,BattModel,BattProductDate,BattInUseDate,Load_curr,install_user,DisCurrMax,station_phone,Station_install" +
                        ") values('"+binf.getStationId()+"','"+binf.getStationName()+"','"+binf.getStationName1()+"','"+binf.getStationName2()+"','"+binf.getStationName3()+"','"+binf.getStationName4()+"','"+binf.getStationName5()+
                        "','"+binf.getStationIp()+"',"+binf.getFBSDeviceId()+",'"+binf.getFbsDeviceIp()+"','"+binf.getFbsDeviceIp_YM()+"','"+binf.getFbsDeviceIp_WG()+"','"+binf.getFBSDeviceName()+"',"+binf.getGroupIndexInFBSDevice()+
                        ","+binf.getBattGroupId()+","+binf.getBattGroupNum()+",'"+binf.getBattGroupName()+"',"+binf.getFloatVolLevel()+","+binf.getOfflineVolLevel()+","+binf.getBattFloatCurrent()+
                        ","+binf.getMonCount()+","+binf.getMonCapStd()+","+binf.getMonVolStd()+","+binf.getMonResStd()+","+binf.getMonSerStd()+","+binf.getMonVolLowToAvg()+
                        ",'"+binf.getBattProducer()+"','"+binf.getBattModel()+"','"+DAOHelper.sdf.format(binf.getBattProductDate())+"','"+DAOHelper.sdf.format(binf.getBattInUseDate())+"',"+binf.getLoad_curr()+",'"+binf.getInstall_user()+"',"+binf.getDisCurrMax()+",'"+binf.getStation_phone()+"',"+binf.getStation_install()+")";
                sql_str.add(sql_insert_binf);
                {
                    String msg=((User_inf)ActionUtil.getUser()).getUId()+"确认添加"+binf.getStationName()+"机房"+binf.getBattGroupId()+"电池组的信息";
                    User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg);
                    listU.add(ulog);
                 }
            }
        }
        Boolean bl=false;
        boolean en=BattinfGroupFactory.backup_battinf();
        if(en){
            bl=DAOHelper.makeManualCommit(DBUtil.getConn(), sql_str);
        }else{
            return false;
        }
        (new User_logService()).addPro(listU);//将用户的操作记录下来
        return bl;
        
    }
 
    public boolean del(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    
    public List searchAll() {
        
        return null;
    }
    //查询出所有需要确认的申请
    public List serchByCondition(Object obj) {
        Battinf_apply bapply=(Battinf_apply) obj;
        BattInf b=bapply.getBinf();
        Page page=b.getPage();
        Connection conn=DBUtil.getConn();
        String numberSql=" SELECT FOUND_ROWS() number";
        String sql=" select SQL_CALC_FOUND_ROWS distinct num,apply_uid,confrim_uid,apply_date,apply_en,apply_note,StationId,StationName,StationName1,StationName2,StationName3,StationName4,StationName5,StationIp,FbsDeviceId,FbsDeviceIp_YM,FbsDeviceIp_WG,FbsDeviceIp"+
                 ",FBSDeviceName,GroupIndexInFBSDevice,battgroupId,BattGroupNum,BattGroupName,FloatVolLevel,OfflineVolLevel,BattFloatCurrent" +
                 ",MonCount,MonCapStd,monVolStd,monResStd,MonSerStd,MonVolLowToAvg,BattProducer,BattModel,BattProductDate,BattInUseDate,Load_curr,install_user,DisCurrMax,station_phone " +
                " from db_battinf.tb_battinf_apply " +
                " where apply_en=0  and stationName1 like ? and stationName2 like ? and stationId like ? and stationName5 like ? " +
                " limit ?,? ";
        List<Battinf_apply> list=DAOHelper.executeQueryLimit(sql, conn, new Object[]{"%"+b.getStationName1()+"%","%"+b.getStationName2()+"%","%"+b.getStationId()+"%","%"+b.getStationName5()+"%",(page.getPageCurr()-1)*page.getPageSize(),page.getPageSize()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Battinf_apply apply=new Battinf_apply();
                        apply.setNum(rs.getInt("num"));
                        apply.setApply_uid(rs.getInt("apply_uid"));
                        apply.setConfrim_uid(rs.getInt("confrim_uid"));
                        apply.setApply_en(rs.getInt("apply_en"));
                        apply.setApply_date(rs.getTimestamp("apply_date"));
                        apply.setApply_note(rs.getString("apply_note"));
                        
                        BattInf binf=new BattInf();
                        binf.setStationId(rs.getString("stationId"));
                        binf.setStationName(rs.getString("stationName"));
                        binf.setStationName1(rs.getString("stationName1"));
                        binf.setStationName2(rs.getString("stationName2"));
                        binf.setStationName3(rs.getString("stationName3"));
                        binf.setStationName4(rs.getString("stationName4"));
                        binf.setStationName5(rs.getString("stationName5"));
                        binf.setStationIp(rs.getString("stationIp"));
                        binf.setFBSDeviceId(rs.getInt("fBSDeviceId"));
                        
                        binf.setFbsDeviceIp(rs.getString("fbsDeviceIp"));
                        binf.setFbsDeviceIp_YM(rs.getString("fbsDeviceIp_YM"));
                        binf.setFbsDeviceIp_WG(rs.getString("fbsDeviceIp_WG"));
                        binf.setFBSDeviceName(rs.getString("fBSDeviceName"));
                        binf.setGroupIndexInFBSDevice(rs.getInt("groupIndexInFBSDevice"));
                        binf.setBattGroupId(rs.getInt("battGroupId"));
                        binf.setBattGroupNum(rs.getInt("battGroupNum"));
                        binf.setBattGroupName(rs.getString("battGroupName"));
                        binf.setFloatVolLevel(rs.getFloat("floatVolLevel"));
                        binf.setOfflineVolLevel(rs.getFloat("offlineVolLevel"));
                        binf.setBattFloatCurrent(rs.getFloat("battFloatCurrent"));
                        binf.setMonCount(rs.getInt("monCount"));
                        binf.setMonCapStd(rs.getFloat("monCapStd"));
                        binf.setMonVolStd(rs.getFloat("monVolStd"));
                        binf.setMonResStd(rs.getFloat("monResStd"));
                        binf.setMonSerStd(rs.getFloat("monSerStd"));
                        binf.setMonVolLowToAvg(rs.getFloat("monVolLowToAvg"));
                        binf.setBattProducer(rs.getString("battProducer"));
                        binf.setBattModel(rs.getString("battModel"));
                        binf.setBattProductDate(rs.getDate("battProductDate"));
                        binf.setBattInUseDate(rs.getDate("battInUseDate"));
                        binf.setLoad_curr(rs.getFloat("load_curr"));
                        binf.setInstall_user(rs.getString("install_user"));
                        binf.setDisCurrMax(rs.getFloat("disCurrMax"));
                        binf.setStation_phone(rs.getString("station_phone"));
                        
                        apply.setBinf(binf);
                        list.add(apply);
                        
                    }
                } 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).setNum(number);
        }
        return list;
    }
    //查询出当前存在内存中最大的设备的id(很重要**********)
    public int searchMaxdevId_apply(){
        String sql="select max(FbsDeviceId) as id  from db_battinf.tb_battinf_apply limit 1";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        int dev_id=0;
                        if(rs.getString("id")!=null){}
                        dev_id=rs.getInt("id");
                        list.add(dev_id);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        int dev_id=0;
        if(list!=null&&list.size()>0){
            dev_id=(Integer) list.get(list.size()-1);
        }
        return dev_id;
    }
    public List serchByInfo(Object obj) {
        // TODO Auto-generated method stub
        return null;
    }
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = sdf.parse("2000-01-01 00:00:00");
        Date date2 = sdf.parse("2020-01-01 23:59:59");
        Battinf_applyImpl bimpl=new Battinf_applyImpl();
        Battinf_apply bapply=new Battinf_apply();
        bapply.setApply_date(ActionUtil.getSimpDate(date2));
        bapply.setApply_uid(1002);
        
        
        BattInf binf=new BattInf();
        binf.setStationName1("湖北省");
        binf.setStationName2("武汉市");
        binf.setStationName3("荆门市");
        binf.setStationName4("BTS设备");
        binf.setStationName5("钟祥");
        binf.setStationId("4011100");
        binf.setStationIp("");
        binf.setFBSDeviceId(910001000);
        binf.setFbsDeviceIp("127.0.0.1");
        binf.setFbsDeviceIp_YM("255.255.255.0");
        binf.setFbsDeviceIp_WG("127.0.0.1");
        binf.setFBSDeviceName("设备名称");
        binf.setGroupIndexInFBSDevice(1); 
        binf.setBattGroupId(1000005); 
        binf.setBattGroupNum(2); 
        binf.setBattGroupName("电池组1");
        binf.setFloatVolLevel(54f);
        binf.setOfflineVolLevel(42.9f ); 
        binf.setBattFloatCurrent(10f); 
        binf.setMonCount(24); 
        binf.setMonCapStd(300f); 
        binf.setMonVolStd(2f); 
        binf.setMonResStd(0.2f); 
        binf.setMonSerStd(5000f); 
        binf.setMonVolLowToAvg(0.05f ); 
        binf.setLoad_curr(15f); 
        binf.setDisCurrMax(39.5f);
        binf.setStation_phone("12345678912"); 
        binf.setBattProducer("");
        binf.setBattModel(""); 
        binf.setBattProductDate(ActionUtil.getSimpDate(date1));
        binf.setBattInUseDate(ActionUtil.getSimpDate(date2));
        binf.setInstall_user("");
 
        Page page=new Page();
        page.setPageCurr(1);
        page.setPageSize(10);
        binf.setPage(page);
        bapply.setBinf(binf);
        /*List list=bimpl.serchByCondition(bapply);
        System.out.println(list.size());*/
        /*List list=new ArrayList();
        list.add(bapply);
        boolean bl=bimpl.add(list);
        System.err.println(bl);*/
        int dev_id=BattinfGroupFactory.searchmaxdev_id();
        System.out.println(dev_id);
    }
}