HomePageManager.java 2.77 KB
Newer Older
张辰's avatar
张辰 committed
1 2
package com.tanpu.community.manager;

刘基明's avatar
刘基明 committed
3
import com.tanpu.community.api.beans.qo.FollowQo;
刘基明's avatar
刘基明 committed
4
import com.tanpu.community.api.beans.req.HomePageReq;
刘基明's avatar
刘基明 committed
5 6 7
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;
刘基明's avatar
刘基明 committed
8
import com.tanpu.community.dao.entity.community.HomePageEntity;
刘基明's avatar
刘基明 committed
9
import com.tanpu.community.service.FollowRelService;
刘基明's avatar
刘基明 committed
10 11
import com.tanpu.community.service.HomePageService;
import com.tanpu.community.util.ConvertUtil;
刘基明's avatar
刘基明 committed
12
import com.tanpu.community.util.PageUtils;
张辰's avatar
张辰 committed
13 14 15 16
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
刘基明's avatar
刘基明 committed
17
import java.util.HashSet;
张辰's avatar
张辰 committed
18
import java.util.List;
刘基明's avatar
刘基明 committed
19
import java.util.Set;
刘基明's avatar
刘基明 committed
20
import java.util.stream.Collectors;
张辰's avatar
张辰 committed
21 22 23 24 25

@Service
public class HomePageManager {

    @Autowired
刘基明's avatar
刘基明 committed
26
    private FollowRelService followRelService;
张辰's avatar
张辰 committed
27

刘基明's avatar
刘基明 committed
28 29
    @Resource
    private HomePageService homePageService;
张辰's avatar
张辰 committed
30

刘基明's avatar
刘基明 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    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;
    }

张辰's avatar
张辰 committed
48

刘基明's avatar
刘基明 committed
49 50 51 52 53 54 55 56
    //获取用户关注、粉丝列表
    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);
张辰's avatar
张辰 committed
57 58
    }

刘基明's avatar
刘基明 committed
59 60
    //判断返回列表中的用户是否被当前用户关注
    public List<FollowQo> judgeFollowed(List<FollowQo> followQos,String followerId){
刘基明's avatar
刘基明 committed
61
        Set<String> idolSet = new HashSet<>(followRelService.queryFansByFollowerId(followerId));
刘基明's avatar
刘基明 committed
62 63 64 65 66 67 68 69 70
        return followQos.stream().map(o->{
            if (idolSet.contains(o.getUserId())){
                o.setFollowed(true);
            }
            return o;
        }).collect(Collectors.toList());

    }

张辰's avatar
张辰 committed
71
    public void addIdol(String idolId, String followerId) {
刘基明's avatar
刘基明 committed
72
        followRelService.addFans(idolId, followerId);
张辰's avatar
张辰 committed
73 74
    }
}