package com.miaxis.question.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.common.exception.CustomException;
import com.miaxis.common.exception.user.UserException;
import com.miaxis.question.domain.QuestionInfo;
import com.miaxis.question.dto.QuestionInfoDTO;
import com.miaxis.question.dto.QuestionInfoFlDTO;
import com.miaxis.question.dto.QuestionInfoSortDTO;
import com.miaxis.question.dto.QuestionInfoSortUpateDTO;
import com.miaxis.question.mapper.QuestionInfoMapper;
import com.miaxis.question.service.IQuestionInfoService;
import com.miaxis.question.vo.*;
import org.apache.ibatis.executor.ExecutorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 题库Service业务层处理
 *
 * @author miaxis
 * @date 2021-10-20
 */
@Service
public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, QuestionInfo> implements IQuestionInfoService {
    @Autowired
    private QuestionInfoMapper questionInfoMapper;

    /**
     * 查询题库列表
     *
     * @param
     * @return 题库
     */
    @Override
    public List<QuestionInfo> selectQuestionInfoList(QuestionInfoDTO questionInfoDTO){

        //1:分类练习：class_sort;2:精选考题:excell_sort;3:地方专题:place_sort;4:顺序练习:seque_sort;
        Integer sort = questionInfoDTO.getSort();
        switch (sort){
            case 1:
                questionInfoDTO.setSortName("class_sort");
                break;
            case 2:
                questionInfoDTO.setSortName("excell_sort");
                break;
            case 3:
                questionInfoDTO.setSortName("place_sort");
                break;
            case 4:
                questionInfoDTO.setSortName("seque_sort");
                break;
            default:
                throw new CustomException("请正常输入sort字段");
        }
        return questionInfoMapper.selectQuestionInfoList(questionInfoDTO);
    }

    @Override
    public List<QuestionInfo> selectQuestionInfoListByIds(Long[] ids) {
        return questionInfoMapper.selectQuestionInfoListIds(ids);
    }

    @Override
    public List<QuestionInfoJxVO> selectJxQuestionInfo(QuestionInfoFlDTO questionInfoFlDTO) {
        return questionInfoMapper.selectJxQuestionInfo(questionInfoFlDTO);
    }

    @Override
    public List<QuestionInfoDfVO> selectDfQuestionInfo(QuestionInfoFlDTO questionInfoFlDTO) {
        return questionInfoMapper.selectDfQuestionInfo(questionInfoFlDTO);
    }

    @Override
    public List<QuestionInfoFlVO> selectFlQuestionInfo(QuestionInfoFlDTO questionInfoFlDTO) {
        return questionInfoMapper.selectFlQuestionInfo(questionInfoFlDTO);
    }

    @Override
    public List<QuestionInfo> selectNormalQuestionInfoList(QuestionInfoDTO questionInfoDTO) {
        return questionInfoMapper.selectNormalQuestionInfoList(questionInfoDTO);
    }

    @Override
    public List<QuestionInfoSxVO> selectSxQuestionInfo(QuestionInfoFlDTO questionInfoFlDTO) {
        return questionInfoMapper.selectSxQuestionInfo(questionInfoFlDTO);
    }

    @Override
    public List<QuestionInfoExcelVo> selectQuestionInfoSortList(QuestionInfoSortDTO questionInfoSortDTO) {
        return questionInfoMapper.selectQuestionInfoSortList(questionInfoSortDTO);
    }

    @Override
    public void updateSortById(QuestionInfoSortUpateDTO dto) {
        questionInfoMapper.updateSortById(dto);
    }

    @Override
    public List<QuestionInfoExcelTypeVo> getIssueTypes(int issueTypeValue, Integer subject) {
        if (issueTypeValue == 1){
            return questionInfoMapper.selectIssueType1(subject);
        }
        if (issueTypeValue == 2){
            return questionInfoMapper.selectIssueType2(subject);
        }
        if (issueTypeValue == 3){
            return questionInfoMapper.selectIssueType3(subject);
        }
        if (issueTypeValue == 4){
            return questionInfoMapper.selectIssueType4(subject);
        }
        return null;



    }

}
