wjc
2023-06-12 715b7407a765deb093b1677705b151d268e3dd4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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;
        }
    }
 
}