mac
2024-05-06 a4e8dee87338beef6f45f053d8fa9c36dc74ed09
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -9,6 +9,7 @@
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.bean.PageNumberObject;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpClient;
@@ -19,8 +20,11 @@
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.sdk.link.HDLLinkLocalSdk;
import com.hdl.sdk.link.common.config.TopicConstant;
@@ -67,6 +71,27 @@
        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;
    }
    /**
     * 获取当前住宅的逆变器列表(包括从的逆变器)
@@ -89,6 +114,154 @@
        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    逆变器mac
     */
    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);
                }
            }
        });
    }
    /**
     * 添加【设备列表】到本地缓存
     *
     * @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,oid)
@@ -284,7 +457,7 @@
            public void onSuccess(String str) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                    //临时的逻辑,上传oid列表到云端(去掉,原因是我上传成功后,网关再次全量上传oid列表,会把之前oid列表覆盖掉)
                    //临时的逻辑,上传oid列表到云端
                    uploadOidDataToCloud(homeId, list, true, null);
                }
            }