package com.qmth.teachcloud.mark.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.teachcloud.mark.dto.mark.ScoreItem;
import com.qmth.teachcloud.mark.enums.MarkTaskStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * 评卷任务表
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@TableName("mark_task")
@ApiModel(value="MarkTask对象", description="评卷任务表")
public class MarkTask implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "主键")
    @TableId(value = "id")
    private Long id;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "考试ID")
    private Long examId;

    @ApiModelProperty(value = "课程代码")
    private String courseCode;
    @ApiModelProperty(value = "课程名称")
    private String courseName;
    @ApiModelProperty(value = "试卷编号")
    private String paperNumber;

    @ApiModelProperty(value = "大题号")
    private Integer groupNumber;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "考生ID")
    private Long studentId;

    @ApiModelProperty(value = "学号")
    private String studentCode;

    @ApiModelProperty(value = "考生密号")
    private String secretNumber;

    @ApiModelProperty(value = "多评任务序号")
    private Integer taskNumber;

    @ApiModelProperty(value = "状态")
    private MarkTaskStatus status;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "评卷员ID")
    private Long userId;

    @ApiModelProperty(value = "评卷时间")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Long markerTime;

    @ApiModelProperty(value = "评卷总分")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Double markerScore;

    @ApiModelProperty(value = "评卷给分明细")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String markerScoreList;

    @ApiModelProperty(value = "评卷时长")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Integer markerSpent;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "科组长ID")
    private Long headerId;

    @ApiModelProperty(value = "科组长评卷时间")
    private Long headerTime;

    @ApiModelProperty(value = "科组长总分")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Double headerScore;

    @ApiModelProperty(value = "科组长给分明细")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String headerScoreList;

    public Long getId() {
        return id;
    }

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

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

    public String getCourseCode() {
        return courseCode;
    }

    public void setCourseCode(String courseCode) {
        this.courseCode = courseCode;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public String getPaperNumber() {
        return paperNumber;
    }

    public void setPaperNumber(String paperNumber) {
        this.paperNumber = paperNumber;
    }
    public Integer getGroupNumber() {
        return groupNumber;
    }

    public void setGroupNumber(Integer groupNumber) {
        this.groupNumber = groupNumber;
    }
    public Long getStudentId() {
        return studentId;
    }

    public void setStudentId(Long studentId) {
        this.studentId = studentId;
    }
    public String getStudentCode() {
        return studentCode;
    }

    public void setStudentCode(String studentCode) {
        this.studentCode = studentCode;
    }
    public String getSecretNumber() {
        return secretNumber;
    }

    public void setSecretNumber(String secretNumber) {
        this.secretNumber = secretNumber;
    }
    public Integer getTaskNumber() {
        return taskNumber;
    }

    public void setTaskNumber(Integer taskNumber) {
        this.taskNumber = taskNumber;
    }
    public MarkTaskStatus getStatus() {
        return status;
    }

    public void setStatus(MarkTaskStatus status) {
        this.status = status;
    }
    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }
    public Long getMarkerTime() {
        return markerTime;
    }

    public void setMarkerTime(Long 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 Integer getMarkerSpent() {
        return markerSpent;
    }

    public void setMarkerSpent(Integer markerSpent) {
        this.markerSpent = markerSpent;
    }
    public Long getHeaderId() {
        return headerId;
    }

    public void setHeaderId(Long headerId) {
        this.headerId = headerId;
    }
    public Long getHeaderTime() {
        return headerTime;
    }

    public void setHeaderTime(Long 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 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;
    }

    @Override
    public String toString() {
        return "MarkTask{" +
            "id=" + id +
            ", examId=" + examId +
            ", courseCode=" + courseCode +
            ", courseName=" + courseName +
            ", paperNumber=" + paperNumber +
            ", groupNumber=" + groupNumber +
            ", studentId=" + studentId +
            ", studentCode=" + studentCode +
            ", secretNumber=" + secretNumber +
            ", taskNumber=" + taskNumber +
            ", status=" + status +
            ", userId=" + userId +
            ", markerTime=" + markerTime +
            ", markerScore=" + markerScore +
            ", markerScoreList=" + markerScoreList +
            ", markerSpent=" + markerSpent +
            ", headerId=" + headerId +
            ", headerTime=" + headerTime +
            ", headerScore=" + headerScore +
            ", headerScoreList=" + headerScoreList +
        "}";
    }
}
