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

import cn.com.qmth.stmms.ms.core.domain.Level;
import cn.com.qmth.stmms.ms.core.domain.MarkStage;
import cn.com.qmth.stmms.ms.core.domain.Paper;
import cn.com.qmth.stmms.ms.core.domain.enums.TrialEnum;
import cn.com.qmth.stmms.ms.core.domain.user.MarkUser;
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/22.
 */
@Entity
@Table(indexes = {
        @Index(name = "idx_mark_task_paper_id", columnList = "paperId")})
public class MarkTask implements Serializable {

    private static final long serialVersionUID = -1095989485341316938L;

    @Id
    @GeneratedValue
    private Long id;

    @NotNull
    private Long markerId;


    @NotNull
    private String markerName;

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

    @NotNull
    private Long workId;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "paperId")
    private Paper paper;

    private Long questionId;

    private String result;

    private String originLevel;

    private Integer levelValue;

    @NotNull
    @Enumerated(value = EnumType.ORDINAL)
    private MarkStage stage;

    /**
     * 是否被打回重评
     */
    private boolean isRejected;

    @Temporal(value = TemporalType.TIMESTAMP)
    private Date createdOn;

    @Temporal(value = TemporalType.TIMESTAMP)
    private Date updatedOn;


    private Integer randomSeq;
    /**
     * 密号
     */
    private String secretNumber;

    private Long randomSeqNew;

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

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

    @Basic
    @Column(name = "batch_no")
    private Long batchNo;

    private String serialNumber;

    private Integer displayNumber;

    public Long getBatchNo() {
        return batchNo;
    }

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

    public boolean isActive() {
        return isActive;
    }

    public void setActive(boolean active) {
        isActive = active;
    }

    public int getTest() {
        return test;
    }

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

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Long getRandomSeqNew() {
        return randomSeqNew;
    }

    public void setRandomSeqNew(Long randomSeqNew) {
        this.randomSeqNew = randomSeqNew;
    }

    public MarkTask(MarkUser marker, Paper paper, MarkStage stage, Long randomSeqNew) {
        this.markerId = marker.getId();
        this.markerName = marker.getName();
        this.subject = marker.getSubject();
        this.workId = marker.getWorkId();
        this.paper = paper;
        this.questionId = paper.getQuestionId();
        this.stage = stage;
        this.createdOn = new Date();
        //随机号生成修改规则
//        this.secretNumber = marker.getId() + subject.ordinal() + paper.getAreaCode() + paper.getExamNumber().substring(3, paper.getExamNumber().length());
        this.secretNumber = marker.getId() + subject.ordinal() + paper.getAreaCode() + randomSeqNew;
        this.randomSeqNew = randomSeqNew;
    }

    public MarkTask(MarkUser marker, Paper paper, MarkStage stage, Long randomSeqNew, int test) {
        this.markerId = marker.getId();
        this.markerName = marker.getName();
        this.subject = marker.getSubject();
        this.workId = marker.getWorkId();
        this.paper = paper;
        this.questionId = paper.getQuestionId();
        this.stage = stage;
        this.createdOn = new Date();
        //随机号生成修改规则
//        this.secretNumber = marker.getId() + subject.ordinal() + paper.getAreaCode() + paper.getExamNumber().substring(3, paper.getExamNumber().length());
        this.secretNumber = marker.getId() + subject.ordinal() + paper.getAreaCode() + randomSeqNew;
        this.randomSeqNew = randomSeqNew;
        this.test = test != TrialEnum.DEFAULT.getId() ? TrialEnum.START_TRIAL.getId() : test;
    }

    public MarkTask(MarkUser marker, Paper paper, Level level, MarkStage stage, Long randomSeqNew, int test) {
        this.markerId = marker.getId();
        this.markerName = marker.getName();
        this.subject = marker.getSubject();
        this.workId = marker.getWorkId();
        this.paper = paper;
        this.questionId = paper.getQuestionId();
        this.stage = stage;
        this.createdOn = new Date();
        //随机号生成修改规则
//        this.secretNumber = marker.getId() + subject.ordinal() + paper.getAreaCode() + paper.getExamNumber().substring(3, paper.getExamNumber().length());
        this.secretNumber = marker.getId() + subject.ordinal() + paper.getAreaCode() + randomSeqNew;
        this.randomSeqNew = randomSeqNew;
        this.test = test != TrialEnum.DEFAULT.getId() ? TrialEnum.START_TRIAL.getId() : test;

        this.result = paper.getLevel();
        this.levelValue = level.getLevelValue();
        this.updatedOn = new Date();
    }

    public MarkTask() {
    }

    public Long getId() {
        return id;
    }

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

    public Long getQuestionId() {
        return questionId;
    }

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

    public MarkStage getStage() {
        return stage;
    }

    public void setStage(MarkStage stage) {
        this.stage = stage;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public Date getUpdatedOn() {
        return updatedOn;
    }

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

    public boolean isRejected() {
        return isRejected;
    }

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

    public Subject getSubject() {
        return subject;
    }

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

    public Long getWorkId() {
        return workId;
    }

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

    public Integer getLevelValue() {
        return levelValue;
    }

    public void setLevelValue(Integer levelValue) {
        this.levelValue = levelValue;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public Long getMarkerId() {
        return markerId;
    }

    public void setMarkerId(Long markerId) {
        this.markerId = markerId;
    }

    public Paper getPaper() {
        return paper;
    }

    public void setPaper(Paper paper) {
        this.paper = paper;
    }

    public String getMarkerName() {
        return markerName;
    }

    public void setMarkerName(String markerName) {
        this.markerName = markerName;
    }

    public String getOriginLevel() {
        return originLevel;
    }

    public void setOriginLevel(String originLevel) {
        this.originLevel = originLevel;
    }

    public Integer getRandomSeq() {
        return randomSeq;
    }

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

    public String getSecretNumber() {
        return secretNumber;
    }

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

    public String getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }

    public Integer getDisplayNumber() {
        return displayNumber;
    }

    public void setDisplayNumber(Integer displayNumber) {
        this.displayNumber = displayNumber;
    }
}
