package com.qmth.themis.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
import com.qmth.themis.business.cache.bean.ExamCacheBean;
import com.qmth.themis.business.cache.bean.ExamCourseCacheBean;
import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
import com.qmth.themis.business.constant.SpringContextHolder;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.dao.TEExamActivityMapper;
import com.qmth.themis.business.dto.MqDto;
import com.qmth.themis.business.dto.response.MonitorStreamDto;
import com.qmth.themis.business.dto.response.TEExamActivityDto;
import com.qmth.themis.business.dto.response.TEExamActivityQueryDto;
import com.qmth.themis.business.dto.response.TEExamActivityWaitDto;
import com.qmth.themis.business.entity.TBUser;
import com.qmth.themis.business.entity.TEAudio;
import com.qmth.themis.business.entity.TEExam;
import com.qmth.themis.business.entity.TEExamActivity;
import com.qmth.themis.business.enums.*;
import com.qmth.themis.business.service.*;
import com.qmth.themis.business.util.*;
import com.qmth.themis.common.enums.ExceptionResultEnum;
import com.qmth.themis.common.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description: 考试场次 服务实现类
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/6/25
 */
@Service
public class TEExamActivityServiceImpl extends ServiceImpl<TEExamActivityMapper, TEExamActivity> implements TEExamActivityService {
    private final static Logger log = LoggerFactory.getLogger(TEExamActivityServiceImpl.class);

    @Resource
    private TEExamActivityMapper teExamActivityMapper;

    @Resource
    private TEExamService teExamService;

    @Resource
    private TEExamStudentService teExamStudentService;

    @Resource
    private TEExamCourseService teExamCourseService;

    @Resource
    private MqDtoService mqDtoService;

    @Resource
    private RedisUtil redisUtil;

    @Resource
    private UidUtil uidUtil;

    @Resource
    private MqUtil mqUtil;

    @Resource
    TEAudioService teAudioService;

    @Resource
    TOeExamRecordService tOeExamRecordService;

    @Resource
    ThemisCacheService themisCacheService;

    /**
     * 表是否存在
     *
     * @param tableName
     * @param schema
     * @return
     */
    @Override
    public Integer existTable(String tableName, String schema) {
        return teExamActivityMapper.existTable(tableName, schema);
    }

    /**
     * 删除表
     *
     * @param tableName
     */
    @Override
    public void dropTable(String tableName) {
        teExamActivityMapper.dropTable(tableName);
    }

    /**
     * 创建表
     *
     * @param tableName
     */
    @Override
    public void createNewTable(String tableName) {
        teExamActivityMapper.createNewTable(tableName);
    }

    /**
     * 新插数据
     *
     * @param tableName
     * @param teExamActivity
     */
    @Override
    public void insertInfo(String tableName, TEExamActivity teExamActivity) {
        teExamActivityMapper.insertInfo(tableName, teExamActivity);
    }

    /**
     * 查询所有数据
     *
     * @param iPage
     * @param tableName
     * @return
     */
    @Override
    public IPage<TEExamActivity> selectListPage(IPage<Map> iPage, String tableName) {
        return teExamActivityMapper.selectListPage(iPage, tableName);
    }

    /**
     * 查询考场场次信息
     *
     * @param iPage
     * @param examId
     * @param code
     * @param startDate
     * @param finishDate
     * @return
     */
    @Override
    public IPage<TEExamActivityQueryDto> examActivityQuery(IPage<Map> iPage, Long id, Long examId, String code, Long startDate, Long finishDate) {
        return teExamActivityMapper.examActivityQuery(iPage, id, examId, code, startDate, finishDate);
    }

    /**
     * 获取考试待考列表
     *
     * @param studentId
     * @param examActivityIds
     * @return
     */
    @Override
    public List<TEExamActivityWaitDto> getWaitingExam(Long studentId, Set<Long> examActivityIds, Long orgId) {
        return teExamActivityMapper.getWaitingExam(studentId, examActivityIds, orgId);
    }

