| | |
| | | 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; |
| | |
| | | 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.photovoltaic.ui.bean.StatusOverviewBean; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.common.config.TopicConstant; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkCode; |
| | |
| | | |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | |
| | | return sHdlDeviceLogic; |
| | | } |
| | | |
| | | public static final String kWp = "kWp"; |
| | | public static final String kWh = "kW.h"; |
| | | |
| | | public static final String kW = "kW"; |
| | | public static final String noValue = "0.00"; |
| | | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表(包括从的逆变器) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取设备列表(安装商) |
| | | * |
| | | * @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) |
| | |
| | | @Override |
| | | public void onSuccess(List<OidBean> oidBeanList) { |
| | | if (oidBeanList == null) { |
| | | HdlLogLogic.print("上传oid列表到云端成功--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->数据是null", true); |
| | | HdlLogLogic.print("上传oid列表到云端成功---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---数据是null", true); |
| | | return; |
| | | } |
| | | //增量添加oid |
| | | updateOidAdd(homeId, oidBeanList, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("上传oid列表到云端成功(增量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n数据--->" + new Gson().toJson(oidBeanList), true); |
| | | HdlLogLogic.print("上传oid列表到云端成功(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---\r\n数据---" + new Gson().toJson(oidBeanList), 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 + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | // updateOidAdd(homeId, oidList, new CloudCallBeak<Boolean>() { |
| | | // @Override |
| | | // public void onSuccess(Boolean obj) { |
| | | // HdlLogLogic.print("上传oid列表到云端成功--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac(), true); |
| | | // 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); |
| | | // HdlLogLogic.print("上传oid列表到云端失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", 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); |
| | | 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); |
| | | HdlLogLogic.print("上传oid列表到云端失败(全量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } |
| | |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (newOidList.size() == 0) { |
| | | HdlLogLogic.print("获取逆变器oid列表失败--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("获取逆变器oid列表失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | return; |
| | | } |
| | | //增量添加oid |
| | | updateOidAdd(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 + "---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); |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } |
| | |
| | | */ |
| | | public void fullUpdateOid(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | if (oidList == null || oidList.size() == 0) { |
| | | HdlLogLogic.print("oid列表为空,无法全量更新oid到云端--->", true); |
| | | HdlLogLogic.print("oid列表为空,无法全量更新oid到云端---", true); |
| | | return; |
| | | } |
| | | String requestUrl = HttpApi.POST_Device_Oid; |
| | |
| | | */ |
| | | public void updateOidAdd(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | if (oidList == null || oidList.size() == 0) { |
| | | HdlLogLogic.print("oid列表为空,无法增量添加oid到云端--->", true); |
| | | HdlLogLogic.print("oid列表为空,无法增量添加oid到云端---", true); |
| | | return; |
| | | } |
| | | String requestUrl = HttpApi.POST_Device_IncrAdd; |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | HdlLogLogic.print("增量添加oid到云端成功--->"); |
| | | HdlLogLogic.print("增量添加oid到云端成功---"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | HdlLogLogic.print("增量添加oid到云端失败--->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("增量添加oid到云端失败---" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | /** |
| | | * 初始化逆变器 |
| | | * |
| | | * @param mac 网关mac |
| | | * @param mac 逆变器mac |
| | | */ |
| | | public void initializeGateway(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | public void initializeInverter(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.GATEWAY_INITIALIZE_REMOTE; |
| | | JsonObject jObject = new JsonObject(); |
| | | jObject.addProperty("device_mac", mac); |
| | |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onError(e); |
| | | } |
| | | HdlLogLogic.print("初始化逆变器失败-->mac:" + mac + "--->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("初始化逆变器失败-->mac:" + mac + "---" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败--->msg--->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | HdlLogLogic.print("获取设备远程通讯信息失败---msg---" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | } |