wjc
2025-04-15 413b905fb1af7f421b801a3d7ad0b84b57e919ab
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -8,6 +8,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.InverterBean;
import com.hdl.photovoltaic.bean.LocalResponse;
import com.hdl.photovoltaic.bean.PageNumberObject;
import com.hdl.photovoltaic.config.AppConfigManage;
@@ -38,6 +39,8 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -290,7 +293,8 @@
     * @param whetherToAdd true表示用增量,false表示用全量
     */
    public void uploadOidDataToCloud(String homeId, List<GatewayBean> list, boolean whetherToAdd, CloudCallBeak<Boolean> callBeak) {
        if (list == null || list.size() == 0) {
        if (list == null || list.isEmpty()) {
            return;
        }
        if (whetherToAdd) {
@@ -323,6 +327,7 @@
                    @Override
                    public void onError(HDLLinkException e) {
                        HdlLogLogic.print("获取oid列表失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                    }
                });
                SystemClock.sleep(200);
@@ -330,10 +335,13 @@
        } else {
            //只有进入详情界面
            List<OidBean> newOidList = new ArrayList<>();
            //表示中间任何一个失败都是改变用增量上传
            AtomicBoolean isIncrementalOidAddition = new AtomicBoolean(false);
            AtomicInteger atomicInteger = new AtomicInteger(0);
            for (int i = 0; i < list.size(); i++) {
                GatewayBean gatewayBean = list.get(i);
                if (gatewayBean == null || TextUtils.isEmpty(gatewayBean.getDevice_mac())) {
//                    isIncrementalOidAddition.set(true);
                    continue;
                }
                getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() {
@@ -341,38 +349,41 @@
                    public void onSuccess(List<OidBean> oidBeanList) {
                        atomicInteger.set(atomicInteger.get() + 1);
                        if (oidBeanList == null) {
//                            isIncrementalOidAddition.set(true);
                            return;
                        }
                        newOidList.addAll(oidBeanList);
                        if (atomicInteger.get() == list.size()) {
                            if (newOidList.size() == 0) {
                            if (newOidList.isEmpty()) {
                                return;
                            }
//                        //增量添加oid
//                        updateOidAdd(homeId, oidList, new CloudCallBeak<Boolean>() {
//                            @Override
//                            public void onSuccess(Boolean obj) {
//                                HdlLogLogic.print("上传oid列表到云端成功---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac(), true);
//                            }
//
//                            @Override
//                            public void onFailure(HDLException e) {
//                                HdlLogLogic.print("上传oid列表到云端失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
//                            }
//                        });
                            if (isIncrementalOidAddition.get()) {
                                //增量添加oid
                                updateOidAdd(homeId, newOidList, new CloudCallBeak<Boolean>() {
                                    @Override
                                    public void onSuccess(Boolean obj) {
                                        HdlLogLogic.print("上传oid列表到云端成功---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac(), true);
                                    }
                            //全部获取后再上传
                            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);
                                }
                                    @Override
                                    public void onFailure(HDLException e) {
                                        HdlLogLogic.print("上传oid列表到云端失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                    }
                                });
                            } else {
                                //全部获取后再上传
                                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);
                                    }
                                @Override
                                public void onFailure(HDLException e) {
                                    HdlLogLogic.print("上传oid列表到云端失败(全量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                }
                            });
                                    @Override
                                    public void onFailure(HDLException e) {
                                        HdlLogLogic.print("上传oid列表到云端失败(全量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                    }
                                });
                            }
                        }
                    }
@@ -380,7 +391,7 @@
                    public void onError(HDLLinkException e) {
                        atomicInteger.set(atomicInteger.get() + 1);
                        if (atomicInteger.get() == list.size()) {
                            if (newOidList.size() == 0) {
                            if (newOidList.isEmpty()) {
                                HdlLogLogic.print("获取逆变器oid列表失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                return;
                            }
@@ -396,6 +407,8 @@
                                    HdlLogLogic.print("上传oid列表到云端失败(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                                }
                            });
                        } else {
                            isIncrementalOidAddition.set(true);
                        }
                    }
                });
@@ -623,7 +636,11 @@
     * @param cloudCallBeak 回调update
     */
    public void fullUpdateOid(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
        if (oidList == null || oidList.size() == 0) {
        if (!UserConfigManage.getInstance().getHomeId().equals(homeId)) {
            HdlLogLogic.print("上传oid列表到云端失败---当前住宅id:" + UserConfigManage.getInstance().getHomeId() + "---上传住宅id:" + homeId, true);
            return;
        }
        if (oidList == null || oidList.isEmpty()) {
            HdlLogLogic.print("oid列表为空,无法全量更新oid到云端---", true);
            return;
        }
@@ -678,6 +695,10 @@
     * @param cloudCallBeak 回调update
     */
    public void updateOidAdd(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
        if (!UserConfigManage.getInstance().getHomeId().equals(homeId)) {
            HdlLogLogic.print("上传oid列表到云端失败---当前住宅id:" + UserConfigManage.getInstance().getHomeId() + "---上传住宅id:" + homeId, true);
            return;
        }
        if (oidList == null || oidList.size() == 0) {
            HdlLogLogic.print("oid列表为空,无法增量添加oid到云端---", true);
            return;
@@ -688,6 +709,10 @@
        JsonArray jsonArray = new JsonArray();
        for (int i = 0; i < oidList.size(); i++) {
            OidBean oidBean = oidList.get(i);
            if (TextUtils.isEmpty(oidBean.getDevice_model())) {
                //为空过滤掉;
                continue;
            }
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("protocolType", oidBean.getProtocolType());
            jsonObject.addProperty("deviceType", oidBean.getDeviceType());
@@ -910,7 +935,7 @@
     * @param mac          网关mac
     * @param linkCallBack 回调
     */
    public void getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) {
    public void getGatewayInfo(String mac, LinkCallBack<InverterBean> linkCallBack) {
        String requestUrl = TopicApi.GET_GATEWAY_INFO;
        JsonObject json = new JsonObject();
        json.addProperty("device_mac", mac);
@@ -926,11 +951,11 @@
                }
                Gson gson = new Gson();
                Type typeOfT = new TypeToken<BaseLocalResponse<GatewayBean>>() {
                Type typeOfT = new TypeToken<BaseLocalResponse<InverterBean>>() {
                }.getType();
                BaseLocalResponse<GatewayBean> baseLocalResponse = gson.fromJson(json, typeOfT);
                BaseLocalResponse<InverterBean> baseLocalResponse = gson.fromJson(json, typeOfT);
                if (baseLocalResponse == null || baseLocalResponse.getObjects() == null) {
                    linkCallBack.onSuccess(new GatewayBean());
                    linkCallBack.onSuccess(new InverterBean());
                } else {
                    linkCallBack.onSuccess(baseLocalResponse.getObjects());
                }
@@ -1131,7 +1156,7 @@
                                List<String> removeSidList = new ArrayList<>();
                                for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
                                    GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
                                    if (gatewayBean.getSpk().equals(INVERTER_DEVICE_SPK)) {
                                    if (!isLoadCenterSpk(gatewayBean.getSpk())) {
                                        //不是负载中心的spk不做处理;
                                        continue;
                                    }
@@ -1347,6 +1372,16 @@
        if (gatewayBean != null) {
            HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean);
        }
    }
    /**
     * 判断spk是否是负载中心
     *
     * @param spk spk
     * @return 真=true,否则返回false
     */
    private boolean isLoadCenterSpk(String spk) {
        return Objects.equals(spk, LC_SPK);
    }
    /**
@@ -1720,6 +1755,9 @@
        gatewayBean.setDevice_name(cloudInverterDeviceBean.getName());//设备名称
        gatewayBean.setGatewayType(cloudInverterDeviceBean.getSpk());//设置spk
        gatewayBean.setLocalEncrypt(true);
        //离网逆变器
        gatewayBean.setOgMaster(cloudInverterDeviceBean.isOgMaster());
        //逆变器
        gatewayBean.setMaster(GatewayMasterType.MasterTrue);//默认都是主逆变器(以后支持从逆变器要更改)
        gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//设备状态
        gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//软件版本号
@@ -1748,6 +1786,7 @@
        List<String> spks = new ArrayList<>();
        spks.add(INVERTER_DEVICE_SPK);
        spks.add(LC_SPK);
        spks.add(OFF_INVERTER_OG_SPK);
        return spks;
    }
@@ -1771,4 +1810,8 @@
     * 负载中心spk
     */
    public final String LC_SPK = "energy.hdl_lc";
    /**
     * 离线逆变器spk
     */
    public final String OFF_INVERTER_OG_SPK = "energy.inverter_og";
}