package com.hdl.photovoltaic.other;
|
|
import com.google.gson.Gson;
|
import com.google.gson.JsonObject;
|
import com.hdl.photovoltaic.bean.HttpResponsePack;
|
import com.hdl.photovoltaic.config.UserConfigManage;
|
import com.hdl.photovoltaic.internet.HttpClient;
|
import com.hdl.photovoltaic.internet.api.HttpApi;
|
import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak;
|
import com.hdl.photovoltaic.listener.CloudCallBeak;
|
import com.hdl.photovoltaic.ui.bean.HouseInfoBean;
|
import com.hdl.photovoltaic.ui.bean.HouseListBean;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class HdlResidenceLogic {
|
|
private static volatile HdlResidenceLogic sHdlResidenceLogic;
|
|
public static synchronized HdlResidenceLogic getInstance() {
|
if (sHdlResidenceLogic == null) {
|
synchronized (HdlResidenceLogic.class) {
|
if (sHdlResidenceLogic == null) {
|
sHdlResidenceLogic = new HdlResidenceLogic();
|
}
|
}
|
|
}
|
return sHdlResidenceLogic;
|
}
|
|
public List<HouseInfoBean> getHouseInfoList() {
|
return houseInfoList;
|
}
|
|
public void setHouseInfoList(List<HouseInfoBean> houseInfoList) {
|
this.houseInfoList = houseInfoList;
|
}
|
|
public List<HouseListBean> getHouseInfoBeanList() {
|
return houseList;
|
}
|
|
public void setHouseInfoBeanList(List<HouseListBean> houseListBeanList) {
|
this.houseList = houseListBeanList;
|
}
|
|
//住宅列表
|
private List<HouseListBean> houseList = new ArrayList<>();
|
//住宅详情列表
|
private List<HouseInfoBean> houseInfoList = new ArrayList<>();
|
|
public HouseListBean getHouseByHouseId(String homeId) {
|
return new HouseListBean();
|
}
|
|
|
/**
|
* 获取住宅(电站)列表
|
*
|
* @param pageNo 当前页数
|
* @param pageSize 一页大小
|
*/
|
public void getResidenceList(int pageNo, int pageSize, CloudCallBeak<Boolean> cloudCallBeak) {
|
if (pageNo == 1) {
|
//第一次进来清空列表
|
houseList.clear();
|
}
|
String requestUrl = HttpApi.POST_PowerStation_List;
|
JsonObject json = new JsonObject();
|
// json.addProperty("powerSort", "descending");//发电功率排序(descending:降序ascending:升序)
|
// json.addProperty("todayElectricitySort", "descending");//今日发电量排序
|
// json.addProperty("createTimeSort", "descending");//创建时间排序
|
// json.addProperty("zoneType", "password");//区域
|
json.addProperty("pageNo", pageNo);//页码
|
json.addProperty("pageSize", pageSize);//页数
|
|
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
|
@Override
|
public void onSuccess(HttpResponsePack httpResponsePack) {
|
if (httpResponsePack != null) {
|
if (httpResponsePack.getData() != null) {
|
Gson gson = new Gson();
|
String jsonStr = gson.toJson(httpResponsePack.getData().toString());
|
HouseInfoBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseInfoBeanClass.class);
|
houseList.addAll(houseInfoBeanClass.getList());
|
//总共有多少页
|
long totalPage = houseInfoBeanClass.totalPage;
|
if (totalPage == houseInfoBeanClass.getPageNo()) {
|
cloudCallBeak.onSuccess(true);
|
return;
|
}
|
getResidenceList(pageNo + 1, 100, cloudCallBeak);
|
} else {
|
cloudCallBeak.onSuccess(false);
|
}
|
|
}
|
}
|
|
|
@Override
|
public void onFailure(Exception exception) {
|
cloudCallBeak.onFailure(exception);
|
}
|
});
|
}
|
|
|
/**
|
* 获取住宅(电站)详情
|
*
|
* @param homeId 住宅id
|
* @param cloudCallBeak 回调
|
*/
|
public void getResidenceInfo(String homeId, CloudCallBeak<HouseInfoBean> cloudCallBeak) {
|
String requestUrl = HttpApi.POST_GET_MEMBER_INFO;
|
JsonObject json = new JsonObject();
|
json.addProperty("homeId", homeId);//电站id
|
//json.addProperty("zoneType", "password");//区域
|
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
|
@Override
|
public void onSuccess(HttpResponsePack httpResponsePack) {
|
if (httpResponsePack != null) {
|
if (httpResponsePack.getData() != null) {
|
Gson gson = new Gson();
|
String jsonStr = gson.toJson(httpResponsePack.getData().toString());
|
HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class);
|
cloudCallBeak.onSuccess(houseInfoBean);
|
} else {
|
cloudCallBeak.onSuccess(null);
|
}
|
|
}
|
}
|
|
@Override
|
public void onFailure(Exception exception) {
|
cloudCallBeak.onFailure(exception);
|
}
|
});
|
|
|
}
|
|
|
/**
|
* 编辑住宅(电站)
|
*
|
* @param houseInfoBean -
|
* @param cloudCallBeak -
|
*/
|
public void editResidence(HouseInfoBean houseInfoBean, CloudCallBeak<Boolean> cloudCallBeak) {
|
String requestUrl = HttpApi.POST_PowerStation_Create;
|
JsonObject json = new JsonObject();
|
JsonObject location = new JsonObject();
|
json.addProperty("homeId", houseInfoBean.getHomeId());
|
location.addProperty("nationCode", houseInfoBean.getLocation().getNationCode());
|
location.addProperty("nationName", houseInfoBean.getLocation().getNationName());
|
location.addProperty("provinceCode", houseInfoBean.getLocation().getProvinceCode());
|
location.addProperty("provinceName", houseInfoBean.getLocation().getProvinceName());
|
location.addProperty("cityCode", houseInfoBean.getLocation().getCityCode());
|
location.addProperty("cityName", houseInfoBean.getLocation().getCityName());
|
json.add("location", location);
|
json.addProperty("address", houseInfoBean.getAddress());
|
json.addProperty("latitude", houseInfoBean.getLatitude());
|
json.addProperty("longitude", houseInfoBean.getLongitude());
|
json.addProperty("homeName", houseInfoBean.getHomeName());
|
json.addProperty("timezone", houseInfoBean.getTimezone());
|
json.addProperty("powerStationType", houseInfoBean.getPowerStationType());
|
json.addProperty("workMode", houseInfoBean.getWorkMode());
|
json.addProperty("installedCapacity", houseInfoBean.getInstalledCapacity());
|
json.addProperty("productionTime", houseInfoBean.getProductionTime());
|
json.addProperty("monetaryUnit", houseInfoBean.getMonetaryUnit());
|
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() {
|
@Override
|
public void onSuccess(HttpResponsePack httpResponsePack) {
|
cloudCallBeak.onSuccess(true);
|
|
}
|
|
@Override
|
public void onFailure(Exception exception) {
|
cloudCallBeak.onFailure(exception);
|
}
|
});
|
}
|
|
/**
|
* 删除住宅(电站)
|
*
|
* @param homeId -
|
* @param cloudCallBeak -
|
*/
|
public void delResidence(String homeId, CloudCallBeak<Boolean> cloudCallBeak) {
|
String requestUrl = HttpApi.POST_PowerStation_Remove;
|
JsonObject json = new JsonObject();
|
json.addProperty("homeId", homeId);//电站id
|
//json.addProperty("zoneType", "password");//区域
|
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
|
@Override
|
public void onSuccess(HttpResponsePack httpResponsePack) {
|
cloudCallBeak.onSuccess(true);
|
|
}
|
|
@Override
|
public void onFailure(Exception exception) {
|
cloudCallBeak.onFailure(exception);
|
}
|
});
|
|
}
|
|
/**
|
* 添加住宅(电站)
|
*
|
* @param houseInfoBean -
|
* @param cloudCallBeak -
|
*/
|
public void addResidence(HouseInfoBean houseInfoBean, CloudCallBeak<Boolean> cloudCallBeak) {
|
String requestUrl = HttpApi.POST_PowerStation_Create;
|
JsonObject json = new JsonObject();
|
JsonObject location = new JsonObject();
|
json.addProperty("powerStationImage", "");
|
location.addProperty("nationCode", houseInfoBean.getLocation().getNationCode());
|
location.addProperty("nationName", houseInfoBean.getLocation().getNationName());
|
location.addProperty("provinceCode", houseInfoBean.getLocation().getProvinceCode());
|
location.addProperty("provinceName", houseInfoBean.getLocation().getProvinceName());
|
location.addProperty("cityCode", houseInfoBean.getLocation().getCityCode());
|
location.addProperty("cityName", houseInfoBean.getLocation().getCityName());
|
json.add("location", location);
|
json.addProperty("address", houseInfoBean.getAddress());
|
json.addProperty("latitude", houseInfoBean.getLatitude());
|
json.addProperty("longitude", houseInfoBean.getLongitude());
|
json.addProperty("homeName", houseInfoBean.getHomeName());
|
json.addProperty("timezone", houseInfoBean.getTimezone());
|
json.addProperty("powerStationType", houseInfoBean.getPowerStationType());
|
json.addProperty("workMode", houseInfoBean.getWorkMode());
|
json.addProperty("installedCapacity", houseInfoBean.getInstalledCapacity());
|
json.addProperty("productionTime", houseInfoBean.getProductionTime());
|
json.addProperty("monetaryUnit", houseInfoBean.getMonetaryUnit());
|
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() {
|
@Override
|
public void onSuccess(HttpResponsePack httpResponsePack) {
|
cloudCallBeak.onSuccess(true);
|
|
}
|
|
@Override
|
public void onFailure(Exception exception) {
|
cloudCallBeak.onFailure(exception);
|
}
|
});
|
|
|
}
|
|
static class HouseInfoBeanClass {
|
|
//总条数
|
private long totalCount;
|
//总页数
|
private long totalPage;
|
//当前页
|
private long pageNo;
|
//页数
|
private long pageSize;
|
//电站列表
|
private List<HouseListBean> list;
|
|
public long getTotalCount() {
|
return totalCount;
|
}
|
|
public void setTotalCount(long totalCount) {
|
this.totalCount = totalCount;
|
}
|
|
public long getTotalPage() {
|
return totalPage;
|
}
|
|
public void setTotalPage(long totalPage) {
|
this.totalPage = totalPage;
|
}
|
|
public long getPageNo() {
|
return pageNo;
|
}
|
|
public void setPageNo(long pageNo) {
|
this.pageNo = pageNo;
|
}
|
|
public long getPageSize() {
|
return pageSize;
|
}
|
|
public void setPageSize(long pageSize) {
|
this.pageSize = pageSize;
|
}
|
|
public List<HouseListBean> getList() {
|
return list == null ? new ArrayList<>() : list;
|
}
|
|
public void setList(List<HouseListBean> list) {
|
this.list = list;
|
}
|
}
|
|
}
|