package cn.com.qmth.stmms.ms.core.domain;

import cn.com.qmth.stmms.ms.core.vo.Subject;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
 * 试卷
 * Created by zhengmin on 2016/9/21.
 */
@Entity
@Table(indexes = {
        @Index(name = "idx_paper_index", columnList = "idx"),
        @Index(name = "idx_paper_exam_number", columnList = "examNumber"),
        @Index(name = "idx_paper_area_code", columnList = "areaCode"),
        @Index(name = "idx_paper_student_name", columnList = "studentName")})
public class Paper implements Serializable {

    private static final long serialVersionUID = 3200579901138269179L;
    @Id
    @GeneratedValue
    private Long id;

    @NotNull
    private Long workId;

    private String secretNumber;

    private Long idx;

    @NotNull
    private String studentName;

    @NotNull
    private String examNumber;

    @NotNull
    @Enumerated(value = EnumType.STRING)
    private Subject subject;

    @NotNull
    private Long questionId;

    @NotNull
    private String areaCode;

    @NotNull
    private String questionName;

    private String level;

    /**
     * 建议重评档位
     */
    private String redoLevel;

    private Double score;

    //抽查成绩
    private Double inspectScore;

    private String inspectLevel;
    private Long inspector;

    /**
     * 是否仲裁状态
     */
    private boolean isArbitrated;

    private boolean isRejected;

    /**
     * 是否由科组长直接评卷
     */
    private boolean markByLeader;

    /**
     * 是否逻辑分档（系统定档）
     */
    private boolean markedLogic;

    private Date updatedOn;

    /**
     * 采集时是否手工绑定
     */
    private boolean isManual;

    private Date uploadedOn;
    private int uploadedCount = 1;

    /**
     * 是否标记
     */
    private boolean isTagged;

    /**
     * 是否标记
     */
    private boolean isSample;

    //抽查范围ID
    private Long inspectRange;
    //生源地
    private String sourceName;
    //原图MD5
    @Column(name = "sheet_md5")
    private String sheetMD5;
    //裁切图MD5
    @Column(name = "slice_md5")
    private String sliceMD5;

    /**
     * 是否缺考
     */
    private boolean isMissing;

    private Long randomSeq;

    private String examRoom;

    @Basic
    @Column(name = "is_test")
    private int test; //是否试评，1:数据已导入，2:试评中

    @Basic
    @Column(name = "is_active")
    private boolean active; //是否激活（false：不是，true：是）

    private Long batchNo;

    private Long scoreBatchNo;

    private boolean isShift;

    private boolean isShiftScore;

    /**
     * 是否一键定档
     */
    private boolean isOneClick;

    private Boolean isRejectedByLeader;

    public int getTest() {
        return test;
    }

    public void setTest(int test) {
        this.test = test;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public boolean getIsMissing() {
        return isMissing;
    }

    public void setIsMissing(boolean isMissing) {
        this.isMissing = isMissing;
    }

    public Long getRandomSeq() {
        return randomSeq;
    }

    public void setRandomSeq(Long randomSeq) {
        this.randomSeq = randomSeq;
    }

    public Paper(Long workId, Long idx, Subject subject, ExamQuestion examQuestion, Student student, boolean isManual, Long randomSeq) {
        this.workId = workId;
        this.idx = idx;
        this.studentName = student.getName();
        String examNumber = student.getExamNumber();
        this.examNumber = examNumber;
        this.sourceName = student.getSourceName();
        this.subject = subject;
        this.questionId = examQuestion.getId();
        this.areaCode = examQuestion.getAreaCode();
        this.questionName = examQuestion.getName();
        //随机号生成修改规则
//        this.secretNumber = subject.ordinal() + examQuestion.getAreaCode() + examNumber.substring(3, examNumber.length());
        this.secretNumber = subject.ordinal() + examQuestion.getAreaCode() + randomSeq;
        this.randomSeq = randomSeq;
        this.isManual = isManual;
        this.uploadedOn = new Date();
    }


    public Paper() {
    }

    public Long getId() {
        return id;
    }

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

    public Long getWorkId() {
        return workId;
    }

    public void setWorkId(Long workId) {
        this.workId = workId;
    }


    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public String getExamNumber() {
        return examNumber;
    }

    public void setExamNumber(String examNumber) {
        this.examNumber = examNumber;
    }

    public Subject getSubject() {
        return subject;
    }

    public void setSubject(Subject subject) {
        this.subject = subject;
    }

    public Long getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Long questionId) {
        this.questionId = questionId;
    }

    public String getQuestionName() {
        return questionName;
    }

    public void setQuestionName(String questionName) {
        this.questionName = questionName;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }


    public boolean isManual() {
        return isManual;
    }

    public void setManual(boolean manual) {
        isManual = manual;
    }

    public Date getUploadedOn() {
        return uploadedOn;
    }

