From 56f5de5eb6c1501175e7a36b10cf3d1b57284b47 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期二, 31 三月 2026 17:13:26 +0800
Subject: [PATCH] 2026年03月31日17:12:34

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  805 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 557 insertions(+), 248 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 2f1d14c..6977834 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -13,6 +13,8 @@
 import com.hdl.photovoltaic.bean.PageNumberObject;
 import com.hdl.photovoltaic.config.AppConfigManage;
 import com.hdl.photovoltaic.config.UserConfigManage;
+import com.hdl.photovoltaic.enums.DeviceType;
+import com.hdl.photovoltaic.enums.PowerStationType;
 import com.hdl.photovoltaic.internet.HttpClient;
 import com.hdl.photovoltaic.internet.TcpClient;
 import com.hdl.photovoltaic.internet.api.HttpApi;
@@ -40,6 +42,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
 
@@ -88,23 +91,98 @@
 
     /**
      * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�)
+     *
+     * @param homeId 鐢电珯ID
      */
     public List<GatewayBean> getCurrentHomeGatewayList(String homeId) {
-        List<GatewayBean> newList = new ArrayList<>();
-        List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList();
-        if (list.size() > 0) {
-            for (int i = 0; i < list.size(); i++) {
-                GatewayBean gatewayBean = list.get(i);
-                if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) {
-                    continue;
-                }
-                //鐢╤omeId绛涢�夊綋鍓嶄綇瀹呯殑閫嗗彉鍣ㄥ垪琛�
-                if (gatewayBean.getHomeId().equals(homeId)) {
-                    newList.add(gatewayBean);
+        try {
+
+            List<GatewayBean> newList = new ArrayList<>();
+            //浜戠鏈夎澶囧垪琛紝鏈湴娌℃湁锛屽嵆HDLLinkLocalGateway.getInstance().getGatewayList()娌℃湁锛岄噷闈細璋冪敤refreshGatewayCacheData()鏂规硶铏氭嫙涓�涓�嗗彉鍣ㄥ疄浣撴坊鍔犳湰鍦板垪琛ㄩ噷闈紱
+            List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList();
+            if (list.size() > 0) {
+                for (int i = 0; i < list.size(); i++) {
+                    GatewayBean gatewayBean = list.get(i);
+                    if (gatewayBean.isActivate()) {
+                        //宸叉縺娲伙紙getGatewayType锛実etDevice_mac锛実etSid锛実etOid锛夋墠鏈夊��
+                        if (!getGatewaySpk().contains(gatewayBean.getGatewayType())) {
+                            continue;
+                        }
+                        if (TextUtils.isEmpty(gatewayBean.getDevice_mac())
+                                || TextUtils.isEmpty(gatewayBean.getSid())
+                                || TextUtils.isEmpty(gatewayBean.getOid())) {
+                            continue;
+                        }
+                    }
+                    //鐢╤omeId绛涢�夊綋鍓嶄綇瀹呯殑閫嗗彉鍣ㄥ垪琛�
+                    if (gatewayBean.getHomeId().equals(homeId)) {
+                        newList.add(gatewayBean);
+                    }
                 }
             }
+
+
+            return newList;
+        } catch (Exception e) {
+            return new ArrayList<>();
         }
-        return newList;
+    }
+
+
+    /**
+     * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�)
+     * 鍙互璁剧疆鏄惁鏁村悎鏈湴閫嗗彉鍣ㄥ垪琛ㄦ暟鎹�
+     *
+     * @param homeId                  鐢电珯ID
+     * @param cloudInverterDeviceList 浜戠涓婄殑閫嗗彉鍣ㄥ垪琛紙骞剁綉锛岀缃戯紝璐熻浇涓績锛�
+     * @param isIntegrateLocalData    鏄惁寮哄埗鏁村悎鏈湴閫嗗彉鍣ㄦ暟鎹紙false锛氫笉闇�瑕侊紙浠ヤ簯绔垪琛ㄤ负涓�(閫嗗彉鍣紝璐熻浇涓績)澶氬皯涓樉绀哄灏戜釜锛�,true锛氶渶瑕侊紙鏈夊缃戯紝浠ヤ簯绔澶囧垪琛ㄤ负鍑�;浜戠娌℃湁锛屾湰鍦板瓨鍦紝鍒欏垹闄ゆ湰鍦帮紱鍚﹀垯锛屾病鏈夊缃戝彧鏈夊眬鍩熺綉锛屼互鏈湴鍒楄〃涓轰富,鎼滅储澶氬皯涓澶囧氨鏄剧ず澶氬皯涓級锛�
+     */
+    public List<GatewayBean> IntegrateCloudAndLocalData(String homeId, List<CloudInverterDeviceBean> cloudInverterDeviceList, boolean isIntegrateLocalData) {
+        try {
+            List<GatewayBean> newList = new ArrayList<>();
+            //浜戠鏈夎澶囧垪琛紝鏈湴娌℃湁锛屽嵆HDLLinkLocalGateway.getInstance().getGatewayList()娌℃湁锛岄噷闈細璋冪敤refreshGatewayCacheData()鏂规硶铏氭嫙涓�涓�嗗彉鍣ㄥ疄浣撴坊鍔犳湰鍦板垪琛ㄩ噷闈紱
+            List<GatewayBean> localList = getCurrentHomeGatewayList(homeId);
+            if (localList != null && localList.size() > 0) {
+                newList.addAll(localList);
+            }
+
+            //鏈夊缃戯紝浠ヤ簯绔澶囧垪琛ㄤ负鍑�;浜戠娌℃湁锛屾湰鍦板瓨鍦紝鍒欏垹闄ゆ湰鍦帮紱鍚﹀垯锛屾病鏈夊缃戝彧鏈夊眬鍩熺綉锛屼互鏈湴newList鍒楄〃涓轰富,鎼滅储澶氬皯涓澶囧氨鏄剧ず澶氬皯涓�
+            if (cloudInverterDeviceList != null && cloudInverterDeviceList.size() > 0) {
+                List<GatewayBean> checkNewList = new ArrayList<>();
+                for (int i = 0; i < cloudInverterDeviceList.size(); i++) {
+                    CloudInverterDeviceBean cloudInverterDevice = cloudInverterDeviceList.get(i);
+                    for (GatewayBean gatewayBean : newList) {
+                        if (cloudInverterDevice.getOsn().equals(gatewayBean.getDevice_mac())) {
+                            //鑾峰彇鏇村叏閫嗗彉鍣ㄨ鎯呭瓧娈�
+                            checkNewList.add(gatewayBean);
+                            break;
+                        }
+                    }
+                }
+                newList.clear();
+                newList.addAll(checkNewList);
+            }
+
+
+//            //妯℃嫙璁惧鍒楄〃鏁版嵁
+//            List<GatewayBean> mockData = getGatewayDeviceListMockData(3);
+//            if (mockData.size() > 0) {
+//                for (GatewayBean mockDatum : mockData) {
+//                    newList.add(0, mockDatum);
+//                }
+//            }
+
+            //鑳″浆瑕佹眰鐨� 2025骞�05鏈�19鏃�13:28:47 鍗充娇閫嗗彉鍣ㄥ垹闄や簡浜戠涓婃垚鍔燂紝鏈湴閫嗗彉鍣ㄥ垵濮嬪寲涓嶆垚鍔燂紙鏂紑锛変緷鐒朵笉鏄剧ず锛�
+            if (!isIntegrateLocalData) {
+                //寮哄埗浠ヤ簯绔负涓伙紝浜戠鏈夊氨鏄剧ず閫嗗彉鍣ㄥ垪琛紝娌℃湁灏变笉鏄剧ず
+                if (cloudInverterDeviceList == null || cloudInverterDeviceList.size() == 0) {
+                    newList.clear();
+                }
+            }
+            return newList;
+        } catch (Exception e) {
+            return new ArrayList<>();
+        }
     }
 
     /**
@@ -173,7 +251,7 @@
         if (TextUtils.isEmpty(deviceId)) {
             return;
         }
-        List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
+        List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList();
         if (list == null || list.size() == 0) {
             return;
         }
@@ -185,9 +263,10 @@
                 break;
             }
         }
-        if (index > 0) {
+        if (index > -1) {
             list.remove(index);
         }
+
     }
 
     /**
@@ -292,7 +371,8 @@
      * @param whetherToAdd true琛ㄧず鐢ㄥ閲�,false琛ㄧず鐢ㄥ叏閲�
      */
     public void uploadOidDataToCloud(String homeId, List<GatewayBean> list, boolean whetherToAdd, CloudCallBeak<Boolean> callBeak) {
-        if (list == null || list.size() == 0) {
+
+        if (list == null || list.isEmpty()) {
             return;
         }
         if (whetherToAdd) {
@@ -325,6 +405,7 @@
 
                     @Override
                     public void onError(HDLLinkException e) {
+                        HdlLogLogic.print("鑾峰彇oid鍒楄〃澶辫触---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                     }
                 });
                 SystemClock.sleep(200);
@@ -332,10 +413,13 @@
         } else {
             //鍙湁杩涘叆璇︽儏鐣岄潰
             List<OidBean> newOidList = new ArrayList<>();
+            //琛ㄧず涓棿浠讳綍涓�涓幏鍙杘id澶辫触銆傞兘瑕佹敼鍙樼敤澧為噺涓婁紶oid鍒楄〃
+            AtomicBoolean isIncrementalOidAddition = new AtomicBoolean(false);
             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())) {
+//                    isIncrementalOidAddition.set(true);
                     continue;
                 }
                 getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() {
@@ -343,46 +427,50 @@
                     public void onSuccess(List<OidBean> oidBeanList) {
                         atomicInteger.set(atomicInteger.get() + 1);
                         if (oidBeanList == null) {
+//                            isIncrementalOidAddition.set(true);
                             return;
                         }
                         newOidList.addAll(oidBeanList);
                         if (atomicInteger.get() == list.size()) {
-                            if (newOidList.size() == 0) {
+                            if (newOidList.isEmpty()) {
                                 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);
-//                            }
-//                        });
+                            if (isIncrementalOidAddition.get()) {
+                                //澧為噺娣诲姞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(oidBeanList), 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);
+                                    }
+                                });
+                            } else {
+                                //鍏ㄩ儴鑾峰彇鍚庡啀涓婁紶
+                                fullUpdateOid(homeId, newOidList, new CloudCallBeak<Boolean>() {
+                                    @Override
+                                    public void onSuccess(Boolean obj) {
+                                        HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(鍏ㄩ噺)---浣忓畢id:" + homeId + "---\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 onFailure(HDLException e) {
+                                        HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(鍏ㄩ噺)---浣忓畢id:" + homeId + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+                                    }
+                                });
+                            }
                         }
                     }
 
                     @Override
                     public void onError(HDLLinkException e) {
+                        isIncrementalOidAddition.set(true);
                         atomicInteger.set(atomicInteger.get() + 1);
                         if (atomicInteger.get() == list.size()) {
-                            if (newOidList.size() == 0) {
+                            if (newOidList.isEmpty()) {
                                 HdlLogLogic.print("鑾峰彇閫嗗彉鍣╫id鍒楄〃澶辫触---浣忓畢id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                 return;
                             }
@@ -433,8 +521,16 @@
             public void onSuccess(String str) {
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
-                    //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
-                    List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId);
+                    List<GatewayBean> list = new ArrayList<>();
+                    GatewayBean gatewayBean = new GatewayBean();
+                    gatewayBean.setHomeId(homeId);
+                    gatewayBean.setDevice_mac(mac);
+                    gatewayBean.setSpk(spk);
+                    gatewayBean.setSid(sid);
+                    gatewayBean.setOid(oid);
+                    gatewayBean.setDevice_name(name);
+                    list.add(gatewayBean);
+                    //娣诲姞璁惧鎴愬姛鍚庯紝涓婁紶oid鍒楄〃鍒颁簯绔�
                     uploadOidDataToCloud(homeId, list, true, null);
                 }
             }
@@ -546,6 +642,43 @@
         });
     }
 
+    /**
+     * 鑾峰彇浜戠BMS璁惧鍒楄〃
+     *
+     * @param homeId        浣忓畢id
+     * @param cloudCallBeak 鍥炶皟
+     */
+    public void getCloudBmsDeviceList(String homeId, CloudCallBeak<List<CloudInverterDeviceBean>> cloudCallBeak) {
+        String requestUrl = HttpApi.POST_Device_bmsDevices;
+        JsonObject json = new JsonObject();
+        json.addProperty("homeId", homeId);
+        // json.addProperty("zoneType", "password");//鍖哄煙
+
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+            @Override
+            public void onSuccess(String jsonStr) {
+                if (TextUtils.isEmpty(jsonStr)) {
+                    if (cloudCallBeak != null) {
+                        cloudCallBeak.onSuccess(null);
+                    }
+                }
+                Type type = new TypeToken<List<CloudInverterDeviceBean>>() {
+                }.getType();
+                List<CloudInverterDeviceBean> list = new Gson().fromJson(jsonStr, type);
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onSuccess(list);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onFailure(e);
+                }
+            }
+        });
+    }
+
 
     /**
      * 鍒犻櫎浜戠涓婇�嗗彉鍣�
@@ -625,13 +758,17 @@
      * @param cloudCallBeak 鍥炶皟update
      */
     public void fullUpdateOid(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
-        if (oidList == null || oidList.size() == 0) {
+        if (!UserConfigManage.getInstance().getHomeId().equals(homeId)) {
+            HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�---褰撳墠浣忓畢id:" + UserConfigManage.getInstance().getHomeId() + "---涓婁紶浣忓畢id:" + homeId, true);
+            return;
+        }
+        if (oidList == null || oidList.isEmpty()) {
             HdlLogLogic.print("oid鍒楄〃涓虹┖锛屾棤娉曞叏閲忔洿鏂皁id鍒颁簯绔�---", true);
             return;
         }
         String requestUrl = HttpApi.POST_Device_Oid;
         JsonObject json = new JsonObject();
-        json.addProperty("operationSource", "PROGRAM_ENERGY");//
+        json.addProperty("operationSource", "PROGRAM_ENERGY");//鎿嶄綔鏉ユ簮锛氬浐瀹氫紶锛歅ROGRAM_ENERGY  = 鑳芥簮锛孭ROGRAM = studio 榛樿
         json.addProperty("homeId", homeId);
         JsonArray jsonArray = new JsonArray();
         for (int i = 0; i < oidList.size(); i++) {
@@ -680,16 +817,25 @@
      * @param cloudCallBeak 鍥炶皟update
      */
     public void updateOidAdd(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
-        if (oidList == null || oidList.size() == 0) {
+        if (!UserConfigManage.getInstance().getHomeId().equals(homeId)) {
+            HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�---褰撳墠浣忓畢id:" + UserConfigManage.getInstance().getHomeId() + "---涓婁紶浣忓畢id:" + homeId, true);
+            return;
+        }
+        if (oidList == null || oidList.isEmpty()) {
             HdlLogLogic.print("oid鍒楄〃涓虹┖锛屾棤娉曞閲忔坊鍔爋id鍒颁簯绔�---", true);
             return;
         }
         String requestUrl = HttpApi.POST_Device_IncrAdd;
         JsonObject json = new JsonObject();
         json.addProperty("homeId", homeId);
+        json.addProperty("operationSource", "PROGRAM_ENERGY");//鎿嶄綔鏉ユ簮锛氬浐瀹氫紶锛歅ROGRAM_ENERGY  = 鑳芥簮锛孭ROGRAM = studio 榛樿
         JsonArray jsonArray = new JsonArray();
         for (int i = 0; i < oidList.size(); i++) {
             OidBean oidBean = oidList.get(i);
+            if (TextUtils.isEmpty(oidBean.getDevice_model())) {
+                //涓虹┖杩囨护鎺�;
+                continue;
+            }
             JsonObject jsonObject = new JsonObject();
             jsonObject.addProperty("protocolType", oidBean.getProtocolType());
             jsonObject.addProperty("deviceType", oidBean.getDeviceType());
@@ -712,7 +858,7 @@
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
                 }
-                HdlLogLogic.print("澧為噺娣诲姞oid鍒颁簯绔垚鍔�---");
+                HdlLogLogic.print("澧為噺娣诲姞oid鍒颁簯绔垚鍔�---", true);
             }
 
             @Override
@@ -1053,183 +1199,235 @@
 
     }
 
+
     /**
-     * 鑾峰彇閫嗗彉鍣ㄥ垪琛�(鏁村悎浜戠鍜屾湰鍦板垪琛�)
-     * 娉ㄦ剰:鏈夊缃戯紝浠ヤ簯绔澶囦负鍑�,鏈湴瀛樺湪锛屼簯绔病鏈夊垯鍒犻櫎锛涘惁鍒欙紝娌℃湁澶栫綉鍙湁灞�鍩熺綉锛屼互鏈湴涓轰富,鎼滅储澶氬皯涓澶囧氨鏄剧ず澶氬皯涓�
+     * 鍒犻櫎oid锛堥�嗗彉鍣紝bms锛岀數姹犲寘锛�
      *
-     * @param homeId        浣忓畢id
-     * @param cloudCallBeak 杩斿洖閫嗗彉鍣ㄥ垪琛�
+     * @param mac          缃戝叧mac
+     * @param linkCallBack 鍥炶皟
      */
-    public void getCurrentHomeLocalAndCloudGatewayList(String homeId, CloudCallBeak<List<GatewayBean>> cloudCallBeak) {
-        searchCurrentHomeGateway(homeId, new GatewayCallBack() {
+    public void deleteOid(String mac, JsonArray oidList, LinkCallBack<Boolean> linkCallBack) {
+        String requestUrl = TopicApi.DELETE_DEVICE;
+        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, oidList, "", new HDLLinkCallBack() {
             @Override
-            public void onSuccess(List<GatewayBean> gatewayBeanList) {
-                //灞�鍩熺綉鏈�2绉嶆儏鍐�(1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�2:鏈夊眬鍩熺綉锛屾病鏈夊缃�);
-                //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
-                getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-                    @Override
-                    public void onSuccess(List<CloudInverterDeviceBean> inverterDeviceList) {
-                        //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛�
-                        getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-                            @Override
-                            public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
-                                if (loadCentreDeviceList != null) {
-                                    //鍚堝苟璐熻浇涓績璁惧鍒楄〃锛岀劧鍚庡湪涓�璧峰仛澶勭悊
-                                    inverterDeviceList.addAll(loadCentreDeviceList);
-                                }
-                                List<String> removeSidList = new ArrayList<>();
-                                for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
-                                    GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
-                                    if (querySidInverter(inverterDeviceList, gatewayBean.getSid())) {
-                                        //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
-                                        removeSidList.add(gatewayBean.getSid());
-                                    }
-                                }
-                                for (int i = 0; i < removeSidList.size(); i++) {
-                                    //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
-                                    removeLocalInverter(removeSidList.get(i));
-                                }
-                                //鎯呭喌1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�
-                                setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
-                            }
-
-                            @Override
-                            public void onFailure(HDLException e) {
-                                //鍚戜簯绔幏鍙栬礋杞戒腑蹇冭澶囧垪琛ㄥけ璐ュ悗锛屼粛鐒跺鐞嗛�嗗彉鍣ㄨ澶囧垪琛�
-                                List<String> removeSidList = new ArrayList<>();
-                                for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
-                                    GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
-                                    if (querySidInverter(inverterDeviceList, gatewayBean.getSid())) {
-                                        //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
-                                        removeSidList.add(gatewayBean.getSid());
-                                    }
-                                }
-                                for (int i = 0; i < removeSidList.size(); i++) {
-                                    //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
-                                    removeLocalInverter(removeSidList.get(i));
-                                }
-                                //鎯呭喌1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�
-                                setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
-                            }
-                        });
-
-
-                    }
-
-                    @Override
-                    public void onFailure(HDLException e) {
-                        ///鎯呭喌2:鏈夊眬鍩熺綉锛屾病鏈夊缃�;
-                        //鏈湴鏈夐�嗗彉鍣ㄥ垪琛�,鑾峰彇浜戠缁戝畾閫嗗彉鍣ㄥけ璐�,榛樿杩斿洖鏈湴閫嗗彉鍣ㄥ垪琛�;
-                        //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛�
-                        getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-                            @Override
-                            public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
-                                if (loadCentreDeviceList == null) {
-                                    if (cloudCallBeak != null) {
-                                        cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
-                                    }
-                                    return;
-                                }
-                                List<String> removeSidList = new ArrayList<>();
-                                for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
-                                    GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
-                                    if (!isLoadCenterSpk(gatewayBean.getSpk())) {
-                                        //涓嶆槸璐熻浇涓績鐨剆pk涓嶅仛澶勭悊锛�
-                                        continue;
-                                    }
-                                    if (querySidInverter(loadCentreDeviceList, gatewayBean.getSid())) {
-                                        //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
-                                        removeSidList.add(gatewayBean.getSid());
-                                    }
-                                }
-                                for (int i = 0; i < removeSidList.size(); i++) {
-                                    //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
-                                    removeLocalInverter(removeSidList.get(i));
-                                }
-                                //鎯呭喌1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�
-                                setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak);
-                            }
-
-                            @Override
-                            public void onFailure(HDLException e) {
-                                //鍚戜簯绔幏鍙栬礋杞戒腑蹇冭澶囧垪琛ㄥけ璐ュ悗锛岄粯璁よ繑鍥炴湰鍦伴�嗗彉鍣ㄥ垪琛�;
-                                if (cloudCallBeak != null) {
-                                    cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
-                                }
-                            }
-                        });
-
-//                        if (cloudCallBeak != null) {
-//                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
-//                        }
-                    }
-                });
+            public void onSuccess(String json) {
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(true);
+                }
             }
 
             @Override
             public void onError(HDLLinkException e) {
-                //澶栫綉鍙湁1绉嶆儏鍐�(鏈湴鎼滅储閫嗗彉鍣ㄥ垪琛ㄥけ璐ヤ簡)
-                //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
-                getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-                    @Override
-                    public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) {
-                        //鍐嶅悜浜戠鑾峰彇璐熻浇涓績鍒楄〃
-                        getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-                            @Override
-                            public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
-                                //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
-                                HDLLinkLocalGateway.getInstance().getGatewayList().clear();
-                                List<CloudInverterDeviceBean> newList = new ArrayList<>();
-                                if (cloudInverterList != null) {
-                                    newList.addAll(cloudInverterList);
-                                }
-                                if (loadCentreDeviceList != null) {
-                                    newList.addAll(loadCentreDeviceList);
-                                }
-                                //閫嗗彉鍣ㄥ垪琛ㄥ拰璐熻浇涓績鍒楄〃鐩稿姞
-                                setDeviceRemoteInfo(newList, homeId, cloudCallBeak);
-                            }
-
-                            @Override
-                            public void onFailure(HDLException e) {
-                                //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
-                                //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛ㄥけ璐�,鐩存帴杩斿洖閫嗗彉鍣ㄥ垪琛紱
-                                HDLLinkLocalGateway.getInstance().getGatewayList().clear();
-                                setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak);
-                            }
-                        });
-//                        //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
-//                        HDLLinkLocalGateway.getInstance().getGatewayList().clear();
-//                        setDeviceRemoteInfo(list, homeId, cloudCallBeak);
-                    }
-
-                    @Override
-                    public void onFailure(HDLException e) {
-                        //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛ㄥけ璐�
-                        //鍐嶅悜浜戠鑾峰彇璐熻浇涓績鍒楄〃
-                        getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-                            @Override
-                            public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
-                                //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
-                                HDLLinkLocalGateway.getInstance().getGatewayList().clear();
-                                //閫嗗彉鍣ㄥ垪琛ㄥ拰璐熻浇涓績鍒楄〃
-                                setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak);
-                            }
-
-                            @Override
-                            public void onFailure(HDLException e) {
-                                if (cloudCallBeak != null) {
-                                    cloudCallBeak.onFailure(e);
-                                }
-                            }
-                        });
-//                        if (cloudCallBeak != null) {
-//                            cloudCallBeak.onFailure(e);
-//                        }
-                    }
-                });
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
+                }
             }
         });
