AppointmentDataFetcher.java
2.95 KB
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
package com.wd.layoutdataimpl.model;
import android.util.Log;
import com.wd.capability.network.BaseObserver;
import com.wd.capability.network.fetcher.BaseDataFetcher;
import com.wd.capability.network.response.BaseResponse;
import com.wd.common.api.RequestApi;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.custom.content.ContentTypeConstant;
import com.wd.foundation.bean.response.AppointmentStatusBean;
import com.wd.foundation.wdkit.utils.PDUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.Observable;
import okhttp3.RequestBody;
public class AppointmentDataFetcher extends BaseDataFetcher<RequestApi> {
private final IAppointmentListener mListener;
public interface IAppointmentListener {
default void onAppointmentSuccess() { };
void onGetFailed(String error);
void onGetAppointmentStatusSuccess(List<AppointmentStatusBean> response);
}
/**
* 构造器
*
* @param listener 监听回调
*/
public AppointmentDataFetcher(IAppointmentListener listener) {
this.mListener = listener;
}
/**
* 批量查询预约状态
*/
public String getAppointmentStatus(List<ContentBean> contentBeanList) {
//没登录不用调用
if (!PDUtils.isLogin()) {
return null;
}
boolean haveLiveData = false;
List<Map<String, Object>> listMap = new ArrayList<>();
for (ContentBean bean : contentBeanList) {
if (String.valueOf(ContentTypeConstant.URL_TYPE_TWO).equals(bean.getObjectType())) {
haveLiveData = true;
Map<String, Object> mapT = new HashMap<>();
mapT.put("liveId", bean.getObjectId());
mapT.put("relationId", bean.getRelId());
listMap.add(mapT);
}
}
if(!haveLiveData){
return null;
}
RequestBody requestBody = getBody(listMap);
Observable<BaseResponse<List<AppointmentStatusBean>>> observable = getRetrofit().getAppointmentStatusBatch(requestBody);
request(observable, new BaseObserver<List<AppointmentStatusBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mListener != null) {
mListener.onGetFailed(message);
}
}
@Override
public void onSuccess(List<AppointmentStatusBean> response) {
if (mListener != null) {
mListener.onGetAppointmentStatusSuccess(response);
}
}
@Override
public void _onError(String e) {
if (mListener != null) {
Log.d("接口调用失败", e);
mListener.onGetFailed(e);
}
}
});
return requestBody.toString();
}
}