From da8bb15e0d0293d373071b44b89f2b953ecc0830 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期二, 27 六月 2023 11:00:37 +0800
Subject: [PATCH] 2023年06月27日11:00:19
---
app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java | 352 +++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 311 insertions(+), 41 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 ec5a1cf..6b2f341 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java
@@ -1,5 +1,9 @@
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;
import com.hdl.photovoltaic.bean.HttpResponsePack;
@@ -11,13 +15,27 @@
import com.hdl.photovoltaic.ui.bean.HouseInfoBean;
import com.hdl.photovoltaic.ui.bean.HouseListBean;
+import org.w3c.dom.Text;
+
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+/**
+ * 浣忓畢閫昏緫鐣岄潰
+ */
public class HdlResidenceLogic {
+
+ public static final int pageSize = 50;
private static volatile HdlResidenceLogic sHdlResidenceLogic;
+ /**
+ * 鑾峰彇褰撳墠瀵硅薄
+ *
+ * @return HdlResidenceLogic
+ */
public static synchronized HdlResidenceLogic getInstance() {
if (sHdlResidenceLogic == null) {
synchronized (HdlResidenceLogic.class) {
@@ -51,24 +69,93 @@
//浣忓畢璇︽儏鍒楄〃
private List<HouseInfoBean> houseInfoList = new ArrayList<>();
- public HouseListBean getHouseByHouseId(String homeId) {
- return new HouseListBean();
- }
+ /**
+ * 鑾峰彇浣忓畢鍒楄〃
+ *
+ * @param cloudCallBeak -
+ */
+ public void getHouseList(CloudCallBeak<Boolean> cloudCallBeak) {
+ //鑾峰彇浣忓畢鍒楄〃
+ getResidenceList("", "", new CloudCallBeak<List<HouseListBean>>() {
+ @Override
+ public void onSuccess(List<HouseListBean> houseListBeanList) {
+ if (houseListBeanList != null && houseListBeanList.size() > 0) {
+ houseList.clear();
+ houseList.addAll(houseListBeanList);
+ //鏍囪鏈�鍚庝竴鏉�
+ AtomicInteger atomicInteger = new AtomicInteger(0);
+ for (int i = 0; i < houseList.size(); i++) {
+ HouseListBean houseListBean = houseList.get(i);
+ atomicInteger.set(i);
+ //鑾峰彇浣忓畢璇︽儏鍒楄〃
+ getResidenceInfo(houseListBean.getHomeId(), new CloudCallBeak<HouseInfoBean>() {
+ @Override
+ public void onSuccess(HouseInfoBean houseInfoBean) {
+ 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:鏁呴殰)
+ //娣诲姞鍒版湰鍦扮紦瀛�
+ addHouseToLocalMemory(houseInfoBean);
+ }
+ if (atomicInteger.get() == houseList.size() - 1) {
+ //鏈�鍚庝竴鏉¢��鍑�
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
+ }
+
+ }
+
+ @Override
+ public void onFailure(Exception exception) {
+ if (atomicInteger.get() == houseList.size() - 1) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
+ }
+ }
+ });
+
+ }
+ } else {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Exception exception) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
+ }
+ });
+
+ }
/**
* 鑾峰彇浣忓畢(鐢电珯)鍒楄〃
*
- * @param pageNo 褰撳墠椤垫暟
- * @param pageSize 涓�椤靛ぇ灏�
+ * @param pageNo 褰撳墠椤垫暟 寮�濮嬮粯璁�1
+ * @param pageSize 涓�椤靛ぇ灏� 寮�濮嬮粯璁�50
+ * @param key 鍙戠數鍔熺巼鎺掑簭(powerSort);浠婃棩鍙戠數閲忔帓搴�(todayElectricitySort);鍒涘缓鏃堕棿鎺掑簭(createTimeSort);
+ * @param keyValue (descending:闄嶅簭ascending:鍗囧簭),
*/
- public void getResidenceList(int pageNo, int pageSize, CloudCallBeak<Boolean> cloudCallBeak) {
+ 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");//鍒涘缓鏃堕棿鎺掑簭
@@ -79,22 +166,28 @@
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
@Override
public void onSuccess(HttpResponsePack httpResponsePack) {
- if (httpResponsePack != null) {
- if (httpResponsePack.getData() != null) {
- Gson gson = new Gson();
- String jsonStr = gson.toJson(httpResponsePack.getData().toString());
- HouseInfoBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseInfoBeanClass.class);
- houseList.addAll(houseInfoBeanClass.getList());
- //鎬诲叡鏈夊灏戦〉
- long totalPage = houseInfoBeanClass.totalPage;
- if (totalPage == houseInfoBeanClass.getPageNo()) {
+ 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;
}
- getResidenceList(pageNo + 1, 100, cloudCallBeak);
- } else {
- cloudCallBeak.onSuccess(false);
+ return;
}
+ if (pageNo > totalPage) {
+ //褰撳墠璇锋眰鐨勯〉鏁板ぇ浜庢�婚〉鏁�,浜戠鍑洪敊浜嗙珛鍗宠繑鍥炲幓;
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
+ return;
+ }
+ getResidenceList(pageNo + 1, pageSize, key, keyValue, cloudCallBeak);
}
}
@@ -102,11 +195,94 @@
@Override
public void onFailure(Exception exception) {
- cloudCallBeak.onFailure(exception);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
}
});
}
+
+ public void getResidenceList(String key, String keyValue, CloudCallBeak<List<HouseListBean>> 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("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<HouseListBean> 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);
+ list.addAll(houseInfoBeanClass.getList());
+ //鎬诲叡鏈夊灏戦〉
+ long totalPage = houseInfoBeanClass.totalPage;
+ if (totalPage < 2) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(list);
+ }
+ return;
+ }
+ //鏍囪鏈�鍚庝竴鏉�
+ AtomicBoolean isLast = new AtomicBoolean(false);
+ //浠庣浜岄〉鑾峰彇鏁版嵁
+ 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) {
+ Gson gson = new Gson();
+ String jsonStr = gson.toJson(httpResponsePack.getData());
+ HouseInfoBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseInfoBeanClass.class);
+ list.addAll(houseInfoBeanClass.getList());
+ if (isLast.get()) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(list);
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Exception exception) {
+ if (isLast.get()) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(list);
+ }
+ }
+ }
+ });
+ }
+
+ } else {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(list);
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Exception exception) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
+ }
+ });
+
+
+ }
/**
* 鑾峰彇浣忓畢(鐢电珯)璇︽儏
@@ -115,29 +291,29 @@
* @param cloudCallBeak 鍥炶皟
*/
public void getResidenceInfo(String homeId, CloudCallBeak<HouseInfoBean> cloudCallBeak) {
- String requestUrl = HttpApi.POST_GET_MEMBER_INFO;
+ String requestUrl = HttpApi.POST_PowerStation_Info;
JsonObject json = new JsonObject();
json.addProperty("homeId", homeId);//鐢电珯id
//json.addProperty("zoneType", "password");//鍖哄煙
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
@Override
public void onSuccess(HttpResponsePack httpResponsePack) {
- if (httpResponsePack != null) {
- if (httpResponsePack.getData() != null) {
- Gson gson = new Gson();
- String jsonStr = gson.toJson(httpResponsePack.getData().toString());
- HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class);
- cloudCallBeak.onSuccess(houseInfoBean);
- } else {
- cloudCallBeak.onSuccess(null);
- }
+ 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);
+ }
}
}
@Override
public void onFailure(Exception exception) {
- cloudCallBeak.onFailure(exception);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
}
});
@@ -146,13 +322,13 @@
/**
- * 缂栬緫浣忓畢(鐢电珯)
+ * 缂栬緫浣忓畢(鐢电珯),
*
* @param houseInfoBean -
* @param cloudCallBeak -
*/
public void editResidence(HouseInfoBean houseInfoBean, CloudCallBeak<Boolean> cloudCallBeak) {
- String requestUrl = HttpApi.POST_PowerStation_Create;
+ String requestUrl = HttpApi.POST_PowerStation_Edit;
JsonObject json = new JsonObject();
JsonObject location = new JsonObject();
json.addProperty("homeId", houseInfoBean.getHomeId());
@@ -179,13 +355,17 @@
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
@Override
public void onSuccess(HttpResponsePack httpResponsePack) {
- cloudCallBeak.onSuccess(true);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
}
@Override
public void onFailure(Exception exception) {
- cloudCallBeak.onFailure(exception);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
}
});
}
@@ -204,25 +384,29 @@
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
@Override
public void onSuccess(HttpResponsePack httpResponsePack) {
- cloudCallBeak.onSuccess(true);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
}
@Override
public void onFailure(Exception exception) {
- cloudCallBeak.onFailure(exception);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
}
});
}
/**
- * 娣诲姞浣忓畢(鐢电珯)
+ * 娣诲姞浣忓畢(鐢电珯)鍒颁簯绔�
*
* @param houseInfoBean -
* @param cloudCallBeak -
*/
- public void addResidence(HouseInfoBean houseInfoBean, CloudCallBeak<Boolean> cloudCallBeak) {
+ public void addHouseToCloud(HouseInfoBean houseInfoBean, CloudCallBeak<Boolean> cloudCallBeak) {
String requestUrl = HttpApi.POST_PowerStation_Create;
JsonObject json = new JsonObject();
JsonObject location = new JsonObject();
@@ -250,19 +434,105 @@
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
@Override
public void onSuccess(HttpResponsePack httpResponsePack) {
- cloudCallBeak.onSuccess(true);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
}
@Override
public void onFailure(Exception exception) {
- cloudCallBeak.onFailure(exception);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(exception);
+ }
}
});
}
+ /**
+ * 鍒囨崲浣忓畢
+ *
+ * @param homeId 浣忓畢id
+ */
+ public Boolean switchHouse(String homeId) {
+ UserConfigManage.getInstance().setHomeId(homeId);
+ HdlThreadLogic.runThread(new Runnable() {
+ @Override
+ public void run() {
+ //鎼滅储涓�涓嬩綇瀹呰澶�
+ }
+ }, null, null);
+
+ //鍏抽棴杩涘害鏉�
+
+ return true;
+ }
+
+
+ /**
+ * 娣诲姞銆愪綇瀹呰鎯呫�戝埌鏈湴缂撳瓨
+ *
+ * @param houseInfoBean 浣忓畢璇︽儏
+ */
+ public void addHouseToLocalMemory(HouseInfoBean houseInfoBean) {
+ if (houseInfoBean == null) {
+ return;
+ }
+ int index = isExistHouse(houseInfoBean.getHomeId());
+ if (index > -1) {
+ houseInfoList.remove(index);
+ houseInfoList.add(index, houseInfoBean);
+ } else {
+ houseInfoList.add(houseInfoBean);
+ }
+ }
+
+ /**
+ * 鏌ヨ鏈湴缂撳瓨浣忓畢鍒楄〃鏄惁瀛樺湪浣忓畢
+ *
+ * @param homeId 浣忓畢id
+ * @return 鍒楄〃绱㈠紩
+ */
+ public int isExistHouse(String homeId) {
+ int index = -1;
+ for (int i = 0; i < houseInfoList.size(); i++) {
+ if (houseInfoList.get(i).getHomeId().equals(homeId)) {
+ index = i;
+ break;
+ }
+ }
+ return index;
+ }
+
+ /**
+ * 鑾峰彇浣忓畢璇︽儏
+ *
+ * @param homeId 浣忓畢id
+ * @return 浣忓畢鎵句笉鍒拌繑鍥瀗ull
+ */
+ public HouseInfoBean getHouse(String homeId) {
+ int position = isExistHouse(homeId);
+ if (position > -1) {
+ return houseInfoList.get(position);
+ }
+ return null;
+ }
+
+ /**
+ * 鍒犻櫎浣忓畢
+ *
+ * @param homeId 浣忓畢id
+ */
+ public void delHouse(String homeId) {
+ int position = isExistHouse(homeId);
+ if (position > -1) {
+ houseInfoList.remove(position);
+ }
+ }
+
+
static class HouseInfoBeanClass {
//鎬绘潯鏁�
--
Gitblit v1.8.0