+
+    }
+
+    /**
+     * 璁惧娓呯┖杩愯鏁版嵁
+     *
+     * @param mac          缃戝叧mac
+     * @param linkCallBack 鍥炶皟
+     */
+    public void DeviceClearData(String mac, LinkCallBack<Boolean> linkCallBack) {
+        String requestUrl = TopicApi.DEVICE_RUN_DATA_CLEAR;
+        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", 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);
+                }
+            }
+        });
+
+    }
+
+    /**
+     * 鑾峰彇閫嗗彉鍣ㄥ垪琛�,鏁村悎浜戠閫嗗彉鍣ㄥ垪琛ㄥ拰鏈湴閫嗗彉鍣ㄥ垪琛�(璁惧绫诲瀷鏈�:骞剁綉閫嗗彉鍣紝绂荤嚎閫嗗彉鍣紝璐熻浇涓績璁惧);
+     * 娉ㄦ剰:鏈夊缃戯紝浠ヤ簯绔澶囧垪琛ㄤ负鍑�;浜戠娌℃湁锛屾湰鍦板瓨鍦紝鍒欏垹闄ゆ湰鍦帮紱鍚﹀垯锛屾病鏈夊缃戝彧鏈夊眬鍩熺綉锛屼互鏈湴涓轰富,鎼滅储澶氬皯涓澶囧氨鏄剧ず澶氬皯涓�
+     *
+     * @param homeId           浣忓畢id
+     * @param cloudCallBeak    杩斿洖閫嗗彉鍣ㄥ垪琛�
+     * @param powerStationType 鐢电珯绫诲瀷锛堥�嗗彉鍣紝BMS鐢电珯锛�
+     */
+    public void getCurrentHomeLocalAndCloudGatewayList(String homeId, String powerStationType, CloudCallBeak<List<GatewayBean>> cloudCallBeak) {
+//        HDLLinkLocalGateway.getInstance().getGatewayList().clear();//鍏堟竻绌轰箣鍓嶉�嗗彉鍣ㄥ垪琛�
+        if (powerStationType.equals(PowerStationType.BMS)) {
+            searchCurrentHomeGateway(homeId, new GatewayCallBack() {
+                @Override
+                public void onSuccess(List<GatewayBean> gatewayBeanList) {
+                    //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
+                    getCloudBmsDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                        @Override
+                        public void onSuccess(List<CloudInverterDeviceBean> inverterDeviceList) {
+                            //璁剧疆璁惧鐨勮繙绋嬩俊鎭�
+                            setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
+                        }
+
+                        @Override
+                        public void onFailure(HDLException e) {
+                            //鏈湴鏈夐�嗗彉鍣ㄥ垪琛�,鑾峰彇浜戠缁戝畾閫嗗彉鍣ㄥけ璐�,榛樿杩斿洖鏈湴閫嗗彉鍣ㄥ垪琛�;
+                            if (cloudCallBeak != null) {
+                                cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false));
+                            }
+
+                        }
+                    });
+                }
+
+                @Override
+                public void onError(HDLLinkException e) {
+//                //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
+//                HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+                    //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
+                    getCloudBmsDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                        @Override
+                        public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) {
+                            //鏁村悎璁惧鍒楄〃鍚�,鍐嶄竴璧疯缃澶囩殑杩滅▼淇℃伅
+                            setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak);
+                        }
+
+                        @Override
+                        public void onFailure(HDLException e) {
+                            //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛ㄥけ璐�
+                            //閮芥槸鑾峰彇澶辫触鐨勮瘽,鐩存帴杩斿洖绌哄垪琛�;
+                            if (cloudCallBeak != null) {
+                                cloudCallBeak.onSuccess(new ArrayList<>());
+                            }
+                        }
+                    });
+                }
+            });
+        } else {
+            searchCurrentHomeGateway(homeId, new GatewayCallBack() {
+                @Override
+                public void onSuccess(List<GatewayBean> gatewayBeanList) {
+                    //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
+                    getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                        @Override
+                        public void onSuccess(List<CloudInverterDeviceBean> inverterDeviceList) {
+                            //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛�
+                            getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                                @Override
+                                public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+                                    if (loadCentreDeviceList != null) {
+                                        //鍚堝苟璐熻浇涓績璁惧鍒楄〃锛岀劧鍚庡湪涓�璧峰仛澶勭悊
+                                        inverterDeviceList.addAll(loadCentreDeviceList);
+                                    }
+                                    //璁剧疆璁惧鐨勮繙绋嬩俊鎭�
+                                    setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    //鍚戜簯绔幏鍙栬礋杞戒腑蹇冭澶囧垪琛ㄥけ璐ュ悗锛屼粛鐒跺鐞嗛�嗗彉鍣ㄨ澶囧垪琛�
+                                    //璁剧疆璁惧鐨勮繙绋嬩俊鎭�
+                                    setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
+                                }
+                            });
+
+
+                        }
+
+                        @Override
+                        public void onFailure(HDLException e) {
+                            //鏈湴鏈夐�嗗彉鍣ㄥ垪琛�,鑾峰彇浜戠缁戝畾閫嗗彉鍣ㄥけ璐�,榛樿杩斿洖鏈湴閫嗗彉鍣ㄥ垪琛�;
+                            //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛�
+                            getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                                @Override
+                                public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+                                    if (loadCentreDeviceList == null) {
+                                        if (cloudCallBeak != null) {
+                                            //娌℃湁鏁版嵁锛岄粯璁よ繑鍥炴湰鍦伴�嗗彉鍣ㄥ垪琛�;
+                                            cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false));
+                                        }
+                                        return;
+                                    }
+                                    //璁剧疆璁惧鐨勮繙绋嬩俊鎭�
+                                    setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak);
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    //鍚戜簯绔幏鍙栬礋杞戒腑蹇冭澶囧垪琛ㄥけ璐ュ悗锛岄粯璁よ繑鍥炴湰鍦伴�嗗彉鍣ㄥ垪琛�;
+                                    if (cloudCallBeak != null) {
+                                        cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false));
+                                    }
+                                }
+                            });
+
+                        }
+                    });
+                }
+
+                @Override
+                public void onError(HDLLinkException e) {
+//                //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
+//                HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+                    //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
+                    getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                        @Override
+                        public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) {
+                            //鍐嶅悜浜戠鑾峰彇璐熻浇涓績鍒楄〃
+                            getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                                @Override
+                                public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+
+                                    List<CloudInverterDeviceBean> newList = new ArrayList<>();
+                                    if (cloudInverterList != null) {
+                                        //娣诲姞閫嗗彉鍣ㄨ澶囧垪琛�
+                                        newList.addAll(cloudInverterList);
+                                    }
+                                    if (loadCentreDeviceList != null) {
+                                        //娣诲姞璐熻浇涓績璁惧鍒楄〃
+                                        newList.addAll(loadCentreDeviceList);
+                                    }
+                                    //鏁村悎璁惧鍒楄〃鍚�,鍐嶄竴璧疯缃澶囩殑杩滅▼淇℃伅
+                                    setDeviceRemoteInfo(newList, homeId, cloudCallBeak);
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    //璁剧疆璁惧鐨勮繙绋嬩俊鎭�
+                                    setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak);
+                                }
+                            });
+                        }
+
+                        @Override
+                        public void onFailure(HDLException e) {
+                            //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛ㄥけ璐�
+                            //鍐嶅悜浜戠鑾峰彇璐熻浇涓績鍒楄〃
+                            getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                                @Override
+                                public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+                                    //璁剧疆璁惧鐨勮繙绋嬩俊鎭�
+                                    setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak);
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+                                    //閮芥槸鑾峰彇澶辫触鐨勮瘽,鐩存帴杩斿洖绌哄垪琛�;
+                                    if (cloudCallBeak != null) {
+                                        cloudCallBeak.onSuccess(new ArrayList<>());
+                                    }
+                                }
+                            });
+                        }
+                    });
+                }
+            });
+        }
     }
 
     /**
@@ -1243,14 +1441,32 @@
         if (list == null || list.size() == 0) {
             //浜戠娌℃湁缁戝畾閫嗗彉鍣�,榛樿杩斿洖鏈湴閫嗗彉鍣ㄥ垪琛�;
             if (cloudCallBeak != null) {
-                cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
+                cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, list, false));
             }
-
             return;
         }
         AtomicInteger atomicInteger = new AtomicInteger(0);
         for (int i = 0; i < list.size(); i++) {
             CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
+            if (cloudInverterDeviceBean == null) {
+                atomicInteger.set(atomicInteger.get() + 1);
+                continue;
+            }
+            if (!cloudInverterDeviceBean.getSpk().equals(HDL_BMS_SPK) && !cloudInverterDeviceBean.isActivate()) {
+                //鏈縺娲昏澶�
+                atomicInteger.set(atomicInteger.get() + 1);
+                //娉ㄦ剰:杩欎釜閫嗗彉鍣ㄥ彧鑳芥湰鍦版帶鍒�(鍥犱负鎷夸笉鍒癿qtt閫氳绉橀挜浠ュ強GatewayID,鏃犳硶杩滅▼鎺у埗)
+                //鏇存柊閫嗗彉鍣ㄦ湰鍦扮紦瀛樹俊鎭�
+                refreshGatewayCacheData(false, cloudInverterDeviceBean, null, homeId);
+                //鍒版渶鍚庝竴鏉★紝鎵嶅鐞嗗洖璋�
+                if (atomicInteger.get() == list.size()) {
+                    if (cloudCallBeak != null) {
+                        cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, list, false));
+                    }
+                }
+                HdlLogLogic.print("璁惧鏈縺娲�(mac:" + cloudInverterDeviceBean.getOsn() + "))", true);
+                continue;
+            }
             //鑾峰彇杩滅▼璁惧閫氳淇℃伅(鎷垮埌缃戝叧ID锛宮qtt閫氳绉橀挜)
             getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() {
                 @Override
@@ -1258,10 +1474,10 @@
                     atomicInteger.set(atomicInteger.get() + 1);
                     //鏇存柊閫嗗彉鍣ㄦ湰鍦扮紦瀛樹俊鎭�
                     refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo, homeId);
-                    //鍒版渶鍚庝竴鏉★紝鎵嶆湁鍥炶皟
+                    //鍒版渶鍚庝竴鏉★紝鎵嶅鐞嗗洖璋�
                     if (atomicInteger.get() == list.size()) {
                         if (cloudCallBeak != null) {
-                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
+                            cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, list, false));
                         }
                     }
                 }
@@ -1269,13 +1485,16 @@
                 @Override
                 public void onFailure(HDLException e) {
                     atomicInteger.set(atomicInteger.get() + 1);
-                    //褰撴渶鍚庝竴鏉¤姹傚け璐ヤ簡锛屾墠鏈夊洖璋�
+                    //娉ㄦ剰:杩欎釜閫嗗彉鍣ㄥ彧鑳芥湰鍦版帶鍒�(鍥犱负鎷夸笉鍒癿qtt閫氳绉橀挜浠ュ強GatewayID,鏃犳硶杩滅▼鎺у埗)
+                    //鏇存柊閫嗗彉鍣ㄦ湰鍦扮紦瀛樹俊鎭�
+                    refreshGatewayCacheData(false, cloudInverterDeviceBean, null, homeId);
+                    //鍒版渶鍚庝竴鏉★紝鎵嶅鐞嗗洖璋�
                     if (atomicInteger.get() == list.size()) {
                         if (cloudCallBeak != null) {
-                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
+                            cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, list, false));
                         }
                     }
-                    HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触---msg---" + e.getMsg() + "(" + e.getCode() + ")");
+                    HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触(mac:" + cloudInverterDeviceBean.getOsn() + ")------" + e.getMsg() + "(" + e.getCode() + ")", true);
                 }
             });
         }
@@ -1283,16 +1502,16 @@
     }
 
     /**
-     * 閫氳繃sid鏌ヨ閫嗗彉鍣ㄦ槸鍚﹀瓨缁戝畾鍦ㄤ簯绔�
+     * 閫氳繃mac鏌ヨ閫嗗彉鍣ㄦ槸鍚﹀瓨缁戝畾鍦ㄤ簯绔�
      *
      * @param list 浜戠涓婇�嗗彉鍣ㄥ垪琛�
      * @return true涓嶅瓨鍦紝鍚﹀垯瀛樺湪
      */