    public void setUploadedOn(Date uploadedOn) {
        this.uploadedOn = uploadedOn;
    }

    public Long getIdx() {
        return idx;
    }

    public void setIdx(Long idx) {
        this.idx = idx;
    }

    public boolean isArbitrated() {
        return isArbitrated;
    }

    public void setArbitrated(boolean arbitrated) {
        isArbitrated = arbitrated;
    }

    public String getRedoLevel() {
        return redoLevel;
    }

    public void setRedoLevel(String redoLevel) {
        this.redoLevel = redoLevel;
    }

    public boolean isRejected() {
        return isRejected;
    }

    public void setRejected(boolean rejected) {
        isRejected = rejected;
    }

    public boolean isTagged() {
        return isTagged;
    }

    public void setTagged(boolean tagged) {
        isTagged = tagged;
    }

    /**
     * 定档
     *
     * @param level
     */
    public void determineLevel(String level) {
        this.setLevel(level);
        this.setRejected(false);
        this.setArbitrated(false);
        this.setRedoLevel(null);
        this.setUpdatedOn(new Date());
    }

    /**
     * 打回
     *
     * @param redoLevel
     */
    public void reject(String redoLevel) {
        this.setRejected(true);
        this.setArbitrated(false);
        this.setRedoLevel(redoLevel);
        this.setLevel(null);
        this.setTagged(true);
        this.setMarkByLeader(false);
        this.setUpdatedOn(new Date());
    }

    /**
     * 仲裁
     */
    public void arbitrate() {
        this.setRejected(false);
        this.setArbitrated(true);
        this.setLevel(null);
        this.setUpdatedOn(new Date());
    }

    public boolean isMarkByLeader() {
        return markByLeader;
    }

    public void setMarkByLeader(boolean markByLeader) {
        this.markByLeader = markByLeader;
    }

    public String getSecretNumber() {
        return secretNumber;
    }

    public void setSecretNumber(String secretNumber) {
        this.secretNumber = secretNumber;
    }

    public Date getUpdatedOn() {
        return updatedOn;
    }

    public void setUpdatedOn(Date updatedOn) {
        this.updatedOn = updatedOn;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public boolean isMarkedLogic() {
        return markedLogic;
    }

    public void setMarkedLogic(boolean markedLogic) {
        this.markedLogic = markedLogic;
    }

    public int getUploadedCount() {
        return uploadedCount;
    }

    public void setUploadedCount(int uploadedCount) {
        this.uploadedCount = uploadedCount;
    }

    public Double getInspectScore() {
        return inspectScore;
    }

    public void setInspectScore(Double inspectScore) {
        this.inspectScore = inspectScore;
    }

    public Long getInspectRange() {
        return inspectRange;
    }

    public void setInspectRange(Long inspectRange) {
        this.inspectRange = inspectRange;
    }

    public String getSourceName() {
        return sourceName;
    }

    public void setSourceName(String sourceName) {
        this.sourceName = sourceName;
    }

    public String getInspectLevel() {
        return inspectLevel;
    }

    public void setInspectLevel(String inspectLevel) {
        this.inspectLevel = inspectLevel;
    }

    public Long getInspector() {
        return inspector;
    }

    public void setInspector(Long inspector) {
        this.inspector = inspector;
    }

    public boolean isSample() {
        return isSample;
    }

    public void setSample(boolean isSample) {
        this.isSample = isSample;
    }

    public String getSheetMD5() {
        return sheetMD5;
    }

    public void setSheetMD5(String sheetMD5) {
        this.sheetMD5 = sheetMD5;
    }

    public String getSliceMD5() {
        return sliceMD5;
    }

    public void setSliceMD5(String sliceMD5) {
        this.sliceMD5 = sliceMD5;
    }

    public String getExamRoom() {
        return examRoom;
    }

    public void setExamRoom(String examRoom) {
        this.examRoom = examRoom;
    }

    public Long getBatchNo() {
        return batchNo;
    }

    public void setBatchNo(Long batchNo) {
        this.batchNo = batchNo;
    }

    public Long getScoreBatchNo() {
        return scoreBatchNo;
    }

    public void setScoreBatchNo(Long scoreBatchNo) {
        this.scoreBatchNo = scoreBatchNo;
    }

    public boolean isShift() {
        return isShift;
    }

    public void setShift(boolean shift) {
        isShift = shift;
    }

    public boolean isShiftScore() {
        return isShiftScore;
    }

    public void setShiftScore(boolean shiftScore) {
        isShiftScore = shiftScore;
    }

    public boolean isOneClick() {
        return isOneClick;
    }

    public void setOneClick(boolean oneClick) {
        isOneClick = oneClick;
    }

    public Boolean isRejectedByLeader() {
        return isRejectedByLeader;
    }

    public void setRejectedByLeader(Boolean rejectedByLeader) {
        isRejectedByLeader = rejectedByLeader;
    }
}
