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)) .stream().map(FollowRelEntity::getFollowUserId).collect(Collectors.toList()); } // @Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator") public List<String> queryFansByIdolId(String idolId) { LambdaQueryWrapper<FollowRelEntity> queryWrapper = new LambdaQueryWrapper<FollowRelEntity>() .eq(FollowRelEntity::getFollowUserId, idolId); return followRelMapper.selectList(queryWrapper) .stream().map(FollowRelEntity::getFollowerId).collect(Collectors.toList()); } public void addFans(String idolId, String followerId) { FollowRelEntity rel = new FollowRelEntity(); rel.setFollowUserId(idolId); rel.setFollowerId(followerId); followRelMapper.insert(rel); } }