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.CoreExamination;
import com.yida.data.common.core.entity.exam.CoreExaminationCoreAverage;
import com.yida.data.common.core.entity.exam.CoreExaminationStudent;
import com.yida.data.common.core.entity.exam.CoreStudentReturnData;
import com.yida.data.school.vo.exam.EduStudentExamVO;
import com.yida.data.school.vo.exam.ExamVO;
import com.yida.data.school.vo.exam.StudentExamListVO;

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

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

@Mapper
public interface CoreExaminationMapper extends BaseMapper<CoreExamination> {

    /**
     * 根据学生id和考试id查询H5学生成绩信息
     *
     * @param studentId
     * @param examinationId
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/15 17:48
     */
    List<CoreStudentReturnData> findStudentExamineGrade(@Param("studentId") Long studentId, @Param(
            "examinationId") Long examinationId);

    /**
     * 根据学生id查询考试列表数据
     *
     * @param studentId
     * @param examinationName
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/17 9:58
     */
    List<StudentExamListVO> findStudentExamineList(@Param("startDate") LocalDate startDate,
                                                   @Param("endDate") LocalDate endDate,
                                                   @Param("studentId") Long studentId,
                                                   @Param("examinationName") String examinationName);

    /**
     * 查询考试列表数据
     */
    IPage<CoreExamination> findExaminationPageList(Page page, @Param("dto") CoreExamination coreExamination);

    /**
     * 根据考试主键id查询考试学科数
     *
     * @param examinationId
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/19 13:43
     */
    Integer countExaminationCourseByExaminationId(Integer examinationId);

    /**
     * 根据考试主键id查询考试班级数
     *
     * @param examinationId
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/19 14:16
     */
    Integer countExaminationClassByExaminationId(Integer examinationId);

    /**
     * 根据考试主键id查询考试学生数
     *
     * @param examinationId
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/19 14:18
     */
    Integer countExaminationStudentByExaminationId(Integer examinationId);

    /**
     * 查询考生年级历史
     *
     * @param schoolId
     * @param studentId
     * @return
     */
    List<CoreExaminationStudent> findHistoryExamination(@Param("schoolId") Long schoolId, @Param("studentId") Long studentId);


    /**
     * 根据年级的id和日期，查询考试列表
     *
     * @param gradeId
     * @param
     * @return
     */
    IPage<CoreExamination> selectGradeList(Page page, @Param("gradeId") List<Long> gradeId, @Param("start") LocalDateTime star, @Param("end") LocalDateTime end, @Param("name") String name);

    /**
     * 查询考试详情
     *
     * @param examId
     * @param courseId
     * @param classId
     * @return
     */
    EduStudentExamVO findClassExamination(@Param("examId") Long examId, @Param("courseId") Long courseId,
                                          @Param("classId") Long classId,
                                          @Param("star") LocalDateTime star,
                                          @Param("end") LocalDateTime end);

    /**
     * 查询班级成绩
     *
     * @param examId
     * @param classId
     * @param studentName
     * @return
     */
    IPage<CoreExaminationStudent> selectClassScore(Page page,
                                                   @Param("classId") List<Long> classId,
                                                   @Param("examId") Long examId,
                                                   @Param("studentName") String studentName);

    /**
     * 查询班级成绩
     *
     * @param examName
     * @param studentId
     * @return
     */
    List<ExamVO> findHistoryExaminationList(@Param("examName") String examName, @Param("studentId") Long studentId);

    EduStudentExamVO findOneClassExamination(@Param("examId") Long examId, @Param("courseId") Long courseId, @Param("classId") Long classId,
                                             @Param("star") LocalDateTime star, @Param("end") LocalDateTime end);

    CoreExaminationCoreAverage findAllScoringRate(@Param("examId") Long examId, @Param("great") Double great, @Param("good") Double good, @Param("pass") Double pass, @Param("poor") Double poor);

    CoreExaminationCoreAverage findOneScoringRate(@Param("examId") Long examId, @Param("great") Double great, @Param("good") Double good, @Param("pass") Double pass, @Param("poor") Double poor, @Param("courseId") Long courseId);

    /**
     * 查询是否存在发布的考试
     *
     * @param ids
     * @return 不为null则存在
     */
    Integer existPublishExam(@Param("ids") Long[] ids);
}