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.user.model.User;
import cn.com.qmth.stmms.biz.utils.ScoreItem;
import cn.com.qmth.stmms.common.enums.HistoryStatus;

/**
 * 多评仲裁记录表
 *
 * @author luoshi
 */
@Entity
@Table(name = "m_arbitrate_history")
public class ArbitrateHistory implements Serializable {

    private static final long serialVersionUID = -6778980854289204628L;

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

    /**
     * 仲裁处理用户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 = "status")
    @Enumerated(EnumType.STRING)
    private HistoryStatus status;

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

    /**
     * 处理时间
     */
    @Column(name = "update_time", nullable = true)
    private Date updateTime;

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

    @Transient
    private User user;

    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 getGroupNumber() {
        return groupNumber;
    }

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

    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 HistoryStatus getStatus() {
        return status;
    }

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

    public Date getUpdateTime() {
        return updateTime;
    }

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

    public Date getCreateTime() {
        return createTime;
    }

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

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<ScoreItem> getScoreItemList() {
        List<ScoreItem> list = new LinkedList<ScoreItem>();
        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 getUnansweredCount() {
        return unansweredCount;
    }

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

}