-    private boolean querySidInverter(List<CloudInverterDeviceBean> list, String sid) {
+    private boolean queryMacInverter(List<CloudInverterDeviceBean> list, String mac) {
         int exists_value = -1;
         for (int i = 0; i < list.size(); i++) {
             CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
-            if (sid.equals(cloudInverterDeviceBean.getSid())) {
+            if (mac.equals(cloudInverterDeviceBean.getOsn())) {
                 exists_value = 1;
                 break;
             }
@@ -1342,10 +1561,10 @@
     /**
      * 鍒犻櫎鏈湴缂撳瓨閫嗗彉鍣�
      *
-     * @param sid 璁惧sid
+     * @param mac 璁惧mac
      */
-    private void removeLocalInverter(String sid) {
-        GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid);
+    private void removeLocalInverter(String mac) {
+        GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac);
         if (gatewayBean != null) {
             HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean);
         }
@@ -1484,32 +1703,60 @@
      *
      * @param deviceMac 璁惧mac
      */
-    public void checkInverterConnectedCloud(String homeId, String deviceMac, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) {
-        this.getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
-            @Override
-            public void onSuccess(List<CloudInverterDeviceBean> list) {
-                CloudInverterDeviceBean cloudInverterDeviceBean = null;
-                if (list != null && list.size() > 0) {
-                    for (int i = 0; i < list.size(); i++) {
-                        if (list.get(i).getOsn().equals(deviceMac)) {
-                            cloudInverterDeviceBean = list.get(i);
-                            break;
-                        }
+    public void checkInverterConnectedCloud(String homeId, String deviceMac, String plantType, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) {
+        if (plantType.equals(PowerStationType.BMS)) {
+            this.getCloudBmsDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                @Override
+                public void onSuccess(List<CloudInverterDeviceBean> list) {
+                    CloudInverterDeviceBean cloudInverterDeviceBean = null;
+                    if (list != null && list.size() > 0) {
+                        for (int i = 0; i < list.size(); i++) {
+                            if (list.get(i).getOsn().equals(deviceMac)) {
+                                cloudInverterDeviceBean = list.get(i);
+                                break;
+                            }
 
+                        }
+                    }
+                    if (cloudCallBeak != null) {
+                        cloudCallBeak.onSuccess(cloudInverterDeviceBean);
                     }
                 }
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onSuccess(cloudInverterDeviceBean);
-                }
-            }
 
-            @Override
-            public void onFailure(HDLException e) {
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(e);
+                @Override
+                public void onFailure(HDLException e) {
+                    if (cloudCallBeak != null) {
+                        cloudCallBeak.onFailure(e);
+                    }
                 }
-            }
-        });
+            });
+        } else {
+            this.getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+                @Override
+                public void onSuccess(List<CloudInverterDeviceBean> list) {
+                    CloudInverterDeviceBean cloudInverterDeviceBean = null;
+                    if (list != null && list.size() > 0) {
+                        for (int i = 0; i < list.size(); i++) {
+                            if (list.get(i).getOsn().equals(deviceMac)) {
+                                cloudInverterDeviceBean = list.get(i);
+                                break;
+                            }
+
+                        }
+                    }
+                    if (cloudCallBeak != null) {
+                        cloudCallBeak.onSuccess(cloudInverterDeviceBean);
+                    }
+                }
+
+                @Override
+                public void onFailure(HDLException e) {
+                    if (cloudCallBeak != null) {
+                        cloudCallBeak.onFailure(e);
+                    }
+                }
+            });
+        }
     }
 
 
