InteractionStatusDataFetcher.java
11.5 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
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
321
322
323
324
325
326
327
package com.wd.common.fetcher;
import android.text.TextUtils;
import com.wd.capability.layout.ui.follow.listener.BatchCallback;
import com.wd.common.listener.InteractionDataListener;
import com.wd.foundation.wdkit.utils.PDUtils;
import com.wd.capability.network.BaseObserver;
import com.wd.capability.network.constant.ParameterConstant;
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.comment.DisplayWorkInfoBean;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.custom.content.ContentTypeConstant;
import com.wd.foundation.bean.live.RoomDataBean;
import com.wd.foundation.bean.mail.LiveInfo;
import com.wd.foundation.wdkit.constant.Constants;
import com.wd.foundation.wdkit.utils.CommonUtil;
import com.wd.foundation.wdkitcore.tools.ArrayUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.Observable;
/**
* 描述:评论相关的数据基础接口,通用性很高,接口隔离原则
*
* @author : lvjinhui
* @since: 2023/5/30
*/
public class InteractionStatusDataFetcher extends BaseDataFetcher<RequestApi> {
private InteractionDataListener mListener;
public InteractionStatusDataFetcher(InteractionDataListener mListener) {
this.mListener = mListener;
}
public InteractionStatusDataFetcher() {
}
/**
* 批量查询点赞和收藏状态不
*
* @param mTempList
*/
public void sendBatchLikeAndCollectStatusRequest(List<ContentBean> mTempList) {
//登录才有必要查询
if (!PDUtils.isLogin()) {
if (mListener != null) {
mListener.onBatchDataFail();
}
return;
}
if (ArrayUtils.isEmpty(mTempList)) {
if (mListener != null) {
mListener.onBatchDataFail();
}
return;
}
Map<String, Object> map = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
for (ContentBean bean : mTempList) {
if (null == bean) {
continue;
}
Map<String, Object> mapT = new HashMap<>();
String contentId = bean.getObjectId();
// 内容 id 为空,不塞到数组里查询点赞收藏状态
if (StringUtils.isBlank(contentId)) {
continue;
}
mapT.put(ParameterConstant.CONTENTID, contentId);
String contentType = bean.getObjectType();
// 内容类型为空,不塞到数组里查询点赞收藏状态
if (StringUtils.isBlank(contentType)) {
continue;
}
mapT.put(ParameterConstant.CONTENT_TYPE, contentType);
if (!TextUtils.isEmpty(bean.getContentRelId()) && !"0".equals(bean.getContentRelId())) {
mapT.put(ParameterConstant.CONTENT_RELLD, bean.getContentRelId());
}
if (0 != bean.getRelType()) {
mapT.put(ParameterConstant.CONTENT_REL_TYPE, bean.getRelType());
}
listMap.add(mapT);
}
// 要查询的点赞和收藏的内容集合为空,则不进行查询点赞收藏状态
if (CommonUtil.isEmpty(listMap)) {
if (mListener != null) {
mListener.onBatchDataFail();
}
return;
}
map.put("contentList", listMap);
Observable<BaseResponse<List<DisplayWorkInfoBean>>> codeData = getRetrofit().batchLikeAndCollectStatus(getBody(map));
request(codeData, new BaseObserver<List<DisplayWorkInfoBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mListener != null) {
mListener.onBatchDataFail();
}
}
@Override
public void onSuccess(List<DisplayWorkInfoBean> backList) {
for (ContentBean bean : mTempList) {
String id = bean.getObjectId();
if (TextUtils.isEmpty(id)) {
continue;
}
for (DisplayWorkInfoBean infoBean : backList) {
String tempId = infoBean.getContentId();
if (id.equals(tempId)) {
bean.setLikeStatus(infoBean.getLikeStatus());
bean.setCollectStatus(infoBean.getCollectStatus());
break;
}
}
}
if (mListener != null) {
mListener.onBatchDataSuccess(1);
}
}
@Override
public void _onError(String e) {
if (mListener != null) {
mListener.onBatchDataFail();
}
}
});
}
/**
* 批量查询点赞和收藏状态不
*
* @param list
*/
public void sendBatchLikeAndCollectStatusRequest(List<ContentBean> list, BatchCallback<List<DisplayWorkInfoBean>> batchCallback) {
Map<String, Object> map = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
for (ContentBean bean : list) {
if (bean == null) {
continue;
}
Map<String, Object> mapT = new HashMap<>();
String contentId = bean.getObjectId();
// 内容 id 为空,不塞到数组里查询点赞收藏状态
if (StringUtils.isBlank(contentId)) {
continue;
}
mapT.put(ParameterConstant.CONTENTID, contentId);
String contentType = bean.getObjectType();
// 内容类型为空,不塞到数组里查询点赞收藏状态
if (StringUtils.isBlank(contentType)) {
continue;
}
mapT.put(ParameterConstant.CONTENT_TYPE, contentType);
if (!TextUtils.isEmpty(bean.getContentRelId()) && !"0".equals(bean.getContentRelId())) {
mapT.put(ParameterConstant.CONTENT_RELLD, bean.getContentRelId());
}
if (0 != bean.getRelType()) {
mapT.put(ParameterConstant.CONTENT_REL_TYPE, bean.getRelType());
}
listMap.add(mapT);
}
// 要查询的点赞和收藏的内容集合为空,则不进行查询点赞收藏状态
if (CommonUtil.isEmpty(listMap)) {
return;
}
map.put("contentList", listMap);
if (batchCallback != null) {
batchCallback.parameter(map.toString());
}
Observable<BaseResponse<List<DisplayWorkInfoBean>>> codeData = getRetrofit().batchLikeAndCollectStatus(getBody(map));
request(codeData, new BaseObserver<List<DisplayWorkInfoBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (batchCallback != null) {
batchCallback.error(message);
}
}
@Override
public void onSuccess(List<DisplayWorkInfoBean> backList) {
for (ContentBean bean : list) {
String id = bean.getObjectId();
if (TextUtils.isEmpty(id)) {
continue;
}
for (DisplayWorkInfoBean infoBean : backList) {
String tempId = infoBean.getContentId();
if (id.equals(tempId)) {
bean.setLikeStatus(infoBean.getLikeStatus());
bean.setCollectStatus(infoBean.getCollectStatus());
break;
}
}
}
if (batchCallback != null) {
batchCallback.success(backList);
}
}
@Override
public void _onError(String e) {
if (batchCallback != null) {
batchCallback.error(e);
}
}
});
}
/**
* 批量查C端查询直播信息(观看人次、点赞人数、评论数、订阅数)
*
* @param list
*/
public void sendBatchLiveRoomDataRequest(List<ContentBean> list, BatchCallback<List<RoomDataBean>> batchCallback) {
HashMap<String, Object> queryMap = new HashMap<>();
List<String> listMap = new ArrayList<>();
String liveType = String.valueOf(ContentTypeConstant.URL_TYPE_TWO);
for (ContentBean bean : list) {
if (bean == null) {
continue;
}
// 直播结束和进行中的业务数据参与批查
if (liveType.equals(bean.getObjectType())) {
LiveInfo liveInfo = bean.getLiveInfo();
if (liveInfo != null) {
String liveState = liveInfo.getLiveState();
if (Constants.LIVE_RUNNING.equals(liveState) || Constants.LIVE_END.equals(liveState)) {
if (!listMap.contains(bean.getObjectId())) {
listMap.add(bean.getObjectId());
}
}
}
}
}
if (CommonUtil.isEmpty(listMap)) {
if (batchCallback != null) {
batchCallback.success(new ArrayList<>());
}
return;
}
StringBuffer sb = new StringBuffer();
int size = listMap.size();
for (int a = 0; a < size; a++) {
sb.append(listMap.get(a));
if (a == size - 1) {
} else {
sb.append(",");
}
}
queryMap.put("liveIdList", sb.toString());
if (batchCallback != null) {
batchCallback.parameter(queryMap.toString());
}
Observable<BaseResponse<List<RoomDataBean>>> codeData = getRetrofit().getRoomBatchData(queryMap);
request(codeData, new BaseObserver<List<RoomDataBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (batchCallback != null) {
batchCallback.error(message);
}
}
@Override
public void onSuccess(List<RoomDataBean> backList) {
if (backList != null) {
// 内容信息匹配直播批量数据
for (ContentBean contentBean : list) {
if (contentBean == null) {
continue;
}
if (liveType.equals(contentBean.getObjectType()) && contentBean.getLiveInfo() != null) {
for (RoomDataBean roomDataBean : backList) {
if (contentBean.getObjectId().equals(roomDataBean.liveId)) {
contentBean.getLiveInfo().infoBean = roomDataBean;
}
}
}
}
}
if (batchCallback != null) {
batchCallback.success(backList);
}
}
@Override
public void _onError(String e) {
if (batchCallback != null) {
batchCallback.error(e);
}
}
});
}
}