wjc
2025-04-15 3b7a44351f3c961812ffa837302518646eae5b0d
2025年04月15日17:05:13

修复了uni猛点获取设备列表UI界面出现逆变器个数不对,导致UI界面有闪动现象。异步线程调用获取全局设备列表方法引起的;
9个文件已修改
132 ■■■■■ 已修改文件
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/ui/bean/CloudInverterDeviceBean.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/ui/bean/HouseIdBean.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -89,14 +89,22 @@
    /**
     * 获取当前住宅的逆变器列表(包括从的逆变器)
     *
     * @param homeId                  电站ID
     * @param cloudInverterDeviceList 远端上的逆变器列表(并网,离网,负载中心)
     */
    public List<GatewayBean> getCurrentHomeGatewayList(String homeId) {
    public List<GatewayBean> getCurrentHomeGatewayList(String homeId, List<CloudInverterDeviceBean> cloudInverterDeviceList) {
        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())) {
                if (!getGatewaySpk().contains(gatewayBean.getGatewayType())) {
                    continue;
                }
                if (TextUtils.isEmpty(gatewayBean.getDevice_mac())
                        || TextUtils.isEmpty(gatewayBean.getSid())
                        || TextUtils.isEmpty(gatewayBean.getOid())) {
                    continue;
                }
                //用homeId筛选当前住宅的逆变器列表
@@ -105,8 +113,24 @@
                }
            }
        }
        //追加这个条件是因为上面把HDLLinkLocalGateway.getInstance().getGatewayList()列表处理完后,接着搜索局域网又还原列表数据,导致出现旧数据;
        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);
        }
        return newList;
    }
    /**
     * 添加逆变器到缓存列表里面去
@@ -118,7 +142,7 @@
        if (newGatewayBean == null || TextUtils.isEmpty(homeId)) {
            return;
        }
        List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
        List<GatewayBean> list = getCurrentHomeGatewayList(homeId,null);
        if (list == null || list.size() == 0) {
            return;
        }
@@ -147,7 +171,7 @@
        if (TextUtils.isEmpty(mac)) {
            return;
        }
        List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
        List<GatewayBean> list = getCurrentHomeGatewayList(homeId,null);
        if (list == null || list.size() == 0) {
            return;
        }
@@ -174,7 +198,7 @@
        if (TextUtils.isEmpty(deviceId)) {
            return;
        }
        List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
        List<GatewayBean> list = getCurrentHomeGatewayList(homeId,null);
        if (list == null || list.size() == 0) {
            return;
        }
@@ -335,7 +359,7 @@
        } else {
            //只有进入详情界面
            List<OidBean> newOidList = new ArrayList<>();
            //表示中间任何一个失败都是改变用增量上传
            //表示中间任何一个获取oid失败。都要改变用增量上传oid列表
            AtomicBoolean isIncrementalOidAddition = new AtomicBoolean(false);
            AtomicInteger atomicInteger = new AtomicInteger(0);
            for (int i = 0; i < list.size(); i++) {
@@ -375,12 +399,12 @@
                                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);
                                        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);
                                        HdlLogLogic.print("上传oid列表到云端失败(全量)---住宅id:" + homeId + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                    }
                                });
                            }
@@ -389,6 +413,7 @@
                    @Override
                    public void onError(HDLLinkException e) {
                        isIncrementalOidAddition.set(true);
                        atomicInteger.set(atomicInteger.get() + 1);
                        if (atomicInteger.get() == list.size()) {
                            if (newOidList.isEmpty()) {
@@ -407,8 +432,6 @@
                                    HdlLogLogic.print("上传oid列表到云端失败(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                }
                            });
                        } else {
                            isIncrementalOidAddition.set(true);
                        }
                    }
                });
@@ -445,7 +468,7 @@
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                    //临时的逻辑,上传oid列表到云端
                    List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId);
                    List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId,null);
                    uploadOidDataToCloud(homeId, list, true, null);
                }
            }
@@ -699,7 +722,7 @@
            HdlLogLogic.print("上传oid列表到云端失败---当前住宅id:" + UserConfigManage.getInstance().getHomeId() + "---上传住宅id:" + homeId, true);
            return;
        }
        if (oidList == null || oidList.size() == 0) {
        if (oidList == null || oidList.isEmpty()) {
            HdlLogLogic.print("oid列表为空,无法增量添加oid到云端---", true);
            return;
        }
@@ -735,7 +758,7 @@
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                }
                HdlLogLogic.print("增量添加oid到云端成功---");
                HdlLogLogic.print("增量添加oid到云端成功---", true);
            }
            @Override
@@ -1100,17 +1123,17 @@
                                    //合并负载中心设备列表,然后在一起做处理
                                    inverterDeviceList.addAll(loadCentreDeviceList);
                                }
                                List<String> removeSidList = new ArrayList<>();
                                List<String> removeMacList = new ArrayList<>();
                                for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
                                    GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
                                    if (querySidInverter(inverterDeviceList, gatewayBean.getSid())) {
                                    if (queryMacInverter(inverterDeviceList, gatewayBean.getDevice_mac())) {
                                        //本地有,云端没有,删除本地;
                                        removeSidList.add(gatewayBean.getSid());
                                        removeMacList.add(gatewayBean.getDevice_mac());
                                    }
                                }
                                for (int i = 0; i < removeSidList.size(); i++) {
                                for (int i = 0; i < removeMacList.size(); i++) {
                                    //删除本地的逆变器
                                    removeLocalInverter(removeSidList.get(i));
                                    removeLocalInverter(removeMacList.get(i));
                                }
                                //情况1:有局域网,有外网;
                                setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
@@ -1119,17 +1142,17 @@
                            @Override
                            public void onFailure(HDLException e) {
                                //向云端获取负载中心设备列表失败后,仍然处理逆变器设备列表
                                List<String> removeSidList = new ArrayList<>();
                                List<String> removeMacList = 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());
                                    if (queryMacInverter(inverterDeviceList, gatewayBean.getDevice_mac())) {
                                        //云端没有,本地有,删除本地;
                                        removeMacList.add(gatewayBean.getDevice_mac());
                                    }
                                }
                                for (int i = 0; i < removeSidList.size(); i++) {
                                for (int i = 0; i < removeMacList.size(); i++) {
                                    //删除本地的逆变器
                                    removeLocalInverter(removeSidList.get(i));
                                    removeLocalInverter(removeMacList.get(i));
                                }
                                //情况1:有局域网,有外网;
                                setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
@@ -1149,25 +1172,25 @@
                            public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
                                if (loadCentreDeviceList == null) {
                                    if (cloudCallBeak != null) {
                                        cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
                                        cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, null));
                                    }
                                    return;
                                }
                                List<String> removeSidList = new ArrayList<>();
                                List<String> removeMacList = new ArrayList<>();
                                for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
                                    GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
                                    if (!isLoadCenterSpk(gatewayBean.getSpk())) {
                                        //不是负载中心的spk不做处理;
                                        continue;
                                    }
                                    if (querySidInverter(loadCentreDeviceList, gatewayBean.getSid())) {
                                        //本地有,云端没有,删除本地;
                                        removeSidList.add(gatewayBean.getSid());
                                    if (queryMacInverter(loadCentreDeviceList, gatewayBean.getDevice_mac())) {
                                        //云端没有,本地有,删除本地;
                                        removeMacList.add(gatewayBean.getDevice_mac());
                                    }
                                }
                                for (int i = 0; i < removeSidList.size(); i++) {
                                for (int i = 0; i < removeMacList.size(); i++) {
                                    //删除本地的逆变器
                                    removeLocalInverter(removeSidList.get(i));
                                    removeLocalInverter(removeMacList.get(i));
                                }
                                //情况1:有局域网,有外网;
                                setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak);
@@ -1177,7 +1200,7 @@
                            public void onFailure(HDLException e) {
                                //向云端获取负载中心设备列表失败后,默认返回本地逆变器列表;
                                if (cloudCallBeak != null) {
                                    cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
                                    cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, null));
                                }
                            }
                        });
@@ -1266,7 +1289,7 @@
        if (list == null || list.size() == 0) {
            //云端没有绑定逆变器,默认返回本地逆变器列表;
            if (cloudCallBeak != null) {
                cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
                cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, list));
            }
            return;
@@ -1284,7 +1307,7 @@
                    //到最后一条,才有回调
                    if (atomicInteger.get() == list.size()) {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, list));
                        }
                    }
                }
@@ -1295,7 +1318,7 @@
                    //当最后一条请求失败了,才有回调
                    if (atomicInteger.get() == list.size()) {
                        if (cloudCallBeak != null) {
                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, list));
                        }
                    }
                    HdlLogLogic.print("获取设备远程通讯信息失败---msg---" + e.getMsg() + "(" + e.getCode() + ")");
@@ -1306,16 +1329,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;
            }
@@ -1365,10 +1388,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);
        }
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -906,7 +906,7 @@
                if (callback != null) {
                    uniSuccessCallback(type, null, callback);
                }
                List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId);
                List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId,null);
                for (int i = 0; i < list.size(); i++) {
                    GatewayBean gatewayBean = list.get(i);
                    HdlDeviceLogic.getInstance().initializeInverter(gatewayBean.getDevice_mac(), null);
app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java
@@ -624,7 +624,7 @@
                return;
            }
            int index = -1;
            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId());
            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId(),null);
            for (int i = 0; i < list.size(); i++) {
                GatewayBean gatewayBean = list.get(i);
                if (gatewayBean.getGatewayId().equals(topics[2])) {
app/src/main/java/com/hdl/photovoltaic/ui/CPowerStationActivity.java
@@ -131,7 +131,7 @@
                return;
            }
            int index = -1;
            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId());
            List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(UserConfigManage.getInstance().getHomeId(), null);
            for (int i = 0; i < list.size(); i++) {
                GatewayBean gatewayBean = list.get(i);
                if (gatewayBean.getGatewayId().equals(topics[2])) {
@@ -205,8 +205,8 @@
            }
            String homeId = event.getData().toString();
            //进去住宅详情uni读取逆变器列表成功后通知
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).get(i).getGatewayId();
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId, null).get(i).getGatewayId();
                //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值;
                String topic = "/user/" + gatewayId + "/#";
                //进去住宅详情开始订阅主题
app/src/main/java/com/hdl/photovoltaic/ui/bean/CloudInverterDeviceBean.java
@@ -127,7 +127,8 @@
    }
    public String getSid() {
        return sid == null ? "" : sid;
        return TextUtils.isEmpty(sid) ? "" : sid;
    }
    public void setSid(String sid) {
@@ -279,7 +280,7 @@
        if (this.location == null) {
            return this.address;
        }
        return this.location.getNationName() + this.location.getProvinceName() + this.location.getCityName() + this.address;
        return this.location.getNationName() + " " + this.location.getProvinceName() + " " + this.location.getCityName() + " " + this.address;
    }
    public String getHomeNameAndDeviceName() {
app/src/main/java/com/hdl/photovoltaic/ui/bean/HouseIdBean.java
@@ -232,6 +232,6 @@
        if (this.location == null) {
            return this.address;
        }
        return this.location.getNationName() +"-"+ this.location.getProvinceName() +"-"+ this.location.getCityName() +"-"+ this.address;
        return this.location.getNationName() +" "+ this.location.getProvinceName() +" "+ this.location.getCityName() +" "+ this.address;
    }
}
app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseAndDeviceFragment.java
@@ -641,8 +641,8 @@
            }
            String homeId = eventBus.getData().toString();
            //进去住宅详情uni读取逆变器列表成功后通知
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId).get(i).getGatewayId();
            for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId,null).size(); i++) {
                String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId,null).get(i).getGatewayId();
                //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值;
                String topic = "/user/" + gatewayId + "/#";
                //进去住宅详情开始订阅主题
app/src/main/java/com/hdl/photovoltaic/ui/test/TestMainActivity.java
@@ -183,7 +183,7 @@
                        return;
                    }
                    showLoading();
                    List<GatewayBean> gatewayBeanList = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(this.mHomeId);
                    List<GatewayBean> gatewayBeanList = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(this.mHomeId,null);
                    gsonConvertJsonStr(gatewayBeanList);
                }
                break;
@@ -512,7 +512,7 @@
     * 选择逆变器调试
     */
    public void selectDevice() {
        List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(this.mHomeId);
        List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(this.mHomeId,null);
        DialogDeviceList dialogDeviceList = new DialogDeviceList(_mActivity, list);
        dialogDeviceList.show();
        dialogDeviceList.DeviceOnclickListener(new DialogDeviceList.OnclickListener() {
sdk/src/main/java/com/hdl/sdk/link/core/bean/gateway/GatewayBean.java
@@ -88,7 +88,7 @@
    private String sid;
    private String spk = "energy.hdl_inverter";
    private String spk = "";
    private String systemStatusDesc;//云端-状态