whyclj
2020-07-22 a5729100cb1eaa3584b3a194e46e1b8b52b3ed1a
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
package com.fgkj.services;
 
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.BaseDAOFactory;
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.impl.BattInfImpl;
import com.fgkj.dao.impl.Batt_maint_infImpl;
import com.fgkj.dao.impl.Batt_maint_processImpl;
import com.fgkj.db.DBUtil;
import com.fgkj.db.IDatabaseName;
import com.fgkj.dto.AllModel;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_Maint_Dealarm;
import com.fgkj.dto.Batt_User_Permit;
import com.fgkj.dto.Batt_maint_inf;
import com.fgkj.dto.Batt_maint_process;
import com.fgkj.dto.Batt_maintenance_inf;
import com.fgkj.dto.Batttestdata_inf;
import com.fgkj.dto.Page;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_inf;
 
public class Batt_maint_infService {
    private ServiceModel model;
    private BaseDAO dao;
    private BaseDAO daoAgain;
    private BaseDAO daoProcess;
    private User_infService uservice;
    private Batt_maint_processService pservice;
    
    public Batt_maint_infService() {
        model=new ServiceModel();
        dao=BaseDAOFactory.getBaseDAO(BaseDAO.BATT_MAINT_INF);
        daoAgain = BaseDAOFactory.getBaseDAO(BaseDAO.BATT_MAINT_INFAGAIN);
        daoProcess=BaseDAOFactory.getBaseDAO(BaseDAO.BATT_MAINT_PROCESS);
        uservice=new User_infService();
        pservice=new Batt_maint_processService();
    }
    
    
    //2.1电池故障维护记录查询
    public ServiceModel serchMaint(Object obj){
        Batt_Maint_Dealarm bmd = (Batt_Maint_Dealarm) obj;
        User_inf uinf=new User_inf();
        Batt_maint_process pinf=new Batt_maint_process();
        List<Batt_Maint_Dealarm> list =dao.serchByCondition(bmd);
        for(int i=0;i<list.size();i++){
            
            Batt_maint_inf mainf=list.get(i).getMainf();
            if(list.get(i).getMainf().getUsr_id()!=null){
                uinf.setUId(list.get(i).getMainf().getUsr_id());
                mainf.setUname(((List<User_inf>) uservice.serchuName(uinf).getData()).get(0).getUName());
            //    System.out.println(mainf.getUname());
                
                }
                
                if(list.get(i).getMainf().getCopy_uids()!=null&&list.get(i).getMainf().getCopy_uids().length()>0){
                    //System.out.println(list.get(i).getMainf().getCopy_uids());
                    String[] names=list.get(i).getMainf().getCopy_uids().split(",");
                    String copyname=new String();
                    for (String string : names) {
                        uinf.setUId(Integer.parseInt(string));
                        copyname+=((List<User_inf>) uservice.serchuName(uinf).getData()).get(0).getUName()+",";
                    }
                    
                    copyname=copyname.substring(0, copyname.length()-1);
                    mainf.setCopy_name(copyname);
                    //System.out.println(mainf.getCopy_name());
                }
                
                if(list.get(i).getMainf().getAppoint_uid()!=null){
                uinf.setUId(list.get(i).getMainf().getAppoint_uid());
                mainf.setAppoint_name(((List<User_inf>) uservice.serchuName(uinf).getData()).get(0).getUName());
            //    System.out.println(mainf.getAppoint_name());
                }
            list.get(i).setMainf(mainf);
            //System.out.println(list.size());
        }
        if(list!=null&&list.size()>0){
            model.setCode(1);
            model.setData(list);
            model.setMsg("查询成功!");
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
    
    // 2.2电池故障处理统计查询
    /*
     * maint_result存放统计方式 
     * fault_caption存放维护区 
     * master_check存放包机人 
     * remark存放品牌
     */
    public List serchByCondition(Object obj) {
        //System.out.println(obj+"&&&&&&&&&&&&");
        Batt_User_Permit bup = (Batt_User_Permit) obj;
        BattInf binf=bup.getBinf();
        List<Batt_maint_inf> list = daoAgain.serchByCondition(binf);
        List<BattInf> listb=(new BattInfImpl()).searchAll();
        // 总电池数
        int allBatt=listb.size();
        // 超时次数
        List<ServiceModel> listmodel=new ArrayList<ServiceModel>();
        
        //System.out.println(list.get(1));
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                //System.out.println(list.size()+"lll");
                int overTime = 0;
                // 未完成次数
                int lastNum = 0;
                // 时间段
                String perid_Time = "";
                
                //System.out.println(i);
                Date maint_time_limit = list.get(i).getMaint_time_limit();
                Date maint_done_time = list.get(i).getMaint_done_time();
                // System.out.println(maint_time_limit);
                // System.out.println(maint_done_time.getTime());
                // System.out.println(maint_time_limit.getTime());
 
                // 获取具体年份,月份和该月的总天数
                int year = maint_time_limit.getYear() + 1900;
                int month = maint_time_limit.getMonth() + 1;
                // int day=ActionUtil.getDaysByYearMonth(year, month);
                // System.out.println(day);
 
                // 获取统计方式
                String method = list.get(i).getMaint_result();
 
                if (method.equals("1")) {// 按月份
                    perid_Time = ActionUtil.getFirstDayOfMonth(year, month - 1);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year, month - 1);
                    // System.out.println(perid_Time);
                } else if (method.equals("2")) {// 按季度
                    if (month < 3) {
                        month = 1;
                    } else {
                        if (month % 3 == 0) {
                            month = month / 3;
                        } else {
                            month = month / 3 + 1;
                        }
                    }
                //    System.out.println(month);
 
                    perid_Time = ActionUtil.getFirstDayOfMonth(year,(month - 1) * 3);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year,month * 3 - 1);
                    // System.out.println(perid_Time);
                } else if (method.equals("3")) {// 按年份
                    perid_Time = ActionUtil.getFirstDayOfMonth(year, 0);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year, 11);
                    // System.out.println(perid_Time);
                }
                if (maint_done_time.getTime() > maint_time_limit.getTime()) {
                    overTime++;
                }
                if (list.get(i).getMaint_done() == 0) {
                    lastNum++;
                }
                model = new ServiceModel();
                model.setCode(1);
                model.setMsgN(perid_Time); // 时间段
                model.setSum(list.size()); // 故障次数
                Float percentBatt=0f;
                if(allBatt!=0){
                    percentBatt= (float) (list.size()/ allBatt);
                }
                //System.out.println(list.size());
                //System.out.println(allBatt);
                //System.out.println(percentBatt);
                model.setLowCH(percentBatt);//电池故障率
                
