From f7c38847b8e00c84c30e51a92c03071d3e9a9da8 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 14 五月 2024 09:08:57 +0800
Subject: [PATCH] 2024年05月14日09:08:49

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  468 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 412 insertions(+), 56 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..0a1e88a 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -1,13 +1,15 @@
 package com.hdl.photovoltaic.other;
 
+import android.os.SystemClock;
 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.bean.PageNumberObject;
 import com.hdl.photovoltaic.config.AppConfigManage;
 import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.internet.HttpClient;
@@ -18,16 +20,25 @@
 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;
 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 +47,6 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
-
-import io.dcloud.common.adapter.util.DeviceInfo;
 
 
 /**
@@ -63,6 +72,28 @@
         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;
+    }
+
     /**
      * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�)
      */
@@ -84,55 +115,306 @@
         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);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鐢电珯鐘舵�佹瑙�(瀹夎鍟�)
+     */
+    public void getStatusOverview(CloudCallBeak<StatusOverviewBean> cloudCallBeak) {
+        String requestUrl = HttpApi.POST_statusOverview;
+        JsonObject json = new JsonObject();
+//        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 StatusOverviewBean());
+                    }
+                }
+                Gson gson = new Gson();
+                StatusOverviewBean statusOverviewBean = gson.fromJson(jsonStr, StatusOverviewBean.class);
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onSuccess(statusOverviewBean);
+                }
+            }
+
+            @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)
      *
-     * @param homeId 浣忓畢id
-     * @param list   閫嗗彉鍣ㄥ垪琛�
+     * @param homeId       浣忓畢id
+     * @param list         閫嗗彉鍣ㄥ垪琛�
+     * @param whetherToAdd true琛ㄧず鐢ㄥ閲�,false琛ㄧず鐢ㄥ叏閲�
      */
-    public void uploadDataToCloud(String homeId, List<GatewayBean> list, CloudCallBeak<Boolean> callBeak) {
+    public void uploadOidDataToCloud(String homeId, List<GatewayBean> list, boolean whetherToAdd, CloudCallBeak<Boolean> callBeak) {
         if (list == null || list.size() == 0) {
             return;
         }
-        List<OidBean> oidList = new ArrayList<>();
-        AtomicInteger atomicInteger = new AtomicInteger(0);
-        for (int i = 0; i < list.size(); i++) {
-            atomicInteger.set(atomicInteger.get() + 1);
-            GatewayBean gatewayBean = list.get(i);
-            if (gatewayBean == null || TextUtils.isEmpty(gatewayBean.getDevice_mac())) {
-                continue;
-            }
-            getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() {
-                @Override
-                public void onSuccess(List<OidBean> oidBeanList) {
-                    if (oidBeanList == null) {
-                        return;
-                    }
-                    oidList.addAll(oidBeanList);
-                    if (atomicInteger.get() == oidList.size()) {
-                        fullUpdateOid(homeId, oidList, new CloudCallBeak<Boolean>() {
+        if (whetherToAdd) {
+            for (int i = 0; i < list.size(); i++) {
+                GatewayBean gatewayBean = list.get(i);
+                if (gatewayBean == null || TextUtils.isEmpty(gatewayBean.getDevice_mac())) {
+                    continue;
+                }
+                getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() {
+                    @Override
+                    public void onSuccess(List<OidBean> oidBeanList) {
+                        if (oidBeanList == null) {
+                            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(), 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);
                             }
                         });
+
                     }
-                }
 
-                @Override
-                public void onError(HDLLinkException e) {
-                    HdlLogLogic.print("鑾峰彇閫嗗彉鍣╫id鍒楄〃澶辫触--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                    @Override
+                    public void onError(HDLLinkException e) {
+                    }
+                });
+                SystemClock.sleep(200);
+            }
+        } else {
+            //鍙湁杩涘叆璇︽儏鐣岄潰
+            List<OidBean> newOidList = new ArrayList<>();
+            AtomicInteger atomicInteger = new AtomicInteger(0);
+            for (int i = 0; i < list.size(); i++) {
+                GatewayBean gatewayBean = list.get(i);
+                if (gatewayBean == null || TextUtils.isEmpty(gatewayBean.getDevice_mac())) {
+                    continue;
                 }
-            });
+                getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() {
+                    @Override
+                    public void onSuccess(List<OidBean> oidBeanList) {
+                        atomicInteger.set(atomicInteger.get() + 1);
+                        if (oidBeanList == null) {
+                            return;
+                        }
+                        newOidList.addAll(oidBeanList);
+                        if (atomicInteger.get() == list.size()) {
+                            if (newOidList.size() == 0) {
+                                return;
+                            }
+//                        //澧為噺娣诲姞oid
+//                        updateOidAdd(homeId, oidList, new CloudCallBeak<Boolean>() {
+//                            @Override
+//                            public void onSuccess(Boolean obj) {
+//                                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);
+//                            }
+//                        });
+
+                            //鍏ㄩ儴鑾峰彇鍚庡啀涓婁紶
+                            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);
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(鍏ㄩ噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                                }
+                            });
+                        }
+                    }
+
+                    @Override
+                    public void onError(HDLLinkException e) {
+                        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);
+                                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);
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                                }
+                            });
+                        }
+                    }
+                });
+                SystemClock.sleep(200);
+            }
         }
-
-
     }
 
     /**
@@ -164,7 +446,7 @@
                     cloudCallBeak.onSuccess(true);
                     //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
                     List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId);
-                    uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), list, null);
+                    uploadOidDataToCloud(UserConfigManage.getInstance().getHomeId(), list, true, null);
                 }
             }
 
@@ -180,10 +462,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();
@@ -208,7 +490,7 @@
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
                     //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
-                    uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), list, null);
+                    uploadOidDataToCloud(homeId, list, true, null);
                 }
             }
 
@@ -617,6 +899,68 @@
     }
 
     /**
+     * 鍒濆鍖栭�嗗彉鍣�
+     *
+     * @param mac 閫嗗彉鍣╩ac
+     */
+    public void initializeInverter(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 +1040,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 +1064,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 +1161,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 +1284,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 +1424,10 @@
         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