package com.yida.data.school.exam.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.yida.data.common.core.entity.exam.CoreExaminationStudent;
import com.yida.data.school.dto.exam.ClassCompareDTO;
import com.yida.data.school.dto.exam.ScoreSectionStasticDTO;
import com.yida.data.school.vo.exam.ClassVO;
import com.yida.data.school.vo.exam.ExamScoreAnalysisVO;
import com.yida.data.school.vo.exam.ScoreSectionStasticVO;
import com.yida.data.school.vo.exam.ScoreTrendVO;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface CoreExaminationStudentMapper extends BaseMapper<CoreExaminationStudent> {

    /**
     * 查询本次考试对应的考试学生列表数据
     */
    IPage<CoreExaminationStudent> findExaminationStudentPage(Page page,
                                                                 @Param("coreExaminationId") Long coreExaminationId,
                                                                 @Param("searchName") String searchName,
                                                                 @Param("classId") Long classId);

    List<CoreExaminationStudent> findExaminationStudentList(@Param("coreExaminationId") Long coreExaminationId,
                                                                 @Param("searchName") String searchName,
                                                                 @Param("classId") Long classId);

    /**
     * @return com.yida.data.entity.CoreExaminationStudent
     * 根据学生id查询考生信息是否存在（确认成绩是否录入）
     * @Author WSJ
     * @Date 8:46 2020/6/29
     * @Param [coreStudentId, delFlag]
     **/
    CoreExaminationStudent findByCoreStudentIdAndCoreExaminationIdAndClassIdAndDelFlag(Long coreStudentId, Long examinationStudentId, Long classId, String delFlag);

    /**
     * 判断身份证号码在学生表中是否存在
     *
     * @param coreExaminationStudent
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/18 17:27
     */
    int checkStudentIdNumber(CoreExaminationStudent coreExaminationStudent);

    /**
     * 查询学生身份证数据
     *
     * @param
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/18 17:44
     */
    List<Long> findStudentIdNumber(String studentIdNumber);

    /**
     * 查询本次考试的排行榜数据列表
     */
    
    IPage<CoreExaminationStudent> findRankPageList(Page page,@Param("coreExaminationId") Long coreExaminationId,
                                                  @Param("studentName") String studentName,
                                                  @Param("classId") Long classId);

    /**
     * 根据考场id和年级id查询年级所有的成绩并排序
     **/
    
    List<CoreExaminationStudent> findByCoreExaminationIdAndGradeId(@Param("examId") Long examId,
                                                                   @Param("gradeId") Long gradeId);

    /**
     * 根据考场id,年级id,班级id查询班级所有的成绩并排序
     **/
    
    List<CoreExaminationStudent> findByCoreExaminationIdAndGradeIdClassId(@Param("examId") Long examId,
                                                                          @Param("gradeId") Long gradeId,
                                                                          @Param("classId") Long classId);

    /**
     * 更新年级排名或班级排名
     **/
    void updateGradleRankOrClassRank(CoreExaminationStudent coreExaminationStudentlist);

    /**
     * 查询单个考生的所有信息
     **/
    CoreExaminationStudent findCoreExaminationStudentDetail(@Param("coreExaminationStudentId") Long coreExaminationStudentId,
                                                            @Param("coreExaminationId") Long coreExaminationId,
                                                            @Param("classId") Long classId,
                                                            @Param("studentName") String studentName);

    List<ClassVO> findClassByExam(Long examId);

    List<ExamScoreAnalysisVO> getScoreAnalysis(ClassCompareDTO dto);

    List<ExamScoreAnalysisVO> getCourseScoreAnalysis(ClassCompareDTO dto);

    List<ScoreSectionStasticVO> getScoreSectionStastic(ScoreSectionStasticDTO dto);

    List<ScoreSectionStasticVO> getCourseScoreSectionStastic(ScoreSectionStasticDTO dto);

    /**
     * 查询成绩趋势信息
     */
    List<ScoreTrendVO> findScoreTrend(@Param("startDate") LocalDate startDate,
                                      @Param("endDate") LocalDate endDate,
                                      @Param("studentId") Long studentId);
}