    /**
     * 获取考试待考列表
     *
     * @param examActivityId
     * @param examStudentId
     * @param courseCode
     * @param prefix
     * @return
     */
    @Override
    public TEExamActivityDto getWaitingExam(Long examActivityId, Long examStudentId, String courseCode, String prefix, Long recordId) {
        TEExamActivityDto teExamActivityDto = teExamActivityMapper.getWaitingExamByExamActivityId(examActivityId);
        ExamCacheBean examCache = teExamService.getExamCacheBean(teExamActivityDto.getExamId());
        ExamStudentCacheBean examStudentCacheBean = teExamStudentService
                .getExamStudentCacheBean(examStudentId);
        teExamActivityDto.setLeftExamCount(
                (examCache.getExamCount().intValue() - (examStudentCacheBean.getAlreadyExamCount().intValue())
                        < 0 ?
                        0 :
                        examCache.getExamCount().intValue() - (examStudentCacheBean.getAlreadyExamCount()
                                .intValue())));
        if (Objects.nonNull(teExamActivityDto.getInProcessLivenessFixedRangeStr())) {
            String[] longs = teExamActivityDto.getInProcessLivenessFixedRangeStr().trim().replaceAll(" ", "").split(",");
            List inProcessLivenessFixedRange = new ArrayList();
            for (int i = 0; i < longs.length; i++) {
                Integer integer = Integer.valueOf(longs[i].trim());
                inProcessLivenessFixedRange.add(integer);
            }
            if (Objects.equals(inProcessLivenessFixedRange.toString().trim().replaceAll(" ", ""), "")) {
                teExamActivityDto.setInProcessLivenessFixedRange(null);
            } else {
                teExamActivityDto.setInProcessLivenessFixedRange(inProcessLivenessFixedRange);
            }
        }
        //取course缓存
        ExamCourseCacheBean examCourseCacheBean = teExamCourseService
                .getExamCourseCacheBean(teExamActivityDto.getExamId(), courseCode);
        if (Objects.nonNull(examCourseCacheBean) && Objects.nonNull(examCourseCacheBean.getMobilePhotoUpload())) {
            teExamActivityDto.setMobilePhotoUpload(examCourseCacheBean.getMobilePhotoUpload());
        }
        if (Objects.nonNull(teExamActivityDto.getMonitorVideoSourceStr()) && !Objects
                .equals(teExamActivityDto.getMonitorVideoSourceStr().toString().trim().replaceAll(" ", ""), "")) {
            Map<String, String> monitorRecordMap = null;
            if (Objects.nonNull(teExamActivityDto.getMonitorRecordStr()) && !Objects.equals(teExamActivityDto.getMonitorRecordStr().trim().replaceAll(" ", ""), "")) {
                List<String> monitorRecordList = Arrays.asList(teExamActivityDto.getMonitorRecordStr().trim().toUpperCase().split(","));
                monitorRecordMap = monitorRecordList.stream()
                        .collect(Collectors.toMap(Function.identity(), s -> s));
            }
            List<String> videoSources = Arrays.asList(teExamActivityDto.getMonitorVideoSourceStr().trim().toUpperCase().replaceAll(" ", "").split(","));
            List<MonitorStreamDto> monitorStreamDtoList = new ArrayList<>();
            Map<String, String> finalMonitorRecordMap = monitorRecordMap;
            videoSources.forEach(s -> {
                if (Objects.isNull(finalMonitorRecordMap) || finalMonitorRecordMap.size() == 0) {
                    monitorStreamDtoList.add(new MonitorStreamDto(MonitorVideoSourceEnum.valueOf(s), SystemConstant.setStreamId(prefix, recordId, MonitorVideoSourceEnum.valueOf(s)), null));
                } else {
                    String monitorRecordStr = finalMonitorRecordMap.get(s);
                    monitorStreamDtoList.add(new MonitorStreamDto(MonitorVideoSourceEnum.valueOf(s), SystemConstant.setStreamId(prefix, recordId, MonitorVideoSourceEnum.valueOf(s)), Objects.nonNull(monitorRecordStr) ? SystemConstant.setStreamId(prefix, recordId, MonitorVideoSourceEnum.valueOf(s)) : null));
                }
            });
            teExamActivityDto.setMonitorVideoSource(monitorStreamDtoList);
            teExamActivityDto.setMonitorAudioEnable(examCache.getMonitorAudioEnable());

            //加入hardwareTest逻辑
            if (teExamActivityDto.getMonitorVideoSourceStr().toUpperCase().contains(MonitorVideoSourceEnum.CLIENT_CAMERA.name())
                    || (Objects.nonNull(teExamActivityDto.getEntryAuthenticationPolicy()) && (
                    Objects.equals(teExamActivityDto.getEntryAuthenticationPolicy(),
                            EntryAuthenticationPolicyEnum.LIVENESS_VERIFY.name()) || Objects
                            .equals(teExamActivityDto.getEntryAuthenticationPolicy(),
                                    EntryAuthenticationPolicyEnum.FACE_VERIFY_FORCE.name()))) || (
                    Objects.nonNull(teExamActivityDto.getCameraPhotoUpload()) && teExamActivityDto.getCameraPhotoUpload() == 1)
                    || Objects.nonNull(teExamActivityDto.getInProcessFaceVerify()) && teExamActivityDto.getInProcessFaceVerify() == 1
                    || Objects.nonNull(teExamActivityDto.getInProcessLivenessVerify()) && teExamActivityDto.getInProcessLivenessVerify() == 1) {
                List<String> hardwareTest = teExamActivityDto.getHardwareTest();
                if (Objects.isNull(hardwareTest)) {
                    hardwareTest = new ArrayList<>();
                }
                hardwareTest.add(HardwareTestEnum.CAMERA.name());
                if ((Objects.nonNull(examCourseCacheBean) && Objects.nonNull(examCourseCacheBean.getHasAudio())
                        && examCourseCacheBean.getHasAudio() == 1)
                        || teExamActivityDto.getMonitorVideoSourceStr().toUpperCase().contains(MonitorVideoSourceEnum.CLIENT_CAMERA.name())) {
                    hardwareTest.add(HardwareTestEnum.AUDIOPLAY.name());
                }
                teExamActivityDto.setHardwareTest(hardwareTest);
            }
        } else if ((Objects.nonNull(teExamActivityDto.getEntryAuthenticationPolicy()) && (
                Objects.equals(teExamActivityDto.getEntryAuthenticationPolicy(),
                        EntryAuthenticationPolicyEnum.LIVENESS_VERIFY.name()) || Objects
                        .equals(teExamActivityDto.getEntryAuthenticationPolicy(),
                                EntryAuthenticationPolicyEnum.FACE_VERIFY_FORCE.name()))) || (
                Objects.nonNull(teExamActivityDto.getCameraPhotoUpload()) && teExamActivityDto.getCameraPhotoUpload() == 1)
                || Objects.nonNull(teExamActivityDto.getInProcessFaceVerify()) && teExamActivityDto.getInProcessFaceVerify() == 1
                || Objects.nonNull(teExamActivityDto.getInProcessLivenessVerify()) && teExamActivityDto.getInProcessLivenessVerify() == 1) {
            List<String> hardwareTest = teExamActivityDto.getHardwareTest();
            if (Objects.isNull(hardwareTest)) {
                hardwareTest = new ArrayList<>();
            }
            hardwareTest.add(HardwareTestEnum.CAMERA.name());
            teExamActivityDto.setHardwareTest(hardwareTest);
        } else {
            teExamActivityDto.setMonitorVideoSource(null);
        }
        return teExamActivityDto;
    }

