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
package com.tanpu.community.manager;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.req.HomePageReq;
import com.tanpu.community.api.beans.req.homepage.QueryFollowReq;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.enums.QueryFollowTypeEnum;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.service.FollowRelService;
import com.tanpu.community.service.HomePageService;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class HomePageManager {
@Autowired
private FollowRelService followRelService;
@Resource
private HomePageService homePageService;
// public void editUserInfo(HomePageReq req,String userId) {
// HomePageEntity entity = HomePageEntity.builder()
// .userId(userId)
// .nickName(req.getNickName())
// .headImg(req.getHeadImg())
// .introduction(req.getIntroduction())
// .sex(req.getSex())
// .location(req.getLocation())
// .build();
// if(homePageService.selectByUserId(userId) == null){
// homePageService.insert(entity);
// }else {
// homePageService.update(entity);
// }
// return;
// }
//获取用户关注、粉丝列表
public Page<FollowQo> queryFollow(QueryFollowReq req) {
List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType())?
followRelService.queryFansByIdolId(req.getUserId()):followRelService.queryFansByFollowerId(req.getUserId());
List<HomePageEntity> list = homePageService.selectListByUserIds(userIds);
List<FollowQo> collect = list.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList());
List<FollowQo> followQos = judgeFollowed(collect, req.getUserId());
return PageUtils.page(req.getPage(),followQos);
}
//判断返回列表中的用户是否被当前用户关注
public List<FollowQo> judgeFollowed(List<FollowQo> followQos,String followerId){
Set<String> idolSet = new HashSet<>(followRelService.queryFansByFollowerId(followerId));
return followQos.stream().map(o->{
if (idolSet.contains(o.getUserId())){
o.setFollowed(true);
}
return o;
}).collect(Collectors.toList());
}
public void addIdol(String idolId, String followerId) {
followRelService.addFans(idolId, followerId);
}
}