package cn.com.qmth.stmms.admin.utils;

import javax.servlet.http.HttpServletRequest;

import cn.com.qmth.stmms.common.session.model.StmmsSession;
import cn.com.qmth.stmms.common.utils.RequestUtils;

public class SessionExamUtils {

    public static final String EXAM_ID_KEY = "examId";

    public static int getExamId(HttpServletRequest request) {
        int examId = 0;
        try {
            examId = Integer.valueOf(RequestUtils.getSession(request).getParameter(EXAM_ID_KEY));
        } catch (Exception e) {
            // log.error("考试-基础参数设置-examId类型转换出错", e);
        }
        if (examId == 0) {
            try {
                examId = Integer.valueOf(request.getParameter(EXAM_ID_KEY));
            } catch (Exception e) {
                // log.error("考试-基础参数设置-examId类型转换出错", e);
            }
        }
        return examId;
    }

    public static void clearExamId(HttpServletRequest request) {
        StmmsSession session = RequestUtils.getSession(request);
        session.setParameter(EXAM_ID_KEY, null);
        request.removeAttribute(EXAM_ID_KEY);
    }

    public static void setExamId(HttpServletRequest request, int examId) {
        StmmsSession session = RequestUtils.getSession(request);
        session.setParameter(EXAM_ID_KEY, String.valueOf(examId));
    }
}