    @Cacheable(value = "exam_activity", key = "#examActivityId", unless = "#result == null")
    @Override
    public ExamActivityCacheBean getExamActivityCacheBean(Long examActivityId) {
        return cacheOperation(examActivityId);
    }

    /**
     * 更新场次缓存
     *
     * @param examActivityId
     * @return
     */
    @Override
    @CachePut(value = "exam_activity", key = "#examActivityId", condition = "#result != null")
    public ExamActivityCacheBean updateExamActivityCacheBean(Long examActivityId) {
        return cacheOperation(examActivityId);
    }

    /**
     * 删除场次缓存
     *
     * @param examActivityId
     */
    @Override
    @CacheEvict(value = "exam_activity", key = "#examActivityId")
    public void deleteExamActivityCacheBean(Long examActivityId) {

    }

    /**
     * 缓存操作
     *
     * @param examActivityId
     * @return
     */
    public ExamActivityCacheBean cacheOperation(Long examActivityId) {
        ExamActivityCacheBean ret = null;
        TEExamActivity ac = getById(examActivityId);
        if (ac == null) {
            return ret;
        }
//        if (ac.getEnable() != null && ac.getEnable().intValue() == 0) {
//            return ret;
//        }
        ret = new ExamActivityCacheBean();
        ret.setId(ac.getId());
        ret.setCode(ac.getCode());
        ret.setExamId(ac.getExamId());
        ret.setPrepareSeconds(ac.getPrepareSeconds());
        ret.setMaxDurationSeconds(ac.getMaxDurationSeconds());
        ret.setOpeningSeconds(ac.getOpeningSeconds());
        ret.setStartTime(ac.getStartTime());
        ret.setFinishTime(ac.getFinishTime());
        ret.setEnable(ac.getEnable());
        return ret;
    }

