whycrzg
2021-02-03 9948b3f9a8d2d471a608b169de946eeb7d08b4b5
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
package com.fgkj.services;
 
import com.fgkj.dto.*;
import com.fgkj.mapper.impl.Batt_electricityMapper;
import com.fgkj.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
 
import javax.annotation.Resource;
@Service
public class Batt_electricityService {
 
    @Resource
    private Batt_electricityMapper mapper;;
 
    ServiceModel model = new ServiceModel();
    
    public ServiceModel add(Batt_electricity obj){
        ServiceModel model = new ServiceModel();
        Boolean bl= null;
        try {
            bl = mapper.add(obj)>0;
        } catch (Exception e) {
            e.printStackTrace();
            model.setCode(0);
            model.setMsg("添加失败!");
            return model;
        }
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }else{
            model.setCode(0);
            model.setMsg("添加失败!");
        }
        return model;
    }
    public ServiceModel update(Batt_electricity obj){
        ServiceModel model = new ServiceModel();
        Boolean bl= null;
        try {
            bl = mapper.update(obj);
        } catch (Exception e) {
            e.printStackTrace();
            model.setCode(0);
            model.setMsg("修改失败!");
            return model;
        }
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }else{
            model.setCode(0);
            model.setMsg("修改失败!");
        }
        return model;
    }
    public ServiceModel del(Batt_electricity obj){
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.del(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }else{
            model.setCode(0);
            model.setMsg("删除失败!");
        }
        return model;
    }
    public ServiceModel searchAll(){
        ServiceModel model = new ServiceModel();
        List list=mapper.searchAll();
        if(list!=null&&list.size()>0){
            model.setCode(1);
            model.setMsg("查询成功!");
            model.setData(list);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
    
    //9.1机房主控中用电量的统计的折线图
    public ServiceModel serchByInfo(BattInf obj){
        ServiceModel model = new ServiceModel();
        List list=mapper.serchByInfo(obj);
        if(list!=null&&list.size()>0){
            model.setCode(1);
            model.setMsg("查询成功!");
            //System.out.println(list.size());
            model.setData(list);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        //System.out.println(model);
        return model;
    }
 
 
    //10.1根据设备id连battinf和batt_devdischarge表
    /* 
     * 统计方式放在battinf的signalname中*/
    public List serchByCondition(BattInf obj) {
        List<Batt_electricity> list = mapper.serchByCondition(obj);
        ServiceModelElectri model = new ServiceModelElectri();
        List<ServiceModelElectri> listmodel = new ArrayList<>();
        //TODO perry
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                // 时间段
                String perid_Time = "";
                // 年份,季度,月份
                Date dev_recordtime = list.get(i).getDev_recordtime();
                // 获取具体年份,月份和该月的总天数
                int year = dev_recordtime.getYear() + 1900;
                int month = dev_recordtime.getMonth() + 1;
                // 获取统计方式
                String method = list.get(i).getNote();
                if (method.equals("1")) {// 按月份
                    perid_Time = ActionUtil.getFirstDayOfMonth(year, month - 1);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year, month - 1);
                } else if (method.equals("2")) {// 按季度
                    if (month < 3) {
                        month = 1;
                    } else {
                        if (month % 3 == 0) {
                            month = month / 3;
                        } else {
                            month = month / 3 + 1;
                        }
                    }
                    perid_Time = ActionUtil.getFirstDayOfMonth(year,
                            (month - 1) * 3);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year,
                            month * 3 - 1);
                } else if (method.equals("3")) {// 按年份
                    perid_Time = ActionUtil.getFirstDayOfMonth(year, 0);
                    perid_Time += " ";
                    perid_Time += ActionUtil.getLastDayOfMonth(year, 11);
                    month = 0;
                }
                model.setCode(year);
                model.setMsgN(perid_Time); // 时间段
                model.setSum(month); // 所有的电度统计次数
 
 
                model.setNewsum(list.get(i).getDev_id());//设备id
                model.setMsg(list.get(i).getDev_name());//设备名称
 
                model.setLowCA(list.get(i).getDev_electricity_CM());
                model.setLowCH(list.get(i).getDev_electricity_CT());
                model.setLowRA(list.get(i).getDev_electricity_CU());
 
                model.setMsgO("");//
                model.setMsgV("");//
                listmodel.add(model);
            }
        } else {
            model.setLowCA(0f);
            model.setLowCH(0f);
            model.setLowRA(0f);
            model.setCode(0);
            model.setMsgN("0");
            listmodel.add(model);
        }
 
        ServiceModelElectri lastModel = new ServiceModelElectri();
        lastModel.setMsgN("0");
        lastModel.setCode(model.getCode());
        lastModel.setMsg(model.getMsg());
        lastModel.setLowCH(0f);
        lastModel.setLowCA(0f);
        lastModel.setLowRA(0f);
        lastModel.setMsgO(model.getMsgO());
        lastModel.setMsgV(model.getMsgV());
        listmodel.add(lastModel);//补全第一次一次时间改变
        float numCA = 0f;//移动电度
        float numCH = 0f;//联通电度
        float numRA = 0f;//电信电度
        String time = "";//时间段统计
        int dev_id = 0;//设备id
        ServiceModel sumModel = null;
