| | |
| | | import com.hdl.photovoltaic.internet.api.HttpApi; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.ui.bean.MessageBean; |
| | | import com.hdl.photovoltaic.ui.bean.MessageNoticeBean; |
| | | import com.hdl.photovoltaic.ui.bean.UnCountBean; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | |
| | | public class HdlMessageLogic { |
| | | private static volatile HdlMessageLogic sHdlMessageLogic; |
| | | |
| | | private final int pageSize = 50;//页数 |
| | | private final int pageSize = 100;//页数 |
| | | private List<MessageBean> mListMessage = new ArrayList<>(); |
| | | |
| | | |
| | |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception ignored) { |
| | | } catch (Exception e) { |
| | | String ss = e.getMessage(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | String mes = e.getMessage(); |
| | | HdlLogLogic.print("--->" + mes); |
| | | HdlLogLogic.print("---" + mes); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | String mes = e.getMessage(); |
| | | HdlLogLogic.print("--->" + mes); |
| | | HdlLogLogic.print("---" + mes); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getMessageUntreatedCount(String homeId, CloudCallBeak<String> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_UntreatedCount; |
| | | public void getMessageUntreatedCount(String homeId, CloudCallBeak<UnCountBean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_Plan_UntreatedCount; |
| | | JsonObject json = new JsonObject(); |
| | | if (!TextUtils.isEmpty(homeId)) { |
| | | json.addProperty("homeId", homeId); |
| | |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String str) { |
| | | if (TextUtils.isEmpty(str)) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(new UnCountBean()); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | UnCountBean unCountBean = new Gson().fromJson(str, UnCountBean.class); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(str); |
| | | cloudCallBeak.onSuccess(unCountBean); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param cloudCallBeak - |
| | | */ |
| | | private void getMessageList(String messageStateType, CloudCallBeak<List<MessageBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_List; |
| | | String requestUrl = HttpApi.POST_Message_Plan_List; |
| | | JsonObject json = new JsonObject(); |
| | | |
| | | if (!MessageStateType.all.equals(messageStateType)) { |
| | |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getPageNoMessageList(int pageNo, String messageStateType, CloudCallBeak<MessageListClass> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_List; |
| | | String requestUrl = HttpApi.POST_Message_Plan_List; |
| | | JsonObject json = new JsonObject(); |
| | | |
| | | if (!MessageStateType.all.equals(messageStateType)) { |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取指定页的获取消息列表(用于C端) |
| | | * 获取指定页的获取消息列表 |
| | | * |
| | | * @param homeId 电站id |
| | | * @param homeId 电站id(填""默认账号下所有消息) |
| | | * @param pageNo 页码 |
| | | * @param messageStateType all:全部,UNTREATED:未处理,PROCESSED:已处理; |
| | | * @param deviceType_filter_key 类型(设备,等级,时间) |
| | | * @param deviceType_filter_value deviceType(INV :逆变器;BMS :BMS控制盒;BATTERY :电池单元); |
| | | * type(FAULT :故障; WARN :告警; EVENT :事件(提示)); |
| | | * timeType(TODAY :今天;LAST_3_DAYS: 近3天;LAST_7_DAYS :近7天;LAST_30_DAYS :近30天); |
| | | * @param search_title 报警名称 |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getPageNoMessageList_C(String homeId, int pageNo, String messageStateType, String deviceType_filter_key, String deviceType_filter_value, String type_filter_key, String type_filter_value, String timeType_filter_key, String timeType_filter_value, CloudCallBeak<MessageListClass> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_List; |
| | | public void getPageNoMessageList( |
| | | String homeId, |
| | | int pageNo, |
| | | String messageStateType, |
| | | String deviceType_filter_key, |
| | | String deviceType_filter_value, |
| | | String type_filter_key, |
| | | String type_filter_value, |
| | | String timeType_filter_key, |
| | | String timeType_filter_value, |
| | | String search_title, CloudCallBeak<MessageListClass> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_Plan_List; |
| | | JsonObject json = new JsonObject(); |
| | | if (!TextUtils.isEmpty(homeId)) { |
| | | json.addProperty("homeId", homeId); |
| | |
| | | } |
| | | if (!TextUtils.isEmpty(timeType_filter_key) && !TextUtils.isEmpty(timeType_filter_value)) { |
| | | json.addProperty(timeType_filter_key, timeType_filter_value); |
| | | } |
| | | if (!TextUtils.isEmpty(search_title)) { |
| | | json.addProperty("title", search_title); |
| | | } |
| | | json.addProperty("pageNo", pageNo);//页码 |
| | | json.addProperty("pageSize", pageSize);//页数 |
| | |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getMessageInfo(String msgId, CloudCallBeak<MessageBean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_Info; |
| | | String requestUrl = HttpApi.POST_Message_Plan_Info; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("msgId", msgId); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | |
| | | /** |
| | | * 消息全部已读 |
| | | * |
| | | * @param homeId 消息id |
| | | * @param homeId 消息id(不传已读所有电站的,传值已读指定电站的) |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void messageAllRead(String homeId, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_AllRead; |
| | | String requestUrl = HttpApi.POST_Message_Plan_AllRead; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | if (!TextUtils.isEmpty(homeId)) { |
| | | json.addProperty("homeId", homeId); |
| | | } |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String str) { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取消息住宅列表 |
| | | * |
| | | * @param homeName 电站名称(搜索用的),如果是空字符串默认读取全部 |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getMessageHouseList(String homeName, CloudCallBeak<List<MessageBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Message_Plan_homeListByPage; |
| | | JsonObject json = new JsonObject(); |
| | | |
| | | if (!TextUtils.isEmpty(homeName)) { |
| | | json.addProperty("homeName", homeName); |
| | | } |
| | | json.addProperty("pageNo", 1);//页码 |
| | | json.addProperty("pageSize", 500);//页数 |
| | | |
| | | final List<MessageBean> list = new ArrayList<>(); |
| | | 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 ArrayList<>()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | MessageListClass oldMessageListClass = gson.fromJson(jsonStr, MessageListClass.class); |
| | | list.addAll(oldMessageListClass.getList()); |
| | | //总共有多少页 |
| | | long totalPage = oldMessageListClass.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); |
| | | MessageListClass newMessageListClass = gson.fromJson(jsonStr, MessageListClass.class); |
| | | list.addAll(newMessageListClass.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(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 消息通知设置详情获取 |
| | | * |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getMessageNoticeInfo(CloudCallBeak<MessageNoticeBean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_notice_setInfo; |
| | | JsonObject JsonObject = new JsonObject(); |
| | | HttpClient.getInstance().requestHttp(requestUrl, JsonObject.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String jsonStr) { |
| | | try { |
| | | Gson gson = new Gson(); |
| | | MessageNoticeBean messageNoticeBean = gson.fromJson(jsonStr, MessageNoticeBean.class); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(messageNoticeBean); |
| | | } |
| | | } catch (Exception e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(new MessageNoticeBean()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 消息通知设置 |
| | | * |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void setMessageNoticeInfo(String type, boolean isTypeBoolean, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_notice_set; |
| | | JsonObject JsonObject = new JsonObject(); |
| | | JsonObject.addProperty(type, isTypeBoolean); |
| | | HttpClient.getInstance().requestHttp(requestUrl, JsonObject.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String jsonStr) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public static class MessageListClass { |
| | | |
| | | //总条数 |