wjc
2023-07-12 823f534dff0da0b34f68e32cdfe2651d1bb81db3
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -7,6 +7,7 @@
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.hdlhttp.HxHttp;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.bean.HttpResponsePack;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.UserConfigManage;
@@ -16,6 +17,7 @@
import com.hdl.photovoltaic.internet.api.TopicApi;
import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak;
import com.hdl.photovoltaic.listener.CloudCallBeak;
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.InverterDeviceBean;
@@ -80,18 +82,18 @@
        json.addProperty("name", name);
        // json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
            public void onSuccess(String str) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                }
            }
            @Override
            public void onFailure(Exception exception) {
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(exception);
                    cloudCallBeak.onFailure(e);
                }
            }
        });
@@ -109,29 +111,24 @@
        json.addProperty("homeId", homeId);
        // json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
                try {
                    if (httpResponsePack != null && httpResponsePack.getData() != null) {
                        Gson gson = new Gson();
                        String json = gson.toJson(httpResponsePack.getData());
                        Type type = new TypeToken<List<CloudInverterDeviceBean>>() {
                        }.getType();
                        List<CloudInverterDeviceBean> list = new Gson().fromJson(json, type);
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(list);
                        }
                    }
                } catch (Exception e) {
            public void onSuccess(String jsonStr) {
                if (TextUtils.isEmpty(jsonStr)) {
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onFailure(e);
                        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(Exception e) {
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                }
@@ -153,18 +150,18 @@
        json.addProperty("deviceId", deviceId);
        // json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
            public void onSuccess(String str) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                }
            }
            @Override
            public void onFailure(Exception exception) {
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(exception);
                    cloudCallBeak.onFailure(e);
                }
            }
        });
@@ -183,25 +180,28 @@
        json.addProperty("parentOid", parentOid);
        // json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
                if (httpResponsePack != null && httpResponsePack.getData() != null) {
                    Gson gson = new Gson();
                    String json = gson.toJson(httpResponsePack.getData());
                    Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() {
                    }.getType();
                    List<CloudInverterChildDeviceBean> list = gson.fromJson(json, typeOfT);
            public void onSuccess(String jsonStr) {
                if (TextUtils.isEmpty(jsonStr)) {
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onSuccess(list);
                        cloudCallBeak.onSuccess(null);
                    }
                    return;
                }
                Gson gson = new Gson();
                Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() {
                }.getType();
                List<CloudInverterChildDeviceBean> list = gson.fromJson(jsonStr, typeOfT);
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(list);
                }
            }
            @Override
            public void onFailure(Exception exception) {
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(exception);
                    cloudCallBeak.onFailure(e);
                }
            }
        });
@@ -236,9 +236,9 @@
        json.add("devices", jsonArray);
        // json.addProperty("zoneType", "password");//区域
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
            public void onSuccess(String str) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
@@ -247,9 +247,9 @@
            }
            @Override
            public void onFailure(Exception exception) {
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(exception);
                    cloudCallBeak.onFailure(e);
                }
            }
        });
@@ -260,10 +260,10 @@
    /**
     * 设置网关远程参数
     *
     * @param mac           设备mac
     * @param cloudCallBeak 回调update
     * @param mac          设备mac
     * @param linkCallBack 回调update
     */
    public void steGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) {
    public void steGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) {
        String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT;
        JsonObject json = new JsonObject();
        json.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
@@ -279,16 +279,16 @@
                        gatewayBean.setLocalEncrypt(true);
                    }
                }
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                if (linkCallBack != null) {
                    linkCallBack.onSuccess(true);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                if (linkCallBack != null) {
                    linkCallBack.onError(e);
                }
            }
        });
