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
package com.fgkj.services;
 
import java.text.ParseException;
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.BattresdataDAOImpl;
import com.fgkj.dao.impl.Battresdata_infDAOImpl;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Battresdata;
import com.fgkj.dto.Battresdata_inf;
import com.fgkj.dto.ServiceModel;
 
public class Battresdata_infService {
    private ServiceModel model;
    private BaseDAO dao;
    private BaseDAO daoB;
    private BaseDAO daoR;
    public Battresdata_infService() {
        model = new ServiceModel();
        dao = BaseDAOFactory.getBaseDAO(BaseDAO.BATTRESDATA_INF);
        daoB= BaseDAOFactory.getBaseDAO(BaseDAO.BATTINF);
        daoR= BaseDAOFactory.getBaseDAO(BaseDAO.BATTRESDATA);
    }
 
    public ServiceModel add(Object obj) {
        Boolean bl = dao.add(obj);
        if (bl) {
            model.setCode(1);
            model.setMsg("添加成功!");
        } else {
            model.setMsg("添加失败!");
        }
        return model;
 
    }
 
    public ServiceModel update(Object obj) {
        Boolean bl = dao.update(obj);
        if (bl) {
            model.setCode(1);
            model.setMsg("修改成功!");
        } else {
            model.setMsg("修改失败!");
        }
        return model;
    }
 
    public ServiceModel delete(Object obj) {
        Boolean bl = dao.del(obj);
        if (bl) {
            model.setCode(1);
            model.setMsg("删除成功!");
        } else {
            model.setMsg("删除失败!");
        }
        return model;
    }
 
