package com.qmth.themis.business.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.themis.business.base.CustomBaseMapper;
import com.qmth.themis.business.bean.admin.ExamDeficiencyListBean;
import com.qmth.themis.business.bean.admin.ExamInfoBean;
import com.qmth.themis.business.bean.admin.ExamStudentLogListBean;
import com.qmth.themis.business.bean.admin.ExamViewCountListBean;
import com.qmth.themis.business.dto.MarkResultSimpleExportDto;
import com.qmth.themis.business.dto.response.MarkResultDto;
import com.qmth.themis.business.dto.response.RoomCodeQueryDto;
import com.qmth.themis.business.dto.response.TEExamStudentDto;
import com.qmth.themis.business.entity.TEExamStudent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * @Description: 考生库 Mapper 接口
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/6/25
 */
@Mapper
public interface TEExamStudentMapper extends CustomBaseMapper<TEExamStudent> {

    /**
     * 查询考生信息
     *
     * @param iPage
     * @param examId
     * @param activityId
     * @param identity
     * @param name
     * @param roomCode
     * @param courseCode
     * @param grade
     * @param enable
     * @param classNo
     * @return
     */
    public IPage<TEExamStudentDto> examStudentQuery(IPage<Map> iPage, @Param("examId") Long examId,
                                                    @Param("activityId") Long activityId, @Param("identity") String identity, @Param("name") String name,
                                                    @Param("roomCode") String roomCode, @Param("courseCode") String courseCode, @Param("grade") String grade,
                                                    @Param("enable") Integer enable, @Param("classNo") String classNo, @Param("hasPhoto") Integer hasPhoto);

    @SuppressWarnings("MybatisXMapperMethodInspection")
    public List<Map<String, Object>> getTotalCount(@Param("orgId") Long orgId, @Param("examId") Long examId, @Param("activityId") Long activityId,
                                                   @Param("roomCode") String roomCode, @Param("courseCode") String courseCode);

    public IPage<ExamViewCountListBean> getTotalCountInfo(IPage<Map> iPage, @Param("orgId") Long orgId, @Param("examId") Long examId, @Param("activityId") Long activityId,
                                                          @Param("roomCode") String roomCode, @Param("courseCode") String courseCode);

    public List<ExamViewCountListBean> getTotalCountInfoExport(@Param("orgId") Long orgId, @Param("examId") Long examId, @Param("activityId") Long activityId,
                                                               @Param("roomCode") String roomCode, @Param("courseCode") String courseCode);

    @SuppressWarnings("MybatisXMapperMethodInspection")
    public List<Map<String, Object>> getDoneCountByActivityIds(@Param("examId") Long examId, @Param("activityIds") List<Long> activityIds);

    @SuppressWarnings("MybatisXMapperMethodInspection")
    public List<Map<String, Object>> getAbsentCountByActivityIds(@Param("examId") Long examId, @Param("activityIds") List<Long> activityIds);

    /**
     * 考场查询
     *
     * @param roomName
     * @return
     */
    public List<RoomCodeQueryDto> examRoomQuery(@Param("roomName") String roomName);

    public IPage<ExamDeficiencyListBean> getExamDeficiencyPage(IPage<ExamDeficiencyListBean> iPage, @Param("examId") Long examId,
                                                               @Param("activityId") Long activityId, @Param("roomCode") String roomCode,
                                                               @Param("courseCode") String courseCode, @Param("name") String name, @Param("identity") String identity, @Param("activityIds") List<Long> activityIds);

    public List<ExamDeficiencyListBean> getExamDeficiencyPageExport(@Param("examId") Long examId,
                                                                    @Param("activityId") Long activityId, @Param("roomCode") String roomCode,
                                                                    @Param("courseCode") String courseCode, @Param("name") String name, @Param("identity") String identity, @Param("activityIds") List<Long> activityIds);


    public IPage<ExamStudentLogListBean> getPageForStudentLog(IPage<ExamStudentLogListBean> iPage, @Param("orgId") Long orgId, @Param("examId") Long examId,
                                                              @Param("activityId") Long activityId, @Param("roomCode") String roomCode,
                                                              @Param("courseCode") String courseCode, @Param("name") String name, @Param("identity") String identity);


    public void updateAlreadyExamCount(@Param("examStudentId") Long examStudentId, @Param("alreadyExamCount") Integer alreadyExamCount);

    public void updateCurrentRecordId(@Param("examStudentId") Long examStudentId, @Param("currentRecordId") Long currentRecordId);

    public void updateAlreadyExamCountAndCurrentRecordId(@Param("examStudentId") Long examStudentId, @Param("alreadyExamCount") Integer alreadyExamCount, @Param("currentRecordId") Long currentRecordId);

    /**
     * 查询学生成绩信息
     *
     * @param iPage
     * @param examId
     * @param activityId
     * @param identity
     * @param name
     * @param courseCode
     * @return
     */
    public IPage<MarkResultDto> markResultQuery(IPage<Map> iPage, @Param("examId") Long examId, @Param("activityId") Long activityId, @Param("identity") String identity, @Param("name") String name, @Param("courseCode") String courseCode);

    /**
     * 查询学生成绩信息(分页导出用)
     *
     * @param iPage
     * @param examId
     * @param activityId
     * @param identity
     * @param name
     * @param courseCode
     * @return
     */
    public IPage<MarkResultSimpleExportDto> markResultQueryExportIpage(IPage<Map> iPage, @Param("examId") Long examId, @Param("activityId") Long activityId, @Param("identity") String identity, @Param("name") String name, @Param("courseCode") String courseCode);

    public List<TEExamStudentDto> findExamStudentNeedMark(@Param("examId") Long examId, @Param("courseCode") String courseCode,
                                                          @Param("idGt") Long idGt, @Param("count") Integer count);

    /**
     * 获取所有待阅卷的考生
     *
     * @param examId
     * @param examPaperIdSet
     * @param examStudentBreachPush
     * @return
     */
    public List<TEExamStudent> findExamStudentNeedMarkAll(@Param("examId") Long examId, @Param("examPaperIdSet") Set<Long> examPaperIdSet, @Param("examStudentBreachPush") Boolean examStudentBreachPush);

    /**
     * 获取考试次数为0的考生
     *
     * @param examId
     * @param examActivityId
     * @param id
     * @param examRecordId
     * @return
     */
    public List<TEExamStudent> findAlreadyExamCountZero(@Param("examId") Long examId, @Param("examActivityId") Long examActivityId, @Param("id") Long id, @Param("examRecordId") Long examRecordId);

    /**
     * 获取缺考考生
     *
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @return
     */
    public Integer getAbsentCount(@Param("examId") Long examId, @Param("examActivityId") Long examActivityId, @Param("roomCode") String roomCode);

    /**
     * 获取考试相关信息
     *
     * @param orgId
     * @return
     */
    public List<ExamInfoBean> getExamInfo(@Param("orgId") Long orgId);
}