package com.miaxis.question.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.common.exception.CustomException;
import com.miaxis.question.dto.*;
import com.miaxis.question.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.miaxis.question.mapper.QuestionInfoMapper;
import com.miaxis.question.domain.QuestionInfo;
import com.miaxis.question.service.IQuestionInfoService;

/**
 * 题库Service业务层处理
 *
 * @author miaxis
 * @date 2021-10-12
 */
@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();
        if(sort!=null) {
            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<QuestionInfo> selectQuestionInfoListByYdtIds(Long[] ids) {
        return questionInfoMapper.selectQuestionInfoListByYdtIds(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;



    }

    @Override
    public List<QuestionInfo> selectTestQuestionInfo(QuestionInfoTestDTO questionInfoTestDTO) {


        if("1".equals(questionInfoTestDTO.getLiceMoto())) {
            if(questionInfoTestDTO.getSubject()==1){
                questionInfoTestDTO.setQuestionType(1);
                questionInfoTestDTO.setNum(20);
                List<QuestionInfo> list1 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                questionInfoTestDTO.setQuestionType(2);
                questionInfoTestDTO.setNum(30);
                List<QuestionInfo> list2 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                list1.addAll(list2);
                return list1;
            } else if (questionInfoTestDTO.getSubject()==4) {
                questionInfoTestDTO.setQuestionType(1);
                questionInfoTestDTO.setNum(20);
                List<QuestionInfo> list1 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                questionInfoTestDTO.setQuestionType(2);
                questionInfoTestDTO.setNum(20);
                List<QuestionInfo> list2 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                questionInfoTestDTO.setQuestionType(3);
                questionInfoTestDTO.setNum(10);
                List<QuestionInfo> list3 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                list1.addAll(list2);
                list1.addAll(list3);
                return list1;
            }
        } else {
            if(questionInfoTestDTO.getSubject()==1){
                //旧判断20题
                questionInfoTestDTO.setQuestionType(1);
                questionInfoTestDTO.setNum(20);
                questionInfoTestDTO.setExcellIssueName("必");
                List<QuestionInfo> list1 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                //新判断20题
                questionInfoTestDTO.setQuestionType(1);
                questionInfoTestDTO.setNum(20);
                questionInfoTestDTO.setExcellIssueName("新");
                List<QuestionInfo> list2 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                //旧选择50题
                questionInfoTestDTO.setQuestionType(2);
                questionInfoTestDTO.setNum(50);
                questionInfoTestDTO.setExcellIssueName("必");
                List<QuestionInfo> list3 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                //新选择10题
                questionInfoTestDTO.setQuestionType(2);
                questionInfoTestDTO.setNum(10);
                questionInfoTestDTO.setExcellIssueName("新");
                List<QuestionInfo> list4 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);

                list1.addAll(list2);
                list1.addAll(list3);
                list1.addAll(list4);
                return list1;
            } else if (questionInfoTestDTO.getSubject()==4) {
                questionInfoTestDTO.setQuestionType(1);
                questionInfoTestDTO.setNum(20);
                questionInfoTestDTO.setExcellIssueName("必");
                List<QuestionInfo> list1 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);

                questionInfoTestDTO.setQuestionType(1);
                questionInfoTestDTO.setNum(10);
                questionInfoTestDTO.setExcellIssueName("新");
                List<QuestionInfo> list2 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);

                questionInfoTestDTO.setQuestionType(2);
                questionInfoTestDTO.setNum(10);
                questionInfoTestDTO.setExcellIssueName("必");
                List<QuestionInfo> list3 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);

                questionInfoTestDTO.setQuestionType(3);
                questionInfoTestDTO.setNum(10);
                questionInfoTestDTO.setExcellIssueName("必");
                List<QuestionInfo> list4 = questionInfoMapper.selectTestQuestionInfoList(questionInfoTestDTO);
                list1.addAll(list2);
                list1.addAll(list3);
                list1.addAll(list4);
                return list1;
            }
        }
        return null;
    }


    @Override
    public List<QuestionInfo> selectFreeQuestionInfo() {
        QuestionInfoFreeDTO freeDTO =  new QuestionInfoFreeDTO();
        freeDTO.setNum(10);
        freeDTO.setQuestionType(1);
        freeDTO.setSubject(1);
        List<QuestionInfo> list1 = questionInfoMapper.selectFreeQuestionInfoList(freeDTO);
        freeDTO.setQuestionType(2);
        List<QuestionInfo> list2 = questionInfoMapper.selectFreeQuestionInfoList(freeDTO);
        freeDTO.setSubject(4);
        freeDTO.setQuestionType(3);
        List<QuestionInfo> list3 = questionInfoMapper.selectFreeQuestionInfoList(freeDTO);
        list1.addAll(list2);
        list1.addAll(list3);
        return list1;
    }
}
