wjc
3 天以前 80f2ca2df62ff1cd03046864af504245be078eb2
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
package com.hdl.photovoltaic.other;
 
import android.text.TextUtils;
 
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.enums.TimeType;
import com.hdl.photovoltaic.internet.HttpClient;
import com.hdl.photovoltaic.internet.api.HttpApi;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.ui.bean.DataOverBean;
import com.hdl.photovoltaic.ui.bean.SocialContributionBean;
import com.hdl.photovoltaic.ui.bean.StatisticsBean;
import com.hdl.photovoltaic.utils.TimeUtils;
 
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
 
/**
 * 电站数据统计逻辑
 */
public class HdlPowerStationDataStatisticsLogic {
    private static volatile HdlPowerStationDataStatisticsLogic sHdlPowerStationDataStatisticsLogic;
 
    /**
     * 获取当前对象
     *
     * @return HdlDeviceLogic
     */
    public static synchronized HdlPowerStationDataStatisticsLogic getInstance() {
        if (sHdlPowerStationDataStatisticsLogic == null) {
            synchronized (HdlPowerStationDataStatisticsLogic.class) {
                if (sHdlPowerStationDataStatisticsLogic == null) {
                    sHdlPowerStationDataStatisticsLogic = new HdlPowerStationDataStatisticsLogic();
                }
            }
 
        }
        return sHdlPowerStationDataStatisticsLogic;
    }
 
 
    /**
     * 获取统计概览数据(公司维度)
     *
     * @param cloudCallBeak 回调
     */
    public void getDataOver(CloudCallBeak<DataOverBean> cloudCallBeak) {
        String requestUrl = HttpApi.POST_Home_page_dataOverview;
        JsonObject json = new JsonObject();
        //json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String jsonStr) {
                try {
                    if (TextUtils.isEmpty(jsonStr)) {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(new DataOverBean());
                        }
                    }
                    Gson gson = new Gson();
                    DataOverBean dataOverBean = gson.fromJson(jsonStr, DataOverBean.class);
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onSuccess(dataOverBean);
                    }
                } catch (Exception ignored) {
                }
            }
 
            @Override
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                }
            }
        });
 
 
    }
 
    /**
     * 发电量统计(公司维度)
     *
     * @param type          类型(例如:TimeType.day:日,TimeType.month:月,TimeType.year : 年,TimeType.all : 生命周期)
     * @param time          时间(type=day(y/M/d),type=month(y/M),type=year(y) ,type = all 可不传,传值也不使用)
     * @param cloudCallBeak 回调
     */
    public void getStatistics(String type, String time, CloudCallBeak<List<StatisticsBean>> cloudCallBeak) {
        String requestUrl = HttpApi.POST_Home_page_statistics;
        JsonObject json = new JsonObject();
        if (TimeType.day.equals(type)) {
            json.addProperty("dataType", "POWER");//发电量(GE : 发电量 ;POWER : 发电功率)
        } else {
            json.addProperty("dataType", "GE");//发电量(GE : 发电量 ;POWER : 发电功率)
        }
        json.addProperty("type", type);//类型
        if (!TextUtils.isEmpty(time)) {
            if (!UserConfigManage.getInstance().isZh()) {
                //英文的时候需要日期格式
                if (TimeType.day.equals(type)) {
                    String[] ary = time.split("/");
                    time = ary[2] + "/" + ary[1] + "/" + ary[0];
                } else if (TimeType.month.equals(type)) {
                    String[] ary = time.split("/");
                    time = ary[1] + "/" + ary[0];
                }
            }
            json.addProperty("time", time);//时间
        }
        //json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String jsonStr) {
                if (TextUtils.isEmpty(jsonStr)) {
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onSuccess(null);
                    }
                }
                Gson gson = new Gson();
                Type typeToken = new TypeToken<List<StatisticsBean>>() {
                }.getType();
                List<StatisticsBean> list = gson.fromJson(jsonStr, typeToken);
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(list);
                }
            }
 
            @Override
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                }
            }
        });
 
 
    }
 
    /**
     * 社会贡献(公司维度)
     *
     * @param cloudCallBeak 回调
     */
    public void getSocialContribution(CloudCallBeak<SocialContributionBean> cloudCallBeak) {
        String requestUrl = HttpApi.POST_Home_page_socialContribution;
        JsonObject json = new JsonObject();
        //json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String jsonStr) {
                if (TextUtils.isEmpty(jsonStr)) {
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onSuccess(null);
                    }
                }
                Gson gson = new Gson();
                SocialContributionBean socialContributionBean = gson.fromJson(jsonStr, SocialContributionBean.class);
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(socialContributionBean);
                }
            }
 
            @Override
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                }
            }
        });
 
 
    }
 
 
}