New file |
| | |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |