package com.qmth.themis.business.cache;

import com.qmth.themis.business.bean.status.*;
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.constant.SpringContextHolder;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.enums.*;
import com.qmth.themis.business.service.TOeExamRecordService;
import com.qmth.themis.business.util.RedisUtil;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 考试记录缓存hash值操作
 *
 * @Description:
 * @Author: xiatian
 * @Date: 2020-07-29
 */
public class ExamRecordCacheUtil {

    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);

    public static Long getId(Long recordId) {
        return (Long) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.id.getCode());
    }

    public static Long getExamStudentId(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.exam_student_id.getCode());
    }

    public static Long getPaperId(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.paper_id.getCode());
    }

    public static void setFirstStartTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.first_start_time.getCode(),
                    date);
        }
    }

    public static void setFirstPrepareTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.first_prepare_time.getCode(),
                    date);
        }
    }

    public static void setLastPrepareTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_prepare_time.getCode(),
                    date);
        }
    }

    public static void setStatus(Long recordId, ExamRecordStatusEnum status, Long timestamp) {
        ExamStatusBean examStatusBean = getStatusBean(recordId);
        if (Objects.isNull(examStatusBean)) {
            examStatusBean = new ExamStatusBean(status, timestamp);
        } else {
            if (Objects.nonNull(examStatusBean.getTimestamp()) && examStatusBean.getTimestamp().longValue() < timestamp
                    .longValue()) {
                examStatusBean.setExamRecordStatusEnum(status);
                examStatusBean.setTimestamp(timestamp);
            }
        }
        redisUtil
                .set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.status.getCode(), examStatusBean);
    }

    public static Long getFirstStartTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.first_start_time.getCode());
    }

    public static Long getFirstPrepareTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.first_prepare_time.getCode());
    }

    public static Long getLastPrepareTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_prepare_time.getCode());
    }

    public static String getClientCurrentIp(Long recordId) {
        return (String) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_current_ip.getCode());
    }

    public static Double getAnswerProgress(Long recordId) {
        return (Double) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.answer_progress.getCode());
    }

    public static ReviewResultEnum getReviewResult(Long recordId) {
        return Objects.nonNull(redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.review_result.getCode())) ?
                ReviewResultEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                        ExamRecordFieldEnum.review_result.getCode())) :
                null;
    }

    public static ScoreStatusEnum getScoreStatus(Long recordId) {
        return Objects.nonNull(redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.score_status.getCode())) ?
                ScoreStatusEnum.valueOf((String) redisUtil
                        .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.score_status.getCode())) :
                null;
    }

    public static Integer getDurationSeconds(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.duration_seconds.getCode());
    }

    public static Double getObjectiveScore(Long recordId) {
        return (Double) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.objective_score.getCode());
    }

    public static Long getExamId(Long recordId) {
        return (Long) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.exam_id.getCode());
    }

    public static String getPaperStructPath(Long recordId) {
        return (String) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.paper_struct_path.getCode());
    }

    public static Integer getPaperStructUpload(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.paper_struct_upload.getCode());
    }

    public static Integer getSerialNumber(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.serial_number.getCode());
    }

    public static VerifyExceptionEnum getEntryAuthenticationResult(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.entry_authentication_result.getCode())) ?
                VerifyExceptionEnum.valueOf((String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                        ExamRecordFieldEnum.entry_authentication_result.getCode())) :
                null;
    }

    public static void setReviewResult(Long recordId, ReviewResultEnum reviewResultEnum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.review_result.getCode(),
                    reviewResultEnum);
        }
    }

    public static void setScoreStatus(Long recordId, ScoreStatusEnum scoreStatusEnum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.score_status.getCode(),
                    scoreStatusEnum);
        }
    }

    public static void setPaperStructPath(Long recordId, String paperStructPath) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.paper_struct_path.getCode(),
                    paperStructPath);
        }
    }

    public static void setPaperStructUpload(Long recordId, Integer paperStructUpload) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil
                    .set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.paper_struct_upload.getCode(),
                            paperStructUpload);
        }
    }

    public static void setSerialNumber(Long recordId, Integer serialNumber) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.serial_number.getCode(),
                    serialNumber);
        }
    }

    public static void setEntryAuthenticationResult(Long recordId, VerifyExceptionEnum entryAuthenticationResult) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.entry_authentication_result.getCode(), entryAuthenticationResult);
        }
    }

    public static void setObjectiveScore(Long recordId, Double objectiveScore) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.objective_score.getCode(),
                    objectiveScore);
        }
    }

    public static void setFinishTime(Long recordId, Long finishTime) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_time.getCode(),
                    finishTime);
        }
    }

    public static Long getFinishTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_time.getCode());
    }

    public static void setDurationSeconds(Long recordId, Integer durationSeconds) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.duration_seconds.getCode(),
                    durationSeconds);
        }
    }

    public static void setFinishType(Long recordId, FinishTypeEnum finishType) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_type.getCode(),
                    finishType);
        }
    }

    public static FinishTypeEnum getFinishType(Long recordId) {
        return Objects.nonNull(
                redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_type.getCode())) ?
                FinishTypeEnum.valueOf((String) redisUtil
                        .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.finish_type.getCode())) :
                null;
    }

    public static Long getClientLastSyncTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_last_sync_time.getCode());
    }

    public static Integer getAlreadyBreakCount(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.already_break_count.getCode())) ?
                Integer.parseInt(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.already_break_count.getCode()).toString()) : null;
    }

    public static void setAlreadyBreakCount(Long recordId, Integer alreadyBreakCount) {
        Integer alreadyBreakCountCache = ExamRecordCacheUtil.getAlreadyBreakCount(recordId);
        if (Objects.isNull(alreadyBreakCountCache)) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.already_break_count.getCode(), alreadyBreakCount);
        } else {
            redisUtil.setInc(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.already_break_count.getCode(), Long.parseLong(alreadyBreakCount.toString()));
        }
    }

    private static ExamStatusBean getStatusBean(Long recordId) {
        return Objects.nonNull(
                redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.status.getCode())) ?
                (ExamStatusBean) redisUtil
                        .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.status.getCode()) :
                null;
    }

    private static BreachStatusBean getBreachStatusBean(Long recordId) {
        return Objects.nonNull(
                redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.breach_status.getCode())) ?
                (BreachStatusBean) redisUtil
                        .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.breach_status.getCode()) :
                null;
    }

    public static ExamRecordStatusEnum getStatus(Long recordId) {
        ExamStatusBean examStatusBean = getStatusBean(recordId);
        if (Objects.isNull(examStatusBean) || Objects.isNull(examStatusBean.getExamRecordStatusEnum())) {
            return null;
        } else {
            return examStatusBean.getExamRecordStatusEnum();
        }
    }

    public static Long getLastBreakId(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_break_id.getCode());
    }

    public static Long getLastBreakTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_break_time.getCode());
    }

    public static void setEntryAuthenticationId(Long recordId, Long entryAuthenticationId) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.entry_authentication_id.getCode(), entryAuthenticationId);
        }
    }

    public static Long getExamActivityId(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.exam_activity_id.getCode());
    }

    public static void setWarningCount(Long recordId, Integer warningCount) {
        Integer warningCountCache = ExamRecordCacheUtil.getWarningCount(recordId);
        if (Objects.isNull(warningCountCache)) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_count.getCode(), warningCount);
        } else {
            redisUtil.setInc(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_count.getCode(), Long.parseLong(warningCount.toString()));
        }
    }

    public static Integer getWarningCount(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_count.getCode())) ?
                Integer.parseInt(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_count.getCode()).toString()) : null;
    }

    public static void setWarningUnread(Long recordId, Integer warningUnread) {
        Integer warningUnreadCache = ExamRecordCacheUtil.getWarningUnread(recordId);
        if (Objects.isNull(warningUnreadCache)) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_unread.getCode(), warningUnread);
        } else {
            redisUtil.setInc(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_unread.getCode(), Long.parseLong(warningUnread.toString()));
        }
    }

    public static Integer getWarningUnread(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_unread.getCode())) ?
                Integer.parseInt(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_unread.getCode()).toString()) : null;
    }

    public static void setWarningMultipleFaceCount(Long recordId, Integer warningMultipleFaceCount) {
        Integer warningMultipleFaceCountCache = ExamRecordCacheUtil.getWarningMultipleFaceCount(recordId);
        if (Objects.isNull(warningMultipleFaceCountCache)) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_multiple_face_count.getCode(), warningMultipleFaceCount);
        } else {
            redisUtil.setInc(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_multiple_face_count.getCode(), Long.parseLong(warningMultipleFaceCount.toString()));
        }
    }

    public static Integer getWarningMultipleFaceCount(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_multiple_face_count.getCode())) ?
                Integer.parseInt(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.warning_multiple_face_count.getCode()).toString()) : null;
    }

    public static void setExceptionCount(Long recordId, Integer exceptionCount) {
        Integer exceptionCountCache = ExamRecordCacheUtil.getExceptionCount(recordId);
        if (Objects.isNull(exceptionCountCache)) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.exception_count.getCode(), exceptionCount);
        } else {
            redisUtil.setInc(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.exception_count.getCode(), Long.parseLong(exceptionCount.toString()));
        }
    }

    public static Integer getExceptionCount(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.exception_count.getCode())) ?
                Integer.parseInt(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.exception_count.getCode()).toString()) : null;
    }

    public static void setBreachStatus(Long recordId, Integer breachStatus, Long timestamp) {
        BreachStatusBean breachStatusBean = getBreachStatusBean(recordId);
        if (Objects.isNull(breachStatusBean)) {
            breachStatusBean = new BreachStatusBean(breachStatus, timestamp);
        } else {
            if (Objects.nonNull(breachStatusBean.getTimestamp()) && breachStatusBean.getTimestamp().longValue() < timestamp
                    .longValue()) {
                breachStatusBean.setStatus(breachStatus);
                breachStatusBean.setTimestamp(timestamp);
            }
        }
        redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.breach_status.getCode(), breachStatusBean);
    }

    public static Integer getBreachStatus(Long recordId) {
        BreachStatusBean breachStatusBean = getBreachStatusBean(recordId);
        if (Objects.isNull(breachStatusBean) || Objects.isNull(breachStatusBean.getStatus())) {
            return null;
        } else {
            return breachStatusBean.getStatus();
        }
    }

    public static void setInProcessLivenessVerifyCount(Long recordId, Integer inProcessLivenessVerifyCount) {
        Integer inProcessLivenessVerifyCountCache = ExamRecordCacheUtil.getInProcessLivenessVerifyCount(recordId);
        if (Objects.isNull(inProcessLivenessVerifyCountCache)) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.in_process_liveness_verify_count.getCode(), inProcessLivenessVerifyCount);
        } else {
            redisUtil.setInc(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.in_process_liveness_verify_count.getCode(), Long.parseLong(inProcessLivenessVerifyCount.toString()));
        }
    }

    public static Integer getInProcessLivenessVerifyCount(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.in_process_liveness_verify_count.getCode())) ?
                Integer.parseInt(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.in_process_liveness_verify_count.getCode()).toString()) : null;
    }

    public static void setMonitorKey(Long recordId, String monitorKey) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.monitor_key.getCode(),
                    monitorKey);
        }
    }

    public static String getMonitorKey(Long recordId) {
        if (Objects.isNull(redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.monitor_key.getCode()))) {
            //            setMonitorKey(recordId, String.valueOf(redisUtil.getRedisSequence()));
            setMonitorKey(recordId, String.valueOf(recordId));
        }
        return (String) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.monitor_key.getCode());
    }

    public static MonitorStatusSourceEnum getMonitorStatus(Long recordId, MonitorVideoSourceEnum source) {
        MonitorStatusBean monitorStatusBean = getMonitorStatusBean(recordId, source);
        if (Objects.isNull(monitorStatusBean)) {
            return null;
        } else {
            return monitorStatusBean.getMonitorStatusSourceEnum();
        }
    }

    public static MonitorStatusBean getMonitorStatusBean(Long recordId, MonitorVideoSourceEnum source) {
        return Objects.nonNull(redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_STATUS_ + source.name())) ?
                (MonitorStatusBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                        SystemConstant.MONITOR_STATUS_ + source.name()) :
                null;
    }

    public static void setMonitorStatus(Long recordId, MonitorVideoSourceEnum source,
                                        MonitorStatusSourceEnum statusSourceEnum, Long timestamp) {
        MonitorStatusBean monitorStatusBean = getMonitorStatusBean(recordId, source);
        if (Objects.isNull(monitorStatusBean)) {
            monitorStatusBean = new MonitorStatusBean(statusSourceEnum, timestamp);
        } else {
            if (Objects.nonNull(monitorStatusBean.getTimestamp())
                    && monitorStatusBean.getTimestamp().longValue() < timestamp.longValue()) {
                monitorStatusBean.setMonitorStatusSourceEnum(statusSourceEnum);
                monitorStatusBean.setTimestamp(timestamp);
            }
        }
        if (Objects.nonNull(getStatus(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), SystemConstant.MONITOR_STATUS_ + source.name(),
                    monitorStatusBean);
        }
    }

    public static MonitorCallStatusSourceEnum getMonitorCallStatus(Long recordId, MonitorVideoSourceEnum source) {
        MonitorCallStatusBean monitorCallStatusBean = getMonitorCallStatusBean(recordId, source);
        if (Objects.isNull(monitorCallStatusBean)) {
            return null;
        } else {
            return monitorCallStatusBean.getMonitorCallStatusSourceEnum();
        }
    }

    private static MonitorCallStatusBean getMonitorCallStatusBean(Long recordId, MonitorVideoSourceEnum source) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                SystemConstant.MONITOR_CALL_STATUS_ + source.name())) ?
                (MonitorCallStatusBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                        SystemConstant.MONITOR_CALL_STATUS_ + source.name()) :
                null;
    }

    public static void setMonitorCallStatus(Long recordId, MonitorVideoSourceEnum source,
                                            MonitorCallStatusSourceEnum callStatusSourceEnum, Long timestamp) {
        MonitorCallStatusBean monitorCallStatusBean = getMonitorCallStatusBean(recordId, source);
        if (Objects.isNull(monitorCallStatusBean)) {
            monitorCallStatusBean = new MonitorCallStatusBean(callStatusSourceEnum, timestamp);
        } else {
            if (Objects.nonNull(monitorCallStatusBean.getTimestamp())
                    && monitorCallStatusBean.getTimestamp().longValue() < timestamp.longValue()) {
                monitorCallStatusBean.setMonitorCallStatusSourceEnum(callStatusSourceEnum);
                monitorCallStatusBean.setTimestamp(timestamp);
            }
        }
        if (Objects.nonNull(getStatus(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    SystemConstant.MONITOR_CALL_STATUS_ + source.name(), monitorCallStatusBean);
        }
    }

    private static MobileWebsocketStatusBean getMobileFirstWebsocketStatusBean(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.mobile_first_websocket_status.getCode())) ?
                (MobileWebsocketStatusBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                        ExamRecordFieldEnum.mobile_first_websocket_status.getCode()) :
                null;
    }

    public static WebsocketStatusEnum getMobileFirstWebsocketStatus(Long recordId) {
        MobileWebsocketStatusBean mobileFirstWebsocketStatusBean = getMobileFirstWebsocketStatusBean(recordId);
        if (Objects.isNull(mobileFirstWebsocketStatusBean)) {
            return null;
        } else {
            return mobileFirstWebsocketStatusBean.getWebsocketStatusEnum();
        }
    }

    public static MobileWebsocketStatusBean getMobileSecondWebsocketStatusBean(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.mobile_second_websocket_status.getCode())) ?
                (MobileWebsocketStatusBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                        ExamRecordFieldEnum.mobile_second_websocket_status.getCode()) :
                null;
    }

    public static WebsocketStatusEnum getMobileSecondWebsocketStatus(Long recordId) {
        MobileWebsocketStatusBean mobileSecondWebsocketStatusBean = getMobileSecondWebsocketStatusBean(recordId);
        if (Objects.isNull(mobileSecondWebsocketStatusBean)) {
            return null;
        } else {
            return mobileSecondWebsocketStatusBean.getWebsocketStatusEnum();
        }
    }

    private static ClientWebsocketStatusBean getClientWebsocketStatusBean(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.client_websocket_status.getCode())) ?
                (ClientWebsocketStatusBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                        ExamRecordFieldEnum.client_websocket_status.getCode()) :
                null;
    }

    public static WebsocketStatusEnum getClientWebsocketStatus(Long recordId) {
        ClientWebsocketStatusBean clientWebsocketStatusBean = getClientWebsocketStatusBean(recordId);
        if (Objects.isNull(clientWebsocketStatusBean)) {
            return null;
        } else {
            return clientWebsocketStatusBean.getWebsocketStatusEnum();
        }
    }

    public static String getClientWebsocketId(Long recordId) {
        return (String) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_websocket_id.getCode());
    }

    public static String getMobileWebsocketId(Long recordId, MonitorVideoSourceEnum source) {
        if (MonitorVideoSourceEnum.MOBILE_FIRST.equals(source)) {
            return getMobileFirstWebsocketId(recordId);
        }
        if (MonitorVideoSourceEnum.MOBILE_SECOND.equals(source)) {
            return getMobileSecondWebsocketId(recordId);
        }
        return null;
    }

    public static String getMobileFirstWebsocketId(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.mobile_first_websocket_id.getCode());
    }

    public static String getMobileSecondWebsocketId(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.mobile_second_websocket_id.getCode());
    }

    public static void setClientWebsocketStatus(Long recordId, WebsocketStatusEnum websocketStatusEnum,
                                                Long timestamp) {
        ClientWebsocketStatusBean clientWebsocketStatusBean = getClientWebsocketStatusBean(recordId);
        if (Objects.isNull(clientWebsocketStatusBean)) {
            clientWebsocketStatusBean = new ClientWebsocketStatusBean(websocketStatusEnum, timestamp);
        } else {
            if (Objects.nonNull(clientWebsocketStatusBean.getTimestamp())
                    && clientWebsocketStatusBean.getTimestamp().longValue() < timestamp.longValue()) {
                clientWebsocketStatusBean.setWebsocketStatusEnum(websocketStatusEnum);
                clientWebsocketStatusBean.setTimestamp(timestamp);
            }
        }
        if (Objects.nonNull(getStatus(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.client_websocket_status.getCode(), clientWebsocketStatusBean);
        }
    }

    public static void setClientCurrentIp(Long recordId, String ip) {
        if (Objects.nonNull(getId(recordId)) && (Objects.nonNull(ip) && !Objects.equals(ip.trim(), "") && !Objects.equals(ip.trim(), "0:0:0:0:0:0:0:1") && !Objects.equals(ip.trim(), "127.0.0.1")
                && !Objects.equals(ip.trim(), "localhost"))) {
//            String historyIp = getClientCurrentIp(recordId);
//            if (Objects.nonNull(historyIp) && !Objects.equals(historyIp.trim(), "") && !Objects.equals(historyIp.trim(), ip.trim())) {
//                Long examId = getExamId(recordId);
//                Long examActivityId = getExamActivityId(recordId);
//                Long examStudentId = getExamStudentId(recordId);
//                TIeInvigilateWarnInfoService tIeInvigilateWarnInfoService = SpringContextHolder.getBean(TIeInvigilateWarnInfoService.class);
//                //ip不同则发生预警
//                TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, VerifyExceptionEnum.IP_CHANGE_ERROR.getLevel().get(0), VerifyExceptionEnum.IP_CHANGE_ERROR.getTitle(), VerifyExceptionEnum.IP_CHANGE_ERROR, 1);
//                tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
//            }
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_current_ip.getCode(),
                    ip.trim());
        }
    }

    public static void setClientWebsocketId(Long recordId, String id) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil
                    .set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.client_websocket_id.getCode(),
                            id);
        }
    }

    public static void setMobileFirstWebsocketId(Long recordId, String id) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.mobile_first_websocket_id.getCode(), id);
        }
    }

    public static void setMobileSecondWebsocketId(Long recordId, String id) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.mobile_second_websocket_id.getCode(), id);
        }
    }

    public static void setMobileWebsocketStatus(Long record, MonitorVideoSourceEnum source, WebsocketStatusEnum status,
                                                Long timestamp) {
        if (MonitorVideoSourceEnum.MOBILE_FIRST.equals(source)) {
            setMobileFirstWebsocketStatus(record, status, timestamp);
        } else if (MonitorVideoSourceEnum.MOBILE_SECOND.equals(source)) {
            setMobileSecondWebsocketStatus(record, status, timestamp);
        }
    }

    public static void setMobileFirstWebsocketStatus(Long recordId, WebsocketStatusEnum websocketStatusEnum,
                                                     Long timestamp) {
        MobileWebsocketStatusBean mobileFirstWebsocketStatusBean = getMobileFirstWebsocketStatusBean(recordId);
        if (Objects.isNull(mobileFirstWebsocketStatusBean)) {
            mobileFirstWebsocketStatusBean = new MobileWebsocketStatusBean(websocketStatusEnum, timestamp);
        } else {
            if (Objects.nonNull(mobileFirstWebsocketStatusBean.getTimestamp())
                    && mobileFirstWebsocketStatusBean.getTimestamp().longValue() < timestamp.longValue()) {
                mobileFirstWebsocketStatusBean.setWebsocketStatusEnum(websocketStatusEnum);
                mobileFirstWebsocketStatusBean.setTimestamp(timestamp);
            }
        }
        if (Objects.nonNull(getStatus(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.mobile_first_websocket_status.getCode(), mobileFirstWebsocketStatusBean);
        }
    }

    public static void setMobileSecondWebsocketStatus(Long recordId, WebsocketStatusEnum websocketStatusEnum,
                                                      Long timestamp) {
        MobileWebsocketStatusBean mobileSecondWebsocketStatusBean = getMobileSecondWebsocketStatusBean(recordId);
        if (Objects.isNull(mobileSecondWebsocketStatusBean)) {
            mobileSecondWebsocketStatusBean = new MobileWebsocketStatusBean(websocketStatusEnum, timestamp);
        } else {
            if (Objects.nonNull(mobileSecondWebsocketStatusBean.getTimestamp())
                    && mobileSecondWebsocketStatusBean.getTimestamp().longValue() < timestamp.longValue()) {
                mobileSecondWebsocketStatusBean.setWebsocketStatusEnum(websocketStatusEnum);
                mobileSecondWebsocketStatusBean.setTimestamp(timestamp);
            }
        }
        if (Objects.nonNull(getStatus(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.mobile_second_websocket_status.getCode(), mobileSecondWebsocketStatusBean);
        }
    }

    public static void setClientLastSyncTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.client_last_sync_time.getCode(), date);
        }
    }

    public static void setPaperDownload(Long recordId, Integer paperDownload) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.paper_download.getCode(),
                    paperDownload);
        }
    }

    public static void setAnswerProgress(Long recordId, Double progress) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.answer_progress.getCode(),
                    progress);
        }
    }

    public static void setLastBreakId(Long recordId, Long breakId) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_break_id.getCode(),
                    breakId);
        }
    }

    public static void setLastBreakTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_break_time.getCode(),
                    date);
        }
    }

    public static void setLastStartTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_start_time.getCode(),
                    date);
        }
    }

    public static Long getLastStartTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.last_start_time.getCode());
    }

    public static Integer getPaperDownload(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.paper_download.getCode());
    }

    public static Long getStartTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.start_time.getCode());
    }

    public static Long getEndTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.end_time.getCode());
    }

    public static Integer getOpeningSeconds(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.opening_seconds.getCode());
    }

    public static Integer getMinDurationSeconds(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.min_duration_seconds.getCode());
    }

    public static Integer getMaxDurationSeconds(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.max_duration_seconds.getCode());
    }

    public static Integer getForceFinish(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.force_finish.getCode());
    }

    public static void setStartTime(Long recordId, Long startTime) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.start_time.getCode(),
                    startTime);
        }
    }

    public static void setEndTime(Long recordId, Long endTime) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.end_time.getCode(), endTime);
        }
    }

    public static void setOpeningSeconds(Long recordId, Integer openingSeconds) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.opening_seconds.getCode(),
                    openingSeconds);
        }
    }

    public static void setMinDurationSeconds(Long recordId, Integer minDurationSeconds) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.min_duration_seconds.getCode(), minDurationSeconds);
        }
    }

    public static void setMaxDurationSeconds(Long recordId, Integer maxDurationSeconds) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.max_duration_seconds.getCode(), maxDurationSeconds);
        }
    }

    public static void setForceFinish(Long recordId, Integer forceFinish) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.force_finish.getCode(),
                    forceFinish);
        }
    }

    public static void setLastPrepareTime(Long recordId, ScoreStatusEnum scoreStatusEnum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.score_status.getCode(),
                    scoreStatusEnum);
        }
    }

    public static void setExamFinalFinishTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "finalFinishTime", date);
        }
    }

    public static Long getExamFinalFinishTime(Long recordId) {
        return (Long) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "finalFinishTime");
    }

    public static void setMultipleFaceCountErrorRandom(Long recordId, String multipleFaceCountErrorRandom) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorRandom",
                    multipleFaceCountErrorRandom);
        }
    }

    public static void setRealnessErrorRandom(Long recordId, String realnessErrorRandom) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorRandom", realnessErrorRandom);
        }
    }

    public static void setLivenessActionErrorRandom(Long recordId, String livenessActionErrorRandom) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "livenessActionErrorRandom", livenessActionErrorRandom);
        }
    }

    public static void setNoFaceCountErrorRandom(Long recordId, String noFaceCountErrorRandom) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil
                    .set(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorRandom", noFaceCountErrorRandom);
        }
    }

    public static void setFaceCompareErrorRandom(Long recordId, String faceCompareErrorRandom) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil
                    .set(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorRandom", faceCompareErrorRandom);
        }
    }

    public static void setEyeCloseErrorRandom(Long recordId, String eyeCloseErrorRandom) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorRandom", eyeCloseErrorRandom);
        }
    }

    public static void setMultipleFaceCountErrorNum(Long recordId, AtomicInteger multipleFaceCountErrorNum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorNum",
                    multipleFaceCountErrorNum);
        }
    }

    public static void setNoFaceCountErrorNum(Long recordId, AtomicInteger noFaceCountErrorNum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorNum", noFaceCountErrorNum);
        }
    }

    public static void setFaceCompareErrorNum(Long recordId, AtomicInteger faceCompareErrorNum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorNum", faceCompareErrorNum);
        }
    }

    public static void setEyeCloseErrorNum(Long recordId, AtomicInteger eyeCloseErrorNum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorNum", eyeCloseErrorNum);
        }
    }

    public static void setRealnessErrorNum(Long recordId, AtomicInteger realnessErrorNum) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorNum", realnessErrorNum);
        }
    }

    public static String getMultipleFaceCountErrorRandom(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorRandom");
    }

    public static String getNoFaceCountErrorRandom(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorRandom");
    }

    public static String getFaceCompareErrorRandom(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorRandom");
    }

    public static String getEyeCloseErrorRandom(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorRandom");
    }

    public static String getRealnessErrorRandom(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorRandom");
    }

    public static String getLivenessActionErrorRandom(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "livenessActionErrorRandom");
    }

    public static AtomicInteger getMultipleFaceCountErrorNum(Long recordId) {
        return Objects
                .nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorNum")) ?
                (AtomicInteger) redisUtil
                        .get(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorNum") :
                new AtomicInteger(0);
    }

    public static AtomicInteger getNoFaceCountErrorNum(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorNum")) ?
                (AtomicInteger) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorNum") :
                new AtomicInteger(0);
    }

    public static AtomicInteger getFaceCompareErrorNum(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorNum")) ?
                (AtomicInteger) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorNum") :
                new AtomicInteger(0);
    }

    public static AtomicInteger getEyeCloseErrorNum(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorNum")) ?
                (AtomicInteger) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorNum") :
                new AtomicInteger(0);
    }

    public static AtomicInteger getRealnessErrorNum(Long recordId) {
        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorNum")) ?
                (AtomicInteger) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorNum") :
                new AtomicInteger(0);
    }

    public static Integer getHasAnswerFile(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.has_answer_file.getCode());
    }

    public static void setCameraPhotoUpload(Long recordId, Integer cameraPhotoUpload) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil
                    .set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.camera_photo_upload.getCode(),
                            cameraPhotoUpload);
        }
    }

    public static void setMobilePhotoUpload(Long recordId, Integer mobilePhotoUpload) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil
                    .set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.mobile_photo_upload.getCode(),
                            mobilePhotoUpload);
        }
    }

    public static void setEntryAuthenticationPolicy(Long recordId, String entryAuthenticationPolicy) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.entry_authentication_policy.getCode(), entryAuthenticationPolicy);
        }
    }

    public static void setInProcessFaceStrangerIgnore(Long recordId, Integer inProcessFaceStrangerIgnore) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.in_process_face_stranger_ignore.getCode(), inProcessFaceStrangerIgnore);
        }
    }

    public static void setInProcessLivenessFixedRange(Long recordId, String inProcessLivenessFixedRange) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.in_process_liveness_fixed_range.getCode(), inProcessLivenessFixedRange);
        }
    }

    public static void setInProcessLivenessJudgePolicy(Long recordId, String inProcessLivenessJudgePolicy) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.in_process_liveness_judge_policy.getCode(), inProcessLivenessJudgePolicy);
        }
    }

    public static void setMonitorVideoSource(Long recordId, String monitorVideoSource) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.monitor_video_source.getCode(), monitorVideoSource);
        }
    }

    public static void setMonitorRecord(Long recordId, String monitorRecord) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.monitor_record.getCode(),
                    monitorRecord);
        }
    }

//    public static void setTencentVideoUrl(Long recordId, String tencentVideoUrl) {
//        if (Objects.nonNull(getId(recordId))) {
//            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.tencent_video_url.getCode(),
//                    tencentVideoUrl);
//        }
//    }

    public static void setInProcessRealnessVerifyStatus(Long recordId, Integer inProcessRealnessVerifyStatus) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.in_process_realness_verify_status.getCode(), inProcessRealnessVerifyStatus);
        }
    }

    public static void setInProcessLivenessVerifyStatus(Long recordId, Integer inProcessLivenessVerifyStatus) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.in_process_liveness_verify_status.getCode(), inProcessLivenessVerifyStatus);
        }
    }

    public static void setInProcessFaceVerifyStatus(Long recordId, Integer inProcessFaceVerifyStatus) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId),
                    ExamRecordFieldEnum.in_process_face_verify_status.getCode(), inProcessFaceVerifyStatus);
        }
    }

    public static Integer getCameraPhotoUpload(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.camera_photo_upload.getCode());
    }

    public static Integer getMobilePhotoUpload(Long recordId) {
        return (Integer) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.mobile_photo_upload.getCode());
    }

    public static Long getEntryAuthenticationId(Long recordId) {
        return (Long) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.entry_authentication_id.getCode());
    }

    public static String getEntryAuthenticationPolicy(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.entry_authentication_policy.getCode());
    }

    public static Integer getInProcessFaceStrangerIgnore(Long recordId) {
        return (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.in_process_face_stranger_ignore.getCode());
    }

    public static String getInProcessLivenessFixedRange(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.in_process_liveness_fixed_range.getCode());
    }

    public static String getInProcessLivenessJudgePolicy(Long recordId) {
        return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.in_process_liveness_judge_policy.getCode());
    }

    public static String getMonitorVideoSource(Long recordId) {
        return (String) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.monitor_video_source.getCode());
    }

    public static Integer getInProcessRealnessVerifyStatus(Long recordId) {
        return (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.in_process_realness_verify_status.getCode());
    }

    public static Integer getInProcessLivenessVerifyStatus(Long recordId) {
        return (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.in_process_liveness_verify_status.getCode());
    }

    public static Integer getInProcessFaceVerifyStatus(Long recordId) {
        return (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId),
                ExamRecordFieldEnum.in_process_face_verify_status.getCode());
    }

    public static String getMonitorRecord(Long recordId) {
        return (String) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.monitor_record.getCode());
    }

