package com.qmth.themis.business.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.themis.business.bean.admin.*;
import com.qmth.themis.business.bean.result.TimeOnlineDataResult;
import com.qmth.themis.business.bean.result.TimeScaleDataResult;
import com.qmth.themis.business.cache.bean.ExamRecordDetailBean;
import com.qmth.themis.business.entity.TOeExamRecord;
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 TOeExamRecordMapper extends BaseMapper<TOeExamRecord> {

    /**
     * 查询实时监控台视频列表
     *
     * @param iPage
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param paperDownload
     * @param status
     * @param name
     * @param identity
     * @param minWarningCount
     * @param maxWarningCount
     * @param clientWebsocketStatus
     * @param cameraMonitorStatus
     * @param screenMonitorStatus
     * @param mobileFirstMonitorStatus
     * @param mobileSecondMonitorStatus
     * @param userId
     * @param orgId
     * @return
     */
    public IPage<InvigilateListVideoBean> invigilatePageListVideo(IPage<Map> iPage, @Param("examId") Long examId,
                                                                  @Param("examActivityId") Long examActivityId,
                                                                  @Param("roomCode") String roomCode,
                                                                  @Param("paperDownload") Integer paperDownload,
                                                                  @Param("status") String status,
                                                                  @Param("name") String name,
                                                                  @Param("identity") String identity,
                                                                  @Param("minWarningCount") Integer minWarningCount,
                                                                  @Param("maxWarningCount") Integer maxWarningCount,
                                                                  @Param("clientWebsocketStatus") String clientWebsocketStatus,
                                                                  @Param("cameraMonitorStatus") String cameraMonitorStatus,
                                                                  @Param("screenMonitorStatus") String screenMonitorStatus,
                                                                  @Param("mobileFirstMonitorStatus") String mobileFirstMonitorStatus,
                                                                  @Param("mobileSecondMonitorStatus") String mobileSecondMonitorStatus,
                                                                  @Param("userId") Long userId,
                                                                  @Param("orgId") Long orgId);

    /**
     * 实时监控台视频随机列表
     *
     * @param examId
     * @param userId
     * @param randomNum
     * @param orgId
     * @return
     */
    public List<InvigilateListVideoBean> invigilatePageListVideoRandom(@Param("examId") Long examId, @Param("userId") Long userId, @Param("randomNum") Integer randomNum, @Param("orgId") Long orgId);

    /**
     * 查询在线巡考列表
     *
     * @param iPage
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param status
     * @param name
     * @param identity
     * @param minMultipleFaceCount
     * @param maxMultipleFaceCount
     * @param minExceptionCount
     * @param maxExceptionCount
     * @param minWarningCount
     * @param maxWarningCount
     * @param clientWebsocketStatus
     * @param userId
     * @param orgId
     * @return
     */
    public IPage<InvigilateListPatrolBean> invigilatePagePatrolList(IPage<Map> iPage, @Param("examId") Long examId,
                                                                    @Param("examActivityId") Long examActivityId,
                                                                    @Param("roomCode") String roomCode,
                                                                    @Param("status") String status,
                                                                    @Param("name") String name,
                                                                    @Param("identity") String identity,
                                                                    @Param("minMultipleFaceCount") Integer minMultipleFaceCount,
                                                                    @Param("maxMultipleFaceCount") Integer maxMultipleFaceCount,
                                                                    @Param("minExceptionCount") Integer minExceptionCount,
                                                                    @Param("maxExceptionCount") Integer maxExceptionCount,
                                                                    @Param("minWarningCount") Integer minWarningCount,
                                                                    @Param("maxWarningCount") Integer maxWarningCount,
                                                                    @Param("clientWebsocketStatus") String clientWebsocketStatus,
                                                                    @Param("userId") Long userId,
                                                                    @Param("orgId") Long orgId);

    /**
     * 预警提醒列表
     *
     * @param iPage
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param approveStatus
     * @param name
     * @param identity
     * @param minMultipleFaceCount
     * @param maxMultipleFaceCount
     * @param minExceptionCount
     * @param maxExceptionCount
     * @param minWarningCount
     * @param maxWarningCount
     * @param userId
     * @param orgId
     * @return
     */
    public IPage<InvigilateListWarningBean> invigilatePageWarningList(IPage<Map> iPage, @Param("examId") Long examId,
                                                                      @Param("examActivityId") Long examActivityId,
                                                                      @Param("roomCode") String roomCode,
                                                                      @Param("approveStatus") Integer approveStatus,
                                                                      @Param("name") String name,
                                                                      @Param("identity") String identity,
                                                                      @Param("minMultipleFaceCount") Integer minMultipleFaceCount,
                                                                      @Param("maxMultipleFaceCount") Integer maxMultipleFaceCount,
                                                                      @Param("minExceptionCount") Integer minExceptionCount,
                                                                      @Param("maxExceptionCount") Integer maxExceptionCount,
                                                                      @Param("minWarningCount") Integer minWarningCount,
                                                                      @Param("maxWarningCount") Integer maxWarningCount,
                                                                      @Param("userId") Long userId,
                                                                      @Param("orgId") Long orgId);

    /**
     * 预警提醒清除未阅列表
     *
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param approveStatus
     * @param name
     * @param identity
     * @param minMultipleFaceCount
     * @param maxMultipleFaceCount
     * @param minExceptionCount
     * @param maxExceptionCount
     * @param minWarningCount
     * @param maxWarningCount
     * @param userId
     * @param orgId
     * @return
     */
    public Integer approveStatusListUpdate(@Param("examId") Long examId,
                                           @Param("examActivityId") Long examActivityId,
                                           @Param("roomCode") String roomCode,
                                           @Param("approveStatus") Integer approveStatus,
                                           @Param("name") String name,
                                           @Param("identity") String identity,
                                           @Param("minMultipleFaceCount") Integer minMultipleFaceCount,
                                           @Param("maxMultipleFaceCount") Integer maxMultipleFaceCount,
                                           @Param("minExceptionCount") Integer minExceptionCount,
                                           @Param("maxExceptionCount") Integer maxExceptionCount,
                                           @Param("minWarningCount") Integer minWarningCount,
                                           @Param("maxWarningCount") Integer maxWarningCount,
                                           @Param("userId") Long userId,
                                           @Param("orgId") Long orgId);

    /**
     * 进度查询列表
     *
     * @param iPage
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param courseCode
     * @param name
     * @param identity
     * @param status
     * @param userId
     * @param orgId
     * @param breachStatus
     * @return
     */
    public IPage<InvigilateListProgressBean> invigilatePageProgressList(IPage<Map> iPage, @Param("examId") Long examId,
                                                                        @Param("examActivityId") Long examActivityId,
                                                                        @Param("roomCode") String roomCode,
                                                                        @Param("courseCode") String courseCode,
                                                                        @Param("name") String name,
                                                                        @Param("identity") String identity,
                                                                        @Param("status") Integer status,
                                                                        @Param("userId") Long userId,
                                                                        @Param("orgId") Long orgId,
                                                                        @Param("breachStatus") Integer breachStatus);

    /**
     * 进度查询列表导出
     *
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param courseCode
     * @param name
     * @param identity
     * @param status
     * @param userId
     * @param orgId
     * @param breachStatus
     * @return
     */
    public List<InvigilateListProgressExcelBean> invigilatePageProgressListExport(@Param("examId") Long examId,
                                                                                  @Param("examActivityId") Long examActivityId,
                                                                                  @Param("roomCode") String roomCode,
                                                                                  @Param("courseCode") String courseCode,
                                                                                  @Param("name") String name,
                                                                                  @Param("identity") String identity,
                                                                                  @Param("status") Integer status,
                                                                                  @Param("userId") Long userId,
                                                                                  @Param("orgId") Long orgId,
                                                                                  @Param("breachStatus") Integer breachStatus);

    /**
     * 监考明细管理列表
     *
     * @param iPage
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param courseCode
     * @param status
     * @param breachStatus
     * @param finishType
     * @param name
     * @param identity
     * @param minMultipleFaceCount
     * @param maxMultipleFaceCount
     * @param minExceptionCount
     * @param maxExceptionCount
     * @param minWarningCount
     * @param maxWarningCount
     * @param userId
     * @param orgId
     * @return
     */
    public IPage<InvigilateListHistoryBean> invigilatePageListHistory(IPage<Map> iPage, @Param("examId") Long examId,
                                                                      @Param("examActivityId") Long examActivityId,
                                                                      @Param("roomCode") String roomCode,
                                                                      @Param("courseCode") String courseCode,
                                                                      @Param("status") String status,
                                                                      @Param("breachStatus") Integer breachStatus,
                                                                      @Param("finishType") String finishType,
                                                                      @Param("name") String name,
                                                                      @Param("identity") String identity,
                                                                      @Param("minMultipleFaceCount") Integer minMultipleFaceCount,
                                                                      @Param("maxMultipleFaceCount") Integer maxMultipleFaceCount,
                                                                      @Param("minExceptionCount") Integer minExceptionCount,
                                                                      @Param("maxExceptionCount") Integer maxExceptionCount,
                                                                      @Param("minWarningCount") Integer minWarningCount,
                                                                      @Param("maxWarningCount") Integer maxWarningCount,
                                                                      @Param("userId") Long userId,
                                                                      @Param("orgId") Long orgId);

    /**
     * 监考明细管理列表导出
     *
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param courseCode
     * @param status
     * @param breachStatus
     * @param finishType
     * @param name
     * @param identity
     * @param minMultipleFaceCount
     * @param maxMultipleFaceCount
     * @param minExceptionCount
     * @param maxExceptionCount
     * @param minWarningCount
     * @param maxWarningCount
     * @param userId
     * @param orgId
     * @return
     */
    public List<InvigilateListHistoryBean> invigilatePageListHistoryExport(Long examId,
                                                                           Long examActivityId,
                                                                           String roomCode,
                                                                           String courseCode,
                                                                           String status,
                                                                           Integer breachStatus,
                                                                           String finishType,
                                                                           String name,
                                                                           String identity,
                                                                           Integer minMultipleFaceCount,
                                                                           Integer maxMultipleFaceCount,
                                                                           Integer minExceptionCount,
                                                                           Integer maxExceptionCount,
                                                                           Integer minWarningCount,
                                                                           Integer maxWarningCount,
                                                                           Long userId,
                                                                           Long orgId);

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

    public Long getCountByExamId(@Param("examId") Long examId);

    public List<TOeExamRecord> getListByExamIdAndStartId(@Param("examId") Long examId, @Param("startId") Long startId);

    public void updateObjectiveScore(@Param("recordId") Long recordId, @Param("score") Double score);

    public TOeExamRecord findOneByPaperId(@Param("paperId") Long paperId);

    /**
     * 在线巡考报表接口
     *
     * @param examId
     * @param userId
     * @return
     */
    public List<InvigilateListPatrolReportBean> patrolReport(@Param("orgId") Long orgId, @Param("examId") Long examId, @Param("userId") Long userId);

    public TOeExamRecord findOneByExamId(@Param("examId") Long examId, @Param("status") String status);

    /**
     * 在线人数
     *
     * @param orgId
     * @return
     */
    public Long getOnlineCount(@Param("orgId") Long orgId);

    /**
     * 异常总数
     *
     * @param orgId
     * @return
     */
    public Long getExceptionCount(@Param("orgId") Long orgId);

    /**
     * 预警总数
     *
     * @param orgId
     * @return
     */
    public Long getWarnCount(@Param("orgId") Long orgId);

    /**
     * 违纪总数
     *
     * @param orgId
     * @return
     */
    public Long getBreachCount(@Param("orgId") Long orgId);

    /**
     * 预警类型排行
     *
     * @param orgId
     * @return
     */
    public List<ExaminationMonitorWarnDistributionBean> getWarnDistribution(@Param("orgId") Long orgId);

    /**
     * 预警地区排行
     *
     * @param orgId
     * @return
     */
    public List<ExaminationMonitorWarnRegionDistributionBean> getWarnRegionDistribution(@Param("orgId") Long orgId);

    /**
     * 地图数据
     *
     * @param orgId
     * @return
     */
    public List<ExaminationMonitorMapBean> getMap(@Param("orgId") Long orgId);

    /**
     * 获取预警数据
     *
     * @param orgId
     * @param timeData
     * @param currentTime
     * @param interval
     * @param minusTime
     * @return
     */
    public List<TimeScaleDataResult> getWarnTrend(@Param("orgId") Long orgId, @Param("timeData") List<String> timeData, @Param("currentTime") Long currentTime, @Param("interval") Integer interval, @Param("minusTime") Long minusTime);

    public void updateHasAnswerFile(@Param("recordId") Long recordId, @Param("hasAnswerFile") Integer hasAnswerFile);

    public List<OpenRecordNeedMarkBean> findExamRecordNeedMark(@Param("examStudentId") Long examStudentId);

    /**
     * 寻找客观分最高
     *
     * @param examId
     * @param examStudentId
     * @return
     */
    public List<TOeExamRecord> findMaxObjectiveScore(@Param("examId") Long examId, @Param("examStudentId") Long examStudentId, @Param("examStudentBreachPush") Boolean examStudentBreachPush);

    /**
     * 根据orgId查找 在线人数/已待考/考试人数
     *
     * @param orgId
     * @return
     */
    List<Long> findByOrgId(@Param("orgId") Long orgId);

    /**
     * 查找监控消息
     *
     * @param examId
     * @param roomCodeSet
     * @return
     */
    List<CountStopBean> findByStopInfo(@Param("examId") Long examId, @Param("roomCodeSet") Set<String> roomCodeSet, @Param("examActivityId") Long examActivityId);

    /**
     * 查找在线消息
     *
     * @param examId
     * @param roomCodeSet
     * @param examActivityId
     * @return
     */
    List<Integer> findByOnlineInfo(@Param("examId") Long examId, @Param("roomCodeSet") Set<String> roomCodeSet, @Param("examActivityId") Long examActivityId);

    /**
     * 管理员报表
     *
     * @param orgId
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param courseCode
     * @return
     */
    List<Integer> findByViewAdmin(@Param("orgId") Long orgId, @Param("examId") Long examId, @Param("examActivityId") Long examActivityId, @Param("roomCode") String roomCode, @Param("courseCode") String courseCode, @Param("monitorStatus") String monitorStatus);

    /**
     * 考试明细查询接口
     *
     * @param iPage
     * @param examId
     * @param examActivityId
     * @param courseCode
     * @param roomCode
     * @param finishType
     * @param name
     * @param identity
     * @return
     */
    public IPage<ExamRecordDetailBean> examRecordDetailQuery(IPage<Map> iPage,
                                                             @Param("examId") Long examId,
                                                             @Param("examActivityId") Long examActivityId,
                                                             @Param("courseCode") String courseCode,
                                                             @Param("roomCode") String roomCode,
                                                             @Param("finishType") String finishType,
                                                             @Param("name") String name,
                                                             @Param("identity") String identity);

    /**
     * 考试明细查询接口
     *
     * @param examId
     * @param courseCodeList
     * @param identityList
     * @return
     */
    public List<String> examRecordDetailListQuery(@Param("examId") Long examId, @Param("courseCodeList") List<String> courseCodeList, @Param("identityList") List<String> identityList);

    /**
     * 获取时间尺度
     *
     * @param timeSize
     * @param currentDate
     * @return
     */
    @SuppressWarnings("MybatisXMapperMethodInspection")
    public Map<String, String> getTimeScale(@Param("timeSize") List<Integer> timeSize, @Param("currentDate") String currentDate);

    /**
     * 获取时间尺度数据
     *
     * @param orgId
     * @param timeData
     * @param currentTime
     * @param minusTime
     * @return
     */
    public List<TimeOnlineDataResult> getTimeOnlineData(@Param("orgId") Long orgId, @Param("timeData") List<String> timeData, @Param("currentTime") Long currentTime, @Param("minusTime") Long minusTime);

    /**
     * 查询没有视频地址的考试记录
     *
     * @param examId
     * @return
     */
    public List<TOeExamRecord> findExamRecordByNotVideoUrl(@Param("examId") Long examId);

    /**
     * 根据考试批次id和场次id查找考试数据
     *
     * @param examId
     * @param examActivityId
     * @return
     */
    public List<TOeExamRecord> findExamRecordByExamIdAndExamActivityId(@Param("examId") Long examId, @Param("examActivityId") Long examActivityId);

    /**
     * 根据考试批次id或考试场次id查找
     *
     * @param examId
     * @param examActivityId
     * @return
     */
    public Integer findByExamIdOrExamActivityIdCount(@Param("examId") Long examId, @Param("examActivityId") Long examActivityId);

    /**
     * 获取所有待阅卷的考试记录
     *
     * @param examId
     * @param examPaperIdSet
     * @param many
     * @param examStudentBreachPush
     * @return
     */
    public List<TOeExamRecord> findExamRecordNeedMarkAll(@Param("examId") Long examId, @Param("examPaperIdSet") Set<Long> examPaperIdSet, @Param("many") Boolean many, @Param("examStudentBreachPush") Boolean examStudentBreachPush);

    /**
     * 修正作答记录缓存到数据库
     *
     * @param examId
     * @param examActivityId
     * @param status
     * @return
     */
    public List<TOeExamRecord> persistedAnswerBatch(@Param("examId") Long examId, @Param("examActivityId") Long examActivityId, @Param("status") String status);

    /**
     * 清除考试缓存
     *
     * @param examIds
     * @return
     */
    @SuppressWarnings("MybatisXMapperMethodInspection")
    public List<Map> cleanExamFirstPrepareCache(@Param("examIds") Set<Long> examIds);

//    /**
//     * 数据统计
//     *
//     * @return
//     */
//    List<Long> dataCount();

//    /**
//     * 机构数据统计
//     *
//     * @return
//     */
//    List<OrgDataCountBean> orgDataCount();

//    /**
//     * 地图数据统计
//     *
//     * @return
//     */
//    List<MapDataCountBean> mapDataCount();

    /**
     * 根据id更新预警数量
     *
     * @param id
     */
    void updateWarningCount(@Param("id") Long id);

    /**
     * 更新预警未读数
     *
     * @param id
     * @param number
     */
    void updateWarningUnread(@Param("id") Long id, @Param("number") Integer number);

    /**
     * 根据预警条件清除未阅
     *
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @param name
     * @param identity
     * @param minMultipleFaceCount
     * @param maxMultipleFaceCount
     * @param minExceptionCount
     * @param maxExceptionCount
     * @param minWarningCount
     * @param maxWarningCount
     * @param userId
     * @param orgId
     * @return
     */
    List<TOeExamRecord> findExamRecordByWarning(@Param("examId") Long examId,
                                                @Param("examActivityId") Long examActivityId,
                                                @Param("roomCode") String roomCode,
                                                @Param("name") String name,
                                                @Param("identity") String identity,
                                                @Param("minMultipleFaceCount") Integer minMultipleFaceCount,
                                                @Param("maxMultipleFaceCount") Integer maxMultipleFaceCount,
                                                @Param("minExceptionCount") Integer minExceptionCount,
                                                @Param("maxExceptionCount") Integer maxExceptionCount,
                                                @Param("minWarningCount") Integer minWarningCount,
                                                @Param("maxWarningCount") Integer maxWarningCount,
                                                @Param("userId") Long userId,
                                                @Param("orgId") Long orgId);

    /**
     * 查找完成人数
     *
     * @param examId
     * @param examActivityId
     * @param roomCode
     * @return
     */
    Integer findExamRecordByFinish(@Param("examId") Long examId, @Param("examActivityId") Long examActivityId, @Param("roomCode") String roomCode);
}