@@ -1736,7 +1983,8 @@
         gatewayBean.setOgMaster(cloudInverterDeviceBean.isOgMaster());
         //閫嗗彉鍣�
         gatewayBean.setMaster(GatewayMasterType.MasterTrue);//榛樿閮芥槸涓婚�嗗彉鍣�(浠ュ悗鏀寔浠庨�嗗彉鍣ㄨ鏇存敼)
-        gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//璁惧鐘舵��
+        gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//璁惧鐘舵�侊紙閫嗗彉鍣ㄨ澶囷級
+        gatewayBean.setWorkStatusDesc(cloudInverterDeviceBean.getWorkStatusDesc());//宸ヤ綔鐘舵�侊紙璐熻浇涓績璁惧锛�
         gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//杞欢鐗堟湰鍙�
         gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());//璁惧绫诲瀷(浜у搧浜岀骇鍒嗙被鍚嶇О
         gatewayBean.setDeviceType(cloudInverterDeviceBean.getDeviceType());//璁惧绫诲瀷(INV:閫嗗彉鍣�;BMS:BMS鎺у埗鐩�;BATTERY:鐢垫睜鍗曞厓)
@@ -1749,10 +1997,34 @@
             gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//璁惧鍨嬪彿
         }
         gatewayBean.setSpk(cloudInverterDeviceBean.getSpk());//璁惧spk