//    public static String getTencentVideoUrl(Long recordId) {
//        return (String) redisUtil
//                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.tencent_video_url.getCode());
//    }

    public static void setUpdateTime(Long recordId, Long date) {
        if (Objects.nonNull(getId(recordId))) {
            redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.update_time.getCode(),
                    date);
        }
    }

    public static Long getUpdateTime(Long recordId) {
        return (Long) redisUtil
                .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.update_time.getCode());
    }

    /**
     * 更新考试记录缓存
     *
     * @param recordId
     * @param examCache
     * @param ac
     * @param examCourseCacheBean
     */
    public static void updateExamRecordCache(Long recordId, ExamCacheBean examCache, ExamActivityCacheBean ac, ExamCourseCacheBean examCourseCacheBean) {
        ExamRecordCacheUtil.setStartTime(recordId, ac.getStartTime());
        ExamRecordCacheUtil.setEndTime(recordId, ac.getFinishTime());
        ExamRecordCacheUtil.setOpeningSeconds(recordId, ac.getOpeningSeconds());
        ExamRecordCacheUtil.setMinDurationSeconds(recordId, examCache.getMinDurationSeconds());
        ExamRecordCacheUtil.setMaxDurationSeconds(recordId, ac.getMaxDurationSeconds());
        ExamRecordCacheUtil.setForceFinish(recordId, examCache.getForceFinish());
        ExamRecordCacheUtil.setCameraPhotoUpload(recordId, examCache.getCameraPhotoUpload());
//        ExamRecordCacheUtil.setMobilePhotoUpload(recordId, examCache.getMobilePhotoUpload());
        ExamRecordCacheUtil.setMobilePhotoUpload(recordId, examCourseCacheBean.getMobilePhotoUpload());
        ExamRecordCacheUtil.setEntryAuthenticationPolicy(recordId, examCache.getEntryAuthenticationPolicy().name());
        ExamRecordCacheUtil.setInProcessRealnessVerifyStatus(recordId, examCache.getInProcessRealnessVerify());
        ExamRecordCacheUtil.setInProcessFaceStrangerIgnore(recordId, examCache.getInProcessFaceStrangerIgnore());
        ExamRecordCacheUtil
                .setInProcessLivenessJudgePolicy(recordId, examCache.getInProcessLivenessJudgePolicy().name());
        ExamRecordCacheUtil.setInProcessLivenessFixedRange(recordId, examCache.getInProcessLivenessFixedRange());
        ExamRecordCacheUtil.setMonitorVideoSource(recordId, examCache.getMonitorVideoSource());
        ExamRecordCacheUtil.setMonitorRecord(recordId, examCache.getMonitorRecord());
        TOeExamRecordService tOeExamRecordService = SpringContextHolder.getBean(TOeExamRecordService.class);
        tOeExamRecordService.sendExamRecordDataSaveMq(recordId, System.currentTimeMillis());
    }
}