package com.ynfy.buss.exam.question.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ynfy.buss.exam.question.dto.QuestionConditionDTO;
import com.ynfy.buss.exam.question.dto.QuestionDTO;
import com.ynfy.buss.exam.question.entity.Question;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description: question
 * @Author: jeecg-boot
 * @Date: 2023-02-22
 * @Version: V1.0
 */
public interface IQuestionService extends IService<Question> {

    void saveQuestion(Question question);

    /**
     * 根据规则生成试题
     *
     * @param repositoryId
     * @param questionType
     * @param num
     * @return
     */
    List<Question> generateQuestionsByRule(String repositoryId, Integer questionType, Integer level,
                                           Integer num, List<Question> ruleQuestions);

    /**
     * 导入题目
     *
     * @param file
     */
    void importExcel(MultipartFile file) throws Exception;


    /**
     * 删除试题及试题选项
     *
     * @param questionId
     */
    void removeQuestionAnswer(String questionId);

    void removeBatch(String ids);

    /**
     * 下载导入模板
     *
     * @throws Exception
     */
    void downloadTemplate(HttpServletResponse response) throws Exception;

    /**
     * 根据条件分页查询
     */
    List<Question> selectQuestionList(List<String> idList, boolean needAnswerFlag, boolean needAnalysis);


    List<QuestionDTO> groupLevelById(List<String> repositoryIds, Integer type, List<String> questionIds);


    List<Question> listByPaperId(String paperId);

    /**
     * 查询题库，对应的题型数量
     *
     * @param repositoryIds
     * @param type
     * @return
     */
    List<Question> groupCount(List<String> repositoryIds, Integer type);


    /**
     * 根据题库，题型，难度的集合获取题目
     *
     * @param dtoList
     * @return
     */
    List<Question> listQuestionByCondition(List<QuestionConditionDTO> dtoList);


    /**
     * 查询用户的考试题目和答案（此时查询的答案可能是乱序的）
     *
     * @param objectiveList  客观题
     * @param subjectiveList 主观题
     * @param needAnswerFlag 是否需要标记答案
     * @param needAnalysis   是否需要解析
     * @param needSubjective 是否需要主观题
     * @return
     */
    List<Question> listUserExamQuestionAnswer(String userExamId, List<String> objectiveList, List<String> subjectiveList,
                                              boolean needAnswerFlag, boolean needAnalysis,
                                              boolean needPathScore, boolean needSubjective);


    /**
     * 根据条件分页查询
     */
    IPage<Question> selectPageList(IPage<Question> page, Question question);

    /**
     * 统计题库题目数量
     *
     * @param repositoryIds
     * @return
     */
    List<QuestionDTO> countQuestionByRepository(List<String> repositoryIds);

    /**
     * 计算指定题库的题目题型数量
     *
     * @param repositoryId
     * @return
     */
    List<QuestionDTO> countQuestionNumByType(String repositoryId);

    IPage<Question> listQuestionByPracticeMode(Integer pageNo, Integer pageSize,
                                               String repositoryId, Integer questionType, Integer mode);


    /**
     * 设置题目的答案
     *
     * @param questionList
     */
    void setQuestionAnswer(List<Question> questionList);

    void castExcel(MultipartFile file) throws Exception;

    /**
     * 统计题库、题型的题目数量
     *
     * @param repositoryIds
     * @return
     */
    List<QuestionDTO> countQuestionType(List<String> repositoryIds);
}
