From a4e8dee87338beef6f45f053d8fa9c36dc74ed09 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期一, 06 五月 2024 19:53:17 +0800
Subject: [PATCH] 2024年05月06日19:53:11

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 174 insertions(+), 1 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
index d432bff..363da34 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -9,6 +9,7 @@
 import com.google.gson.JsonObject;
 import com.google.gson.reflect.TypeToken;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
+import com.hdl.photovoltaic.bean.PageNumberObject;
 import com.hdl.photovoltaic.config.AppConfigManage;
 import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.internet.HttpClient;
@@ -19,8 +20,11 @@
 import com.hdl.photovoltaic.listener.LinkCallBack;
 import com.hdl.photovoltaic.ui.bean.CloudInverterChildDeviceBean;
 import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
+import com.hdl.photovoltaic.ui.bean.DeviceBean;
 import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo;
 import com.hdl.photovoltaic.ui.bean.DeviceTimeBean;
+import com.hdl.photovoltaic.ui.bean.HouseInfoBean;
+import com.hdl.photovoltaic.ui.bean.MessageBean;
 import com.hdl.photovoltaic.ui.bean.OidBean;
 import com.hdl.sdk.link.HDLLinkLocalSdk;
 import com.hdl.sdk.link.common.config.TopicConstant;
@@ -67,6 +71,27 @@
         return sHdlDeviceLogic;
     }
 
+    public static final String kWp = "kWp";
+    public static final String kWh = "kW.h";
+
+    public static final String kW = "kW";
+    private List<DeviceBean> mListDevice = new ArrayList<>();
+
+    public void clearDeviceList() {
+        if (mListDevice == null) {
+            return;
+        }
+        if (mListDevice.size() > 0) {
+            mListDevice.clear();
+        }
+    }
+
+    public List<DeviceBean> getDeviceList() {
+        if (mListDevice == null) {
+            return new ArrayList<>();
+        }
+        return mListDevice;
+    }
 
     /**
      * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�)
@@ -89,6 +114,154 @@
         return newList;
     }
 
+    /**
+     * 娣诲姞閫嗗彉鍣ㄥ埌缂撳瓨鍒楄〃閲岄潰鍘�
+     *
+     * @param homeId         鐢电珯id
+     * @param newGatewayBean 閫嗗彉鍣ㄥ璞�
+     */
+    public void addGatewayToLocalCacheMemory(String homeId, GatewayBean newGatewayBean) {
+        if (newGatewayBean == null || TextUtils.isEmpty(homeId)) {
+            return;
+        }
+        List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
+        if (list == null || list.size() == 0) {
+            return;
+        }
+        int index = -1;
+        for (int i = 0; i < list.size(); i++) {
+            GatewayBean gatewayBean = list.get(i);
+            if (gatewayBean.getDevice_mac().equals(newGatewayBean.getDevice_mac())) {
+                index = i;
+                break;
+            }
+        }
+        if (index > 0) {
+            list.remove(index);
+            list.add(index, newGatewayBean);
+
+        }
+    }
+
+    /**
+     * 绉婚櫎缂撳瓨鍒楄〃閲岄潰閫嗗彉鍣�
+     *
+     * @param homeId 鐢电珯id
+     * @param mac    閫嗗彉鍣╩ac
+     */
+    public void removeLocalCacheMemoryGateway(String homeId, String mac) {
+        if (TextUtils.isEmpty(mac)) {
+            return;
+        }
+        List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
+        if (list == null || list.size() == 0) {
+            return;
+        }
+        int index = -1;
+        for (int i = 0; i < list.size(); i++) {
+            GatewayBean gatewayBean = list.get(i);
+            if (gatewayBean.getDevice_mac().equals(mac)) {
+                index = i;
+                break;
+            }
+        }
+        if (index > 0) {
+            list.remove(index);
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧鍒楄〃(瀹夎鍟�)
+     *
+     * @param searchTxt 鎼滅储鍐呭
+     * @param pageNo    椤电爜
+     * @param pageSize  椤垫暟
+     */
+    public void getPowerStationDeviceList(String searchTxt, long pageNo, long pageSize, CloudCallBeak<PageNumberObject<DeviceBean>> cloudCallBeak) {
+        String requestUrl = HttpApi.POST_deviceList;
+        JsonObject json = new JsonObject();
+        if (!TextUtils.isEmpty(searchTxt)) {
+            json.addProperty("searchTxt", searchTxt);
+        }
+        json.addProperty("pageNo", pageNo);//椤电爜
+        json.addProperty("pageSize", pageSize);//椤垫暟
+//        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 PageNumberObject<>());
+                    }
+                }
+                Gson gson = new Gson();
+                Type type = new TypeToken<PageNumberObject<DeviceBean>>() {
+                }.getType();
+                PageNumberObject<DeviceBean> pageNumberObject = gson.fromJson(jsonStr, type);
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onSuccess(pageNumberObject);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onFailure(e);
+                }
+            }
+        });
+    }
+
+    /**
+     * 娣诲姞銆愯澶囧垪琛ㄣ�戝埌鏈湴缂撳瓨
+     *
+     * @param list -璁惧鍒楄〃
+     */
+    public void setListDevice(List<DeviceBean> list) {
+        try {
+            if (list == null || list.size() == 0) {
+                return;
+            }
+            if (this.mListDevice.size() == 0) {
+                this.mListDevice.addAll(list);
+                return;
+            }
+            for (int i = 0; i < list.size(); i++) {
+                this.setSingleDevice(list.get(i));
+            }
+        } catch (Exception ignored) {
+        }
+    }
+
+    /**
+     * 娣诲姞璁惧鍒板垪琛ㄩ噷闈�
+     *
+     * @param deviceBean -璁惧瀵硅薄
+     */
+    public void setSingleDevice(DeviceBean deviceBean) {
+        try {
+            if (deviceBean == null) {
+                return;
+            }
+            boolean if_boolean = false;
+            for (int i = 0; i < mListDevice.size(); i++) {
+                if (mListDevice.get(i).getOsn().equals(deviceBean.getOsn())) {
+                    //瀛樺湪鏇挎崲
+                    mListDevice.remove(i);
+                    mListDevice.add(i, deviceBean);
+                    if_boolean = true;
+                    break;
+                }
+            }
+            if (!if_boolean) {
+                //娌℃湁娣诲姞
+                this.mListDevice.add(deviceBean);
+            }
+        } catch (Exception e) {
+            String mes = e.getMessage();
+            HdlLogLogic.print("--->" + mes);
+        }
+    }
 
     /**
      * 閫嗗彉鍣ㄤ笂浼犳暟鎹埌浜戠(鍖呮嫭:sid锛宱id)
@@ -284,7 +457,7 @@
             public void onSuccess(String str) {
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
-                    //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔紙鍘绘帀锛屽師鍥犳槸鎴戜笂浼犳垚鍔熷悗锛岀綉鍏冲啀娆″叏閲忎笂浼爋id鍒楄〃锛屼細鎶婁箣鍓峯id鍒楄〃瑕嗙洊鎺夛級
+                    //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
                     uploadOidDataToCloud(homeId, list, true, null);
                 }
             }

--
Gitblit v1.8.0