package com.keao.edu.user.dao;

import com.keao.edu.common.dal.BaseDAO;
import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
import com.keao.edu.user.dto.ExamRoomStudentRelationDto;
import com.keao.edu.user.dto.RoomStudentListDto;
import org.apache.ibatis.annotations.Param;

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

public interface ExamRoomStudentRelationDao extends BaseDAO<Long, ExamRoomStudentRelation> {

    int batchInsert(@Param("roomStudents") List<ExamRoomStudentRelation> examRoomStudentRelations);

    /**
     * 开启/关闭教室
     * @param openFlag
     * @param examinationBasicId
     * @param studentId
     */
    void switchClassRoom(@Param("openFlag") Integer openFlag, @Param("examinationBasicId") Integer examinationBasicId, @Param("studentId") Integer studentId);

    List<ExamRoomStudentRelationDto> findExamRoomStudents(Map<String, Object> params);
    int countExamRoomStudents(Map<String, Object> params);

    /**
     * @describe 获取指定教室的学员
     * @author Joburgess
     * @date 2020.06.24
     * @param examRoomId:
     * @return java.util.List<com.keao.edu.user.api.entity.ExamRoomStudentRelation>
     */
    List<ExamRoomStudentRelation> findStudentsWithExamRoom(@Param("examRoomId") Long examRoomId);


    List<ExamRoomStudentRelation> findStudentsWithExamRooms(@Param("examRoomIds") List<Long> examRoomIds);

    /**
     * @describe 删除指定教室的学员
     * @author Joburgess
     * @date 2020.06.24
     * @param examRoomId:
     * @param registIds:
     * @return int
     */
    int deleteStudentsFromExamRoom(@Param("examRoomId") Long examRoomId,
                                    @Param("registIds") List<Long> registIds);

    /**
     * @describe 根据班级删除记录
     * @author Joburgess
     * @date 2020.06.24
     * @param examRoomIds:
     * @return int
     */
    int deleteWithExamRooms(@Param("examRoomIds") List<Long> examRoomIds);

    /**
     * @describe 获取考级项目下指定分部未发送考试安排的学员
     * @author Joburgess
     * @date 2020.07.22
     * @param examId:
     * @param organIds:
     * @return java.util.List<com.keao.edu.user.api.entity.ExamRoomStudentRelation>
     */
    List<ExamRoomStudentRelation> getNoSendExamPlanRooms(@Param("examId") Long examId,
                                                               @Param("organIds") List<Integer> organIds);

    /**
     * @describe 获取考试时间在指定日期的考场学生记录
     * @author Joburgess
     * @date 2020.07.22
     * @return java.util.List<com.keao.edu.user.api.entity.ExamRoomStudentRelation>
     */
    List<ExamRoomStudentRelation> getTomorrowExamStudents(@Param("day") String day);

    /**
     * 获取教室学员关联
     * @param basicId
     * @param roomId
     * @param studentId
     * @return
     */
    List<ExamRoomStudentRelation> getExamRoomStudentRelations(@Param("basicId") Long basicId, @Param("roomId") String roomId, @Param("studentId") Integer studentId);

    /**
     * @describe 获取报名学员所在教室
     * @author Joburgess
     * @date 2020.07.08
     * @param registId:
     * @return com.keao.edu.user.api.entity.ExamRoomStudentRelation
     */
    ExamRoomStudentRelation getStudentExamRoom(@Param("registId") Long registId);

    /**
     * 获取教室
     * @param roomId
     * @param currentUserId
     * @return
     */
    ExamRoomStudentRelation findByStudentIdAndRoomId(@Param("roomId") Long roomId, @Param("currentUserId") Integer currentUserId);

    /**
     * 清除签到时间
     * @param examRegistrationId
     */
    void cleanSignInTime(Long examRegistrationId);

    /**
     * 获取房间学员队列
     * @param roomId
     * @return
     */
    List<RoomStudentListDto> queryStudentList(Long roomId);

    /**
     * 获取总人数
     * @param roomId
     * @return
     */
    Integer queryTotalNum(Long roomId);

    /**
     * 获取已完成总人数
     * @param roomId
     * @return
     */
    Integer queryEndNum(Long roomId);

    /**
     * 获取当前学员需要等待人数
     * @param examRoomId
     * @param signInTime
     * @return
     */
    Integer sumWaitNum(@Param("examRoomId") Long examRoomId,
                       @Param("signInTime") String signInTime,
                       @Param("studentId") Integer studentId,
                       @Param("ersrId") Long ersrId);

    /**
     * 获取所有参考学员编号
     * @param examRoomId
     * @return
     */
    String getStudentIds(Long examRoomId);

    /**
     * 获取学员编号注册编号map
     * @param examRoomId
     * @return
     */
    List<Map<Integer, String>> getStuRegistrationMap(Long examRoomId);

    /**
     * 获取房间学员数
     * @param roomIds
     * @return
     */
    List<Map<Long,Integer>> getStudentNumMap(@Param("roomIds") Set<Long> roomIds);

    /**
     * 获取已签到学员数
     * @param examRoomId
     * @return
     */
    Integer countSignInNum(Long examRoomId);

    /**
     * @describe 统计指定教师学员数量
     * @author Joburgess
     * @date 2020.07.28
     * @param examRoomId:
     * @return int
     */
    int countStudentsWithRoom(Long examRoomId);
}