    //筛选存在battresdata_inf表中的数据
    public ServiceModel serchByCondition(Object obj){
            model=new ServiceModel();
            List list=dao.serchByCondition(obj);
            if(list!=null && list.size()>0){
                model.setCode(1);
                model.setData(list);
            }else{
                model.setCode(0);
            }
            //System.out.println(list.size());
        
            return model;
        }
    //测试battgroupid在battresdata_inf中是否存在
    public ServiceModel judge(Object obj){
        model=new ServiceModel();
        List<String> list=((Battresdata_infDAOImpl)dao).judge(obj);
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
        }
        /*for (String u :list) {
            System.out.println(u);
        }*/
        return model;
    }
    //查询所有
    public ServiceModel searchAll() {
        List<Battresdata_inf> list = dao.searchAll();
//        for (Battresdata_inf u : list) {
//            System.out.println(u);
//        }
        // System.out.println(list);
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setData(list);
        }
        return model;
    }
    //6.4.1根据条件查询符合条件的测试完成的电池组(蓄电池电导测试完成率)
        /*
         * data_available中存放层次
         * test_record_count 中存放统计方式:年度统计为0 季度统计为1
         * test_record_count_ex中存放统计季度:一季度为1 以此类推
         * test_type 中存放年份
         * upload_usr_id 中存上传方式 100:全部  0:自动上传  用户ID对应手动上传*/
    public ServiceModel serchComplete(Object obj){
        Battresdata_inf rinf=(Battresdata_inf) obj;
        int level=rinf.getData_available();
        int year=rinf.getTest_type();//获取年份
        int firstMonth=0;//获取起始月份
        int lastMonth=0;//获取结束月份
        String dateFirst=""; //起始时间
        String dateLast="";  //结束时间
        //做时间判断
        if(rinf.getTest_record_count()==0){
             firstMonth=0;//获取起始月份
             lastMonth=11;//获取结束月份
        }else if(rinf.getTest_record_count()==1){
             if(rinf.getTest_record_count_ex()==1){
                 firstMonth=0;//获取起始月份
                 lastMonth=2;//获取结束月份
             }else if(rinf.getTest_record_count_ex()==2){
                 firstMonth=3;//获取起始月份
                 lastMonth=5;//获取结束月份
             }else if(rinf.getTest_record_count_ex()==3){
                 firstMonth=6;//获取起始月份
                 lastMonth=8;//获取结束月份
             }else if(rinf.getTest_record_count_ex()==4){
                 firstMonth=9;//获取起始月份
                 lastMonth=11;//获取结束月份
             }
        }
        dateFirst=ActionUtil.getFirstDayOfMonth(year,firstMonth);//起始时间
        try {
            rinf.setTest_starttime(DAOHelper.sdf.parse(dateFirst));
            //System.out.println(dateFirst.substring(0,10));
            dateLast=ActionUtil.getLastDayOfMonth(year,lastMonth);//结束时间
            rinf.setTest_starttime_ex(DAOHelper.sdf.parse(dateLast));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //System.out.println(dateLast.substring(0,10));
        //System.out.println(dateFirst.substring(0,11).concat(dateLast.substring(0,10)));
        
        List<BattInf> listB=((BattInfImpl)daoB).serchBylevel(level);
        if(listB!=null&&listB.size()>0){
          for(int i=0;i<listB.size();i++){
             if(level==1){
                 rinf.setStationname1(listB.get(i).getStationName1());
                 rinf.setStationname2("");
                 rinf.setStationname3("");
                 rinf.setStationname4("");
            }else if(level==2){
                rinf.setStationname1(listB.get(i).getStationName1());
                 rinf.setStationname2(listB.get(i).getStationName2());
                 rinf.setStationname3("");
                 rinf.setStationname4("");
            }else if(level==3){
                rinf.setStationname1(listB.get(i).getStationName1());
                 rinf.setStationname2(listB.get(i).getStationName2());
                 rinf.setStationname3(listB.get(i).getStationName3());
                 rinf.setStationname4("");
            }else if(level==4){
                rinf.setStationname1(listB.get(i).getStationName1());
                 rinf.setStationname2(listB.get(i).getStationName2());
                 rinf.setStationname3(listB.get(i).getStationName3());
                 rinf.setStationname4(listB.get(i).getStationName4());
            }
            List<Battresdata_inf> list=((Battresdata_infDAOImpl)(dao)).serchComplete(rinf);   
            listB.get(i).setMonCount(list.size());//完成数
            listB.get(i).setStationName9(dateFirst.substring(0,11).concat(dateLast.substring(0,10)));
            if(listB.get(i).getMonNum()!=0){
                int numC=listB.get(i).getMonCount();
                int numM=listB.get(i).getMonNum();
                Float percent=(float) (((numC*1.0)/numM)*100);
                //System.out.println(percent);
                listB.get(i).setMonVolLowToAvg(percent);//完成率
            }
            }
         /* for (BattInf binf : listB) {
            System.out.println(binf);
        }*/
          model.setCode(1);
          model.setData(listB);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
 
    //6.4.3根据条件查询符合条件的测试完成的电池组(蓄电池电导合格率)
        /*
         * data_available中存放层次
         * test_record_count 中存放统计方式:年度统计为0 季度统计为1
         * test_record_count_ex中存放统计季度:一季度为1 以此类推
         * test_type 中存放年份*/
    public ServiceModel serchSer(Object obj) {
        Battresdata_inf rinf=(Battresdata_inf) obj;
        int level=rinf.getData_available();
        int year=rinf.getTest_type();//获取年份
        int firstMonth=0;//获取起始月份
        int lastMonth=0;//获取结束月份
        String dateFirst=""; //起始时间
        String dateLast="";  //结束时间
        //做时间判断
        if(rinf.getTest_record_count()==0){
             firstMonth=0;//获取起始月份
             lastMonth=11;//获取结束月份
        }else if(rinf.getTest_record_count()==1){
             if(rinf.getTest_record_count_ex()==1){
                 firstMonth=0;//获取起始月份
                 lastMonth=2;//获取结束月份
             }else if(rinf.getTest_record_count_ex()==2){
                 firstMonth=3;//获取起始月份
                 lastMonth=5;//获取结束月份
             }else if(rinf.getTest_record_count_ex()==3){
                 firstMonth=6;//获取起始月份
                 lastMonth=8;//获取结束月份
             }else if(rinf.getTest_record_count_ex()==4){
                 firstMonth=9;//获取起始月份
                 lastMonth=11;//获取结束月份
             }
        }
        dateFirst=ActionUtil.getFirstDayOfMonth(year,firstMonth);//起始时间
        try {
            rinf.setTest_starttime(DAOHelper.sdf.parse(dateFirst));
            //System.out.println(dateFirst.substring(0,10));
            dateLast=ActionUtil.getLastDayOfMonth(year,lastMonth);//结束时间
            rinf.setTest_starttime_ex(DAOHelper.sdf.parse(dateLast));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        List<BattInf> listB=((BattInfImpl)daoB).serchBylevel(level);
        if(listB!=null&&listB.size()>0){
            for(int i=0;i<listB.size();i++){
                if(level==1){
                    rinf.setStationname1(listB.get(i).getStationName1());
                    rinf.setStationname2("");
                    rinf.setStationname3("");
                    rinf.setStationname4("");
                }else if(level==2){
                    rinf.setStationname1(listB.get(i).getStationName1());
                     rinf.setStationname2(listB.get(i).getStationName2());
                     rinf.setStationname3("");
                     rinf.setStationname4("");
                }else if(level==3){
                    rinf.setStationname1(listB.get(i).getStationName1());
                     rinf.setStationname2(listB.get(i).getStationName2());
                     rinf.setStationname3(listB.get(i).getStationName3());
                     rinf.setStationname4("");
                }else if(level==4){
                    rinf.setStationname1(listB.get(i).getStationName1());
                     rinf.setStationname2(listB.get(i).getStationName2());
                     rinf.setStationname3(listB.get(i).getStationName3());
                     rinf.setStationname4(listB.get(i).getStationName4());
                }
                 listB.get(i).setStationName9(dateFirst.substring(0,11).concat(dateLast.substring(0,10)));
                 Float monSerStd=0f;//标存电导
                List<Battresdata_inf> list=((Battresdata_infDAOImpl)(dao)).serchSer(rinf); 
                int numC=0;//已完成个数总数
                int numQ=0;//80%合格个数总数
                if(list!=null&&list.size()>0){
                    Battresdata rdata=new Battresdata();
                    for(int j=0;j<list.size();j++){
                        rdata.setBattGroupId(list.get(j).getBattGroupId());
                        rdata.setTest_starttime(list.get(j).getTest_starttime());
                        rdata.setTest_record_count(list.get(j).getTest_record_count());
                        rdata.setMon_ser(0f);
                        List listC=((BattresdataDAOImpl)(daoR)).serchSer(rdata);//已测试
                        numC+=listC.size();
                        BattInf binf=new BattInf();//求battgroupid标存电导
                        binf.setBattGroupId(list.get(j).getBattGroupId());
                        List<BattInf> listS=(new BattInfImpl()).serchByCondition(binf);
                        if(list!=null&&list.size()>0){
                            monSerStd=listS.get(list.size()-1).getMonSerStd();
                        }
                        rdata.setMon_ser((float) 0.8*monSerStd);
                        List listQ=((BattresdataDAOImpl)(daoR)).serchSer(rdata);//80%合格测试
                        numQ+=listQ.size();
                        // System.out.println("1:"+numC+"   "+numQ);
                   }
                      
                }
                
                listB.get(i).setStationId(list.size()+"");//已经测试电池组数  monnum中存放的所有的电池组数(某个分组)
                listB.get(i).setGroupIndexInFBSDevice(numC);//已经测试的电池单体总数
                listB.get(i).setBattGroupNum(numQ);//大于80%容量的电池单体总数
            }
//            for(BattInf binf : listB) {
//                System.out.println(binf.getGroupIndexInFBSDevice()+"  "+binf.getBattGroupNum());
//            }
            model.setCode(1);
            model.setData(listB);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
 
    
    public static void main(String[] args) {
        Battresdata_infService brids = new Battresdata_infService();
        Battresdata_inf brid = new Battresdata_inf();
        brid.setTest_record_count(1);
        // brids.serchByCondition(brid);
        //brids.searchAll();
        Battresdata_inf brsdata=new Battresdata_inf();
        brsdata.setBattGroupId(1002561);
        brids.serchByCondition(brsdata);
    }
}