FansRelService.java 1.41 KB
package com.tanpu.community.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.FansRelEntity;
import com.tanpu.community.dao.mapper.community.FansRelMapper;
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 FansRelService {

    @Resource
    private FansRelMapper fansRelMapper;

    public List<String> queryFansByFollowerId(String followerId) {
        return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>()
                .eq(FansRelEntity::getFollowerId, followerId))
                .stream().map(FansRelEntity::getIdolId).collect(Collectors.toList());
    }

//    @Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator")
    public List<String> queryFansByIdolId(String idolId) {
        return fansRelMapper.selectList(new LambdaQueryWrapper<FansRelEntity>()
                .eq(FansRelEntity::getIdolId, idolId))
                .stream().map(FansRelEntity::getFollowerId).collect(Collectors.toList());
    }

    public void addFans(String idolId, String followerId) {
        FansRelEntity rel = new FansRelEntity();
        rel.setIdolId(idolId);
        rel.setFollowerId(followerId);

        fansRelMapper.insert(rel);
    }
}