package com.ruoyi.mingxue.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mingxue.dto.AppQuestionCollectionResDto;
import com.ruoyi.mingxue.domain.QuestionCollection;
import com.ruoyi.mingxue.mapper.QuestionCollectionMapper;
import com.ruoyi.mingxue.service.IQuestionCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 题库收藏Service业务层处理
 * 
 * @author mingxue
 * @date 2021-06-24
 */
@Service
public class QuestionCollectionServiceImpl implements IQuestionCollectionService 
{
    @Autowired
    private QuestionCollectionMapper questionCollectionMapper;

    /**
     * 查询题库收藏
     * 
     * @param questionId 题库收藏ID
     * @return 题库收藏
     */
    @Override
    public QuestionCollection selectQuestionCollectionById(Long questionId)
    {
        return questionCollectionMapper.selectQuestionCollectionById(questionId);
    }

    /**
     * 查询题库收藏列表
     * 
     * @param questionCollection 题库收藏
     * @return 题库收藏
     */
    @Override
    public List<QuestionCollection> selectQuestionCollectionList(QuestionCollection questionCollection)
    {
        return questionCollectionMapper.selectQuestionCollectionList(questionCollection);
    }

    /**
     * 新增题库收藏
     * 
     * @param questionCollection 题库收藏
     * @return 结果
     */
    @Override
    public int insertQuestionCollection(QuestionCollection questionCollection)
    {
        questionCollection.setCreateTime(DateUtils.getNowDate());
        return questionCollectionMapper.insertQuestionCollection(questionCollection);
    }

    /**
     * 修改题库收藏
     * 
     * @param questionCollection 题库收藏
     * @return 结果
     */
    @Override
    public int updateQuestionCollection(QuestionCollection questionCollection)
    {
        return questionCollectionMapper.updateQuestionCollection(questionCollection);
    }

    /**
     * 批量删除题库收藏
     * 
     * @param questionIds 需要删除的题库收藏ID
     * @return 结果
     */
    @Override
    public int deleteQuestionCollectionByIds(Long[] questionIds)
    {
        return questionCollectionMapper.deleteQuestionCollectionByIds(questionIds);
    }

    /**
     * 删除题库收藏信息
     * 
     * @param questionId 题库收藏ID
     * @return 结果
     */
    @Override
    public int deleteQuestionCollectionById(Long questionId, Long userId)
    {
        return questionCollectionMapper.deleteQuestionCollectionById(questionId, userId);
    }

    @Override
    public List<AppQuestionCollectionResDto> getQuestionCollectionList(Long userId) {
        return questionCollectionMapper.getQuestionCollectionList(userId);
    }

    @Override
    public List<String> selectSubjects(Long userId) {
        QuestionCollection questionCollection = new QuestionCollection();
        questionCollection.setUserId(userId);
        List<QuestionCollection> list = questionCollectionMapper.selectSubjects(questionCollection);
        return list.stream().map(QuestionCollection::getSubjectName).collect(Collectors.toList());
    }

    @Override
    public List<String> selectQtypes(Long userId, Long subjectId) {
        QuestionCollection questionCollection = new QuestionCollection();
        questionCollection.setUserId(userId);
        questionCollection.setSubjectId(subjectId);
        List<QuestionCollection> list = questionCollectionMapper.selectQtypes(questionCollection);
        return list.stream().map(QuestionCollection::getSubjectName).collect(Collectors.toList());
    }
}
