From 70c1ba24af27ba64e1d9ad50eb722541212ed8b6 Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期五, 30 六月 2023 17:26:54 +0800 Subject: [PATCH] 2023年06月30日17:26:51 --- app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java | 127 ++++++++++++++++++++++++++++++++++++------ 1 files changed, 108 insertions(+), 19 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 1faea0a..4e7f0d6 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java @@ -10,8 +10,14 @@ 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.HouseInfoBean; import com.hdl.photovoltaic.ui.bean.HouseIdBean; +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.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import java.util.ArrayList; import java.util.List; @@ -53,6 +59,9 @@ } public void setHouseInfoList(List<HouseInfoBean> houseInfoList) { + if (houseInfoList == null) { + houseInfoList = new ArrayList<>(); + } this.houseInfoList = houseInfoList; } @@ -66,6 +75,9 @@ } public void setHouseIdList(List<HouseIdBean> houseIdList) { + if (houseIdList == null) { + houseIdList = new ArrayList<>(); + } this.houseIdList = houseIdList; } @@ -82,7 +94,7 @@ */ public void getHouseList(CloudCallBeak<Boolean> cloudCallBeak) { //鑾峰彇浣忓畢ID鍒楄〃 - getResidenceList("", "", new CloudCallBeak<List<HouseIdBean>>() { + getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { @Override public void onSuccess(List<HouseIdBean> houseListBeanIDList) { if (houseListBeanIDList != null && houseListBeanIDList.size() > 0) { @@ -151,7 +163,7 @@ * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort);浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort);鍒涘缓鏃堕棿鎺掑簭(createTimeSort); * @param keyValue (descending:闄嶅簭ascending:鍗囧簭), */ - public void getResidenceList(String key, String keyValue, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { + public void getResidenceIdList(String key, String keyValue, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { String requestUrl = HttpApi.POST_PowerStation_List; JsonObject json = new JsonObject(); @@ -247,13 +259,19 @@ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { @Override public void onSuccess(HttpResponsePack httpResponsePack) { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String jsonStr = gson.toJson(httpResponsePack.getData()); - HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); + try { + if (httpResponsePack != null && httpResponsePack.getData() != null) { + Gson gson = new Gson(); + String jsonStr = gson.toJson(httpResponsePack.getData()); + HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(houseInfoBean); + } + } + } catch (Exception exception) { if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(houseInfoBean); + cloudCallBeak.onFailure(exception); } } } @@ -401,24 +419,36 @@ } /** - * 鍒囨崲浣忓畢 - * - * @param homeId 浣忓畢id + * 鑾峰彇浣忓畢鍥剧墖 */ - public Boolean switchHouse(String homeId) { - UserConfigManage.getInstance().setHomeId(homeId); - HdlThreadLogic.runThread(new Runnable() { + public void getResidenceImage(String imageUrl, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { + String requestUrl = imageUrl; + JsonObject json = new JsonObject(); + List<HouseIdBean> list = new ArrayList<>(); + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { @Override - public void run() { - //鎼滅储涓�涓嬩綇瀹呰澶� + public void onSuccess(HttpResponsePack httpResponsePack) { + if (httpResponsePack != null && httpResponsePack.getData() != null) { + Gson gson = new Gson(); + String jsonStr = gson.toJson(httpResponsePack.getData()); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); + } else { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + } } - }, null, null); - //鍏抽棴杩涘害鏉� + @Override + public void onFailure(Exception exception) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(exception); + } + } + }); - return true; + } - /** * 娣诲姞銆愪綇瀹呰鎯呫�戝埌鏈湴缂撳瓨 @@ -481,6 +511,65 @@ } } + /** + * 鍒囨崲浣忓畢 + * + * @param houseIdBean 浣忓畢Id瀵硅薄 + */ + public void switchHouse(HouseIdBean houseIdBean) { + String oidHomeId = UserConfigManage.getInstance().getHomeId(); +// if (houseIdBean.getHomeId().equals(oidHomeId)) { +// return; +// } + //鍒犻櫎鏃х殑浣忓畢鏂囦欢澶� + HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); + //閲嶆柊璁剧疆浣忓畢id + UserConfigManage.getInstance().setHomeId(houseIdBean.getHomeId()); + //閲嶆柊璁剧疆鏈湴閫氳绉橀挜 + UserConfigManage.getInstance().setLocalSecret(houseIdBean.getLocalSecret()); + //閲嶆柊鍒涘缓浣忓畢鏂囦欢澶� + HdlFileLogic.getInstance().createDirectory(); + //閰嶇疆鏈湴閫氫俊鐨勪俊鎭� + initLocalLinkSdk(); + +// HdlDeviceLogic.getInstance().getInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<CloudInverterDeviceBean>() { +// @Override +// public void onSuccess(CloudInverterDeviceBean obj) { +// +// +// } +// +// @Override +// public void onFailure(Exception exception) { +// +// } +// }); + HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { + @Override + public void onSuccess(List<GatewayBean> gatewayBeanList) { + + } + + @Override + public void onError(HDLLinkException e) { + + } + }); + + + + } + + /** + * 閰嶇疆鏈湴閫氫俊鐨勪俊鎭�(tcp閫氫俊鐢ㄥ埌) + */ + private void initLocalLinkSdk() { + HDLLinkConfig.getInstance().setHomeId(UserConfigManage.getInstance().getHomeId()); + HDLLinkConfig.getInstance().setLocalSecret(UserConfigManage.getInstance().getLocalSecret()); + + + } + static class HouseBeanClass { -- Gitblit v1.8.0