                model.setNewsum(lastNum); // 未完成次数
                Float percent = (float) (overTime / list.size());
                model.setLowCA(percent); // 超时率
                model.setMsg(list.get(i).getFault_caption());//维护区
                model.setMsgO(list.get(i).getMaster_check());    //责任人
                model.setMsgV(list.get(i).getRemark());//电池品牌
                listmodel.add(model);
            }
        } else {    
            model.setCode(0);
            model.setMsgN("0");
            listmodel.add(model);
        }
        ServiceModel lastModel=new ServiceModel();
        lastModel.setMsgN("0");
        lastModel.setCode(model.getCode());
        lastModel.setMsg(model.getMsg());
        lastModel.setLowCH(model.getLowCH());
        lastModel.setLowCA(model.getLowCA());
        lastModel.setMsgO(model.getMsgO());
        lastModel.setMsgV(model.getMsgV());
        listmodel.add(lastModel);//补全最后一次时间改变
    //    System.out.println(listmodel.size());
        int num=0;//存放下发作业数
        String time="";
        ServiceModel sumModel=null;
        List<ServiceModel> last=new ArrayList<ServiceModel>();
        for (int i=0;i<listmodel.size();i++) {
            //System.out.println(listmodel.get(i));
              if(listmodel.get(i).getMsgN().equals(time)){
                   num++;
               }else{
                   if(i!=0){
                        sumModel=new ServiceModel();
                        sumModel.setSum(num+1);// 故障次数
                        sumModel.setNewsum(listmodel.get(i).getNewsum());// 未完成次数
                        sumModel.setCode(listmodel.get(i).getCode());
                        sumModel.setLowCH(listmodel.get(i).getLowCH());//故障率
                        sumModel.setLowCA(listmodel.get(i).getLowCA());// 超时率
                        sumModel.setMsgN(time);//时间段
                        sumModel.setMsgV(listmodel.get(i).getMsgV());//电池平拍
                        sumModel.setMsgO(listmodel.get(i).getMsgO()); //责任人
                        sumModel.setMsg(listmodel.get(i).getMsg());//维护区
                        last.add(sumModel);        
                   }
                num=0;                  
                time=listmodel.get(i).getMsgN();
            }
                
        } 
