From fdcfe6ef562cc3e8bbd6fcf2faedfbd9571f4490 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期一, 01 四月 2024 14:33:42 +0800
Subject: [PATCH] 解决小程序白屏的问题

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  134 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 106 insertions(+), 28 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 24939e9..43a4fde 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -2,12 +2,12 @@
 
 import android.text.TextUtils;
 
+import com.facebook.imagepipeline.image.OriginalEncodedImageInfo;
 import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.reflect.TypeToken;
 import com.hdl.linkpm.sdk.core.exception.HDLException;
-import com.hdl.linkpm.sdk.home.type.GatewayType;
 import com.hdl.photovoltaic.config.AppConfigManage;
 import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.internet.HttpClient;
@@ -22,12 +22,17 @@
 import com.hdl.photovoltaic.ui.bean.DeviceTimeBean;
 import com.hdl.photovoltaic.ui.bean.OidBean;
 import com.hdl.sdk.link.HDLLinkLocalSdk;
+import com.hdl.sdk.link.common.config.TopicConstant;
+import com.hdl.sdk.link.common.exception.HDLLinkCode;
 import com.hdl.sdk.link.common.exception.HDLLinkException;
+import com.hdl.sdk.link.common.utils.IdUtils;
+import com.hdl.sdk.link.core.bean.LinkRequest;
 import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
 import com.hdl.sdk.link.core.bean.response.BaseLocalResponse;
 import com.hdl.sdk.link.core.callback.GatewayCallBack;
 import com.hdl.sdk.link.core.callback.HDLLinkCallBack;
 import com.hdl.sdk.link.core.config.HDLLinkConfig;
+import com.hdl.sdk.link.core.connect.HDLConnectHelper;
 import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
 import com.hdl.sdk.link.gateway.type.GatewayMasterType;
 
@@ -36,8 +41,6 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
-
-import io.dcloud.common.adapter.util.DeviceInfo;
 
 
 /**
@@ -62,6 +65,7 @@
         }
         return sHdlDeviceLogic;
     }
+
 
     /**
      * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�)
@@ -110,7 +114,8 @@
                         return;
                     }
                     oidList.addAll(oidBeanList);
-                    if (atomicInteger.get() == oidList.size()) {
+                    if (atomicInteger.get() == list.size()) {
+                        //鍏ㄩ儴鑾峰彇鍚庡啀涓婁紶
                         fullUpdateOid(homeId, oidList, new CloudCallBeak<Boolean>() {
                             @Override
                             public void onSuccess(Boolean obj) {
@@ -180,10 +185,10 @@
     /**
      * 娣诲姞澶氫釜閫嗗彉鍣ㄥ埌浜戠涓�
      *
-     * @param mac           -
+     * @param list          閫嗗彉鍣ㄥ垪琛�
      * @param cloudCallBeak -
      */
-    public void addAllInverterDeviceToCloud(String homeId, String mac, List<GatewayBean> list, CloudCallBeak<Boolean> cloudCallBeak) {
+    public void addAllInverterDeviceToCloud(String homeId, List<GatewayBean> list, CloudCallBeak<Boolean> cloudCallBeak) {
 
         String requestUrl = HttpApi.POST_Device_Add_All;
         JsonObject json = new JsonObject();
@@ -207,8 +212,8 @@
             public void onSuccess(String str) {
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
-                    //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
-                    uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), list, null);
+                    //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔紙鍘绘帀锛屽師鍥犳槸鎴戜笂浼犳垚鍔熷悗锛岀綉鍏冲啀娆″叏閲忎笂浼爋id鍒楄〃锛屼細鎶婁箣鍓峯id鍒楄〃瑕嗙洊鎺夛級
+//                    uploadDataToCloud(homeId, list, null);
                 }
             }
 
