FollowRelService.java 1.53 KB
Newer Older
刘基明's avatar
刘基明 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
package com.tanpu.community.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@EnableCaching
@Service
public class FollowRelService {

    @Resource
    private FollowRelMapper followRelMapper;

    public List<String> queryFansByFollowerId(String followerId) {
        return followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
                .eq(FollowRelEntity::getFollowerId, followerId))
刘基明's avatar
刘基明 committed
23
                .stream().map(FollowRelEntity::getFollowUserId).collect(Collectors.toList());
刘基明's avatar
刘基明 committed
24 25 26 27
    }

//    @Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator")
    public List<String> queryFansByIdolId(String idolId) {
刘基明's avatar
刘基明 committed
28
        LambdaQueryWrapper<FollowRelEntity> queryWrapper = new LambdaQueryWrapper<FollowRelEntity>()
刘基明's avatar
刘基明 committed
29
                .eq(FollowRelEntity::getFollowUserId, idolId);
刘基明's avatar
刘基明 committed
30
        return followRelMapper.selectList(queryWrapper)
刘基明's avatar
刘基明 committed
31 32 33 34 35
                .stream().map(FollowRelEntity::getFollowerId).collect(Collectors.toList());
    }

    public void addFans(String idolId, String followerId) {
        FollowRelEntity rel = new FollowRelEntity();
刘基明's avatar
刘基明 committed
36
        rel.setFollowUserId(idolId);
刘基明's avatar
刘基明 committed
37 38 39 40 41
        rel.setFollowerId(followerId);

        followRelMapper.insert(rel);
    }
}