From 63b0ee228bf52e8e9c4d7fc51a1117543c9a67af Mon Sep 17 00:00:00 2001 From: 刘卫锦 <lwj@hdlchina.com.cn> Date: 星期一, 03 七月 2023 19:02:40 +0800 Subject: [PATCH] Merge branch 'master' of http://172.16.1.23:6688/r/~wjc/HDLPhotovoltaicDebugAPP --- app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java | 345 +++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 222 insertions(+), 123 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 6b2f341..83e6b6a 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java @@ -1,8 +1,6 @@ package com.hdl.photovoltaic.other; -import android.os.SystemClock; import android.text.TextUtils; -import android.util.Log; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -12,14 +10,17 @@ 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.HouseListBean; - -import org.w3c.dom.Text; +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; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /** @@ -48,24 +49,40 @@ return sHdlResidenceLogic; } + /** + * 鑾峰彇浣忓畢鍒楄〃 + * + * @return 浣忓畢鍒楄〃 + */ public List<HouseInfoBean> getHouseInfoList() { return houseInfoList; } public void setHouseInfoList(List<HouseInfoBean> houseInfoList) { + if (houseInfoList == null) { + houseInfoList = new ArrayList<>(); + } this.houseInfoList = houseInfoList; } - public List<HouseListBean> getHouseInfoBeanList() { - return houseList; + /** + * 鑾峰彇浣忓畢ID鍒楄〃 + * + * @return 浣忓畢ID鍒楄〃 + */ + public List<HouseIdBean> getHouseIdList() { + return houseIdList; } - public void setHouseInfoBeanList(List<HouseListBean> houseListBeanList) { - this.houseList = houseListBeanList; + public void setHouseIdList(List<HouseIdBean> houseIdList) { + if (houseIdList == null) { + houseIdList = new ArrayList<>(); + } + this.houseIdList = houseIdList; } - //浣忓畢鍒楄〃 - private List<HouseListBean> houseList = new ArrayList<>(); + //浣忓畢ID鍒楄〃 + private List<HouseIdBean> houseIdList = new ArrayList<>(); //浣忓畢璇︽儏鍒楄〃 private List<HouseInfoBean> houseInfoList = new ArrayList<>(); @@ -76,32 +93,32 @@ * @param cloudCallBeak - */ public void getHouseList(CloudCallBeak<Boolean> cloudCallBeak) { - //鑾峰彇浣忓畢鍒楄〃 - getResidenceList("", "", new CloudCallBeak<List<HouseListBean>>() { + //鑾峰彇浣忓畢ID鍒楄〃 + getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { @Override - public void onSuccess(List<HouseListBean> houseListBeanList) { - if (houseListBeanList != null && houseListBeanList.size() > 0) { - houseList.clear(); - houseList.addAll(houseListBeanList); - //鏍囪鏈�鍚庝竴鏉� + public void onSuccess(List<HouseIdBean> houseListBeanIDList) { + if (houseListBeanIDList != null && houseListBeanIDList.size() > 0) { + houseIdList.clear(); + houseIdList.addAll(houseListBeanIDList); + //璁板綍璇锋眰鏉℃暟 AtomicInteger atomicInteger = new AtomicInteger(0); - for (int i = 0; i < houseList.size(); i++) { - HouseListBean houseListBean = houseList.get(i); - atomicInteger.set(i); + for (int i = 0; i < houseIdList.size(); i++) { + HouseIdBean houseIdBean = houseIdList.get(i); //鑾峰彇浣忓畢璇︽儏鍒楄〃 - getResidenceInfo(houseListBean.getHomeId(), new CloudCallBeak<HouseInfoBean>() { + getResidenceInfo(houseIdBean.getHomeId(), new CloudCallBeak<HouseInfoBean>() { @Override public void onSuccess(HouseInfoBean houseInfoBean) { + atomicInteger.set(atomicInteger.get() + 1); if (houseInfoBean != null) { - houseInfoBean.setHomeImage(houseListBean.getHomeImage());//鐢电珯鍥剧墖 - houseInfoBean.setInstalledCapacity(houseListBean.getInstalledCapacity());//瑁呮満瀹归噺 - houseInfoBean.setPower(houseListBean.getPower());//鍙戠數鍔熺巼 - houseInfoBean.setTodayElectricity(houseListBean.getTodayElectricity());//浠婂ぉ鍙戠數閲� - houseInfoBean.setPowerStationStatus(houseListBean.getPowerStationStatus());//鐢电珯鐘舵��(鐢电珯鐘舵�� 1:姝e父(杩愯),2:绂荤嚎,3:杩炴帴涓�,4:鏁呴殰) + houseInfoBean.setHomeImage(houseIdBean.getHomeImage());//鐢电珯鍥剧墖 + houseInfoBean.setInstalledCapacity(houseIdBean.getInstalledCapacity());//瑁呮満瀹归噺 + houseInfoBean.setPower(houseIdBean.getPower());//鍙戠數鍔熺巼 + houseInfoBean.setTodayElectricity(houseIdBean.getTodayElectricity());//浠婂ぉ鍙戠數閲� + houseInfoBean.setPowerStationStatus(houseIdBean.getPowerStationStatus());//鐢电珯鐘舵��(鐢电珯鐘舵�� 1:姝e父(杩愯),2:绂荤嚎,3:杩炴帴涓�,4:鏁呴殰) //娣诲姞鍒版湰鍦扮紦瀛� addHouseToLocalMemory(houseInfoBean); } - if (atomicInteger.get() == houseList.size() - 1) { + if (atomicInteger.get() == houseIdList.size()) { //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); @@ -112,7 +129,9 @@ @Override public void onFailure(Exception exception) { - if (atomicInteger.get() == houseList.size() - 1) { + atomicInteger.set(atomicInteger.get() + 1); + if (atomicInteger.get() == houseIdList.size()) { + //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { cloudCallBeak.onFailure(exception); } @@ -139,71 +158,12 @@ } /** - * 鑾峰彇浣忓畢(鐢电珯)鍒楄〃 + * 鑾峰彇浣忓畢(鐢电珯)ID鍒楄〃 * - * @param pageNo 褰撳墠椤垫暟 寮�濮嬮粯璁�1 - * @param pageSize 涓�椤靛ぇ灏� 寮�濮嬮粯璁�50 * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort);浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort);鍒涘缓鏃堕棿鎺掑簭(createTimeSort); * @param keyValue (descending:闄嶅簭ascending:鍗囧簭), */ - public void getResidenceList(int pageNo, int pageSize, String key, String keyValue, CloudCallBeak<Boolean> cloudCallBeak) { - if (pageNo == 1) { - //绗竴娆¤繘鏉ユ竻绌哄垪琛� - houseList.clear(); - } - 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("powerSort", "descending");//鍙戠數鍔熺巼鎺掑簭(descending:闄嶅簭ascending:鍗囧簭) -// json.addProperty("todayElectricitySort", "descending");//浠婃棩鍙戠數閲忔帓搴� -// json.addProperty("createTimeSort", "descending");//鍒涘缓鏃堕棿鎺掑簭 -// json.addProperty("zoneType", "password");//鍖哄煙 - json.addProperty("pageNo", pageNo);//椤电爜 - json.addProperty("pageSize", pageSize);//椤垫暟 - - 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()); - HouseInfoBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseInfoBeanClass.class); - //娣诲姞銆愪綇瀹呫�戝埌鏈湴缂撳瓨 - houseList.addAll(houseInfoBeanClass.getList()); - //鎬诲叡鏈夊灏戦〉 - long totalPage = houseInfoBeanClass.totalPage; - if (totalPage == houseInfoBeanClass.getPageNo()) { - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(true); - } - return; - } - if (pageNo > totalPage) { - //褰撳墠璇锋眰鐨勯〉鏁板ぇ浜庢�婚〉鏁�,浜戠鍑洪敊浜嗙珛鍗宠繑鍥炲幓; - if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(true); - } - return; - } - getResidenceList(pageNo + 1, pageSize, key, keyValue, cloudCallBeak); - - } - } - - - @Override - public void onFailure(Exception exception) { - if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); - } - } - }); - } - - - public void getResidenceList(String key, String keyValue, CloudCallBeak<List<HouseListBean>> cloudCallBeak) { + public void getResidenceIdList(String key, String keyValue, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { String requestUrl = HttpApi.POST_PowerStation_List; JsonObject json = new JsonObject(); @@ -216,14 +176,14 @@ // json.addProperty("zoneType", "password");//鍖哄煙 json.addProperty("pageNo", 1);//椤电爜 json.addProperty("pageSize", pageSize);//椤垫暟 - List<HouseListBean> list = new ArrayList<>(); + List<HouseIdBean> list = new ArrayList<>(); 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()); - HouseInfoBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseInfoBeanClass.class); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); list.addAll(houseInfoBeanClass.getList()); //鎬诲叡鏈夊灏戦〉 long totalPage = houseInfoBeanClass.totalPage; @@ -233,22 +193,21 @@ } return; } - //鏍囪鏈�鍚庝竴鏉� - AtomicBoolean isLast = new AtomicBoolean(false); + //璁板綍璇锋眰鏉℃暟 + AtomicInteger atomicInteger = new AtomicInteger(0); //浠庣浜岄〉鑾峰彇鏁版嵁 for (int i = 2; i <= totalPage; i++) { - if (totalPage == i) { - isLast.set(true); - } 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()); - HouseInfoBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseInfoBeanClass.class); + HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); list.addAll(houseInfoBeanClass.getList()); - if (isLast.get()) { + if (atomicInteger.get() == totalPage - 1) { + //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { cloudCallBeak.onSuccess(list); } @@ -257,7 +216,9 @@ @Override public void onFailure(Exception exception) { - if (isLast.get()) { + atomicInteger.set(atomicInteger.get() + 1); + if (atomicInteger.get() == totalPage - 1) { + //鏈�鍚庝竴鏉¢��鍑� if (cloudCallBeak != null) { cloudCallBeak.onSuccess(list); } @@ -285,7 +246,7 @@ } /** - * 鑾峰彇浣忓畢(鐢电珯)璇︽儏 + * 鑾峰彇浣忓畢(鐢电珯)ID璇︽儏 * * @param homeId 浣忓畢id * @param cloudCallBeak 鍥炶皟 @@ -298,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); } } } @@ -452,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; + } - /** * 娣诲姞銆愪綇瀹呰鎯呫�戝埌鏈湴缂撳瓨 @@ -532,8 +511,128 @@ } } + /** + * 鍒囨崲浣忓畢 + * + * @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(); - static class HouseInfoBeanClass { + HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { + @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()); + } + + } + } + 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); + } + + } + + @Override + public void onFailure(Exception exception) { + + } + }); + } + }); + + + } + + /** + * 鍒犻櫎鏈湴閫嗗彉鍣� + * + * @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 { //鎬绘潯鏁� private long totalCount; @@ -544,7 +643,7 @@ //椤垫暟 private long pageSize; //鐢电珯鍒楄〃 - private List<HouseListBean> list; + private List<HouseIdBean> list; public long getTotalCount() { return totalCount; @@ -578,11 +677,11 @@ this.pageSize = pageSize; } - public List<HouseListBean> getList() { + public List<HouseIdBean> getList() { return list == null ? new ArrayList<>() : list; } - public void setList(List<HouseListBean> list) { + public void setList(List<HouseIdBean> list) { this.list = list; } } -- Gitblit v1.8.0