From b75795836a851a13e54cc4efb597262fb448217c Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 08 五月 2024 15:22:01 +0800 Subject: [PATCH] 2024年05月08日15:21:54 --- app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java | 650 +++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 438 insertions(+), 212 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 83e6b6a..a7b54f7 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java @@ -1,30 +1,40 @@ package com.hdl.photovoltaic.other; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Build; import android.text.TextUtils; 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.DeviceBean; 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.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; import java.util.concurrent.atomic.AtomicInteger; /** - * 浣忓畢閫昏緫鐣岄潰 + * 浣忓畢閫昏緫 */ public class HdlResidenceLogic { @@ -50,7 +60,7 @@ } /** - * 鑾峰彇浣忓畢鍒楄〃 + * 鑾峰彇缂撳瓨浣忓畢鍒楄〃 * * @return 浣忓畢鍒楄〃 */ @@ -65,30 +75,119 @@ this.houseInfoList = houseInfoList; } + public void clearHouseList() { + if (houseInfoList == null) { + return; + } + if (houseInfoList.size() > 0) { + houseInfoList.clear(); + } + } + + /** - * 鑾峰彇浣忓畢ID鍒楄〃 + * 鑾峰彇缂撳瓨浣忓畢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); + } + } + + + /** + * 鍒犻櫎鐢电珯 + * + * @param houseId 鐢电珯id + */ + public void delHouseId(String houseId) { + if (TextUtils.isEmpty(houseId)) { + return; + } + for (int i = 0; i < mHouseIdList.size(); i++) { + if (mHouseIdList.get(i).getHomeId().equals(houseId)) { + mHouseIdList.remove(i); + break; + } + } + } + + /** + * 绉诲姩鐢电珯浣嶇疆 + * + * @param houseId 鐢电珯id + */ + public void moveHouseId(String houseId) { + if (TextUtils.isEmpty(houseId)) { + return; + } + int index = -1; + for (int i = 0; i < mHouseIdList.size(); i++) { + if (mHouseIdList.get(i).getHomeId().equals(houseId)) { + index = i; + break; + } + } + if (index == -1) { + return; + } + //index==0琛ㄧず鍙湁涓�涓厓绱犳垨鑰呭湪棣栦綅,涓嶉渶瑕佺Щ鍔ㄤ綅缃� + if (index > 0) { + 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<>(); /** - * 鑾峰彇浣忓畢鍒楄〃 + * 鑾峰彇浣忓畢鍒楄〃锛屽寘鎷幏鍙栦綇瀹卛d鍒楄〃锛屼綇瀹呰鎯呭垪琛紱 * * @param cloudCallBeak - */ @@ -98,19 +197,19 @@ @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 public void onSuccess(HouseInfoBean houseInfoBean) { atomicInteger.set(atomicInteger.get() + 1); if (houseInfoBean != null) { - houseInfoBean.setHomeImage(houseIdBean.getHomeImage());//鐢电珯鍥剧墖 + houseInfoBean.setPowerStationImage(houseIdBean.getPowerStationImage());//鐢电珯鍥剧墖 houseInfoBean.setInstalledCapacity(houseIdBean.getInstalledCapacity());//瑁呮満瀹归噺 houseInfoBean.setPower(houseIdBean.getPower());//鍙戠數鍔熺巼 houseInfoBean.setTodayElectricity(houseIdBean.getTodayElectricity());//浠婂ぉ鍙戠數閲� @@ -118,7 +217,7 @@ //娣诲姞鍒版湰鍦扮紦瀛� addHouseToLocalMemory(houseInfoBean); } - if (atomicInteger.get() == houseIdList.size()) { + if (atomicInteger.get() == mHouseIdList.size()) { //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); @@ -128,12 +227,12 @@ } @Override - public void onFailure(Exception exception) { + 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(exception); + cloudCallBeak.onFailure(e); } } } @@ -148,9 +247,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -160,8 +259,11 @@ /** * 鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃 * - * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort);浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort);鍒涘缓鏃堕棿鎺掑簭(createTimeSort); - * @param keyValue (descending:闄嶅簭ascending:鍗囧簭), + * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort); + * 浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort); + * 鍒涘缓鏃堕棿鎺掑簭(createTimeSort); + * @param keyValue (descending:闄嶅簭 + * ascending:鍗囧簭), */ public void getResidenceIdList(String key, String keyValue, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { @@ -170,72 +272,116 @@ if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(keyValue)) { json.addProperty(key, keyValue);//鍙戠數鍔熺巼鎺掑簭(descending:闄嶅簭ascending:鍗囧簭) } -// json.addProperty("powerSort", "descending");//鍙戠數鍔熺巼鎺掑簭(descending:闄嶅簭ascending:鍗囧簭) -// json.addProperty("todayElectricitySort", "descending");//浠婃棩鍙戠數閲忔帓搴� -// json.addProperty("createTimeSort", "descending");//鍒涘缓鏃堕棿鎺掑簭 // json.addProperty("zoneType", "password");//鍖哄煙 json.addProperty("pageNo", 1);//椤电爜 json.addProperty("pageSize", pageSize);//椤垫暟 List<HouseIdBean> list = new ArrayList<>(); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - 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); - list.addAll(houseInfoBeanClass.getList()); - //鎬诲叡鏈夊灏戦〉 - long totalPage = houseInfoBeanClass.totalPage; - if (totalPage < 2) { - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - return; - } - //璁板綍璇锋眰鏉℃暟 - AtomicInteger atomicInteger = new AtomicInteger(0); - //浠庣浜岄〉鑾峰彇鏁版嵁 - for (int i = 2; i <= totalPage; i++) { - json.addProperty("pageNo", i);//鏇存柊椤电爜 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { - @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - atomicInteger.set(atomicInteger.get() + 1); - Gson gson = new Gson(); - String jsonStr = gson.toJson(httpResponsePack.getData()); - HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); - list.addAll(houseInfoBeanClass.getList()); - if (atomicInteger.get() == totalPage - 1) { - //鏈�鍚庝竴鏉¢��鍑� - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - } - } - - @Override - public void onFailure(Exception exception) { - atomicInteger.set(atomicInteger.get() + 1); - if (atomicInteger.get() == totalPage - 1) { - //鏈�鍚庝竴鏉¢��鍑� - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); - } - } - } - }); - } - - } else { + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(list); } } + Gson gson = new Gson(); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); + list.addAll(houseInfoBeanClass.getList()); + //鎬诲叡鏈夊灏戦〉 + long totalPage = houseInfoBeanClass.totalPage; + if (totalPage < 2) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + return; + } + //璁板綍璇锋眰鏉℃暟 + AtomicInteger atomicInteger = new AtomicInteger(0); + //浠庣浜岄〉鑾峰彇鏁版嵁 + for (int i = 2; i <= totalPage; i++) { + json.addProperty("pageNo", i);//鏇存柊椤电爜 + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String jsonStr) { + atomicInteger.set(atomicInteger.get() + 1); + Gson gson = new Gson(); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); + list.addAll(houseInfoBeanClass.getList()); + if (atomicInteger.get() == totalPage - 1) { + //鏈�鍚庝竴鏉¢��鍑� + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + } + } + + @Override + public void onFailure(HDLException e) { + atomicInteger.set(atomicInteger.get() + 1); + if (atomicInteger.get() == totalPage - 1) { + //鏈�鍚庝竴鏉¢��鍑� + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + } + } + }); + } + } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException exception) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(exception); + } + } + }); + + + } + + /** + * 鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃 + * + * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort); + * 浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort); + * 鍒涘缓鏃堕棿鎺掑簭(createTimeSort); + * @param keyValue (descending:闄嶅簭 + * ascending:鍗囧簭), + * @param pageNo 椤电爜 + * @param pageSize 椤垫暟锛堜竴椤靛灏戞暟鎹級 + */ + public void getResidenceIdList(String key, String keyValue, 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:鍗囧簭) + } +// 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); + } + + + } + + @Override + public void onFailure(HDLException exception) { if (cloudCallBeak != null) { cloudCallBeak.onFailure(exception); } @@ -256,30 +402,25 @@ JsonObject json = new JsonObject(); json.addProperty("homeId", homeId);//鐢电珯id //json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { - 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) { + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onSuccess(null); } + } + Gson gson = new Gson(); + HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(houseInfoBean); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -319,9 +460,9 @@ json.addProperty("electrovalence", houseInfoBean.getElectrovalence()); json.addProperty("totalCost", houseInfoBean.getTotalCost()); json.addProperty("zoneType", houseInfoBean.getZoneType()); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } @@ -329,9 +470,42 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); + } + } + }); + } + + /** + * 浣忓畢(鐢电珯)绉诲姩浣嶇疆 + * + * @param homeId 鐢电珯id + * @param frontHomeId 鍓嶉潰鐨勭數绔檌d锛屽鏋滀笉浼犺〃绀烘帓鍒扮涓�浣� + * @param cloudCallBeak - + */ + public void moveResidence(String homeId, String frontHomeId, CloudCallBeak<Boolean> cloudCallBeak) { + String requestUrl = HttpApi.POST_PowerStation_UserSort; + JsonObject json = new JsonObject(); + json.addProperty("homeId", homeId); + if (!TextUtils.isEmpty(frontHomeId)) { + json.addProperty("frontHomeId", frontHomeId); + } +// json.addProperty("zoneType", "zoneType"); + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String str) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + + } + + @Override + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); } } }); @@ -348,9 +522,9 @@ JsonObject json = new JsonObject(); json.addProperty("homeId", homeId);//鐢电珯id //json.addProperty("zoneType", "password");//鍖哄煙 - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } @@ -358,9 +532,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -398,9 +572,9 @@ json.addProperty("electrovalence", houseInfoBean.getElectrovalence()); json.addProperty("totalCost", houseInfoBean.getTotalCost()); json.addProperty("zoneType", houseInfoBean.getZoneType()); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(HttpResponsePack httpResponsePack) { + public void onSuccess(String str) { if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); } @@ -408,9 +582,9 @@ } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -421,28 +595,89 @@ /** * 鑾峰彇浣忓畢鍥剧墖 */ - public void getResidenceImage(String imageUrl, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { + public void getResidenceImage(String imageUrl, CloudCallBeak<Bitmap> cloudCallBeak) { String requestUrl = imageUrl; JsonObject json = new JsonObject(); - List<HouseIdBean> list = new ArrayList<>(); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - 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 { + public void onSuccess(String jsonStr) { + if (TextUtils.isEmpty(jsonStr)) { if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(list); + cloudCallBeak.onSuccess(null); } + return; + } + Bitmap bitmap = BitmapFactory.decodeByteArray(jsonStr.getBytes(), 0, jsonStr.getBytes().length); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(bitmap); } } @Override - public void onFailure(Exception exception) { + public void onFailure(HDLException e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); + } + } + }); + + + } + + + /** + * 鐢ㄦ埛鑷畾涔夐厤缃俯搴﹀崟浣� + * + * @param tempType 娓╁害鍗曚綅绫诲瀷 (C 锛氭憚姘忓害锛� F 锛氬崕姘忓害) + * @param cloudCallBeak - + */ + public void setResidenceTemperatureUnit(String tempType, CloudCallBeak<Boolean> cloudCallBeak) { + String requestUrl = HttpApi.POST_C_F_CustomConfig; + JsonObject json = new JsonObject(); + json.addProperty("tempType", tempType); + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String str) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + } + + @Override + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + + + } + + /** + * 鑾峰彇鐢ㄦ埛鑷畾涔夐厤缃俯搴﹀崟浣嶈鎯� + * + * @param cloudCallBeak - + */ + public void getResidenceTemperatureUnit(CloudCallBeak<String> cloudCallBeak) { + String requestUrl = HttpApi.POST_C_F_CustomConfigInfo; + 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) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(jsonStr); + } + + } + + @Override + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); } } }); @@ -512,127 +747,118 @@ } /** + * 鑾峰彇浣忓畢Id瀵硅薄 + * + * @param homeId 浣忓畢id + * @return 鍒楄〃绱㈠紩 + */ + public HouseIdBean getHouseId(String homeId) { + for (int i = 0; i < mHouseIdList.size(); i++) { + if (mHouseIdList.get(i).getHomeId().equals(homeId)) { + return mHouseIdList.get(i); + } + } + return null; + } + + /** * 鍒囨崲浣忓畢 * * @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()); + String homeId = UserConfigManage.getInstance().getHomeId(); + if (houseIdBean.getHomeId().equals(homeId)) { + HdlLogLogic.print("鐐瑰嚮鍚屼竴涓綇瀹�--->" + homeId); + return; + } + //璁㈤槄瑕佸叏閮ㄥ彇娑� + if (MqttRecvClient.getInstance() != null) { + MqttRecvClient.getInstance().removeAllTopic(); + } + //瑕佹竻绌轰箣鍓峵cp杩炴帴缂撳瓨 + //TODO: 10/10/23 + //鍒犻櫎鏃х殑浣忓畢鏂囦欢澶� 2023骞�11鏈�03鏃�14:28:19鏆傛椂鍘绘帀 +// HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); //閲嶆柊璁剧疆浣忓畢id UserConfigManage.getInstance().setHomeId(houseIdBean.getHomeId()); + UserConfigManage.getInstance().setHomeName(houseIdBean.getHomeName()); //閲嶆柊璁剧疆鏈湴閫氳绉橀挜 UserConfigManage.getInstance().setLocalSecret(houseIdBean.getLocalSecret()); + UserConfigManage.getInstance().Save(); + //閰嶇疆鏈湴閫氫俊鐨勪俊鎭� + HDLLinkConfig.getInstance().setHomeId(UserConfigManage.getInstance().getHomeId()); + HDLLinkConfig.getInstance().setLocalSecret(UserConfigManage.getInstance().getLocalSecret()); //閲嶆柊鍒涘缓浣忓畢鏂囦欢澶� HdlFileLogic.getInstance().createDirectory(); - //閰嶇疆鏈湴閫氫俊鐨勪俊鎭� - initLocalLinkSdk(); + //杩涘幓浣忓畢璇︽儏鎼滅储涓�涓嬮�嗗彉鍣ㄥ垪琛�,鐩殑鏄缓绔嬮�氳閫氶亾; + HdlDeviceLogic.getInstance().searchCurrentHomeGateway(null); + } - HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { + + /** + * 鐢电珯鏁版嵁(缁熻) + * + * @param homeId 浣忓畢id + */ + public void getResidenceInverterAllInfo(String homeId, CloudCallBeak<Bitmap> cloudCallBeak) { + String requestUrl = HttpApi.POST_inverter_allInfo; + JsonObject json = new JsonObject(); + json.addProperty("homeId", homeId); + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { @Override - public void onSuccess(List<GatewayBean> gatewayBeanList) { - HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { - @Override - public void onSuccess(List<CloudInverterDeviceBean> list) { - if (list == null) { - //浜戠娌℃湁缁戝畾閫嗗彉鍣�,娓呯┖鏈湴鍒楄〃; - HDLLinkLocalGateway.getInstance().getGatewayList().clear(); - return; - } - //鏀堕泦鍒犻櫎閫嗗彉鍣╯id - List<String> removeSidList = new ArrayList<>(); - for (int i = 0; i < list.size(); i++) { - CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); - for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { - GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); - if (!cloudInverterDeviceBean.getSid().equals(gatewayBean.getSid())) { - //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛� - removeSidList.add(gatewayBean.getSid()); - } + public void onSuccess(String jsonStr) { + if (cloudCallBeak != null) { +// cloudCallBeak.onSuccess(jsonStr); + } - } - } - for (int i = 0; i < removeSidList.size(); i++) { - //鑾峰彇鏈湴鐨勬绫虫尝 - removeInverter(removeSidList.get(i)); - } - } - - @Override - public void onFailure(Exception exception) { - - } - }); } @Override - public void onError(HDLLinkException e) { - HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { - @Override - public void onSuccess(List<CloudInverterDeviceBean> list) { - if (list == null) { - return; - } - if (list.size() <= 0) { - return; - } - HDLLinkLocalGateway.getInstance().getGatewayList().clear(); - for (int i = 0; i < list.size(); i++) { - CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); - GatewayBean gatewayBean = new GatewayBean(); - gatewayBean.setOid(cloudInverterDeviceBean.getOid()); - gatewayBean.setSid(cloudInverterDeviceBean.getSid()); - gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId()); - gatewayBean.setOnline(cloudInverterDeviceBean.isOnline()); - gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName()); - gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId()); - gatewayBean.setLocalEncrypt(true); - gatewayBean.setMaster("true"); - HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean); - } + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + } - } - @Override - public void onFailure(Exception exception) { + /** + * 娣诲姞鎺ㄩ�乀oken + * + * @param cloudCallBeak - + */ + public void pushAdd(CloudCallBeak<String> cloudCallBeak) { + String requestUrl = HttpApi.POST_push_add; + JsonObject json = new JsonObject(); + json.addProperty("deviceName", Build.MODEL);//璁惧鍚嶇О + json.addProperty("deviceType", "Android");//璁惧绫诲瀷 + json.addProperty("produce", AppConfigManage.isIsOnlineServer());//琛ㄧず鏄惁鏄寮忔湇鍔″櫒 + json.addProperty("pushToken", UserConfigManage.getInstance().getRegistrationID());//App鐨勬帹閫乀oken锛屽湪鏋佸厜涓篟egId + json.addProperty("software", "PHOTOVOLTAIC");//杞欢鏉ユ簮 - } - }); + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String jsonStr) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(jsonStr); + } + + } + + @Override + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } } }); } - /** - * 鍒犻櫎鏈湴閫嗗彉鍣� - * - * @param sid 璁惧sid - */ - private void removeInverter(String sid) { - //鑾峰彇鏈湴鐨勬绫虫尝 - GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid); - if (gatewayBean != null) { - HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean); - } - } - - /** - * 閰嶇疆鏈湴閫氫俊鐨勪俊鎭�(tcp閫氫俊鐢ㄥ埌) - */ - private void initLocalLinkSdk() { - HDLLinkConfig.getInstance().setHomeId(UserConfigManage.getInstance().getHomeId()); - HDLLinkConfig.getInstance().setLocalSecret(UserConfigManage.getInstance().getLocalSecret()); - - - } - - - static class HouseBeanClass { + public static class HouseBeanClass { //鎬绘潯鏁� private long totalCount; -- Gitblit v1.8.0