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/HdlResidenceLogic.java | 259 +++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 226 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java index a21d962..3e61f84 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java @@ -8,25 +8,18 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.hdl.linkpm.sdk.core.exception.HDLException; -import com.hdl.photovoltaic.bean.HttpResponsePack; import com.hdl.photovoltaic.config.AppConfigManage; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.internet.HttpClient; import com.hdl.photovoltaic.internet.api.HttpApi; -import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; import com.hdl.photovoltaic.listener.CloudCallBeak; -import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; +import com.hdl.photovoltaic.ui.bean.ContactBean; import com.hdl.photovoltaic.ui.bean.HouseInfoBean; import com.hdl.photovoltaic.ui.bean.HouseIdBean; -import com.hdl.photovoltaic.ui.bean.MessageBean; -import com.hdl.sdk.link.common.exception.HDLLinkException; -import com.hdl.sdk.link.core.bean.gateway.GatewayBean; -import com.hdl.sdk.link.core.callback.GatewayCallBack; +import com.hdl.photovoltaic.ui.bean.StatusOverviewBean; import com.hdl.sdk.link.core.config.HDLLinkConfig; import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; -import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -74,21 +67,68 @@ this.houseInfoList = houseInfoList; } + public void clearHouseList() { + if (mHouseIdList != null && mHouseIdList.size() > 0) { + mHouseIdList.clear(); + } + if (houseInfoList != null && houseInfoList.size() > 0) { + houseInfoList.clear(); + } + } + + /** * 鑾峰彇缂撳瓨浣忓畢ID鍒楄〃 * * @return 浣忓畢ID鍒楄〃 */ public List<HouseIdBean> getHouseIdList() { - return houseIdList; + return mHouseIdList; } - public void setHouseIdList(List<HouseIdBean> houseIdList) { - if (houseIdList == null) { - houseIdList = new ArrayList<>(); + public void setHouseIdList(List<HouseIdBean> list) { + if (list == null || list.size() == 0) { + return; } - this.houseIdList = houseIdList; + if (this.mHouseIdList.size() == 0) { + this.mHouseIdList.addAll(list); + return; + } + for (int i = 0; i < list.size(); i++) { + this.setSingleHouseId(list.get(i)); + } } + + /** + * 娣诲姞鐢电珯Id鍒板垪琛ㄩ噷闈� + * + * @param houseIdBean -鐢电珯Id瀵硅薄 + */ + public void setSingleHouseId(HouseIdBean houseIdBean) { + try { + if (houseIdBean == null) { + return; + } + boolean if_boolean = false; + for (int i = 0; i < mHouseIdList.size(); i++) { + if (mHouseIdList.get(i).getHomeId().equals(houseIdBean.getHomeId())) { + //瀛樺湪鏇挎崲 + mHouseIdList.remove(i); + mHouseIdList.add(i, houseIdBean); + if_boolean = true; + break; + } + } + if (!if_boolean) { + //娌℃湁娣诲姞 + this.mHouseIdList.add(houseIdBean); + } + } catch (Exception e) { + String mes = e.getMessage(); + HdlLogLogic.print("--->" + mes); + } + } + /** * 鍒犻櫎鐢电珯 @@ -99,9 +139,9 @@ if (TextUtils.isEmpty(houseId)) { return; } - for (int i = 0; i < houseIdList.size(); i++) { - if (houseIdList.get(i).getHomeId().equals(houseId)) { - houseIdList.remove(i); + for (int i = 0; i < mHouseIdList.size(); i++) { + if (mHouseIdList.get(i).getHomeId().equals(houseId)) { + mHouseIdList.remove(i); break; } } @@ -117,8 +157,8 @@ return; } int index = -1; - for (int i = 0; i < houseIdList.size(); i++) { - if (houseIdList.get(i).getHomeId().equals(houseId)) { + for (int i = 0; i < mHouseIdList.size(); i++) { + if (mHouseIdList.get(i).getHomeId().equals(houseId)) { index = i; break; } @@ -128,12 +168,12 @@ } //index==0琛ㄧず鍙湁涓�涓厓绱犳垨鑰呭湪棣栦綅,涓嶉渶瑕佺Щ鍔ㄤ綅缃� if (index > 0) { - Collections.swap(houseIdList, index - 1, index); + Collections.swap(mHouseIdList, index - 1, index); } } //浣忓畢ID鍒楄〃 - private List<HouseIdBean> houseIdList = new ArrayList<>(); + private List<HouseIdBean> mHouseIdList = new ArrayList<>(); //浣忓畢璇︽儏鍒楄〃 private List<HouseInfoBean> houseInfoList = new ArrayList<>(); @@ -149,12 +189,12 @@ @Override public void onSuccess(List<HouseIdBean> houseListBeanIDList) { if (houseListBeanIDList != null && houseListBeanIDList.size() > 0) { - houseIdList.clear(); - houseIdList.addAll(houseListBeanIDList); + mHouseIdList.clear(); + mHouseIdList.addAll(houseListBeanIDList); //璁板綍璇锋眰鏉℃暟 AtomicInteger atomicInteger = new AtomicInteger(0); - for (int i = 0; i < houseIdList.size(); i++) { - HouseIdBean houseIdBean = houseIdList.get(i); + for (int i = 0; i < mHouseIdList.size(); i++) { + HouseIdBean houseIdBean = mHouseIdList.get(i); //鑾峰彇浣忓畢璇︽儏鍒楄〃 getResidenceInfo(houseIdBean.getHomeId(), new CloudCallBeak<HouseInfoBean>() { @Override @@ -169,7 +209,7 @@ //娣诲姞鍒版湰鍦扮紦瀛� addHouseToLocalMemory(houseInfoBean); } - if (atomicInteger.get() == houseIdList.size()) { + if (atomicInteger.get() == mHouseIdList.size()) { //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); @@ -181,7 +221,7 @@ @Override public void onFailure(HDLException e) { atomicInteger.set(atomicInteger.get() + 1); - if (atomicInteger.get() == houseIdList.size()) { + if (atomicInteger.get() == mHouseIdList.size()) { //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { cloudCallBeak.onFailure(e); @@ -279,6 +319,94 @@ } }); } + + } + + @Override + public void onFailure(HDLException exception) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(exception); + } + } + }); + + + } + + /** + * 鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃 + * + * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort); + * 浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort); + * 鍒涘缓鏃堕棿鎺掑簭(createTimeSort); + * @param keyValue (descending:闄嶅簭 + * ascending:鍗囧簭), + * @param installedCapacityMin 鏈�灏忕粍涓插閲�(瑁呮満瀹归噺) + * @param installedCapacityMax 鏈�澶х粍涓插閲�(瑁呮満瀹归噺) + * @param gridType 骞剁綉鐘舵�� (鍏ㄩ儴 锛�"";FULL_GRID 锛� 骞剁綉;OFFLINE 锛氱缃�) + * @param powerStationStatus 鐢电珯鐘舵�� (鍏ㄩ儴 锛�"";1 锛� 姝e父;2 锛� 绂荤嚎; 3 锛� 寰呮帴鍏�;4 锛� 鏁呴殰) + * @param pageNo 椤电爜 + * @param pageSize 椤垫暟锛堜竴椤靛灏戞暟鎹級 + */ + public void getResidenceIdList( + String key, + String keyValue, + String installedCapacityMin, + String installedCapacityMax, + String gridType, + String powerStationStatus, + long pageNo, long pageSize, CloudCallBeak<HouseBeanClass> cloudCallBeak) { + + String requestUrl = HttpApi.POST_PowerStation_List; + JsonObject json = new JsonObject(); + if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(keyValue)) { + json.addProperty(key, keyValue);//鍙戠數鍔熺巼鎺掑簭(descending:闄嶅簭ascending:鍗囧簭) + } + if (!TextUtils.isEmpty(installedCapacityMin)) { + try { + int value = Integer.parseInt(installedCapacityMin);//鍙兘鏈夊紓甯�,鐢ㄦ埛杈撳叆鍊艰秴鏃秈nt鏈�澶ц嚧瀵艰嚧鐨� + json.addProperty("installedCapacityMin", value); + } catch (Exception ignored) { + } + } + if (!TextUtils.isEmpty(installedCapacityMax)) { + try { + int value = Integer.parseInt(installedCapacityMax);//鍙兘鏈夊紓甯�,鐢ㄦ埛杈撳叆鍊艰秴鏃秈nt鏈�澶ц嚧瀵艰嚧鐨� + json.addProperty("installedCapacityMax", value); + } catch (Exception ignored) { + } + } + if (!TextUtils.isEmpty(gridType)) { + try { + json.addProperty("gridType", gridType); + } catch (Exception ignored) { + } + } + if (!TextUtils.isEmpty(powerStationStatus)) { + try { + int value = Integer.parseInt(powerStationStatus); + json.addProperty("powerStationStatus", value); + } catch (Exception ignored) { + } + } +// json.addProperty("zoneType", "password");//鍖哄煙 + json.addProperty("pageNo", pageNo);//椤电爜 + json.addProperty("pageSize", pageSize);//椤垫暟 + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(new HouseBeanClass()); + } + return; + } + Gson gson = new Gson(); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(houseInfoBeanClass); + } + } @@ -444,6 +572,37 @@ } /** + * 鐢电珯鐘舵�佹瑙�(瀹夎鍟�) + */ + public void getStatusOverview(CloudCallBeak<StatusOverviewBean> cloudCallBeak) { + String requestUrl = HttpApi.POST_statusOverview; + JsonObject json = new JsonObject(); +// json.addProperty("zoneType", zoneType);//鍖哄煙 + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(new StatusOverviewBean()); + } + } + Gson gson = new Gson(); + StatusOverviewBean statusOverviewBean = gson.fromJson(jsonStr, StatusOverviewBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(statusOverviewBean); + } + } + + @Override + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + } + + /** * 娣诲姞浣忓畢(鐢电珯)鍒颁簯绔� * * @param houseInfoBean - @@ -556,6 +715,41 @@ } + + /** + * 鑱旂郴鎴戜滑 + * + * @param cloudCallBeak - + */ + public void getResidenceUtilContact(CloudCallBeak<ContactBean> cloudCallBeak) { + String requestUrl = HttpApi.B_POST_GET_UTIL_CONTACT; + JsonObject json = new JsonObject(); + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(new ContactBean()); + return; + } + } + ContactBean contactBean = new Gson().fromJson(jsonStr, ContactBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(contactBean); + } + } + + @Override + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + + + } + /** * 鑾峰彇鐢ㄦ埛鑷畾涔夐厤缃俯搴﹀崟浣嶈鎯� * @@ -566,7 +760,6 @@ JsonObject json = new JsonObject(); // json.addProperty("homeId", homeId); - List<MessageBean> list = new ArrayList<>(); HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override public void onSuccess(String jsonStr) { @@ -655,9 +848,9 @@ * @return 鍒楄〃绱㈠紩 */ public HouseIdBean getHouseId(String homeId) { - for (int i = 0; i < houseIdList.size(); i++) { - if (houseIdList.get(i).getHomeId().equals(homeId)) { - return houseIdList.get(i); + for (int i = 0; i < mHouseIdList.size(); i++) { + if (mHouseIdList.get(i).getHomeId().equals(homeId)) { + return mHouseIdList.get(i); } } return null; @@ -694,7 +887,7 @@ //閲嶆柊鍒涘缓浣忓畢鏂囦欢澶� HdlFileLogic.getInstance().createDirectory(); //杩涘幓浣忓畢璇︽儏鎼滅储涓�涓嬮�嗗彉鍣ㄥ垪琛�,鐩殑鏄缓绔嬮�氳閫氶亾; - HdlDeviceLogic.getInstance().searchCurrentHomeGateway(null); + HdlDeviceLogic.getInstance().searchCurrentHomeGateway(houseIdBean.getHomeId(),null); } @@ -760,7 +953,7 @@ } - static class HouseBeanClass { + public static class HouseBeanClass { //鎬绘潯鏁� private long totalCount; -- Gitblit v1.8.0