| 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.exception.ValidationException; | 
| import com.mzl.flower.config.security.SecurityUtils; | 
| import com.mzl.flower.dto.request.customer.CreateCollectDTO; | 
| import com.mzl.flower.dto.request.flower.FlowerShowQueryDTO; | 
| import com.mzl.flower.dto.response.flower.FlowerShowListDTO; | 
| import com.mzl.flower.dto.response.flower.FlowerSupplierListDTO; | 
| import com.mzl.flower.entity.customer.Collect; | 
| import com.mzl.flower.mapper.customer.CollectMapper; | 
| import com.mzl.flower.mapper.flower.FlowerMapper; | 
| import org.apache.ibatis.annotations.Param; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.List; | 
|   | 
| @Service | 
| @Transactional | 
| public class CollectService { | 
|   | 
|     private final CollectMapper collectMapper; | 
|   | 
|     private final FlowerMapper flowerMapper; | 
|   | 
|     public CollectService(CollectMapper collectMapper, FlowerMapper flowerMapper) { | 
|         this.collectMapper = collectMapper; | 
|         this.flowerMapper = flowerMapper; | 
|     } | 
|   | 
|     public void add(CreateCollectDTO dto) { | 
|         String userId = SecurityUtils.getUserId(); | 
|         Collect collect = collectMapper.selectOne(new LambdaQueryWrapper<Collect>() | 
|                 .eq(Collect::getUserId, userId) | 
|                 .eq(Collect::getFlowerId, dto.getFlowerId())); | 
|         if(collect==null){ | 
|             collect = new Collect(); | 
|             collect.setUserId(userId); | 
|             collect.setFlowerId(dto.getFlowerId()); | 
|             collect.create(userId); | 
|             collectMapper.insert(collect); | 
|         } | 
|     } | 
|   | 
|     public void delete(Long flowerId) { | 
|         Collect collect = collectMapper.selectOne(new LambdaQueryWrapper<Collect>() | 
|                 .eq(Collect::getFlowerId, flowerId) | 
|                 .eq(Collect::getUserId, SecurityUtils.getUserId())); | 
|         if(collect!=null && collect.getUserId().equals(SecurityUtils.getUserId())){ | 
|             collectMapper.deleteById(collect.getId()); | 
|         }else { | 
|             throw new ValidationException("取消收藏失败或者权限不足"); | 
|         } | 
|     } | 
| } |