package com.qmth.distributed.print.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qmth.distributed.print.business.bean.dto.*;
import com.qmth.distributed.print.business.bean.dto.approvalForm.ExamTaskApprovalFormDto;
import com.qmth.distributed.print.business.bean.dto.examObject.ExamObjectDto;
import com.qmth.distributed.print.business.bean.params.ExamTaskReApplyParam;
import com.qmth.distributed.print.business.bean.params.MakeupExamTaskTotalParam;
import com.qmth.distributed.print.business.bean.result.WorkResult;
import com.qmth.distributed.print.business.bean.result.examTaskStudent.ExamTaskExamStudentImportResult;
import com.qmth.distributed.print.business.bean.result.examTaskStudent.ExamTaskStudentObjectResult;
import com.qmth.distributed.print.business.entity.*;
import com.qmth.distributed.print.business.enums.MakeMethodEnum;
import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
import com.qmth.teachcloud.common.bean.tiku.TikuPaperInfo;
import com.qmth.teachcloud.common.entity.BasicExam;
import com.qmth.teachcloud.common.entity.SysUser;
import com.qmth.teachcloud.common.entity.TBTask;
import com.qmth.teachcloud.common.enums.FlowStatusEnum;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 命题任务 服务类
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
public interface ExamTaskService extends IService<ExamTask> {

    IPage<ExamTaskDto> list(Long semesterId, Long examId, Boolean enable, String status, Long cardRuleId, String courseCode, String paperNumber, Long startTime, Long endTime, String userName, String createName, Integer pageNumber, Integer pageSize);

    List<BlurryUserDto> listUser(String param);

    ExamTask assignUser(ExamTask examTask);

    boolean enable(ExamTask examTask);

    /**
     * 保存命题任务新
     *
     * @param examTask
     * @return
     */
    ExamTask saveExamTaskNew(ExamTask examTask);

    ExamTaskImportResultDto importFile(MultipartFile file) throws IOException, NoSuchFieldException;

    List<ExamTask> saveBatch(ExamTask task);

    IPage<ExamTaskDto> listTaskApply(Long semesterId, Long examId, String auditStatus, Long cardRuleId, String courseCode, String paperNumber, Long startTime, Long endTime, String userName, Integer pageNumber, Integer pageSize);

    IPage<ExamTaskDto> listTaskReviewUnaudited(Long semesterId, Long examId, String courseCode, String paperNumber, Long userId, Long cardRuleId, Long startTime, Long endTime, Long startCreateTime, Long endCreateTime, String createName, Integer pageNumber, Integer pageSize);

    IPage<ExamTaskDto> listTaskReviewAudited(Long semesterId, Long examId, String reviewStatus, String courseCode, String paperNumber, Long userId, Long cardRuleId, Long startTime, Long endTime, Long startCreateTime, Long endCreateTime, String createName, Integer pageNumber, Integer pageSize);

    boolean taskReviewSave(ExamTaskReviewLog taskReviewLog) throws IOException;

    IPage<ExamTaskDetailDto> listTaskPaper(Long semesterId, Long examId, String courseCode, String paperNumber, Long startTime, Long endTime, MakeMethodEnum makeMethodEnum, Long cardRuleId, Integer pageNumber, Integer pageSize);

    List<RelatePaperDto> listPaperTypes(Long examTaskId, Long printPlanId, String courseCode);

    Map<String, Object> saveExamTaskDetail(ExamTaskDetail examTaskDetail) throws IOException;

    Map<String, Object> status(ExamTask examTask);

    ExamTaskDetailCardDto applyGetOne(Long examTaskId, String source);

    void paperDownload(HttpServletResponse response, Long examTaskId) throws Exception;

    /**
     * 根据考务-考场检验该考场下的所有命题任务是否已经完成，全部完成则生成pdf
     *
     * @param examDetailIdList 考务考场ids
     * @param user             用户id
     */
    void checkDataByExamination(Long printPlanId, List<Long> examDetailIdList, SysUser user) throws IOException;

    List<ExamTaskDetailDto> listTaskPaper(Long semesterId, Long examId, String courseCode, String paperNumber, Long cardRuleId, MakeMethodEnum makeMethod, Long startTime, Long endTime);

    TBTask taskDownloadPdf(Long semesterId, Long examId, String courseCode, String paperNumber, Long cardRuleId, MakeMethodEnum makeMethod, Long startTime, Long endTime);

