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
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 sun.print.SunMinMaxPage;
 
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.BaseDAOFactory;
import com.fgkj.dao.impl.BattInfImpl;
import com.fgkj.dao.impl.User_task_batt_testImpl;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_maint_inf;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.Task_Batt_Test;
import com.fgkj.dto.User_inf;
import com.fgkj.dto.User_task_batt_test;
import com.fgkj.dto.User_task_param;
 
public class User_task_batt_testService {
 
    private ServiceModel model;
    private BaseDAO dao;
    
    public User_task_batt_testService() {
        model=new ServiceModel();
        dao=BaseDAOFactory.getBaseDAO(BaseDAO.USER_TASK_BATT_TEST);
    }
    public ServiceModel add(Object obj) {
        Boolean bl=dao.add(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }
        else{
            model.setMsg("添加失败!");
        }
        return model;
        
    }
    //4.1作业管理(修改执行人)
    public ServiceModel updateTask(Object obj) {
        Boolean bl=((User_task_batt_testImpl)dao).updateTask(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;    
    }
    //4.1作业管理(作业删除)
    public ServiceModel delete(Object obj) {
        Boolean bl=dao.del(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }
        else{
            model.setMsg("删除失败!");
        }
        return model;    
    }
    //4.6作业报表(根据电池组信息以及统计方式查询user_task_batt_test信息)
    public List serchByInfo(Object obj){
        Task_Batt_Test tbt=(Task_Batt_Test) obj;
        System.out.println(tbt);
        // 总作业数
        List<Task_Batt_Test> list=dao.serchByInfo(tbt);
        //System.out.println(list.size());
        int allTask=list.size();
        //已完成作业总数
        tbt.getUtest().setTest_complete(1);
        //System.out.println(tbt.getUtest().getTest_complete());
        List<Task_Batt_Test> listCompelete = dao.serchByInfo(tbt);
        int compeleteTask=listCompelete.size();
        //及时完成作业数
        tbt.getUtest().setTest_complete(2);
        //System.out.println(tbt.getUtest().getTest_complete());
        List<Task_Batt_Test> listRightNow = dao.serchByInfo(tbt);
        int rightNowTask=listRightNow.size();
    //    System.out.println(allTask+"  "+compeleteTask+"   "+rightNowTask);
    //    System.out.println(allTask+"  "+compeleteTask+"   "+uncompeleteTask);
        List<ServiceModel> listmodel=new ArrayList<ServiceModel>();
        
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                // 时间段
                String perid_Time = "";
                Date Task_exe_date = list.get(i).getUtest().getTask_exe_date();
                Date Task_exe_date1 = list.get(i).getUtest().getTask_exe_date1();
                // System.out.println(maint_time_limit);
                // System.out.println(maint_done_time.getTime());
                // System.out.println(maint_time_limit.getTime());
 
                // 获取具体年份,月份和该月的总天数
                int year = Task_exe_date.getYear() + 1900;
                int month = Task_exe_date.getMonth() + 1;
                int day=ActionUtil.getDaysByYearMonth(year, month);
                 //System.out.println(day);
                // 获取统计方式
                String method = list.get(i).getUtest().getNote();
                if (method.equals("1")) {// 按月份
                    perid_Time = ActionUtil.getFirstDayOfMonth(year, month - 1);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year, month - 1);
                //    System.out.println(method+":"+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(method+":"+perid_Time);
                } else if (method.equals("3")) {// 按年份
                    perid_Time = ActionUtil.getFirstDayOfMonth(year, 0);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year, 11);
                // System.out.println(method+":"+perid_Time);
                }
                model = new ServiceModel();
                
                model.setMsgN(perid_Time); // 时间段
                model.setSum(allTask);     //总数
                Float percentTask=0f;
                if(allTask!=0){
                    percentTask= (float) (compeleteTask/ allTask);
                }
                model.setLowCH(percentTask);//完成率
                model.setNewsum(compeleteTask); // 完成次数
                model.setLowCA((float)rightNowTask);//及时完成数
                model.setLowRA((float)(compeleteTask-rightNowTask));//未及时完成数
                Float percentRightTask=0f;
                if(compeleteTask!=0){
                    percentRightTask= (float) (rightNowTask/ compeleteTask);
                }
                model.setLowRH(percentRightTask);//及时完成率
 
