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
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.impl.Batt_electricityImpl;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_electricity;
import com.fgkj.dto.ServiceModel;
 
public class Batt_electricityService {
    private BaseDAO dao;
    private ServiceModel model;
    
    public Batt_electricityService() {
        dao = BaseDAOFactory.getBaseDAO(BaseDAO.BATT_ELECTRICITY);
        model = new ServiceModel();;
    }
    
    public ServiceModel add(Object obj){
        Boolean bl=dao.add(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }else{
            model.setCode(0);
            model.setMsg("添加失败!");
        }
        return model;
    }
    public ServiceModel update(Object obj){
        Boolean bl=dao.update(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }else{
            model.setCode(0);
            model.setMsg("修改失败!");
        }
        return model;
    }
    public ServiceModel del(Object obj){
        Boolean bl=dao.del(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }else{
            model.setCode(0);
            model.setMsg("删除失败!");
        }
        return model;
    }
    public ServiceModel searchAll(){
        List list=dao.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(Object obj){
        List list=dao.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(Object obj){
        List<Batt_electricity> list=dao.serchByCondition(obj);
        List<ServiceModel> listmodel=new ArrayList<ServiceModel>();
        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 = new ServiceModel();
                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);
        }
        
        ServiceModel lastModel=new ServiceModel();
        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<ServiceModel> last=new ArrayList<ServiceModel>();
        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)){
                           ServiceModel newModel=new ServiceModel();
                           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{
                       ServiceModel newModel=new ServiceModel();
                       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);
                   }
                   
               }
                   
            }
        /*for (ServiceModel s : last) {
            System.out.println(s);
        }*/
        //System.out.println(last.size());
        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);
    }
}