| package com.mzl.flower.service.customer; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.mzl.flower.config.security.SecurityUtils; | 
| import com.mzl.flower.dto.request.customer.CreateFollowDTO; | 
| import com.mzl.flower.dto.response.customer.FollowDTO; | 
| import com.mzl.flower.entity.customer.Follow; | 
| import com.mzl.flower.mapper.customer.FollowMapper; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.List; | 
|   | 
| @Service | 
| @Transactional | 
| public class FollowService { | 
|   | 
|     private final FollowMapper followMapper; | 
|   | 
|     public FollowService(FollowMapper followMapper) { | 
|         this.followMapper = followMapper; | 
|     } | 
|   | 
|     public void add(CreateFollowDTO dto) { | 
|         String userId = SecurityUtils.getUserId(); | 
|         Follow follow = followMapper.selectOne(new LambdaQueryWrapper<Follow>() | 
|                 .eq(Follow::getUserId, userId) | 
|                 .eq(Follow::getSupplierId, dto.getSupplierId())); | 
|         if(follow==null){ | 
|             follow = new Follow(); | 
|             follow.setUserId(userId); | 
|             follow.setSupplierId(dto.getSupplierId()); | 
|             follow.create(userId); | 
|             followMapper.insert(follow); | 
|         } | 
|     } | 
|   | 
|     public void delete(Long supplierId) { | 
|         followMapper.delete(new LambdaQueryWrapper<Follow>() | 
|                 .eq(Follow::getSupplierId, supplierId) | 
|                 .eq(Follow::getUserId, SecurityUtils.getUserId())); | 
|     } | 
|   | 
|     public Page<FollowDTO> myFollow(Page page, String userId) { | 
|         List<FollowDTO> list= followMapper.myFollow(page,userId); | 
|         page.setRecords(list); | 
|         return page; | 
|     } | 
|   | 
|     public Boolean followed(String userId, Long supplierId)  { | 
|         int count = followMapper.selectCount(new LambdaQueryWrapper<Follow>() | 
|                 .eq(Follow::getUserId, userId) | 
|                 .eq(Follow::getSupplierId, supplierId)); | 
|         if(count>0){ | 
|             return true; | 
|         } | 
|         return false; | 
|     } | 
|   | 
|     public int fansCount(Long supplierId) { | 
|         int count = followMapper.selectCount(new LambdaQueryWrapper<Follow>() | 
|                 .eq(Follow::getSupplierId, supplierId)); | 
|         return count; | 
|     } | 
|   | 
|   | 
|     public Integer getStatisFansCount(Long supplierId) { | 
|   | 
|         Integer count = followMapper.getStatisFansCount(supplierId); | 
|   | 
|         return count; | 
|     } | 
| } |