package com.ruoyi.mingxue.service.impl;

import com.ruoyi.mingxue.domain.CustomerFavorites;
import com.ruoyi.mingxue.mapper.CustomerFavoritesMapper;
import com.ruoyi.mingxue.service.ICustomerFavoritesService;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户收藏Service业务层处理
 * 
 * @author mingxue
 * @date 2021-07-25
 */
@Service
public class CustomerFavoritesServiceImpl implements ICustomerFavoritesService 
{
    @Autowired
    private CustomerFavoritesMapper customerFavoritesMapper;

    /**
     * 查询客户收藏
     * 
     * @param id 客户收藏ID
     * @return 客户收藏
     */
    @Override
    public CustomerFavorites selectCustomerFavoritesById(Long id)
    {
        return customerFavoritesMapper.selectCustomerFavoritesById(id);
    }

    /**
     * 查询客户收藏列表
     * 
     * @param customerFavorites 客户收藏
     * @return 客户收藏
     */
    @Override
    public List<CustomerFavorites> selectCustomerFavoritesList(CustomerFavorites customerFavorites)
    {
        return customerFavoritesMapper.selectCustomerFavoritesList(customerFavorites);
    }

    /**
     * 新增客户收藏
     * 
     * @param customerFavorites 客户收藏
     * @return 结果
     */
    @Override
    public int insertCustomerFavorites(CustomerFavorites customerFavorites)
    {
        return customerFavoritesMapper.insertCustomerFavorites(customerFavorites);
    }

    /**
     * 修改客户收藏
     * 
     * @param customerFavorites 客户收藏
     * @return 结果
     */
    @Override
    public int updateCustomerFavorites(CustomerFavorites customerFavorites)
    {
        return customerFavoritesMapper.updateCustomerFavorites(customerFavorites);
    }

    /**
     * 批量删除客户收藏
     * 
     * @param ids 需要删除的客户收藏ID
     * @return 结果
     */
    @Override
    public int deleteCustomerFavoritesByIds(Long[] ids)
    {
        return customerFavoritesMapper.deleteCustomerFavoritesByIds(ids);
    }

    /**
     * 删除客户收藏信息
     * 
     * @param id 客户收藏ID
     * @return 结果
     */
    @Override
    public int deleteCustomerFavoritesById(Long id)
    {
        return customerFavoritesMapper.deleteCustomerFavoritesById(id);
    }

    @Override
    public List<String> selectSubjects(String customerCode, String type) {
        CustomerFavorites query = new CustomerFavorites();
        query.setCustomercode(customerCode);
        query.setType(type);
        List<CustomerFavorites> customerFavorites = customerFavoritesMapper.selectSubjects(query);
        List<String> list = Lists.newArrayList();
        customerFavorites.forEach(e -> {
            list.add(e.getCourse());
        });
        return list;
    }
}
