wjc
2023-07-07 22494af577e21a930abef309f2f60c03c9615bd1
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -139,6 +139,7 @@
        });
    }
    /**
     * 删除逆变器
     *
@@ -321,6 +322,49 @@
    }
    /**
     * 获取网关详情信息
     *
     * @param mac           网关mac
     * @param cloudCallBeak 回调
     */
    public void getGatewayInfo(String mac, CloudCallBeak<GatewayBean> cloudCallBeak) {
        String requestUrl = TopicApi.GET_GATEWAY_INFO;
        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                try {
                    if (!TextUtils.isEmpty(msg)) {
                        Gson gson = new Gson();
                        String json = gson.toJson(msg);
                        GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class);
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(gatewayBean);
                        }
                    } else {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(new GatewayBean());
                        }
                    }
                } catch (Exception e) {
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onFailure(e);
                    }
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                }
            }
        });
    }
    /**
     * 获取网关oid列表
     *
@@ -365,6 +409,119 @@
    }
    /**
     * 获取本地设备列表
     * 注意:有外网以云端设备为准,本地存在,云端没有则删除;内网以本地为主,搜索多少个设备就显示多少个;
     *
     * @param cloudCallBeak -
     */
    public void getLocalGatewayList(CloudCallBeak<Boolean> cloudCallBeak) {
        HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
            @Override
            public void onSuccess(List<GatewayBean> gatewayBeanList) {
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                    @Override
                    public void onSuccess(List<CloudInverterDeviceBean> list) {
                        if (list == null) {
                            //云端没有绑定逆变器,清空本地列表;
                            HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                            if (cloudCallBeak != null) {
                                cloudCallBeak.onSuccess(true);
                            }
                            return;
                        }
                        //收集删除逆变器sid
                        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 i = 0; i < removeSidList.size(); i++) {
                            //获取本地的毫米波
                            removeInverter(removeSidList.get(i));
                        }
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(true);
                        }
                    }
                    @Override
                    public void onFailure(Exception exception) {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onFailure(exception);
                        }
                    }
                });
            }
            @Override
            public void onError(HDLLinkException e) {
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                    @Override
                    public void onSuccess(List<CloudInverterDeviceBean> list) {
                        if (list == null) {
                            if (cloudCallBeak != null) {
                                cloudCallBeak.onSuccess(true);
                            }
                            return;
                        }
                        if (list.size() <= 0) {
                            if (cloudCallBeak != null) {
                                cloudCallBeak.onSuccess(true);
                            }
                            return;
                        }
                        HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                        for (int i = 0; i < list.size(); i++) {
                            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
                            GatewayBean gatewayBean = new GatewayBean();
                            gatewayBean.setOid(cloudInverterDeviceBean.getOid());
                            gatewayBean.setSid(cloudInverterDeviceBean.getSid());
                            gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId());
                            gatewayBean.setOnline(cloudInverterDeviceBean.isOnline());
                            gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName());
                            gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());
                            gatewayBean.setLocalEncrypt(true);
                            gatewayBean.setMaster("true");
                            HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean);
                        }
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(true);
                        }
                    }
                    @Override
                    public void onFailure(Exception exception) {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onFailure(exception);
                        }
                    }
                });
            }
        });
    }
    /**
     * 删除本地逆变器
     *
     * @param sid 设备sid
     */
    private void removeInverter(String sid) {
        //获取本地的毫米波
        GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid);
        if (gatewayBean != null) {
            HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean);
        }
    }
    /**
     * 搜索网关列表