//        for (ServiceModel m : listmodel) {
//            System.out.println(m.getMsgN()+"  "+m.getNewsum()+" "+m.getLowCA()+" "+m.getLowCH()+" "+m.getLowRA());
//        }
        List<ServiceModelElectri> last=new ArrayList<>();
        for (int i = 0; i < listmodel.size(); i++) {
            time = listmodel.get(i).getMsgN();
            dev_id = listmodel.get(i).getNewsum();
            numCA += listmodel.get(i).getLowCA();
            numCH += listmodel.get(i).getLowCH();
            numRA += listmodel.get(i).getLowRA();
            if ((i + 1) < listmodel.size()) {
                if (listmodel.get(i + 1).getNewsum() == dev_id) {
                    if (!listmodel.get(i + 1).getMsgN().equals(time)) {
                        ServiceModelElectri newModel = new ServiceModelElectri();
                        newModel.setCode(listmodel.get(i).getCode());
                        newModel.setMsgN(listmodel.get(i).getMsgN());
                        newModel.setMsg(listmodel.get(i).getMsg());
                        newModel.setNewsum(listmodel.get(i).getNewsum());
                        newModel.setSum(listmodel.get(i).getSum());
                        newModel.setLowCA(numCA);
                        newModel.setLowCH(numCH);
                        newModel.setLowRA(numRA);
                        numCA = 0f;
                        numCH = 0f;
                        numRA = 0f;
                        last.add(newModel);
                    }
                } else {
                    ServiceModelElectri newModel = new ServiceModelElectri();
                    newModel.setCode(listmodel.get(i).getCode());
                    newModel.setMsgN(listmodel.get(i).getMsgN());
                    newModel.setMsg(listmodel.get(i).getMsg());
                    newModel.setNewsum(listmodel.get(i).getNewsum());
                    newModel.setSum(listmodel.get(i).getSum());
                    newModel.setLowCA(numCA);
                    newModel.setLowCH(numCH);
                    newModel.setLowRA(numRA);
                    numCA = 0f;
                    numCH = 0f;
                    numRA = 0f;
                    last.add(newModel);
                }
 
            }
 
        }
        return last;
    }
 
    /*public static void main(String[] args) throws ParseException {
        Batt_electricityImpl bimpl=new Batt_electricityImpl();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2015-01-01");
        Date date2 = sdf.parse("2017-12-01");
        BattInf binf=new BattInf();
        binf.setStationName("");
        binf.setStationName1("");
        binf.setSignalName("1");
        binf.setBattProductDate(ActionUtil.getSimpDate(date1));
        binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
        Batt_electricityService  bservice=new Batt_electricityService();
        bservice.serchByCondition(binf);
        
        
        //binf.setStationId("42070218");
        //bservice.serchByInfo(binf);
    }*/
}