| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.BitmapFactory; |
| | | import android.text.TextUtils; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.bean.HttpResponsePack; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == houseIdList.size()) { |
| | | //最后一条退出 |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | |
| | | /** |
| | | * 获取住宅(电站)ID列表 |
| | | * |
| | | * @param key 发电功率排序(powerSort);今日发电量排序(todayElectricitySort);创建时间排序(createTimeSort); |
| | | * @param keyValue (descending:降序ascending:升序), |
| | | * @param key 发电功率排序(powerSort); |
| | | * 今日发电量排序(todayElectricitySort); |
| | | * 创建时间排序(createTimeSort); |
| | | * @param keyValue (descending:降序 |
| | | * ascending:升序), |
| | | */ |
| | | public void getResidenceIdList(String key, String keyValue, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { |
| | | |
| | |
| | | if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(keyValue)) { |
| | | json.addProperty(key, keyValue);//发电功率排序(descending:降序ascending:升序) |
| | | } |
| | | // json.addProperty("powerSort", "descending");//发电功率排序(descending:降序ascending:升序) |
| | | // json.addProperty("todayElectricitySort", "descending");//今日发电量排序 |
| | | // json.addProperty("createTimeSort", "descending");//创建时间排序 |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | json.addProperty("pageNo", 1);//页码 |
| | | json.addProperty("pageSize", pageSize);//页数 |
| | | List<HouseIdBean> list = new ArrayList<>(); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(HttpResponsePack httpResponsePack) { |
| | | if (httpResponsePack != null && httpResponsePack.getData() != null) { |
| | | Gson gson = new Gson(); |
| | | String jsonStr = gson.toJson(httpResponsePack.getData()); |
| | | HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); |
| | | list.addAll(houseInfoBeanClass.getList()); |
| | | //总共有多少页 |
| | | long totalPage = houseInfoBeanClass.totalPage; |
| | | if (totalPage < 2) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | return; |
| | | } |
| | | //记录请求条数 |
| | | AtomicInteger atomicInteger = new AtomicInteger(0); |
| | | //从第二页获取数据 |
| | | for (int i = 2; i <= totalPage; i++) { |
| | | json.addProperty("pageNo", i);//更新页码 |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { |
| | | @Override |
| | | public void onSuccess(HttpResponsePack httpResponsePack) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | Gson gson = new Gson(); |
| | | String jsonStr = gson.toJson(httpResponsePack.getData()); |
| | | HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); |
| | | list.addAll(houseInfoBeanClass.getList()); |
| | | if (atomicInteger.get() == totalPage - 1) { |
| | | //最后一条退出 |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == totalPage - 1) { |
| | | //最后一条退出 |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } else { |
| | | public void onSuccess(String jsonStr) { |
| | | if (TextUtils.isEmpty(jsonStr)) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | Gson gson = new Gson(); |
| | | HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); |
| | | list.addAll(houseInfoBeanClass.getList()); |
| | | //总共有多少页 |
| | | long totalPage = houseInfoBeanClass.totalPage; |
| | | if (totalPage < 2) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | return; |
| | | } |
| | | //记录请求条数 |
| | | AtomicInteger atomicInteger = new AtomicInteger(0); |
| | | //从第二页获取数据 |
| | | for (int i = 2; i <= totalPage; i++) { |
| | | json.addProperty("pageNo", i);//更新页码 |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String jsonStr) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | Gson gson = new Gson(); |
| | | HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); |
| | | list.addAll(houseInfoBeanClass.getList()); |
| | | if (atomicInteger.get() == totalPage - 1) { |
| | | //最后一条退出 |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == totalPage - 1) { |
| | | //最后一条退出 |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException exception) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | } |
| | |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId);//电站id |
| | | //json.addProperty("zoneType", "password");//区域 |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(HttpResponsePack httpResponsePack) { |
| | | try { |
| | | if (httpResponsePack != null && httpResponsePack.getData() != null) { |
| | | Gson gson = new Gson(); |
| | | String jsonStr = gson.toJson(httpResponsePack.getData()); |
| | | HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); |
| | | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(houseInfoBean); |
| | | } |
| | | } |
| | | } catch (Exception exception) { |
| | | public void onSuccess(String jsonStr) { |
| | | if (TextUtils.isEmpty(jsonStr)) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onSuccess(null); |
| | | } |
| | | } |
| | | Gson gson = new Gson(); |
| | | HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(houseInfoBean); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | |
| | | json.addProperty("electrovalence", houseInfoBean.getElectrovalence()); |
| | | json.addProperty("totalCost", houseInfoBean.getTotalCost()); |
| | | json.addProperty("zoneType", houseInfoBean.getZoneType()); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(HttpResponsePack httpResponsePack) { |
| | | public void onSuccess(String str) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId);//电站id |
| | | //json.addProperty("zoneType", "password");//区域 |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(HttpResponsePack httpResponsePack) { |
| | | public void onSuccess(String str) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | |
| | | json.addProperty("electrovalence", houseInfoBean.getElectrovalence()); |
| | | json.addProperty("totalCost", houseInfoBean.getTotalCost()); |
| | | json.addProperty("zoneType", houseInfoBean.getZoneType()); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(HttpResponsePack httpResponsePack) { |
| | | public void onSuccess(String str) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | |
| | | /** |
| | | * 获取住宅图片 |
| | | */ |
| | | public void getResidenceImage(String imageUrl, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { |
| | | public void getResidenceImage(String imageUrl, CloudCallBeak<Bitmap> cloudCallBeak) { |
| | | String requestUrl = imageUrl; |
| | | JsonObject json = new JsonObject(); |
| | | List<HouseIdBean> list = new ArrayList<>(); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(HttpResponsePack httpResponsePack) { |
| | | if (httpResponsePack != null && httpResponsePack.getData() != null) { |
| | | Gson gson = new Gson(); |
| | | String jsonStr = gson.toJson(httpResponsePack.getData()); |
| | | HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); |
| | | } else { |
| | | public void onSuccess(String jsonStr) { |
| | | if (TextUtils.isEmpty(jsonStr)) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | cloudCallBeak.onSuccess(null); |
| | | } |
| | | return; |
| | | } |
| | | Bitmap bitmap = BitmapFactory.decodeByteArray(jsonStr.getBytes(), 0, jsonStr.getBytes().length); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(bitmap); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | |
| | | HdlFileLogic.getInstance().createDirectory(); |
| | | //配置本地通信的信息 |
| | | initLocalLinkSdk(); |
| | | |
| | | HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | if (list == null) { |
| | | //云端没有绑定逆变器,清空本地列表; |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | return; |
| | | } |
| | | //收集删除逆变器sid |
| | | List<String> removeSidList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); |
| | | if (!cloudInverterDeviceBean.getSid().equals(gatewayBean.getSid())) { |
| | | //本地有,云端没有,删除本地; |
| | | removeSidList.add(gatewayBean.getSid()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | for (int i = 0; i < removeSidList.size(); i++) { |
| | | //获取本地的毫米波 |
| | | removeInverter(removeSidList.get(i)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | if (list == null) { |
| | | return; |
| | | } |
| | | if (list.size() <= 0) { |
| | | return; |
| | | } |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | GatewayBean gatewayBean = new GatewayBean(); |
| | | gatewayBean.setOid(cloudInverterDeviceBean.getOid()); |
| | | gatewayBean.setSid(cloudInverterDeviceBean.getSid()); |
| | | gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId()); |
| | | gatewayBean.setOnline(cloudInverterDeviceBean.isOnline()); |
| | | gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName()); |
| | | gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId()); |
| | | gatewayBean.setLocalEncrypt(true); |
| | | gatewayBean.setMaster("true"); |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 删除本地逆变器 |
| | | * |
| | | * @param sid 设备sid |
| | | */ |
| | | private void removeInverter(String sid) { |
| | | //获取本地的毫米波 |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid); |
| | | if (gatewayBean != null) { |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 配置本地通信的信息(tcp通信用到) |