+        gatewayBean.setActivate(cloudInverterDeviceBean.isActivate());//鏄惁婵�娲昏澶�(true锛氭縺娲伙紱false锛氭湭婵�娲�)
+        gatewayBean.setPopUpgrade(cloudInverterDeviceBean.isPopUpgrade());//鏀硅澶囨槸鍚︽湁寮圭獥鍗囩骇
+        gatewayBean.setSubPopUpgrade(cloudInverterDeviceBean.isSubPopUpgrade());//涓嬫寕璁惧鏄惁鏈夊脊绐楀崌绾�
 
+        if (cloudInverterDeviceBean.getDeviceType().equals(DeviceType.bms)) {
+            gatewayBean.setDeviceOidId(cloudInverterDeviceBean.getDeviceOidId());
+            gatewayBean.setFwVersion(cloudInverterDeviceBean.getFwVersion());
+        }
+        gatewayBean.setBmsSource(cloudInverterDeviceBean.getBmsSource());
+        //鏄惁鍙敮鎸佽繙绋嬪彂閫佸懡浠�
+        gatewayBean.setSupportLocalSendCommands(!this.isBmsDevice(gatewayBean.getDevice_model()));
 
     }
 
+    /**
+     * 鏄惁鏄疊MS璁惧锛堜负浠�涔堜娇鐢ㄨ澶囩被鍨嬫煡鎵撅紝鏄洜涓烘湁浜汢MS璁惧鏈夊彲鑳芥敮鎸乀CP鍜岃繙绋嬶紝鏈変簺BMS璁惧鍙敮鎸佽繙绋嬶紝鍥犱负鏈夊彲鑳戒娇鐢ㄥ拰閫嗗彉鍣ㄤ竴鏍风殑绯荤粺锛岃�屼笉鏄幇鍦ㄧ敤鍗曠墖鏈猴級
+     *
+     * @param model 璁惧绫诲瀷
+     * @return true琛ㄧず鏄疊MS璁惧锛屽惁鍒欎笉鏄�
+     */
+    private boolean isBmsDevice(String model) {
+        List<String> bmsModels = new ArrayList<>();
+        bmsModels.add("ME-GLE-BW5K");
+        if (bmsModels.contains("ME-GLE-BW5K")) {
+            return true;
+        }
+        return false;
+    }
 
     /**
      * 鑾峰彇缃戝叧鏀寔spk鍒楄〃
@@ -1764,6 +2036,7 @@
         spks.add(INVERTER_DEVICE_SPK);
         spks.add(LC_SPK);
         spks.add(OFF_INVERTER_OG_SPK);
+        spks.add(HDL_BMS_SPK);
         return spks;
     }
 
@@ -1780,6 +2053,38 @@
     }
 
     /**
+     * 妯℃嫙閫嗗彉鍣ㄨ澶囧垪琛�
+     *
+     * @param sum 妯℃嫙澶氬皯涓�
+     * @return 杩斿洖閫嗗彉鍣ㄥ垪琛�
+     */
+    public List<GatewayBean> getGatewayDeviceListMockData(int sum) {
+
+        try {
+            List<GatewayBean> list = new ArrayList<>();
+            for (int i = 0; i < sum; i++) {
+                String spk = getGatewaySpk().get(i % getGatewaySpk().size());
+                GatewayBean gatewayBean = new GatewayBean();
+                gatewayBean.setHomeId("100000000" + i);
+                gatewayBean.setDevice_mac("200000000" + i);
+                gatewayBean.setSpk(spk);
+                gatewayBean.setGateway_type(spk);
+                gatewayBean.setMaster("true");
+                gatewayBean.setSid("300000000" + i);
+                gatewayBean.setOid("400000000" + i);
+                gatewayBean.setGatewayId("500000000" + i);
+                gatewayBean.setDevice_name("妯℃嫙-" + i + "(" + spk + ")");
+                gatewayBean.setDeviceStatus(5);//榛樿閮芥槸绂荤嚎卢
+                list.add(gatewayBean);
+            }
+            return list;
+        } catch (Exception ignored) {
+            return new ArrayList<>();
+        }
+
+    }
+
+    /**
      * 閫嗗彉鍣╯pk
      */
     public final String INVERTER_DEVICE_SPK = "energy.hdl_inverter";
@@ -1791,4 +2096,8 @@
      * 绂荤嚎閫嗗彉鍣╯pk
      */
     public final String OFF_INVERTER_OG_SPK = "energy.inverter_og";
+    /**
+     * BMS璁惧spk
+     */
+    public final String HDL_BMS_SPK = "energy.hdl_bms";
 }

--
Gitblit v1.8.0