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.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;

/**
 * 打回记录表
 */
@Entity
@Table(name = "m_reject_history")
public class RejectHistory implements Serializable {

    private static final long serialVersionUID = 1571356905196537231L;

    @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 = "library_id")
    private Integer libraryId;

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

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

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

    /**
     * 处理用户ID
     */
    @Column(name = "user_id", nullable = true)
    private Integer userId;

    /**
     * 给分总分
     */
    @Column(name = "total_score", nullable = true)
    private Double totalScore;

    /**
     * 给分明细
     */
    @Column(name = "score_list", nullable = true, length = 255)
    private String scoreList;

    /**
     * 打回后给分明细
     */
    @Column(name = "reject_score_list", nullable = true, length = 255)
    private String rejectScoreList;

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

    /**
     * 创建时间
     */
    @Column(name = "create_time", nullable = false)
    private Date createTime;

    @Transient
    private String markerLoginName;

    @Transient
    private String title;

    @Transient
    private String headerLoginName;

    @Transient
    private ExamSubject subject;

    public RejectHistory() {
    }

    public RejectHistory(MarkLibrary library) {
        this.createTime = new Date();
        this.examId = library.getExamId();
        this.examNumber = library.getExamNumber();
        this.groupNumber = library.getGroupNumber();
        this.libraryId = library.getId();
        this.markerId = library.getMarkerId();
        this.scoreList = library.getMarkerScoreList();
        this.secretNumber = library.getSecretNumber();
        this.studentId = library.getStudentId();
        this.subjectCode = library.getSubjectCode();
        this.totalScore = library.getMarkerScore();
    }

    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 getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Double getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(Double totalScore) {
        this.totalScore = totalScore;
    }

    public String getScoreList() {
        return scoreList;
    }

    public void setScoreList(String scoreList) {
        this.scoreList = scoreList;
    }

    public Date getCreateTime() {
        return createTime;
    }

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

    public Integer getGroupNumber() {
        return groupNumber;
    }

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

    public Integer getLibraryId() {
        return libraryId;
    }

    public void setLibraryId(Integer libraryId) {
        this.libraryId = libraryId;
    }

    public Integer getMarkerId() {
        return markerId;
    }

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

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getRejectScoreList() {
        return rejectScoreList;
    }

    public void setRejectScoreList(String rejectScoreList) {
        this.rejectScoreList = rejectScoreList;
    }

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

    public String getMarkerLoginName() {
        return markerLoginName;
    }

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

    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;
    }

}