//        for (ServiceModel s : last) {
//            System.out.println(s);
//        }
        
        
        List<ServiceModel> listd=new ArrayList();
        for(int i=(bup.getPage().getPageCurr()-1)*bup.getPage().getPageSize();i<bup.getPage().getPageSize()*bup.getPage().getPageCurr()&&i<last.size();i++){
            last.get(i).setLowRA((float)last.size());
            listd.add(last.get(i));
        }
        return listd;
 
    }
 
    public ServiceModel add(Object obj) {
        Boolean bl=dao.add(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }
        else{
            model.setMsg("添加失败!");
        }
        return model;
        
    }
    //2.1 电池维护记录查询(编辑记录)
    public ServiceModel update(Object obj1,Object obj2) {
        Batt_maint_inf mainf=(Batt_maint_inf) obj1;
        Boolean bl = dao.update(mainf);
        //System.out.println(bl);
        List<Batt_maint_process> process = (List<Batt_maint_process>)obj2;
        ArrayList<String> sql_str = new ArrayList<String>();//存放所有的sql语句
        if (bl) {
            for(int i=0;i<process.size();i++){
                Batt_maint_process bprocess=process.get(i);
                bprocess.setBatt_maint_rec_id(mainf.getNum());
                sql_str.add(((Batt_maint_processImpl)daoProcess).addPro(bprocess));
                //System.out.println("sql_str:"+sql_str);
                
            }
            Boolean blP= DAOHelper.makeManualCommit(DBUtil.getConn(),sql_str);
            if(blP){
                model.setCode(1);
                model.setMsg("修改成功!");
            }    
            else {
                model.setCode(0);
                model.setMsg("修改失败!");
            }
                
        } else {
            model.setMsg("修改失败!");
        }
        return model;
    }
 
    //2.1 电池维护记录查询(删除记录)
    public ServiceModel delete(Object obj) {
        Batt_maint_inf mainf=(Batt_maint_inf) obj;
        Batt_maint_process bprocess=new Batt_maint_process();
        bprocess.setBatt_maint_rec_id(mainf.getNum());                //通过Batt_maint_rec_id属性删除
        Boolean bl = dao.del(mainf);
        if (bl) {
            Boolean blp=daoProcess.del(bprocess);
            if(blp){
                model.setCode(1);
                model.setMsg("删除成功!");
            }else{
                model.setCode(0);
                model.setMsg("删除失败!");
            }
            
        } else {
            model.setCode(0);
            model.setMsg("删除失败!");
        }
        return model;
    }
 
 
    //1.1,1.2根据battgroupid查时间
    public ServiceModel serchByInfo(Object obj) {
        model=new ServiceModel();
        Batt_maint_inf mainf =(Batt_maint_inf) obj;
        List<Batt_maint_inf> list = dao.serchByInfo(mainf);
        /*for (Batt_maint_inf u : list) {
            System.out.println(u);
        }*/
 
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setData(list);
            model.setSum(list.size());
        }
        return model;
    }
 
    //0.3查询所有的维护记录(只传page对象)
    public ServiceModel search(){
        //Batt_Maint_Dealarm bmd=(Batt_Maint_Dealarm) obj;
        List<Batt_Maint_Dealarm> list=((Batt_maint_infImpl)dao).search();
        if(list!=null&&list.size()>0){
            model.setCode(1);
            model.setData(list);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
 
    //0.4电池组故障率
    public ServiceModel searchAll() {
        List<Batt_maint_inf> list = dao.searchAll();
        List<BattInf> listb=new BattInfImpl().searchAll();
        if(list!=null && listb!=null){
            model.setCode(1);
            model.setNewsum(list.size());
            model.setSum(listb.size());
        }
        //System.out.println(model);
        return model;
    }
 
    //0.4/0.8电池组故障率/维护率(最新)
    public ServiceModel searchByStationName(Object obj) {
        Batt_Maint_Dealarm bmd=(Batt_Maint_Dealarm) obj;
        BattInf binf=bmd.getBinf();
        Batt_maint_inf mainf=bmd.getMainf();
        List<Batt_maint_inf> list = ((Batt_maint_infImpl)dao).searchByStationName(bmd);        //故障数
        mainf.setMaint_done(1);
        List<Batt_maint_inf> listD = ((Batt_maint_infImpl)dao).searchByStationName(bmd);    //故障维护数
        
        List<BattInf> listB=new BattInfImpl().search(binf);//
        model.setCode(listD.size());      ////故障维护数
        model.setNewsum(listB.size());    //电池组数
        model.setSum(list.size());          //故障数    
        //System.out.println(model);
        return model;
    }
    
    //根据电池组id查询电池的故障记录
    public ServiceModel searchByBattgroupId(Object obj) {
        model=new ServiceModel();
        List<Batt_maint_inf> list = ((Batt_maint_infImpl)dao).searchByBattgroupId(obj);
        User_inf uinf=new User_inf();        
        if(list!=null && list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                uinf.setUId(list.get(i).getUsr_id());
                List<User_inf> users=(List<User_inf>) uservice.serchuName(uinf).getData();
                //System.out.println(users);
                if(users.size()>0){
                    list.get(i).setUname(users.get(0).getUName());
                }
                //System.out.println(list.get(i));
            }
            model.setCode(1);
            model.setData(list);
            model.setMsg("查询成功");
        }else{
            model.setMsg("查询失败");
        }
        return model;
    }
 
    public static void main(String[] args) throws ParseException {
        Batt_maint_infService us = new Batt_maint_infService();
 
        BattInf binf = new BattInf();
        /*
         * 维护区:stationname1 包机人:stationname 电池品牌:battproducer 统计方式:devicename
         * 统计开始时间:battproductdate 统计结束时间:battproductdata1
         */
        binf.setStationName("");
        binf.setStationName1("");
        binf.setBattGroupName("");
        binf.setBattGroupName1("");
        binf.setBattProducer("");
        binf.setBattGroupId(0);
 
        binf.setDeviceName("2");
        binf.setMonCapStd(0f);
        binf.setMonVolStd(0f);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2000-01-01");
        Date date2 = sdf.parse("2016-12-30");
        binf.setBattProductDate(ActionUtil.getSimpDate(date1));
        binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
        binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
        binf.setBattInUseDate1(ActionUtil.getSimpDate(date2));
 
        /*
         * binf.getStationName1(), binf.getStationName(),
         * binf.getBattGroupName(), binf.getBattProducer(),
         * binf.getBattGroupName1(), binf.getBattProductDate(),
         * binf.getBattProductDate1(), binf.getBattInUseDate(),
         * binf.getBattInUseDate1(),uinf.getuName()
         */
 
        Batt_maint_inf mainf = new Batt_maint_inf();
        mainf.setRemark("100");
        mainf.setMaint_done_time(ActionUtil.getSimpDate(date1));
        mainf.setMaint_done_time1(ActionUtil.getSimpDate(date2));
        mainf.setMaint_done(100);
 
        Batttestdata_inf tdata = new Batttestdata_inf();
        tdata.setTest_type(0);
        tdata.setTest_starttype(0);
        tdata.setRecord_time(ActionUtil.getSimpDate(date1));
        tdata.setRecord_time1(ActionUtil.getSimpDate(date2));
 
        User_inf uinf = new User_inf();
        uinf.setUName("0");
 
        Page p = new Page();
        p.setPageCurr(1);
        p.setPageSize(1);
 
        Batt_User_Permit bup=new Batt_User_Permit();
        bup.setBinf(binf);
        bup.setPage(p);
        bup.setUinf(uinf);
        
        Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
        bmd.setBinf(binf);
        bmd.setMainf(mainf);
        bmd.setTdata(tdata);
        bmd.setPage(p);
        bmd.setUinf(uinf);
        
        
        //us.searchByStationName(bmd);
       // us.serchMaint(bmd);
        //us.serchByCondition(bup);
        //us.search();
        //us.searchAll();
        mainf.setBattGroupId(1000001);
        us.searchByBattgroupId(mainf);
    }    
}