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

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
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.Transient;

import org.apache.commons.lang.StringUtils;

import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
import cn.com.qmth.stmms.biz.utils.ScoreItem;
import cn.com.qmth.stmms.common.enums.LibraryStatus;

@Entity
@Table(name = "m_library")
public class MarkLibrary implements Serializable {

    private static final long serialVersionUID = 7121951721670633060L;

    @Id
    @GeneratedValue
    private Integer id;

    /**
     * 考试ID
     */
    @Column(name = "exam_id")
    private Integer examId;

    /**
     * 科目CODE
     */
    @Column(name = "subject_code")
    private String subjectCode;

    /**
     * 大题序号
     */
    @Column(name = "group_number")
    private Integer groupNumber;

    /**
     * 考生编号
     */
    @Column(name = "student_id")
    private Integer studentId;

    /**
     * 准考证号
     */
    @Column(name = "exam_number")
    private String examNumber;

    /**
     * 考生密号
     */
    @Column(name = "secret_number")
    private String secretNumber;

    /**
     * 多评任务编号，单评时为1
     */
    @Column(name = "task_number")
    private Integer taskNumber;

    /**
     * 任务状态
     */
    @Column(name = "status")
    @Enumerated(EnumType.STRING)
    private LibraryStatus status;

    /**
     * 评卷员
     */
    @Column(name = "marker_id")
    private Integer markerId;

    /**
     * 评卷时间
     */
    @Column(name = "marker_time")
    private Date markerTime;

    /**
     * 评卷员给分总分
     */
    @Column(name = "marker_score")
    private Double markerScore;

    /**
     * 评卷员给分明细
     */
    @Column(name = "marker_score_list")
    private String markerScoreList;

    /**
     * 评卷时长
     */
    @Column(name = "marker_spent")
    private Integer markerSpent;

    /**
     * 评卷组长
     */
    @Column(name = "header_id")
    private Integer headerId;

    /**
     * 评卷组长评卷时间
     */
    @Column(name = "header_time")
    private Date headerTime;

    /**
     * 评卷组长给分总分
     */
    @Column(name = "header_score")
    private Double headerScore;

    /**
     * 评卷组长给分明细
     */
    @Column(name = "header_score_list")
    private String headerScoreList;

    /**
     * 未作答的步骤数量
     */
    @Column(name = "unanswered_count", nullable = true)
    private Integer unansweredCount;

    @Column(name = "reject_reason", nullable = true)
    private String rejectReason;

    @Transient
    private String markerLoginName;

    @Transient
    private String title;

    @Transient
    private String headerLoginName;

    @Transient
    private ExamSubject subject;

    public Integer getId() {
        return id;
    }

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

    public Integer getExamId() {
        return examId;
    }

    public void setExamId(Integer examId) {
        this.examId = examId;
    }

    public String getSubjectCode() {
        return subjectCode;
    }

    public void setSubjectCode(String subjectCode) {
        this.subjectCode = subjectCode;
    }

    public Integer getStudentId() {
        return studentId;
    }

    public void setStudentId(Integer studentId) {
        this.studentId = studentId;
    }

    public String getExamNumber() {
        return examNumber;
    }

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

    public String getSecretNumber() {
        return secretNumber;
    }

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

    public Integer getMarkerId() {
        return markerId;
    }

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

    public Date getMarkerTime() {
        return markerTime;
    }

    public void setMarkerTime(Date markerTime) {
        this.markerTime = markerTime;
    }

    public Double getMarkerScore() {
        return markerScore;
    }

    public void setMarkerScore(Double markerScore) {
        this.markerScore = markerScore;
    }

    public String getMarkerScoreList() {
        return markerScoreList;
    }

    public void setMarkerScoreList(String markerScoreList) {
        this.markerScoreList = markerScoreList;
    }

    public LibraryStatus getStatus() {
        return status;
    }

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

    public List<ScoreItem> getScoreList() {
        List<ScoreItem> list = new LinkedList<ScoreItem>();
        String scoreList = null;
        if (StringUtils.isNotBlank(headerScoreList)) {
            scoreList = headerScoreList;
        } else if (StringUtils.isNotBlank(markerScoreList)) {
            scoreList = markerScoreList;
        }
        if (StringUtils.isNotBlank(scoreList)) {
            try {
                String[] values = scoreList.split(",");
                for (String value : values) {
                    if (value.equals("#")) {
                        list.add(new ScoreItem(false));
                    } else {
                        ScoreItem item = ScoreItem.parse(value, false);
                        if (item != null) {
                            list.add(item);
                        }
                    }
                }
                if (scoreList.endsWith(",")) {
                    list.add(new ScoreItem(false));
                }
            } catch (Exception e) {
            }
        }
        return list;
    }

    public List<ScoreItem> getMarkerScoreItem() {
        List<ScoreItem> list = new LinkedList<ScoreItem>();
        String scoreList = null;
        if (StringUtils.isNotBlank(markerScoreList)) {
            scoreList = markerScoreList;
        }
        if (StringUtils.isNotBlank(scoreList)) {
            try {
                String[] values = scoreList.split(",");
                for (String value : values) {
                    if (value.equals("#")) {
                        list.add(new ScoreItem(false));
                    } else {
                        ScoreItem item = ScoreItem.parse(value, false);
                        if (item != null) {
                            list.add(item);
                        }
                    }
                }
                if (scoreList.endsWith(",")) {
                    list.add(new ScoreItem(false));
                }
            } catch (Exception e) {
            }
        }
        return list;
    }

    public Integer getGroupNumber() {
        return groupNumber;
    }

    public void setGroupNumber(Integer groupNumber) {
        this.groupNumber = groupNumber;
    }

    public Integer getHeaderId() {
        return headerId;
    }

    public void setHeaderId(Integer headerId) {
        this.headerId = headerId;
    }

    public Date getHeaderTime() {
        return headerTime;
    }

    public void setHeaderTime(Date headerTime) {
        this.headerTime = headerTime;
    }

    public Double getHeaderScore() {
        return headerScore;
    }

    public void setHeaderScore(Double headerScore) {
        this.headerScore = headerScore;
    }

    public String getHeaderScoreList() {
        return headerScoreList;
    }

    public void setHeaderScoreList(String headerScoreList) {
        this.headerScoreList = headerScoreList;
    }

    public Integer getTaskNumber() {
        return taskNumber;
    }

    public void setTaskNumber(Integer taskNumber) {
        this.taskNumber = taskNumber;
    }

    public Integer getMarkerSpent() {
        return markerSpent;
    }

    public void setMarkerSpent(Integer markerSpent) {
        this.markerSpent = markerSpent;
    }

    public String getMarkerLoginName() {
        return markerLoginName;
    }

    public void setMarkerLoginName(String markerLoginName) {
        this.markerLoginName = markerLoginName;
    }

    public Integer getUnansweredCount() {
        return unansweredCount;
    }

    public void setUnansweredCount(Integer unansweredCount) {
        this.unansweredCount = unansweredCount;
    }

    public String getRejectReason() {
        return rejectReason;
    }

    public void setRejectReason(String rejectReason) {
        this.rejectReason = rejectReason;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getHeaderLoginName() {
        return headerLoginName;
    }

    public void setHeaderLoginName(String headerLoginName) {
        this.headerLoginName = headerLoginName;
    }

    public ExamSubject getSubject() {
        return subject;
    }

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

}
