| | |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表(包括从的逆变器) |
| | | * |
| | | * @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筛选当前住宅的逆变器列表 |
| | |
| | | } |
| | | } |
| | | } |
| | | //追加这个条件是因为上面把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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加逆变器到缓存列表里面去 |
| | |
| | | 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; |
| | | } |
| | |
| | | if (TextUtils.isEmpty(mac)) { |
| | | return; |
| | | } |
| | | List<GatewayBean> list = getCurrentHomeGatewayList(homeId); |
| | | List<GatewayBean> list = getCurrentHomeGatewayList(homeId,null); |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | |
| | | if (TextUtils.isEmpty(deviceId)) { |
| | | return; |
| | | } |
| | | List<GatewayBean> list = getCurrentHomeGatewayList(homeId); |
| | | List<GatewayBean> list = getCurrentHomeGatewayList(homeId,null); |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | |
| | | } 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++) { |
| | |
| | | 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); |
| | | } |
| | | }); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | isIncrementalOidAddition.set(true); |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (newOidList.isEmpty()) { |
| | |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } else { |
| | | isIncrementalOidAddition.set(true); |
| | | } |
| | | } |
| | | }); |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | HdlLogLogic.print("增量添加oid到云端成功---"); |
| | | HdlLogLogic.print("增量添加oid到云端成功---", true); |
| | | } |
| | | |
| | | @Override |
| | |
| | | //合并负载中心设备列表,然后在一起做处理 |
| | | 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); |
| | |
| | | @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); |
| | |
| | | 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); |
| | |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取负载中心设备列表失败后,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, null)); |
| | | } |
| | | } |
| | | }); |
| | |
| | | if (list == null || list.size() == 0) { |
| | | //云端没有绑定逆变器,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, list)); |
| | | } |
| | | |
| | | return; |
| | |
| | | //到最后一条,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, list)); |
| | | } |
| | | } |
| | | } |
| | |
| | | //当最后一条请求失败了,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId, list)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败---msg---" + e.getMsg() + "(" + e.getCode() + ")"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过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; |
| | | } |
| | |
| | | /** |
| | | * 删除本地缓存逆变器 |
| | | * |
| | | * @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); |
| | | } |