    /**
     * 获取待办任务
     *
     * @param iPage
     * @param schoolId
     * @param orgId
     * @param userId
     * @return
     */
    IPage<WorkResult> getFlowTaskReadyList(IPage<Map> iPage, Long schoolId, Long orgId, Long userId);

    /**
     * 根据流程id和任务节点id获取待办
     *
     * @param flowId
     * @param taskId
     * @return
     */
    WorkResult getFlowInfo(Long flowId, Long taskId);

    /**
     * 根据流程状态查找命题任务
     *
     * @param schoolId
     * @param courseCode
     * @param paperNumber
     * @param flowStatus
     * @return
     */
    ExamTask findExamTaskByFlowStatus(Long schoolId, Long examId, String courseCode, String paperNumber, FlowStatusEnum flowStatus);

    void removeByExamTaskId(Long examTaskId);

    /**
     * 查找题卡规则标题
     *
     * @param cardRuleId 题卡规则主键
     * @return 标题名称
     */
    String findCardTitle(Long cardRuleId);

    /**
     * 新增命题申请
     *
     * @param examTaskApplyTemp
     * @return
     */
    Map<String, Object> submitTaskApply(ExamTaskApplyTemp examTaskApplyTemp);

    /**
     * 查找命题任务审核表
     *
     * @param examTaskId 命题任务id
     * @return 命题任务审核表参数
     */
    ExamTaskApprovalFormDto findExamTaskApprovalForm(Long examTaskId, Long examId, String paperNumber);


    void findExamTaskApprovalPdf(HttpServletResponse response, Long examTaskId, String htmlContext) throws Exception;

    /**
     * 根据试卷编号查找考试对象
     *
     * @param paperNumber 试卷编号
     * @return 考试对象
     */
    ExamObjectDto findExamObjectDtoByPaperNumber(Long examId, String paperNumber);

    /**
     * 根据流程id查找examtask
     *
     * @param flowId
     * @return
     */
    public ExamTask findByFlowId(Long flowId);

    /**
     * 印刷员驳回，命题老师重新提交
     *
     * @param map
     */
    Map<String, Object> applyResave(ExamTaskReApplyParam map);

    ExamTaskDto getByExamTaskId(Long examTaskId);

    /**
     * 查找命题任务考试对象
     * <p>
     * 1.选择教学班当考试对象 - TEACH_CLAZZ_STUDENT -> 以学生的教学班当考试对象集合，但学生信息中附带教学班和行政班数据。
     * 2.选择行政班当考试对象 - BASIC_CLAZZ_STUDENT -> 以学生的行政班当考试对象集合，且学生信息只包含行政班数据。
     * </P>
     *
     * @param examId      考试id
     * @param courseCode  基础课程编号
     * @param teacher
     * @param className
     * @param requestUser 请求的用户
     * @return 命题任务考试对象查询结果
     */
    List<ExamTaskStudentObjectResult> findExamTaskStudentObject(Long examId, String courseCode, String teacher, String className, SysUser requestUser) throws Exception;

    /**
     * 命题任务考生导入
     *
     * @param file        命题任务考生导入excel
     * @param requestUser 请求用户
     * @return 命题任务考生导入
     */
    List<ExamTaskExamStudentImportResult> examTaskExamStudentImport(MultipartFile file, SysUser requestUser) throws IOException, NoSuchFieldException, IllegalAccessException;

    void delete(Long id);

    void applyDelete(Long id);

    boolean savePreviewLog(Long examTaskId, String paperType, String type);

    List<String> listPaperNumber(String param, List<Long> printPlanIdList);

    ExamTask getByExamIdAndCourseCodeAndPaperNumber(Long examId, String courseCode, String paperNumber);

    IPage<MakeupExamTaskDto> listMakeupExamTask(Long printPlanId, Long semesterId, Long examId, Long collegeId, String courseCode, String paperNumber, String userName, Integer pageNumber, Integer pageSize);

    void saveMakeupTask(MakeupExamTaskTotalParam makeupExamTaskTotalParam);

    IPage<TikuPaperInfo> pageTikuPaper(String courseCode, String paperName, String account, Integer pageNumber, Integer pageSize);

    Map<String, Object> getTikuPaperData(Long examId, Long paperId, String uuid);

    List<ExamDetail> matchBasicExamStudent(BasicExam basicExam, ExamTask examTask, ExamTaskDetail examTaskDetail, SysUser user);
}