    @Override
    public List<TEExamActivity> findByExamIdAndOrgId(Long examId, Long orgId) {
        return teExamActivityMapper.findByExamIdAndOrgId(examId, orgId);
    }

    @Transactional
    @Override
    public void saveExamActivity(List<TEExamActivity> teExamActivityList) {
        if (CollectionUtils.isEmpty(teExamActivityList)) {
            throw new BusinessException(ExceptionResultEnum.EXAM_INFO_IS_NULL);
        }
        Long examId = null;
        AtomicReference<Integer> size = new AtomicReference<>(0);
        TEExamActivityService teExamActivityService = SpringContextHolder.getBean(TEExamActivityService.class);
        try {
            TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
            examId = teExamActivityList.get(0).getExamId();
            ExamCacheBean examCacheBean = teExamService.getExamCacheBean(teExamActivityList.get(0).getExamId());
            TEExam teExam = teExamService.cacheConvert(examCacheBean);
            if (Objects.nonNull(teExam.getMonitorStatus()) && Objects
                    .equals(teExam.getMonitorStatus(), InvigilateMonitorStatusEnum.FINISHED)) {
                throw new BusinessException("监考结束的考试场次不可以修改");
            }
            List<TEAudio> teAudioList = new ArrayList<>();
            teExamActivityList.forEach(s -> {
                if (Objects.nonNull(s.getId())) {
                    s.setUpdateId(tbUser.getId());
                    QueryWrapper<TEAudio> teAudioQueryWrapper = new QueryWrapper<>();
                    teAudioQueryWrapper.lambda().eq(TEAudio::getActivityId, s.getId())
                            .eq(TEAudio::getType, AudioTypeEnum.BEFORE.name())
                            .eq(TEAudio::getAudioDefault, AudioDefaultEnum.SYS.name());
                    int count = teAudioService.count(teAudioQueryWrapper);
                    if (count == 0) {
                        teAudioList.add(new TEAudio(tbUser.getOrgId(), s.getId(), SystemConstant.BEFORE_AUDIO_ATTACHMENT_ID, AudioTypeEnum.BEFORE.getTitle(), AudioTypeEnum.BEFORE, AudioDefaultEnum.SYS, tbUser.getId(), SystemConstant.BEFORE_AUDIO_SECOND, teExam, s));//开考前语音
                    }

                    teAudioQueryWrapper = new QueryWrapper<>();
                    teAudioQueryWrapper.lambda().eq(TEAudio::getActivityId, s.getId())
                            .eq(TEAudio::getType, AudioTypeEnum.AFTER.name())
                            .eq(TEAudio::getAudioDefault, AudioDefaultEnum.SYS.name());
                    count = teAudioService.count(teAudioQueryWrapper);
                    if (count == 0) {
                        teAudioList.add(new TEAudio(tbUser.getOrgId(), s.getId(), SystemConstant.AFTER_AUDIO_ATTACHMENT_ID, AudioTypeEnum.AFTER.getTitle(), AudioTypeEnum.AFTER, AudioDefaultEnum.SYS, tbUser.getId(), SystemConstant.AFTER_AUDIO_SECOND, teExam, s));//考试结束前语音
                    }
                    if (Objects.nonNull(s.getEnable()) && s.getEnable().intValue() == 0) {
                        Integer examCount = tOeExamRecordService.findByExamIdOrExamActivityIdCount(teExam.getId(), s.getId());
                        if (Objects.nonNull(examCount) && examCount.intValue() > 0) {
                            throw new BusinessException("已有考试记录不能禁用");
                        }
                    } else {
                        if (Objects.nonNull(s.getFinishTime())) {
                            TEExamActivity teExamActivityDb = teExamActivityService.getById(s.getId());
                            if (Objects.nonNull(teExamActivityDb)) {
                                s.setCode(teExamActivityDb.getCode());
                                if (s.getFinishTime().longValue() < System.currentTimeMillis()) {
                                    throw new BusinessException("修改的场次结束时间只能大于当前时间");
                                }
                                if (Objects.nonNull(teExam.getForceFinish()) && teExam.getForceFinish().intValue() == 1
                                        && s.getFinishTime().longValue() != teExamActivityDb.getFinishTime().longValue()) {
                                    //删除再新增quartz任务,发送mq消息start
                                    Map<String, Object> prop = new HashMap<>();
                                    prop.put(SystemConstant.OPER, SystemConstant.INSERT);
                                    prop.put(SystemConstant.EXAM, teExam);
                                    MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_ACTIVITY.name(),
                                            JacksonUtil.parseJson(Arrays.asList(s)), MqTagEnum.EXAM_ACTIVITY,
                                            String.valueOf(teExam.getId()), prop, tbUser.getName());
                                    mqDtoService.assembleSendAsyncOrderMsg(mqDto);
                                    //删除再新增quartz任务,发送mq消息end
                                }
                            }
                        }
                    }
                } else {
                    size.getAndSet(size.get() + 1);
                    s.setId(uidUtil.getId());
                    s.setCreateId(tbUser.getId());
                    s.setCode(String.valueOf(redisUtil.getRedisActivityCodeSequence(s.getExamId())));
                    teAudioList.add(new TEAudio(tbUser.getOrgId(), s.getId(), SystemConstant.BEFORE_AUDIO_ATTACHMENT_ID, AudioTypeEnum.BEFORE.getTitle(), AudioTypeEnum.BEFORE, AudioDefaultEnum.SYS, tbUser.getId(), SystemConstant.BEFORE_AUDIO_SECOND, teExam, s));//开考前语音
                    teAudioList.add(new TEAudio(tbUser.getOrgId(), s.getId(), SystemConstant.AFTER_AUDIO_ATTACHMENT_ID, AudioTypeEnum.AFTER.getTitle(), AudioTypeEnum.AFTER, AudioDefaultEnum.SYS, tbUser.getId(), SystemConstant.AFTER_AUDIO_SECOND, teExam, s));//考试结束前语音
                }
            });
            teExamActivityService.saveOrUpdateBatch(teExamActivityList);
            for (TEExamActivity ac : teExamActivityList) {
                teExamActivityService.updateExamActivityCacheBean(ac.getId());
                //加入更新考试列表缓存方法
                ExamActivityCacheBean examActivityCacheBean = this.getExamActivityCacheBean(ac.getId());
                if (Objects.nonNull(examActivityCacheBean.getEnable()) && examActivityCacheBean.getEnable().intValue() == 1 && Objects.nonNull(teExam.getEnable()) && teExam.getEnable().intValue() == 1 && Objects.nonNull(teExam.getEndTime()) && teExam.getEndTime().longValue() > System.currentTimeMillis()) {
                    themisCacheService.updateCurrentExamListCache(ac.getExamId().toString(), ac.getId());
                    themisCacheService.updateOrgExamListCache(teExam.getOrgId().toString(), ac.getExamId().toString(), ac.getId());
                } else {
                    themisCacheService.removeCurrentExamListCache(ac.getExamId().toString(), ac.getId());
                    themisCacheService.removeOrgExamListCache(teExam.getOrgId().toString(), ac.getExamId().toString(), ac.getId());
                }
//                //最后开考时间发送定时任务
//                //删除再新增quartz任务,发送mq消息start
//                Map<String, Object> prop = new HashMap<>();
//                prop.put(SystemConstant.OPER, SystemConstant.INSERT);
//                prop.put(SystemConstant.EXAM, teExam);
//                MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_ACTIVITY_FINAL_PREPARE_TIME.name(), JacksonUtil.parseJson(ac), MqTagEnum.EXAM_ACTIVITY_FINAL_PREPARE_TIME, String.valueOf(teExam.getId()), prop, tbUser.getName());
//                mqDtoService.assembleSendAsyncOrderMsg(mqDto);
//                //删除再新增quartz任务,发送mq消息end
            }

            if (!CollectionUtils.isEmpty(teAudioList)) {
                teAudioService.saveOrUpdateBatch(teAudioList);
//                for (TEAudio t : teAudioList) {
//                    teAudioService.sendAudioMessage(t);
//                }
            }
            if (size.get() > 0 && (Objects.nonNull(teExam.getForceFinish()) && teExam.getForceFinish().intValue() == 1)) {
                //新增quartz任务,发送mq消息start
                Map<String, Object> prop = new HashMap<>();
                prop.put(SystemConstant.OPER, SystemConstant.INSERT);
                prop.put(SystemConstant.EXAM, teExam);
                MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_ACTIVITY.name(),
                        JacksonUtil.parseJson(teExamActivityList), MqTagEnum.EXAM_ACTIVITY,
                        String.valueOf(teExam.getId()), prop, tbUser.getName());
                mqDtoService.assembleSendAsyncOrderMsg(mqDto);
                //新增quartz任务,发送mq消息end
            }
        } catch (Exception e) {
            log.error(SystemConstant.LOG_ERROR, e);
            if (Objects.nonNull(examId) && redisUtil.lock(SystemConstant.REDIS_LOCK_EXAM_ACTIVITY_CODE_PREFIX + examId, SystemConstant.REDIS_LOCK_EXAM_ACTIVITY_CODE_TIME_OUT)) {
                try {
                    Integer value = redisUtil.getRedisActivityCodeSequenceValue(examId);
                    redisUtil.setRedisActivityCodeSequence(examId, value - size.get());
                } finally {
                    redisUtil.releaseLock(SystemConstant.REDIS_LOCK_EXAM_ACTIVITY_CODE_PREFIX + examId);
                }
            }
            if (e instanceof DuplicateKeyException) {
                String errorColumn = e.getCause().toString();
                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length())
                        .replaceAll("'", "");
                throw new BusinessException(
                        "机构id[" + teExamActivityList.get(0).getExamId() + "]下的" + FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
            } else if (e instanceof BusinessException) {
                throw new BusinessException(e.getMessage());
            } else {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public List<Long> findExamIdToday() {
        try {
            Date now = new Date();
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
            String today = sdf1.format(now);
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Long start = sdf2.parse(today + " 00:00:00").getTime();
            Long end = sdf2.parse(today + " 23:59:59").getTime();
            return teExamActivityMapper.findExamIdToday(start, end);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 查找当前待考列表
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public List<TEExamActivity> findCurrentExamActivity(Long startTime, Long endTime) {
        return this.baseMapper.findCurrentExamActivity(startTime, endTime);
    }

    /**
     * 根据天数获取待考列表
     *
     * @param day
     * @return
     */
    @Override
    public List<TEExamActivity> findWaitingExamList(Integer day) {
        return this.baseMapper.findWaitingExamList(day);
    }
}
