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.ExamTaskApplyParam;
import com.qmth.distributed.print.business.bean.params.ExamTaskReApplyParam;
import com.qmth.distributed.print.business.bean.result.WorkResult;
import com.qmth.distributed.print.business.entity.ExamTask;
import com.qmth.distributed.print.business.entity.ExamTaskApplyTemp;
import com.qmth.distributed.print.business.entity.ExamTaskDetail;
import com.qmth.distributed.print.business.entity.ExamTaskReviewLog;
import com.qmth.distributed.print.business.enums.ExamStatusEnum;
import com.qmth.distributed.print.business.enums.MakeMethodEnum;
import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
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> {

    List<ExamTask> listByCourseCode(Long schoolId, String code);


    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<String> listPaperNumber(String param, List<Long> printPlanIdList);

    List<BlurryUserDto> listUser(String param);

    Boolean assignUser(ExamTask examTask);

    boolean enable(ExamTask examTask);

    @Deprecated
    ExamTask saveExamTask(ExamTask examTask);

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

    ExamTaskImportDto 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;

    boolean taskReviewSaveBatch(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);

    boolean saveExamTaskDetail(ExamTaskDetail examTaskDetail) throws IOException;

    boolean status(ExamTask examTask);

    ExamTaskDetailCardDto applyGetOne(Long examTaskId, String source);

    /**
     * 查询我的工作台
     *
     * @param iPage
     * @param userId
     * @param schoolId
     * @param status
     * @return
     */
    IPage<WorkResult> queryByMyWork(IPage<Map> iPage, Long userId, Long schoolId, String... status);

    IPage<WorkResult> queryUserByMyWork(IPage<Map> iPage, Long userId, Long schoolId, String... status);

    /**
     * 查询我的工作台-审核待办
     *
     * @param iPage
     * @param userId
     * @param schoolId
     * @param status
     * @return
     */
    IPage<WorkResult> queryByMyWorkSubmit(IPage<Map> iPage, Long userId, Long schoolId, ExamStatusEnum status);

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

    ExamTask getByCourseCodeAndPaperNumber(Long schoolId, String courseCode, String paperNumber);

    IPage<ClientExamTaskDto> listTryTask(Long schoolId, String machineCode, Long orgId, Long printPlanId, String courseCode, String paperNumber, Boolean isTry, Boolean isPass, Integer pageNumber, Integer pageSize);

    List<ClientExamTaskDto> listTryTask(Long schoolId, String machineCode, Long orgId, Long printPlanId, String courseCode, String paperNumber, Boolean isTry, Boolean isPass);

    /**
     * 检测考务数据的试卷编号和课程代码的正确性(根据试卷编号查询命题任务的试卷编号，如果存在，查询该命题任务记录对应的课程代码和考务数据导入的该条课程代码是否一致)
     *
     * @param schoolId    考务数据导入的学校代码
     * @param paperNumber 考务数据导入的试卷编号
     * @param courseCode  考务数据导入的课程代码
     */
    void verifyCourseCodeByPaperNumber(Long schoolId, String paperNumber, String courseCode);

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

    List<ExamTask> listExamTaskByCardId(Long cardId);

    /**
     * 根据命题任务id从（'exam_task_detail'表和'exam_task_paper_log'表查找审核样品信息）
     *
     * @param examTaskId 命题任务主键
     * @return 命题任务信息
     */
    ReviewSampleDto findReviewSampleInfoByExamTaskId(Long examTaskId);

    /**
     * 发送即将到期数据短信提醒
     */
    void sendSmsExpireTask();

    /**
     * 发送已逾期数据短信提醒
     */
    void sendSmsOverdueTask();

    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
     */
    public IPage<WorkResult> getFlowTaskReadyList(IPage<Map> iPage, Long schoolId, Long orgId, Long userId);

    void switchCard(Long examTaskId);

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

    void removeByExamTaskId(Long examTaskId);

    ExamTask saveExamTaskAndExamTaskDetail(ExamTaskApplyParam examTaskApplyParam);

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

    /**
     * 获取自己可以审核的流程id集合
     *
     * @param currentUserId
     * @return
     */
    List<Long> findFlowIdToMySelf(Long currentUserId);

    /**
     * 获取不是自己可以审核的流程id集合
     *
     * @param currentUserId
     * @return
     */
    List<Long> findFlowIdToNotMySelf(Long currentUserId);

    /**
     * 新增命题申请
     *
     * @param examTaskApplyTemp
     * @return
     */
    ExamTask submitTaskApply(ExamTaskApplyTemp examTaskApplyTemp);

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


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

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

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

    /**
     * 获取ProcessDefinitionId
     *
     * @param key
     * @return
     */
    public String getProcessDefinitionIdByMaxVersion(String key);

    /**
     * 印刷员驳回，命题老师重新提交
     *
     * @param map
     */
    void applyResave(ExamTaskReApplyParam map);

    ExamTaskDto getByExamTaskId(Long examTaskId);


}