@@ -617,6 +622,68 @@
     }
 
     /**
+     * 鍒濆鍖栭�嗗彉鍣�
+     *
+     * @param mac 缃戝叧mac
+     */
+    public void initializeGateway(String mac, LinkCallBack<Boolean> linkCallBack) {
+        String requestUrl = TopicApi.GATEWAY_INITIALIZE_REMOTE;
+        JsonObject jObject = new JsonObject();
+        jObject.addProperty("device_mac", mac);
+        jObject.addProperty("reset_factory", "true");//涓篺alse鎴栨棤姝ゅ瓧娈碉紝鍒欎负"娓呴櫎鏁版嵁"
+        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jObject, "", new HDLLinkCallBack() {
+            @Override
+            public void onSuccess(String json) {
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(true);
+                }
+                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄦ垚鍔�-->mac:" + mac, true);
+            }
+
+            @Override
+            public void onError(HDLLinkException e) {
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
+                }
+                HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄥけ璐�-->mac:" + mac + "--->" + e.getMsg() + "(" + e.getCode() + ")", true);
+            }
+        });
+
+    }
+
+
+    /**
+     * 鍒犻櫎oid
+     *
+     * @param mac 缃戝叧mac
+     * @param oid 璁惧oid
+     */
+    public void deleteOid(String mac, String oid, LinkCallBack<Boolean> linkCallBack) {
+        String requestUrl = TopicApi.DELETING_GATEWAY_SLAVE;
+        JsonArray jsonArray = new JsonArray();
+        JsonObject jsonObject = new JsonObject();
+        jsonObject.addProperty("oid", oid);//璁惧oid
+        jsonArray.add(jsonObject);
+        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jsonArray, "", new HDLLinkCallBack() {
+            @Override
+            public void onSuccess(String json) {
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(true);
+                }
+            }
+
+            @Override
+            public void onError(HDLLinkException e) {
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
+                }
+            }
+        });
+
+    }
+
+
+    /**
      * 鑾峰彇閫嗗彉鍣╫id鍒楄〃
      *
      * @param mac          缃戝叧mac
@@ -696,15 +763,11 @@
                                     if (atomicInteger.get() == list.size()) {
                                         //鏀堕泦鍒犻櫎閫嗗彉鍣╯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 j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
+                                            GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
+                                            if (!querySidInverter(list, gatewayBean.getSid())) {
+                                                //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
+                                                removeSidList.add(gatewayBean.getSid());
                                             }
                                         }
                                         for (int i = 0; i < removeSidList.size(); i++) {
@@ -724,15 +787,11 @@
                                     if (atomicInteger.get() == list.size()) {
                                         //鏀堕泦鍒犻櫎閫嗗彉鍣╯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 j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
+                                            GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
+                                            if (!querySidInverter(list, gatewayBean.getSid())) {
+                                                //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
+                                                removeSidList.add(gatewayBean.getSid());
                                             }
                                         }
                                         for (int i = 0; i < removeSidList.size(); i++) {
@@ -825,6 +884,22 @@
                 });
             }
         });
+    }
+
+    /**
+     * 閫氳繃sid鏌ヨ閫嗗彉鍣�
+     *
+     * @param list 浜戠涓婇�嗗彉鍣ㄥ垪琛�
+     * @return 瀛樺湪涓簍rue, 鍚﹀垯涓篺alse
+     */
+    private boolean querySidInverter(List<CloudInverterDeviceBean> list, String sid) {
+        for (int i = 0; i < list.size(); i++) {
+            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
+            if (sid.equals(cloudInverterDeviceBean.getSid())) {
+                return true;
+            }
+        }
+        return false;
     }
 
     /**
@@ -932,8 +1007,9 @@
      * @param gatewayCallBack -
      */
     public void searchAllNetworkGateway(GatewayCallBack gatewayCallBack) {
+        List<String> spks = this.getGatewaySpk();
         //缃戝叧鎼滅储
-        HDLLinkLocalSdk.getInstance().refreshGateway(gatewayCallBack, this.getGatewaySpk());
+        HDLLinkLocalGateway.getInstance().refreshGatewayBySpk(spks, true, gatewayCallBack);
     }
 
     /**
@@ -1071,7 +1147,9 @@
         gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//瀛愮綉鍙�/璁惧鍙�,閫嗗彉鍣ㄥ湴鍧�
         gatewayBean.setPowerPvNow(cloudInverterDeviceBean.getPowerPvNow());//鍙戠數鍔熺巼
         gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//浠婃棩鍙戠數閲�
-        gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//璁惧鍨嬪彿
+        if (!TextUtils.isEmpty(cloudInverterDeviceBean.getOmodel())) {
+            gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//璁惧鍨嬪彿
+        }
         gatewayBean.setSpk(cloudInverterDeviceBean.getSpk());//璁惧spk
 
 

--
Gitblit v1.8.0