whycrzg
2021-02-23 351b9a53cb9ecebdf8f79db0117f540d9c42c2a4
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
package com.fgkj.services;
 
import com.fgkj.dto.User_task;
import com.fgkj.util.*;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.Task_Batt_Test;
import com.fgkj.mapper.impl.User_task_batt_testMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
@Service
public class User_task_batt_testService {
 
    @Resource
    private User_task_batt_testMapper mapper;;
    
    public ServiceModel add(Object obj) {
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.add(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }
        else{
            model.setMsg("添加失败!");
        }
        return model;
        
    }
    //4.1作业管理(修改执行人)
    public ServiceModel updateTask(Object obj) {
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.updateTask(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;    
    }
    //4.1作业管理(作业删除)
    public ServiceModel delete(Object obj) {
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.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){
        ServiceModel model = new ServiceModel();
        Task_Batt_Test tbt=(Task_Batt_Test) obj;
        System.out.println(tbt);
        // 总作业数
        List<Task_Batt_Test> list=mapper.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 = mapper.serchByInfo(tbt);
        int compeleteTask=listCompelete.size();
        //及时完成作业数
        tbt.getUtest().setTest_complete(2);
        //System.out.println(tbt.getUtest().getTest_complete());
        List<Task_Batt_Test> listRightNow = mapper.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();
                //TODO perry
                /*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();
        List<ServiceModel> last=new ArrayList<ServiceModel>();
        //TODO perry
        /*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(User_task obj){
        ServiceModel model = new ServiceModel();
        List list=mapper.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(){
        ServiceModel model = new ServiceModel();
        List list=mapper.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;
    } 
    
}