From 88fa5aa9631b263e6e3d99d9ee787f73e78c6fda Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期五, 17 五月 2024 14:54:53 +0800
Subject: [PATCH] 2024年05月17日14:54:51

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  161 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 143 insertions(+), 18 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 d364f58..4be1d77 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,9 +20,13 @@
 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.photovoltaic.ui.bean.StatusOverviewBean;
 import com.hdl.sdk.link.HDLLinkLocalSdk;
 import com.hdl.sdk.link.common.config.TopicConstant;
 import com.hdl.sdk.link.common.exception.HDLLinkCode;
@@ -39,6 +44,8 @@
 
 
 import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -67,6 +74,31 @@
         return sHdlDeviceLogic;
     }
 
+    public static final String kWp = "kWp";
+    public static final String kWh = "kW.h";
+
+    public static final String kW = "kW";
+    public static final String noValue = "0.00";
+
+    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;
+    }
 
     /**
      * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�)
@@ -145,6 +177,99 @@
         }
     }
 
+    /**
+     * 鑾峰彇璁惧鍒楄〃(瀹夎鍟�)
+     *
+     * @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)
@@ -167,19 +292,19 @@
                     @Override
                     public void onSuccess(List<OidBean> oidBeanList) {
                         if (oidBeanList == null) {
-                            HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->鏁版嵁鏄痭ull", true);
+                            HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---鏁版嵁鏄痭ull", true);
                             return;
                         }
                         //澧為噺娣诲姞oid
                         updateOidAdd(homeId, oidBeanList, new CloudCallBeak<Boolean>() {
                             @Override
                             public void onSuccess(Boolean obj) {
-                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n鏁版嵁--->" + new Gson().toJson(oidBeanList), true);
+                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(澧為噺)---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---\r\n鏁版嵁---" + new Gson().toJson(oidBeanList), true);
                             }
 
                             @Override
                             public void onFailure(HDLException e) {
-                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(澧為噺)---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                             }
                         });
 
@@ -216,12 +341,12 @@
 //                        updateOidAdd(homeId, oidList, new CloudCallBeak<Boolean>() {
 //                            @Override
 //                            public void onSuccess(Boolean obj) {
-//                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac(), true);
+//                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac(), true);
 //                            }
 //
 //                            @Override
 //                            public void onFailure(HDLException e) {
-//                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+//                                HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
 //                            }
 //                        });
 
@@ -229,12 +354,12 @@
                             fullUpdateOid(homeId, newOidList, new CloudCallBeak<Boolean>() {
                                 @Override
                                 public void onSuccess(Boolean obj) {
-                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(鍏ㄩ噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n鏁版嵁--->" + new Gson().toJson(newOidList), true);
+                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(鍏ㄩ噺)---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---\r\n鏁版嵁---" + new Gson().toJson(newOidList), true);
                                 }
 
                                 @Override
                                 public void onFailure(HDLException e) {
-                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(鍏ㄩ噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(鍏ㄩ噺)---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                 }
                             });
                         }
@@ -245,19 +370,19 @@
                         atomicInteger.set(atomicInteger.get() + 1);
                         if (atomicInteger.get() == list.size()) {
                             if (newOidList.size() == 0) {
-                                HdlLogLogic.print("鑾峰彇閫嗗彉鍣╫id鍒楄〃澶辫触--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                                HdlLogLogic.print("鑾峰彇閫嗗彉鍣╫id鍒楄〃澶辫触---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                 return;
                             }
                             //澧為噺娣诲姞oid
                             updateOidAdd(homeId, newOidList, new CloudCallBeak<Boolean>() {
                                 @Override
                                 public void onSuccess(Boolean obj) {
-                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n鏁版嵁--->" + new Gson().toJson(newOidList), true);
+                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(澧為噺)---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---\r\n鏁版嵁---" + new Gson().toJson(newOidList), true);
                                 }
 
                                 @Override
                                 public void onFailure(HDLException e) {
-                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(澧為噺)---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                 }
                             });
                         }
@@ -471,7 +596,7 @@
      */
     public void fullUpdateOid(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
         if (oidList == null || oidList.size() == 0) {
-            HdlLogLogic.print("oid鍒楄〃涓虹┖锛屾棤娉曞叏閲忔洿鏂皁id鍒颁簯绔�--->", true);
+            HdlLogLogic.print("oid鍒楄〃涓虹┖锛屾棤娉曞叏閲忔洿鏂皁id鍒颁簯绔�---", true);
             return;
         }
         String requestUrl = HttpApi.POST_Device_Oid;
@@ -526,7 +651,7 @@
      */
     public void updateOidAdd(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
         if (oidList == null || oidList.size() == 0) {
-            HdlLogLogic.print("oid鍒楄〃涓虹┖锛屾棤娉曞閲忔坊鍔爋id鍒颁簯绔�--->", true);
+            HdlLogLogic.print("oid鍒楄〃涓虹┖锛屾棤娉曞閲忔坊鍔爋id鍒颁簯绔�---", true);
             return;
         }
         String requestUrl = HttpApi.POST_Device_IncrAdd;
@@ -557,7 +682,7 @@
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
                 }
-                HdlLogLogic.print("澧為噺娣诲姞oid鍒颁簯绔垚鍔�--->");
+                HdlLogLogic.print("澧為噺娣诲姞oid鍒颁簯绔垚鍔�---");
             }
 
             @Override
@@ -565,7 +690,7 @@
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onFailure(e);
                 }
-                HdlLogLogic.print("澧為噺娣诲姞oid鍒颁簯绔け璐�--->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                HdlLogLogic.print("澧為噺娣诲姞oid鍒颁簯绔け璐�---" + e.getMsg() + "(" + e.getCode() + ")", true);
             }
         });
 
@@ -752,9 +877,9 @@
     /**
      * 鍒濆鍖栭�嗗彉鍣�
      *
-     * @param mac 缃戝叧mac
+     * @param mac 閫嗗彉鍣╩ac
      */
-    public void initializeGateway(String mac, LinkCallBack<Boolean> linkCallBack) {
+    public void initializeInverter(String mac, LinkCallBack<Boolean> linkCallBack) {
         String requestUrl = TopicApi.GATEWAY_INITIALIZE_REMOTE;
         JsonObject jObject = new JsonObject();
         jObject.addProperty("device_mac", mac);
@@ -773,7 +898,7 @@
                 if (linkCallBack != null) {
                     linkCallBack.onError(e);
                 }
-                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄥけ璐�-->mac:" + mac + "--->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄥけ璐�-->mac:" + mac + "---" + e.getMsg() + "(" + e.getCode() + ")", true);
             }
         });
 
@@ -995,7 +1120,7 @@
                                             cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
                                         }
                                     }
-                                    HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触--->msg--->" + e.getMsg() + "(" + e.getCode() + ")");
+                                    HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触---msg---" + e.getMsg() + "(" + e.getCode() + ")");
                                 }
                             });
                         }

--
Gitblit v1.8.0