                model.setMsg(list.get(i).getBinf().getSignalName());//执行人
                model.setMsgO(list.get(i).getBinf().getStationName1());    //维护区
                model.setMsgV(list.get(i).getBinf().getStationName());//机房站点
                model.setMsgT(list.get(i).getBinf().getBattGroupName());//电池组名称
                listmodel.add(model);
            }
        } else {
            model.setMsg("查询失败!");
            model.setCode(0);
            listmodel.add(model);
        }
        ServiceModel lastModel=new ServiceModel();
        lastModel.setMsgN("0");
        lastModel.setCode(model.getCode());
        lastModel.setMsg(model.getMsg());
        lastModel.setLowCA(model.getLowCA());
        lastModel.setLowCH(model.getLowCH());
        lastModel.setLowRA(model.getLowRA());
        lastModel.setLowRH(model.getLowRH());
 
        lastModel.setMsgV(model.getMsgV());
        lastModel.setMsgO(model.getMsgO());
        lastModel.setMsgT(model.getMsgT());
        listmodel.add(lastModel);//补全最后一次时间改变
        int num=0;//存放下发作业数
        String time="";
        ServiceModel sumModel=null;
        List<ServiceModel> last=new ArrayList<ServiceModel>();
        //System.out.println(listmodel.size()+"***");
        if(listmodel.size()>2){
            for (int i=0;i<listmodel.size();i++) {    
                //System.out.println(listmodel.get(i).getMsgN());
                if(listmodel.get(i).getMsgN().equals(time)){
                    num++;
                }else{
                    if(i!=0){
                        sumModel=new ServiceModel();    
                        sumModel.setSum(num+1);
                        sumModel.setMsg(listmodel.get(i).getMsg());//执行人
                        sumModel.setNewsum(listmodel.get(i).getNewsum());// 完成次数
                        //未完成数
                        int uncompeleteTask=sumModel.getSum()-sumModel.getNewsum();
                        sumModel.setCode(uncompeleteTask);//未完成数
                        sumModel.setLowCH(listmodel.get(i).getLowCH());//完成率
                        sumModel.setLowCA(listmodel.get(i).getLowCA());//及时完成数
                        sumModel.setLowRA(listmodel.get(i).getLowRA());//未及时完成数
                        sumModel.setLowRH(listmodel.get(i).getLowRH());//及时完成率
                        sumModel.setMsgN(time);//时间段
                        sumModel.setMsgV(listmodel.get(i).getMsgV());//机房站点
                        sumModel.setMsgO(listmodel.get(i).getMsgO()); //维护区
                        sumModel.setMsgT(listmodel.get(i).getMsgT());//电池组名称
                        
                        last.add(sumModel);
                    }
                    num=0;            
                    time=listmodel.get(i).getMsgN();
                }    
            }    
        }
        /*for (ServiceModel s : last) {
            System.out.println(s);
        }*/
        //System.out.println(last.size());
        return last;
    }
    
    public ServiceModel serchByCondition(Object obj){
        List list=dao.serchByCondition(obj);
//        for (Object object : list) {
//            System.out.println(object);
//        }
        
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
        }
        //System.out.println(model);        
        return model;
    } 
    public ServiceModel searchAll(){
        List list=dao.searchAll();
//        for (Object object : list) {
//            System.out.println(object);
//        }
        //System.out.println(list);
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
        }        
        return model;
    } 
    public static void main(String[] args) throws ParseException {
        User_task_batt_testService us = new User_task_batt_testService();
        /*User_task_batt_test u=new User_task_batt_test();
        u.setNum(10578);
        us.serchByCondition(u);
        //us.searchAll();*/    
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2000-01-01");
        Date date2 = sdf.parse("2016-11-30");
        Date date3 = sdf.parse("2000-01-01");
        Date date4 = sdf.parse("2016-11-30");
        
        User_task_batt_test utest=new User_task_batt_test();
        utest.setTask_usr_ids("0");
        utest.setTest_complete(100);//已完成:1 未完成:0 全部:100
        utest.setTask_exe_date(date3);
        utest.setTask_exe_date1(date4);
        utest.setNote("1");//1:按月份 2:按季度 3:按年份
        
        BattInf binf = new BattInf();
        binf.setStationName("");
        binf.setStationName1("");
        binf.setBattGroupName("");        //电池组名
        binf.setSignalName("");            //执行人
        binf.setBattGroupId(0);
        binf.setBattGroupName1("");
        binf.setBattProducer("");
        binf.setMonCapStd(0f);
        binf.setMonVolStd(0f);
        binf.setBattProductDate(ActionUtil.getSimpDate(date1));
        binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
        binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
        binf.setBattInUseDate1(ActionUtil.getSimpDate(date2));
        
        User_inf uinf=new User_inf();
        uinf.setUId(0);
        
        Task_Batt_Test tbt=new Task_Batt_Test();
        tbt.setBinf(binf);
        tbt.setUtest(utest);
        tbt.setUinf(uinf);
        us.serchByInfo(tbt);
    }    
}