From 12d6db5780d8a2121a3bef2d58bf897b24ff552a Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 12 六月 2024 15:54:29 +0800 Subject: [PATCH] Merge branch 'dev' --- app/src/main/java/com/hdl/photovoltaic/other/HdlPowerStationDataStatisticsLogic.java | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 180 insertions(+), 0 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlPowerStationDataStatisticsLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlPowerStationDataStatisticsLogic.java new file mode 100644 index 0000000..afa02c2 --- /dev/null +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlPowerStationDataStatisticsLogic.java @@ -0,0 +1,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); + } + } + }); + + + } + + +} -- Gitblit v1.8.0