package com.qmth.themis.business.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qmth.themis.business.bean.admin.OpenExamBean;
import com.qmth.themis.business.bean.exam.*;
import com.qmth.themis.business.bean.result.VideoQueryResult;
import com.qmth.themis.business.cache.bean.ExamCacheBean;
import com.qmth.themis.business.dto.MqDto;
import com.qmth.themis.business.dto.response.TEExamQueryDto;
import com.qmth.themis.business.dto.response.TEExamWaitDto;
import com.qmth.themis.business.entity.TEExam;
import com.qmth.themis.business.enums.InvigilateMonitorStatusEnum;
import com.qmth.themis.business.enums.ScoreStatusEnum;
import com.qmth.themis.business.enums.SystemOperationEnum;
import com.qmth.themis.business.enums.VideoTypeEnum;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * @Description: 考试批次 服务类
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/6/25
 */
public interface TEExamService extends IService<TEExam> {

    /**
     * 查询考试批次
     *
     * @param iPage
     * @param userId
     * @param id
     * @param code
     * @param name
     * @param mode
     * @param enable
     * @param orgId
     * @param type
     * @param finished
     * @return
     */
    public IPage<TEExamQueryDto> examQuery(IPage<Map> iPage, Long userId, Long id, String code, String name, String mode, Integer enable, Long orgId, String type, Boolean finished);

    /**
     * 根据考试批次编码查询考场接口
     *
     * @param code
     * @return
     */
    public List<Map> examroomQuery(String code);

    /**
     * 获取考试待考列表
     *
     * @param studentId
     * @param examId
     * @param orgId
     * @return
     */
    public List<TEExamWaitDto> getWaitingExam(Long studentId, Long examId, Long orgId);

    /**
     * 开始候考
     *
     * @param studentId
     * @param examStudentId
     * @return
     */
    public ExamPrepareBean prepare(Long studentId, Long examStudentId);

    /**
     * 开始考试
     *
     * @param studentId
     * @param recordId
     * @return
     */
    public ExamStartBean start(Long studentId, Long recordId);

    /**
     * 上传个人试卷结构
     *
     * @param studentId
     * @param recordId
     * @param content
     * @return
     */
    public StudentPaperStructBean studentPaperStruct(Long studentId, Long recordId, String content);

    /**
     * 提交作答结果
     *
     * @param studentId
     * @param recordId
     * @param mainNumber
     * @param subNumber
     * @param subIndex
     * @param answer
     * @param version
     * @param durationSeconds
     * @return
     */
    public AnswerSubmitBean answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber, Integer subIndex,
                                         String answer, Long version, Integer durationSeconds);

    /**
     * 更新音频剩余播放次数
     *
     * @param studentId
     * @param recordId
     * @param key
     * @param count
     * @return
     */
    public AudioLeftPlayCountSubmitBean audioLeftPlayCountSubmit(Long studentId, Long recordId, String key, Integer count);


    /**
     * 文件上传
     *
     * @param studentId
     * @param recordId
     * @param file
     * @param suffix
     * @param md5
     * @return
     */
    public ExamFileUploadBean fileUpload(Long studentId, Long recordId, MultipartFile file, String suffix, String md5);

    /**
     * 断点恢复
     *
     * @param studentId
     * @param recordId
     * @return
     */
    public ExamResumeBean resume(Long studentId, Long recordId);

    /**
     * 结束考试
     *
     * @param studentId
     * @param recordId
     * @param type
     * @param durationSeconds
     * @return
     */
    public ExamFinishBean finish(Long studentId, Long recordId, String type, Integer durationSeconds);

    ExamCacheBean getExamCacheBean(Long examId);

    /**
     * 更新批次缓存
     *
     * @param examId
     * @return
     */
    ExamCacheBean updateExamCacheBean(Long examId);

    /**
     * 删除批次缓存
     *
     * @param examId
     */
    void deleteExamCacheBean(Long examId);

    /**
     * 查询交卷结果
     *
     * @param recordId
     * @return
     */
    public ExamResultBean result(Long recordId);

    /**
     * 试卷下载
     *
     * @param recordId
     * @return
     */
    public ExamPaperDownloadBean paperDownload(Long recordId);

    /**
     * 监考端获取考试批次列表
     *
     * @param userId
     * @param orgId
     * @return
     */
    public List<Map> examList(Long userId, Long orgId);

    /**
     * 发送考试轨迹消息
     *
     * @param systemOperationEnum
     * @param examStudentId
     * @param recordId
     * @param mqDto
     */
    public void sendOeLogMessage(SystemOperationEnum systemOperationEnum, Long examStudentId, Long recordId, MqDto mqDto);

    /**
     * 考试批次权限过滤
     *
     * @param userId
     * @param orgId
     * @param type
     * @return
     */
    public List<TEExam> examPrivilegeQuery(Long userId, Long orgId, String type);

    /**
     * 重新算分
     *
     * @param examId
     * @param taskId
     */
    void calculateScore(Long examId, Long taskId);

    void updateInvigilateMonitorStatus(InvigilateMonitorStatusEnum monitorStatus, Long examId);

    void updateScoreStatus(ScoreStatusEnum scoreStatus, Long examId);

    public IPage<OpenExamBean> examQueryForOpen(Page<OpenExamBean> ipage, Long examId, String examCode);

    /**
     * 缓存转换
     *
     * @param examCacheBean
     * @return
     */
    public TEExam cacheConvert(ExamCacheBean examCacheBean);

    /**
     * 视频存储查询接口
     *
     * @param iPage
     * @param examName
     * @param orgName
     * @param type
     * @return
     */
    public IPage<VideoQueryResult> videoQuery(IPage<Map> iPage, String examName, String orgName, VideoTypeEnum type);
}