wjc
2026-03-24 c4ae4589c6c001329ebb731589b209e8ddcbf7ca
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;
@@ -38,7 +40,6 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -1257,9 +1258,58 @@
     *
     * @param homeId        住宅id
     * @param cloudCallBeak 返回逆变器列表
     * @param powerStationType 电站类型(逆变器,BMS电站)
     */
    public void getCurrentHomeLocalAndCloudGatewayList(String homeId, CloudCallBeak<List<GatewayBean>> cloudCallBeak) {
    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) {
@@ -1379,6 +1429,7 @@
            }
        });
    }
    }
    /**
     * 设置设备的远程信息(拿到网关ID,mqtt通讯秘钥等信息)
@@ -1398,7 +1449,8 @@
        AtomicInteger atomicInteger = new AtomicInteger(0);
        for (int i = 0; i < list.size(); i++) {
            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
            if (cloudInverterDeviceBean == null || !cloudInverterDeviceBean.isActivate()) {
            if (cloudInverterDeviceBean == null) {
                if (cloudInverterDeviceBean.getDeviceType().equals(DeviceType.bms)) {
                //未激活设备
                atomicInteger.set(atomicInteger.get() + 1);
                //注意:这个逆变器只能本地控制(因为拿不到mqtt通讯秘钥以及GatewayID,无法远程控制)
@@ -1412,6 +1464,23 @@
                }
                HdlLogLogic.print("设备未激活(mac:" + cloudInverterDeviceBean.getOsn() + "))", true);
                continue;
                } else {
                    if (!cloudInverterDeviceBean.isActivate()) {
                        //未激活设备
                        atomicInteger.set(atomicInteger.get() + 1);
                        //注意:这个逆变器只能本地控制(因为拿不到mqtt通讯秘钥以及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,mqtt通讯秘钥)
            getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() {
@@ -1911,7 +1980,7 @@
        gatewayBean.setOutputActivePower(cloudInverterDeviceBean.getOutputActivePower());//逆变器输出有功功率
        gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//今日发电量
        if (!TextUtils.isEmpty(cloudInverterDeviceBean.getOmodel())) {
            //可能设备没有上报给云端,建议绑定逆变器时候追加一个参数;//todo 添加设备型号BMS获取类型值不一样
            //可能设备没有上报给云端,建议绑定逆变器时候追加一个参数;
            gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//设备型号
        }
        gatewayBean.setSpk(cloudInverterDeviceBean.getSpk());//设备spk
@@ -1919,7 +1988,10 @@
        gatewayBean.setPopUpgrade(cloudInverterDeviceBean.isPopUpgrade());//改设备是否有弹窗升级
        gatewayBean.setSubPopUpgrade(cloudInverterDeviceBean.isSubPopUpgrade());//下挂设备是否有弹窗升级
        if (cloudInverterDeviceBean.getDeviceType().equals(DeviceType.bms)) {
            gatewayBean.setDeviceOidId(cloudInverterDeviceBean.getDeviceOidId());
            gatewayBean.setFwVersion(cloudInverterDeviceBean.getFwVersion());
        }
    }