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

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.distributed.print.business.bean.dto.*;
import com.qmth.distributed.print.business.bean.dto.approvalForm.ExamPackageDetail;
import com.qmth.distributed.print.business.bean.result.WorkResult;
import com.qmth.distributed.print.business.entity.ExamTask;
import com.qmth.distributed.print.business.enums.MakeMethodEnum;
import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
import org.apache.ibatis.annotations.Param;

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

/**
 * <p>
 * 命题任务 Mapper 接口
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
public interface ExamTaskMapper extends BaseMapper<ExamTask> {

    IPage<ExamTaskDto> listPage(Page<ExamTaskDto> page, @Param("schoolId") Long schoolId, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("enable") Boolean enable, @Param("status") String status, @Param("cardRuleId") Long cardRuleId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("orgIds") Set<Long> orgIds, @Param("userName") String userName, @Param("createName") String createName);

    List<BlurryUserDto> listUser(@Param("schoolId") Long schoolId, @Param("param") String param, @Param("orgIds") Set<Long> orgIds);

    IPage<ExamTaskDto> listTaskApply(Page<ExamTaskDto> page, @Param("schoolId") Long schoolId, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("auditStatus") String auditStatus, @Param("cardRuleId") Long cardRuleId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("userId") Long userId, @Param("orgIds") Set<Long> orgIds, @Param("userName") String userName);

    IPage<ExamTaskDto> listTaskReviewUnaudited(Page<ExamTaskDto> page, @Param("schoolId") Long schoolId, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("userId") Long userId, @Param("cardRuleId") Long cardRuleId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("orgIds") Set<Long> orgIds, @Param("startCreateTime") Long startCreateTime, @Param("endCreateTime") Long endCreateTime, @Param("createName") String createName, @Param("currentUserId") Long currentUserId);

    IPage<ExamTaskDto> listTaskReviewAudited(Page<ExamTaskDto> page, @Param("schoolId") Long schoolId, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("reviewStatus") String reviewStatus, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("userId") Long userId, @Param("cardRuleId") Long cardRuleId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("orgIds") Set<Long> orgIds, @Param("startCreateTime") Long startCreateTime, @Param("endCreateTime") Long endCreateTime, @Param("createName") String createName, @Param("currentUserId") Long currentUserId);

    IPage<ExamTaskDetailDto> listTaskPaper(Page<ExamTaskDetailDto> page, @Param("schoolId") Long schoolId, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("orgIds") Set<Long> orgIds, @Param("containsQuestionTeacher") boolean containsQuestionTeacher, @Param("userId") Long userId, @Param("makeMethod") MakeMethodEnum makeMethod, @Param("cardRuleId") Long cardRuleId);

    List<RelatePaperDto> listPaperNumbers(@Param("schoolId") Long schoolId, @Param("courseCode") String courseCode, @Param("status") String status);

    ExamTaskDetailCardDto applyGetOne(@Param("examTaskId") Long examTaskId, @Param("source") String source);

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

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

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

    IPage<ClientExamTaskDto> listClientExamTaskPage(Page<ClientExamTaskDto> page, @Param("schoolId") Long schoolId, @Param("machineCode") String machineCode, @Param("printPlanId") Long printPlanId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("isTry") Boolean isTry, @Param("isPass") Boolean isPass, @Param("orgId") Long orgId, @Param("printPlanStatus") String printPlanStatus, @Param("examDetailStatus") String[] examDetailStatus);

    List<ClientExamTaskDto> listClientExamTaskPage(@Param("schoolId") Long schoolId, @Param("machineCode") String machineCode, @Param("printPlanId") Long printPlanId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("isTry") Boolean isTry, @Param("isPass") Boolean isPass, @Param("orgId") Long orgId, @Param("printPlanStatus") String printPlanStatus, @Param("examDetailStatus") String[] examDetailStatus);

    List<ExamTask> listExamTaskByCardId(Long cardId);

    /**
     * 查询审核样品
     *
     * @param examTaskId 命题任务id
     * @return 结果
     */
    List<ReviewSampleDto> listReviewSampleInfoByExamTaskId(@Param("examTaskId") Long examTaskId);

    List<ExamTask> listExamTaskExpire(@Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("status") String[] status);

    List<ExamTask> listExamTaskAuditExpire(@Param("startTime") Long startTime, @Param("endTime") Long endTime);

    List<ExamTaskDetailDto> listTaskPaper(@Param("schoolId") Long schoolId, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("cardRuleId") Long cardRuleId, @Param("makeMethod") MakeMethodEnum makeMethod, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("orgIds") Set<Long> orgIds, @Param("containsQuestionTeacher") boolean containsQuestionTeacher, @Param("userId") Long userId);

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

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

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

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

    /**
     * 根据试卷编号查询考场详细数据集（印刷计划状态为‘PRINTING’、‘PRINTING_FINISH‘的）
     *
     * @param paperNumber             试卷编号
     * @param printPlanStatusEnumList 印刷计划状态集合
     * @return 数据集
     */
    List<ExamPackageDetail> findExamPackageDetailByPaperNumber(@Param("schoolId") Long schoolId, @Param("examId") Long examId, @Param("courseCode") String courseCode, @Param("paperNumber") String paperNumber, @Param("printPlanStatusEnumList") List<PrintPlanStatusEnum> printPlanStatusEnumList);

    ExamTask findByFlowId(@Param("flowId") Long flowId);

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

    ExamTaskDto getByExamTaskId(Long examTaskId);

    IPage<ExamTaskDetailDto> listExamTaskDetailDownload(@Param("page") Page<ExamTaskDetailDto> page, @Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("courseName") String courseName, @Param("orgIds") Set<Long> orgIds);

    /**
     * 根据条件查询要下载的试卷文件
     *
     * @param semesterId 学期id
     * @param examId     考试id
     * @param courseName 课程明后才能
     * @param orgIds     机构id
     * @param idSet      命题任务id集合
     * @return 命题任务试卷信息
     */
    List<ExamTaskDetailDto> listExamTaskDetailDownloadByQuery(@Param("semesterId") Long semesterId, @Param("examId") Long examId, @Param("courseName") String courseName, @Param("orgIds") Set<Long> orgIds, @Param("idSet") Set<Long> idSet);
}
