package cn.com.qmth.stmms.biz.exam.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;

import cn.com.qmth.stmms.biz.file.enums.FormatType;
import cn.com.qmth.stmms.biz.mark.model.PictureConfigItem;
import cn.com.qmth.stmms.common.enums.ExamStatus;
import cn.com.qmth.stmms.common.enums.ExamType;
import cn.com.qmth.stmms.common.enums.MarkMode;
import cn.com.qmth.stmms.common.enums.ObjectiveStatus;

@Entity
@Table(name = "eb_exam")
public class Exam implements Serializable {

    private static final long serialVersionUID = 5179623303410999209L;

    public static final String SUBJECT_ID_SPLIT = ",";

    @Id
    @GeneratedValue
    private Integer id;

    private String name;

    @Column(name = "school_id")
    private Integer schoolId;

    private String code;

    @Temporal(TemporalType.DATE)
    @Column(name = "exam_time")
    private Date examTime;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 16, nullable = false)
    private ExamStatus status;

    @Column(name = "description", length = 128, nullable = true)
    private String description;

    /**
     * 开启强制特殊标记
     */
    @Column(name = "force_special_tag", nullable = false)
    private boolean forceSpecialTag;

    /**
     * 裁切图配置
     */
    @Column(name = "slice_config", nullable = true)
    private String sliceConfig;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time")
    private Date createTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "update_time")
    private Date updateTime;

    @Column(name = "creator_id", nullable = true)
    private Integer creatorId;

    /**
     * 统计配置
     */
    @Column(name = "sas_config", nullable = true)
    private String sasConfig;

    /**
     * 原图遮盖配置
     */
    @Column(name = "sheet_config", nullable = true)
    private String sheetConfig;

    /**
     * 考试类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "type", length = 16, nullable = false)
    private ExamType type;

    /**
     * 题卡类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "card_type", length = 16, nullable = true)
    private FormatType cardType;

    /**
     * 禁止管理员以外人查看考生个人信息
     */
    @Column(name = "forbidden_info", nullable = false)
    private boolean forbiddenInfo;

    /**
     * 禁止查看成绩
     */
    @Column(name = "forbidden_score", nullable = false)
    private boolean forbiddenScore;

    /**
     * 客观题统分状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "objective_status", length = 16, nullable = false)
    private ObjectiveStatus objectiveStatus;

    /**
     * 评卷起始时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "mark_start_time")
    private Date startTime;

    /**
     * 评卷结束时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "mark_end_time")
    private Date endTime;

    /**
     * 强制评卷模式
     */
    @Column(name = "mark_mode", nullable = true, length = 16)
    @Enumerated(EnumType.STRING)
    private MarkMode markMode;

    /**
     * 开启/关闭 原卷显示
     */
    @Column(name = "sheet_view", nullable = false)
    private boolean sheetView;

    /**
     * 扫描配置
     */
    @Column(name = "scan_config", nullable = true)
    private String scanConfig;

    /**
     * 自动跳转
     */
    @Column(name = "auto_scroll", nullable = false)
    private boolean autoScroll;

    /**
     * 是否裁切
     */
    @Column(name = "enable_split", nullable = false)
    private boolean enableSplit;

    /**
     * 打回后是否显示原分值
     */
    @Column(name = "show_reject", nullable = false)
    private boolean showReject;
    
    /**
     * 全卷多次复核时不能为同一账号
     */
    @Column(name = "inspect_unrepeated", nullable = false)
    private boolean inspectUnrepeated;
    
    /**
     * 全卷复核时强制试卷拉到底部
     */
    @Column(name = "inspect_scroll_bottom", nullable = false)
    private boolean inspectScrollBottom;
    
    /**
     * 回评卷数
     */
    @Column(name = "remark_count")
    private Integer remarkCount;
    
    /**
     * 评卷端是否显示客观分
     */
    @Column(name = "show_objective_score", nullable = false)
    private boolean showObjectiveScore;

    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getExamTime() {
        return examTime;
    }

    public void setExamTime(Date examTime) {
        this.examTime = examTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(Integer creatorId) {
        this.creatorId = creatorId;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public ExamStatus getStatus() {
        return status;
    }

    public void setStatus(ExamStatus status) {
        this.status = status;
    }

    public Integer getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(Integer schoolId) {
        this.schoolId = schoolId;
    }

    public boolean isForceSpecialTag() {
        return forceSpecialTag;
    }

    public void setForceSpecialTag(boolean forceSpecialTag) {
        this.forceSpecialTag = forceSpecialTag;
    }

    public String getSliceConfig() {
        return sliceConfig;
    }

    public void setSliceConfig(String sliceConfig) {
        this.sliceConfig = sliceConfig;
    }

    public List<PictureConfigItem> getSliceConfigList() {
        return PictureConfigItem.parse(sliceConfig);
    }

    public Double getPassScore() {
        String text = StringUtils.trimToEmpty(sasConfig);
        if (StringUtils.isNotBlank(text)) {
            JSONObject jsonObject = JSONObject.fromObject(text);
            Double passScore = jsonObject.getDouble("passScore");
            return passScore;
        }
        return null;
    }

    public Double getExcellentScore() {
        String text = StringUtils.trimToEmpty(sasConfig);
        if (StringUtils.isNotBlank(text)) {
            JSONObject jsonObject = JSONObject.fromObject(text);
            Double excellentScore = jsonObject.getDouble("excellentScore");
            return excellentScore;
        }
        return null;
    }

    public String getSasConfig() {
        return sasConfig;
    }

    public void setSasConfig(String sasConfig) {
        this.sasConfig = sasConfig;
    }

    public String getSheetConfig() {
        return sheetConfig;
    }

    public void setSheetConfig(String sheetConfig) {
        this.sheetConfig = sheetConfig;
    }

    public List<PictureConfigItem> getSheetConfigList() {
        return PictureConfigItem.parse(sheetConfig);
    }

    public ExamType getType() {
        return type;
    }

    public void setType(ExamType type) {
        this.type = type;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public FormatType getCardType() {
        return cardType;
    }

    public void setCardType(FormatType cardType) {
        this.cardType = cardType;
    }

    public boolean isForbiddenInfo() {
        return forbiddenInfo;
    }

    public void setForbiddenInfo(boolean forbiddenInfo) {
        this.forbiddenInfo = forbiddenInfo;
    }

    public boolean isForbiddenScore() {
        return forbiddenScore;
    }

    public void setForbiddenScore(boolean forbiddenScore) {
        this.forbiddenScore = forbiddenScore;
    }

    public ObjectiveStatus getObjectiveStatus() {
        return objectiveStatus;
    }

    public void setObjectiveStatus(ObjectiveStatus objectiveStatus) {
        this.objectiveStatus = objectiveStatus;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public MarkMode getMarkMode() {
        return markMode;
    }

    public void setMarkMode(MarkMode markMode) {
        this.markMode = markMode;
    }

    public boolean isSheetView() {
        return sheetView;
    }

    public void setSheetView(boolean sheetView) {
        this.sheetView = sheetView;
    }

    public String getScanConfig() {
        return scanConfig;
    }

    public void setScanConfig(String scanConfig) {
        this.scanConfig = scanConfig;
    }

    public boolean isAutoScroll() {
        return autoScroll;
    }

    public void setAutoScroll(boolean autoScroll) {
        this.autoScroll = autoScroll;
    }

    public boolean isEnableSplit() {
        return enableSplit;
    }

    public void setEnableSplit(boolean enableSplit) {
        this.enableSplit = enableSplit;
    }

    public boolean isShowReject() {
        return showReject;
    }

    public void setShowReject(boolean showReject) {
        this.showReject = showReject;
    }

	public Boolean getInspectUnrepeated() {
		return inspectUnrepeated;
	}

	public void setInspectUnrepeated(Boolean inspectUnrepeated) {
		this.inspectUnrepeated = inspectUnrepeated;
	}

	public Boolean getInspectScrollBottom() {
		return inspectScrollBottom;
	}

	public void setInspectScrollBottom(Boolean inspectScrollBottom) {
		this.inspectScrollBottom = inspectScrollBottom;
	}

	public Integer getRemarkCount() {
		return remarkCount;
	}

	public void setRemarkCount(Integer remarkCount) {
		this.remarkCount = remarkCount;
	}

	public Boolean getShowObjectiveScore() {
		return showObjectiveScore;
	}

	public void setShowObjectiveScore(Boolean showObjectiveScore) {
		this.showObjectiveScore = showObjectiveScore;
	}

}