@@ -297,25 +297,25 @@
    /**
     * 编辑网关参数
     *
     * @param mac           设备mac
     * @param cloudCallBeak 回调update
     * @param mac          设备mac
     * @param linkCallBack 回调update
     */
    public void editGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) {
    public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) {
        String requestUrl = TopicApi.SET_GATEWAY_EDIT;
        JsonObject json = new JsonObject();
        json.addProperty("master", "true");
        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                if (linkCallBack != null) {
                    linkCallBack.onSuccess(true);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                if (linkCallBack != null) {
                    linkCallBack.onError(e);
                }
            }
        });
@@ -326,39 +326,31 @@
    /**
     * 获取网关详情信息
     *
     * @param mac           网关mac
     * @param cloudCallBeak 回调
     * @param mac          网关mac
     * @param linkCallBack 回调
     */
    public void getGatewayInfo(String mac, CloudCallBeak<GatewayBean> cloudCallBeak) {
    public void getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) {
        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());
                        }
            public void onSuccess(String json) {
                if (TextUtils.isEmpty(json)) {
                    if (linkCallBack != null) {
                        linkCallBack.onSuccess(null);
                    }
                } catch (Exception e) {
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onFailure(e);
                    }
                    return;
                }
                Gson gson = new Gson();
                GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class);
                if (linkCallBack != null) {
                    linkCallBack.onSuccess(gatewayBean);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                if (linkCallBack != null) {
                    linkCallBack.onError(e);
                }
            }
        });
@@ -368,41 +360,33 @@
    /**
     * 获取网关oid列表
     *
     * @param mac           网关mac
     * @param cloudCallBeak 回调
     * @param mac          网关mac
     * @param linkCallBack 回调
     */
    public void getGatewayOidList(String mac, CloudCallBeak<List<OidBean>> cloudCallBeak) {
    public void getGatewayOidList(String mac, LinkCallBack<List<OidBean>> linkCallBack) {
        String requestUrl = TopicApi.GET_GATEWAY_OID_LIST;
        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);
                        Type typeOfT = new TypeToken<List<OidBean>>() {
                        }.getType();
                        List<OidBean> list = gson.fromJson(json, typeOfT);
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(list);
                        }
                    } else {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(new ArrayList<>());
                        }
            public void onSuccess(String json) {
                if (TextUtils.isEmpty(json)) {
                    if (linkCallBack != null) {
                        linkCallBack.onSuccess(null);
                    }
                } catch (Exception e) {
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onFailure(e);
                    }
                    return;
                }
                Gson gson = new Gson();
                Type typeOfT = new TypeToken<List<OidBean>>() {
                }.getType();
                List<OidBean> list = gson.fromJson(json, typeOfT);
                if (linkCallBack != null) {
                    linkCallBack.onSuccess(list);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(e);
                if (linkCallBack != null) {
                    linkCallBack.onError(e);
                }
            }
        });
@@ -422,9 +406,9 @@
                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 (list == null || list.size() == 0) {
//                            //云端没有绑定逆变器,以本地为主;
//                            HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                            if (cloudCallBeak != null) {
                                cloudCallBeak.onSuccess(true);
                            }
@@ -454,9 +438,9 @@
                    }
                    @Override
                    public void onFailure(Exception exception) {
                    public void onFailure(HDLException e) {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onFailure(exception);
                            cloudCallBeak.onFailure(e);
                        }
                    }
                });
@@ -467,18 +451,13 @@
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                    @Override
                    public void onSuccess(List<CloudInverterDeviceBean> list) {
                        if (list == null) {
                        if (list == null || list.size() == 0) {
                            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);
@@ -491,6 +470,7 @@
                            gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());
                            gatewayBean.setLocalEncrypt(true);
                            gatewayBean.setMaster("true");
                            //添加网关
                            HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean);
                        }
                        if (cloudCallBeak != null) {
@@ -500,9 +480,9 @@
                    }
                    @Override
                    public void onFailure(Exception exception) {
                    public void onFailure(HDLException e) {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onFailure(exception);
                            cloudCallBeak.onFailure(e);
                        }
                    }
                });