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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
package com.tanpu.community.service;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.enums.fund.ProductTypeEnum;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.AttachmentDetailVo;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.vo.feign.course.CourseSimpleResp;
import com.tanpu.community.api.beans.vo.feign.course.ShortVideoBaseInfoResp;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.beans.vo.feign.product.FundInfoBaseResp;
import com.tanpu.community.api.beans.vo.feign.product.ProductInfoVO;
import com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboListResp;
import com.tanpu.community.api.enums.RelTypeEnum;
import com.tanpu.community.api.enums.UserLevelEnum;
import com.tanpu.community.dao.entity.community.FileRecordEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.feign.course.FeignClientForCourse;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.feign.product.FeignClientForProducts;
import com.tanpu.community.feign.product.FeignForFund;
import com.tanpu.community.feign.product.FeignForPublicFund;
import com.tanpu.community.feign.tanpuroom.FeignClientForTanpuroom;
import com.tanpu.community.feign.zhibo.FeignClientForZhibo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* 批量调用Feign查询接口
*/
@Service
public class BatchFeignCallService {
@Resource
private FeignClientForTanpuroom feignClientForTanpuroom;
@Resource
private FeignClientForZhibo feignClientForZhibo;
@Resource
private FeignClientForProducts feignForProduct;
@Resource
private FeignClientForCourse feignForCourse;
@Resource
private FeignForFund feignForFund;
@Resource
private FeignForPublicFund feignForPublicFund;
@Resource
private FeignClientForFatools feignClientForFatools;
@Resource
private OSSFileService ossFileService;
@Autowired
private FeignService feignService;
@Resource
private TopicService topicService;
public void getAttachDetail(ThemeQo themeQo) {
ArrayList<ThemeQo> themeQos = new ArrayList<>();
themeQos.add(themeQo);
getAttachDetailByBatch(themeQos);
}
public void getAttachDetailByBatch(List<ThemeQo> themeQos) {
// 短视频信息
Map<String, ShortVideoBaseInfoResp> shortVideoMap = Maps.newHashMap();
// 课程信息
Map<String, ShortVideoBaseInfoResp> curriculumMap = Maps.newHashMap();
// 新课程信息
Map<String, CourseSimpleResp> courseMap = Maps.newHashMap();
// 直播信息
Map<String, ZhiboListResp> zhiboMap = Maps.newHashMap();
// 设置产品信息
Map<String, FundInfoBaseResp> fundMap = Maps.newHashMap();
// 图片信息
Map<String, FileRecordEntity> imgMap = Maps.newHashMap();
// 话题标题
Map<String, String> topicMap = Maps.newHashMap();
// 图片信息
Map<String, UserInfoResp> userMap = Maps.newHashMap();
// 批量查询资源信息
this.getResInfo(shortVideoMap, curriculumMap, courseMap, zhiboMap, fundMap, imgMap, topicMap, userMap, themeQos);
//逐个装入
setResInfo(themeQos, shortVideoMap, curriculumMap, courseMap, zhiboMap, fundMap, imgMap, userMap, topicMap);
}
/**
* 获取资源信息
*
* @param shortVideoMap
* @param curriculumMap
* @param zhiboMap
* @param fundMap
*/
private void getResInfo(Map<String, ShortVideoBaseInfoResp> shortVideoMap,
Map<String, ShortVideoBaseInfoResp> curriculumMap,
Map<String, CourseSimpleResp> courseMap,
Map<String, ZhiboListResp> zhiboMap,
Map<String, FundInfoBaseResp> fundMap,
Map<String, FileRecordEntity> imgMap,
Map<String, String> topicMap,
Map<String, UserInfoResp> userMap,
List<ThemeQo> themeQos
) {
// 白名单基金id
HashSet<String> tanpuFundIds = Sets.newHashSet();
// 私募基金id
HashSet<String> fundIds = Sets.newHashSet();
// 理财师导入
HashSet<String> ifaFundIds = Sets.newHashSet();
// 公募基金id
HashSet<String> publicFundIds = Sets.newHashSet();
// 无净值产品id
HashSet<String> notNetFundIds = Sets.newHashSet();
// 短视频id
HashSet<String> shortVideoIds = Sets.newHashSet();
// 直播id
HashSet<String> zhiboIds = Sets.newHashSet();
// 课程id
HashSet<String> curriculumIds = Sets.newHashSet();
// 新课程id
HashSet<String> courseIds = Sets.newHashSet();
// 图片id
HashSet<String> imageIds = Sets.newHashSet();
// 话题id
HashSet<String> topicIds = Sets.newHashSet();
// 用户id
HashSet<String> userIds = Sets.newHashSet();
// 获取关联资源id
if (themeQos != null) {
themeQos.forEach(o -> {
userIds.add(o.getAuthorId());
if (o.getTopicId() != null) {
topicIds.add(o.getTopicId());
}
});
themeQos.forEach(o -> o.getContent().forEach(c -> {
if (c.getType().equals(RelTypeEnum.LIVE.type)) {
zhiboIds.add(c.getValue());
} else if (c.getType().equals(RelTypeEnum.SHORT_VIDEO.type)) {
shortVideoIds.add(c.getValue());
} else if (c.getType().equals(RelTypeEnum.FUND.type)) {
if (c.getProductType() == ProductTypeEnum.PUBLIC.type) {
publicFundIds.add(c.getValue());
} else if (c.getProductType() == ProductTypeEnum.PRIVATE.type) {
fundIds.add(c.getValue());
} else if (c.getProductType() == ProductTypeEnum.TAMP.type) {
tanpuFundIds.add(c.getValue());
} else if (c.getProductType() == ProductTypeEnum.CUSTOMER_IMPORT.type) {
ifaFundIds.add(c.getValue());
} else if (c.getProductType() == ProductTypeEnum.NOT_NET_PRODUCT.type) {
notNetFundIds.add(c.getValue());
}
} else if (c.getType().equals(RelTypeEnum.VIDEO.type) || c.getType().equals(RelTypeEnum.AUDIO.type)) {
curriculumIds.add(c.getValue());
} else if (c.getType().equals(RelTypeEnum.SINGLE_IMG.type)) {
imageIds.add(c.getValue());
} else if (c.getType().equals(RelTypeEnum.NEW_COURSE_SECTION_AUDIO.type) ||
c.getType().equals(RelTypeEnum.NEW_COURSE_SECTION_VIDEO.type)) {
courseIds.add(c.getValue());
}
})
);
}
if (!CollectionUtils.isEmpty(shortVideoIds)) {
// 短视频列表
List<ShortVideoBaseInfoResp> list = feignService.batchGetShortVideoBaseInfo(setToList(shortVideoIds));
shortVideoMap.putAll(list.stream().collect(Collectors.toMap(ShortVideoBaseInfoResp::getSourceId, item -> item,(oldValue,newValue)->oldValue)));
}
if (!CollectionUtils.isEmpty(curriculumIds)) {
// 课程列表
List<ShortVideoBaseInfoResp> commonResp =
feignClientForFatools.getCurriculumByColumnRelId(setToList(curriculumIds));
if (commonResp != null && !CollectionUtils.isEmpty(commonResp)) {
curriculumMap.putAll(commonResp.stream()
.collect(Collectors.toMap(ShortVideoBaseInfoResp::getColumnRelId, item -> item,(oldValue,newValue)->oldValue)));
}
}
if (!CollectionUtils.isEmpty(courseIds)) {
// 新版课程列表
CommonResp<List<CourseSimpleResp>> commonResp =
feignForCourse.getCourseSimpleList(setToList(courseIds));
if (commonResp.isSuccess() & !CollectionUtils.isEmpty(commonResp.getData())) {
courseMap.putAll(commonResp.getData().stream().collect(Collectors.toMap(CourseSimpleResp::getCourseId, item -> item,(oldValue,newValue)->oldValue)));
}
}
if (!CollectionUtils.isEmpty(zhiboIds)) {
// 直播列表
CommonResp<List<ZhiboListResp>> commonResp =
feignClientForZhibo.simpleList(setToList(zhiboIds));
if (commonResp.isSuccess() && !CollectionUtils.isEmpty(commonResp.getData())) {
zhiboMap.putAll(commonResp.getData().stream().collect(Collectors.toMap(ZhiboListResp::getId, item -> item,(oldValue,newValue)->oldValue)));
}
}
if (!CollectionUtils.isEmpty(imageIds)) {
// 查询图片
List<FileRecordEntity> fileRecordEntities =
ossFileService.queryByIds(setToList(imageIds));
if (!CollectionUtils.isEmpty(fileRecordEntities)) {
imgMap.putAll(fileRecordEntities.stream().collect(Collectors
.toMap(FileRecordEntity::getFileId, o -> o)));
}
}
if (!CollectionUtils.isEmpty(topicIds)) {
// 查询话题标题
List<TopicEntity> topicEntities =
topicService.queryByIds(setToList(topicIds));
if (!CollectionUtils.isEmpty(topicEntities)) {
topicMap.putAll(topicEntities.stream().collect(Collectors
.toMap(TopicEntity::getTopicId, TopicEntity::getTopicTitle)));
}
}
if (!CollectionUtils.isEmpty(userIds)) {
// 查询用户信息
List<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUserListNew(setToList(userIds));
if (!CollectionUtils.isEmpty(userIds)) {
userMap.putAll(queryUsersListNew.stream().collect(Collectors
.toMap(UserInfoResp::getUserId, o -> o)));
}
}
this.getFundInfo(tanpuFundIds, fundIds, publicFundIds, ifaFundIds, notNetFundIds, fundMap);
}
/**
* 设置产品信息
*
* @param tanpuFundIds
* @param fundIds
* @param publicFundIds
* @param fundMap
*/
private void getFundInfo(Set<String> tanpuFundIds,
Set<String> fundIds,
Set<String> publicFundIds,
Set<String> ifaFundIds,
Set<String> notNetFundIds,
Map<String, FundInfoBaseResp> fundMap) {
Map<String, FundInfoBaseResp> tampFundMap = null;
Map<String, FundInfoBaseResp> privateFundMap = null;
Map<String, FundInfoBaseResp> publicFundMap = null;
Map<String, FundInfoBaseResp> ifaFundMap = null;
Map<String, FundInfoBaseResp> notNetFundMap = null;
if (!CollectionUtils.isEmpty(tanpuFundIds)) {
// ProductListReq productListReq = ProductListReq.builder()
// .fundIds(Lists.newArrayList(tanpuFundIds))
// .build();
// 探普产品
CommonResp<List<ProductInfoVO>> commonResp =
feignForProduct.getProductInfoByIds(setToList(tanpuFundIds));
if (commonResp.isSuccess() && !CollectionUtils.isEmpty(commonResp.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = commonResp.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
BeanUtils.copyProperties(item, fundInfoBaseResp);
return fundInfoBaseResp;
}).collect(Collectors.toList());
tampFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
}
if (tampFundMap != null && tampFundMap.size() > 0) {
fundMap.putAll(tampFundMap);
}
}
// 私募产品
if (!CollectionUtils.isEmpty(fundIds)) {
// 私募产品
CommonResp<List<ProductInfoVO>> fundResult =
feignForFund.getProductList(setToList(fundIds));
if (fundResult.isSuccess() && !CollectionUtils.isEmpty(fundResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = fundResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
BeanUtils.copyProperties(item, fundInfoBaseResp);
return fundInfoBaseResp;
}).collect(Collectors.toList());
privateFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
}
if (privateFundMap != null && privateFundMap.size() > 0) {
fundMap.putAll(privateFundMap);
}
}
// 理财师导入产品
if (!CollectionUtils.isEmpty(ifaFundIds)) {
CommonResp<List<ProductInfoVO>> ifaFundResult =
feignForFund.getPrivateFundList(setToList(ifaFundIds));
if (ifaFundResult.isSuccess() && !CollectionUtils.isEmpty(ifaFundResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = ifaFundResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
BeanUtils.copyProperties(item, fundInfoBaseResp);
return fundInfoBaseResp;
}).collect(Collectors.toList());
ifaFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
}
if (ifaFundMap != null && ifaFundMap.size() > 0) {
fundMap.putAll(ifaFundMap);
}
}
if (!CollectionUtils.isEmpty(publicFundIds)) {
// 公募产品
CommonResp<List<ProductInfoVO>> publicFundResult =
feignForPublicFund.getProductList(setToList(publicFundIds));
if (publicFundResult.isSuccess() && !CollectionUtils.isEmpty(publicFundResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = publicFundResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
BeanUtils.copyProperties(item, fundInfoBaseResp);
return fundInfoBaseResp;
}).collect(Collectors.toList());
publicFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
}
if (publicFundMap != null && publicFundMap.size() > 0) {
fundMap.putAll(publicFundMap);
}
}
if (!CollectionUtils.isEmpty(notNetFundIds)) {
// 无净值产品
CommonResp<List<ProductInfoVO>> notNetInfoResult =
feignForFund.getProductListNotNetInfo(setToList(notNetFundIds));
if (notNetInfoResult.isSuccess() && !CollectionUtils.isEmpty(notNetInfoResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = notNetInfoResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
BeanUtils.copyProperties(item, fundInfoBaseResp);
return fundInfoBaseResp;
}).collect(Collectors.toList());
notNetFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
}
if (notNetFundMap != null && notNetFundMap.size() > 0) {
fundMap.putAll(notNetFundMap);
}
}
}
/**
* 设置资源信息
*/
private void setResInfo(List<ThemeQo> themeQos,
Map<String, ShortVideoBaseInfoResp> shortVideoMap,
Map<String, ShortVideoBaseInfoResp> curriculumMap,
Map<String, CourseSimpleResp> courseMap,
Map<String, ZhiboListResp> zhiboMap,
Map<String, FundInfoBaseResp> fundMap,
Map<String, FileRecordEntity> imgUrlMap,
Map<String, UserInfoResp> userMap,
Map<String, String> topicMap) {
for (ThemeQo themeQo : themeQos) {
if (!StringUtils.isEmpty(themeQo.getTopicId()) && topicMap.containsKey(themeQo.getTopicId())) {
//话题标题
themeQo.setTopicTitle(topicMap.get(themeQo.getTopicId()));
}
if (!StringUtils.isEmpty(themeQo.getAuthorId()) && userMap.containsKey(themeQo.getAuthorId())) {
//用户信息
UserInfoResp userInfo = userMap.get(themeQo.getAuthorId());
//昵称头像简介
themeQo.setNickName(userInfo.getNickName());
themeQo.setUserImg(userInfo.getHeadImageUrl());
themeQo.setUserIntroduction(userInfo.getIntroduction());
//认证标签相关
themeQo.setUserType(userInfo.getUserType());
themeQo.setLevelGrade(userInfo.getLevelGrade());
themeQo.setUserInvestorType(userInfo.getUserInvestorType());
themeQo.setBelongUserOrgId(userInfo.getBelongUserOrgId());
themeQo.setBelongUserOrgName(userInfo.getBelongUserOrgName());
//工作室相关
themeQo.setWorkshopName(userInfo.getWorkshopName());
themeQo.setWorkshopStatus(userInfo.getWorkshopStatus());
themeQo.setWorkshopIntroduction(userInfo.getWorkshopIntroduction());
//首席投顾
if (UserLevelEnum.USER_CHIEF_FINANCIAL_ADVISER.getCode() == userInfo.getLevelGrade()
&& userInfo.getUserInfoNewChief() != null) {
themeQo.setNickName(userInfo.getUserInfoNewChief().getUserName());
themeQo.setUserImg(userInfo.getUserInfoNewChief().getHeadImageUrl());
themeQo.setUserIntroduction(userInfo.getUserInfoNewChief().getPersonalProfile());
}
}
if (themeQo.getContent() == null) {
continue;
}
for (ThemeContentQo themeContent : themeQo.getContent()) {
if (themeContent.getType().equals(RelTypeEnum.LIVE.type)) {
if (zhiboMap.containsKey(themeContent.getValue())) {
ZhiboListResp zhibo = zhiboMap.get(themeContent.getValue());
themeContent.setDetail(AttachmentDetailVo.builder().zhibo(zhibo).build());
}
} else if (themeContent.getType().equals(RelTypeEnum.SHORT_VIDEO.type)) {
if (shortVideoMap.containsKey(themeContent.getValue())) {
themeContent.setDetail(AttachmentDetailVo.builder()
.shortVideo(shortVideoMap.get(themeContent.getValue())).build());
}
} else if (themeContent.getType().equals(RelTypeEnum.VIDEO.type) ||
themeContent.getType().equals(RelTypeEnum.AUDIO.type)) {
if (curriculumMap.containsKey(themeContent.getValue())) {
themeContent.setDetail(AttachmentDetailVo.builder()
.curriculum(curriculumMap.get(themeContent.getValue())).build());
}
} else if (themeContent.getType().equals(RelTypeEnum.NEW_COURSE_SECTION_VIDEO.type) ||
themeContent.getType().equals(RelTypeEnum.NEW_COURSE_SECTION_AUDIO.type)) {
if (courseMap.containsKey(themeContent.getValue())) {
themeContent.setDetail(AttachmentDetailVo.builder()
.course(courseMap.get(themeContent.getValue())).build());
}
} else if (themeContent.getType().equals(RelTypeEnum.FUND.type)) {
if (fundMap.containsKey(themeContent.getValue())) {
FundInfoBaseResp product = fundMap.get(themeContent.getValue());
// 推荐语
product.setRemark(themeContent.getRemark());
// 产品类型
product.setProductType(themeContent.getProductType());
themeContent.setDetail(AttachmentDetailVo.builder()
.product(product).build());
}
} else if (themeContent.getType().equals(RelTypeEnum.SINGLE_IMG.type)) {
//单图封装到imglist列表中
if (imgUrlMap.containsKey(themeContent.getValue())) {
FileRecordEntity imgEntity = imgUrlMap.get(themeContent.getValue());
String extInfo = imgEntity.getExtInfo();
if (!StringUtils.isEmpty(extInfo)) {
Map<String, Object> extMap = JsonUtil.toMap(extInfo);
ImagesDTO imagesDTO = ImagesDTO.builder().imgHeight((Integer) extMap.get("height"))
.imgWidth((Integer) extMap.get("width"))
.remark(imgEntity.getUrl())
.relId(imgEntity.getFileId())
.build();
themeContent.setImgList(Collections.singletonList(imagesDTO));
}
}
} else if (themeContent.getType().equals(RelTypeEnum.MULTIPLE_IMAGE.type)) {
//多图写入图片宽高
List<ImagesDTO> imgList = themeContent.getImgList();
for (ImagesDTO imagesDTO : imgList) {
if (imgUrlMap.containsKey(imagesDTO.getRelId())) {
FileRecordEntity imgEntity = imgUrlMap.get(themeContent.getValue());
String extInfo = imgEntity.getExtInfo();
if (!StringUtils.isEmpty(extInfo)) {
Map<String, Object> extMap = JsonUtil.toMap(extInfo);
imagesDTO.setImgHeight((Integer) extMap.get("height"));
imagesDTO.setImgWidth((Integer) extMap.get("width"));
}
}
}
}
}
// String formerThemeId = themeQo.getFormerThemeId();
// if (!StringUtils.isEmpty(formerThemeId)) {
// FormerThemeQo formerTheme = themeQo.getFormerTheme();
//
// //单个查询详情
//// productService.getAttachDetail(formerTheme);
//
// FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(formerTheme);
// themeQo.setFormerTheme(f);
// }
}
}
private List<String> setToList(Set<String> set) {
List<String> l = new ArrayList<>();
l.addAll(set);
return l;
}
//组装被转发主题
private void buildFormerTheme(ThemeQo themeQo) {
}
}