package cn.com.qmth.examcloud.core.questions.service;

import cn.com.qmth.examcloud.api.commons.security.bean.User;
import cn.com.qmth.examcloud.api.commons.security.bean.UserDataRule;
import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
import cn.com.qmth.examcloud.core.questions.dao.entity.*;
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitExp;
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperExp;
import cn.com.qmth.examcloud.core.questions.service.bean.paper.PaperAnswerDomain;
import org.springframework.data.domain.Page;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * @author chenken
 * @date 2017年9月12日 上午11:21:48
 * @company QMTH
 * @description PaperService.java
 */
public interface PaperService {

    /**
     * 查询所有已导入试卷
     *
     * @param paperSearchInfo
     * @param curPage
     * @param pageSize
     * @return
     */

    public Page<Paper> getImportPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize, UserDataRule userDataRule);

    /**
     * 查询所有待审核和审核不通过的导入试卷
     *
     * @param paperSearchInfo
     * @param curPage
     * @param pageSize
     * @return
     */
    public Page<Paper> getImportPapersNotSuccess(PaperSearchInfo paperSearchInfo, int curPage, int pageSize);

    /**
     * 根据条件查询
     *
     * @param paperSearchInfo
     * @return
     */
    public List<Paper> getImportPapersBySearch(PaperSearchInfo paperSearchInfo);

    /**
     * 根据条件查询
     *
     * @param paperSearchInfo
     * @return
     */
    public List<Paper> getGenPapersBySearch(PaperSearchInfo paperSearchInfo);

    /**
     * 保存试卷
     *
     * @param paperExp
     * @return
     */
    public Map<String, Object> savePaper(PaperExp paperExp, User user);

    /**
     * 查询所有已组试卷
     *
     * @param paperSearchInfo
     * @param curPage
     * @param pageSize
     * @return
     */
    public Page<Paper> getGenPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize,UserDataRule ud);

    /**
     * 查询考试试卷
     *
     * @param id
     * @param courseCode
     * @param groupCode
     * @return
     */
    public List<Paper> listExamPapers(long id, String courseCode, String groupCode);

    /**
     * 设置考试试卷
     *
     * @param examId
     * @param courseCode
     * @param groupCode
     * @param paperId
     * @return
     */
    public void joinToExamPaper(long examId, String courseCode, String groupCode, String paperId);

    public void releaseExamPaper(long examId, String courseCode, String groupCode, String paperId);

    public Set<String> listGroupCodes(long examId, String courseCode);

    public void deletGroupCode(long examId, String courseCode, String groupCode);

    /**
     * 根据试卷ID获取试卷下面的大题
     *
     * @param id
     * @return
     */
    public List<PaperDetail> findPaperDetailsById(String id);

    /**
     * 批量删除试卷
     *
     * @param paperIds
     */
    public void deletePapers(List<String> paperIds, User user);

    /**
     * 批量通过试卷
     *
     * @param paperIds
     */
    public void passPapers(List<String> paperIds);

    /**
     * 批量不通过试卷
     *
     * @param paperIds
     */
    public void noPassPapers(List<String> paperIds);

    /**
     * 批量待审核试卷
     *
     * @param paperIds
     */
    public void backPapers(List<String> paperIds);

    /**
     * 初始化导出试卷DTO
     *
     * @param id
     * @return
     */
    public PaperExp getPaperDto(String id);

    /**
     * 重新对选择题option进行排序(多选、单选、套题下选择题)
     */
    public void reorderChoicequestionOption(List<PaperDetailUnitExp> paperDetailUnitExps);

    /**
     * 初始化试卷内容(增加序号)
     *
     * @param paperExp
     */
    public void initPaper(PaperExp paperExp);

    /**
     * 格式化查询条件
     *
     * @param paperSearchInfo
     */
    public void formatPaperSearchInfo(PaperSearchInfo paperSearchInfo);

    /**
     * 1.重新设置小题number，并返回试卷总分
     * 2.重新计算大题的总分和小题总数
     * 3.重新保存试卷大题数量、小题数量、试卷总分等信息
     *
     * @param paper
     */
    public void formatPaper(Paper paper, User user);

    /**
     * 先备份准备删掉的试题，然后再删掉
     *
     * @param questionId
     * @return
     */
    public void deleteImportQuestionById(String detailUnitId, String questionId, User user);

    /**
     * 向试卷中插入一个试题
     *
     * @param paperId
     * @param paperDetailId
     * @return
     */
    public Paper insertQuestionToPaper(String paperId, String paperDetailId, Question question, User user);

    /**
     * 获取试题所在的试卷名称
     *
     * @param questionId
     * @return
     */
    public List<String> getPaperNamesByQuestionId(String questionId);

    public Page<Question> listQuestionforSelect(String paperId, int curPage, int pageSize, QuesStructType quesType, User user, String quesBody,UserDataRule ud);

    public Paper selectQuestionsToPaper(String paperId, String paperDetailId, List<Question> questions, User user);

    public boolean checkPaperName(String paperName, String orgId);

    public void checkPaperNameNew(String paperName, String orgId) throws Exception;

    public Page<Paper> getPapersNotInIds(PaperSearchInfo paperSearchInfo, String[] ids, int curPage, int pageSize, PaperType paperType,UserDataRule ud);

    /**
     * 将选中的导入试卷复制为卷库试卷
     */
    public void useBasePaper(String selectedPaperIds, String userId);

    /**
     * 根据试卷名称、试卷类型检查名称是否存在
     *
     * @param paperName
     * @param paperType
     * @param orgId
     * @return
     * @throws Exception
     */
    public boolean checkPaperName(String paperName, PaperType paperType, String orgId) throws Exception;

    /**
     * 上传音频文件检查
     *
     * @param paperId
     * @param filesName
     * @return
     */
    public Map<String, String> checkRadioFile(String paperId, List<String> filesName);

    //判断选项
    public Map<String, String> checkOptions(List<PaperDetailUnit> paperDetailUnits, String fileNames[], String fileName);

    /**
     * 上传音频文件到又拍云
     *
     * @param files
     * @param paperId
     */
    public void uploadRadio(List<MultipartFile> files, String paperId, User user);

    /**
     * 计算试卷难度
     *
     * @param paper
     * @param paperTotalScore
     * @return
     */
    public Double reSetDifficulty(Paper paper, double paperTotalScore);

    /**
     * 获取Html片段
     *
     * @param paperId
     * @return
     */
    public Map<String, Object> getPaperPDF(String paperId, String type) throws Exception;

    /**
     * pdf路径传至印刷平台
     *
     * @param paperId
     */
    public String sendPrint(String paperId, String orgId, String examId);

    /**
     * 根据试卷id查询主观题与客观题的数量
     *
     * @param paperId
     */
    public String findQuestionStructure(String paperId) throws Exception;

    /**
     * 导出试卷Dto
     *
     * @param paperId
     * @return
     */
    public PaperExp getDownPaperExp(String paperId);

    /**
     * 根据试卷id,公开度，难度查询题目数量
     *
     * @param paperId
     * @param publicityType
     * @param difficultyType
     * @return
     */
    public int getQuestionTypeNumbers(String paperId, Integer publicityType, Integer difficultyType);

    /**
     * 根据试卷id,公开度，难度查询题目分数
     *
     * @param paperId
     * @param publicityType
     * @param difficultyType
     * @return
     */
    public double getQuestionTypeScore(String paperId, Integer publicityType, Integer difficultyType);

    public List<PaperAnswerDomain> answerExport(Paper paper);

    public void answerImport(Paper paper, MultipartFile dataFile);

    Page<Paper> getStoragePaperPage(PaperSearchInfo paperSearchInfo, int curPage, int pageSize,UserDataRule ud);

    void updatePapersStorage(List<String> paperIds, int storage, String orgId);

	public List<String> findPaperId(Long fromRootOrgId);

	public void deletePapersPlus(List<String> paperList, User user);

}
