package com.qmth.teachcloud.mark.bean.archivescore;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.teachcloud.common.annotation.ExcelProperty;
import com.qmth.teachcloud.common.entity.MarkQuestion;
import com.qmth.teachcloud.mark.dto.mark.ScoreItem;

public class ArchiveStudentVo {

    public static final String SPLIT = ";";
    @JsonSerialize(using = ToStringSerializer.class)
    private Long studentId;

    @ExcelProperty(name = "学生姓名", width = 20, index = 1)
    private String studentName;
    @ExcelProperty(name = "学号", width = 20, index = 2)
    private String studentCode;
    @ExcelProperty(name = "学院", width = 20, index = 3)
    private String college;
    private String majorName;
    @ExcelProperty(name = "班级", width = 20, index = 4)
    private String className;
    @ExcelProperty(name = "课程代码", width = 20, index = 5)
    private String courseCode;
    @ExcelProperty(name = "课程名称", width = 20, index = 6)
    private String courseName;
    @ExcelProperty(name = "客观分", width = 20, index = 7)
    private Double objectiveScore;
    @ExcelProperty(name = "主观分", width = 20, index = 8)
    private Double subjectiveScore;
    @ExcelProperty(name = "成绩", width = 20, index = 9)
    private Double totalScore;

    private String subjectiveScoreList;

    private String objectiveScoreList;

    private List<String> sheetUrls;

    private String sheetPath;
    private Long examStartTime;
    private Long examEndTime;

    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 getStudentCode() {
        return studentCode;
    }

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

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public String getCollege() {
        return college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    public String getMajorName() {
        return majorName;
    }

    public void setMajorName(String majorName) {
        this.majorName = majorName;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public Double getTotalScore() {
        return totalScore;
    }

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

    public List<String> getSheetUrls() {
        return sheetUrls;
    }

    public void setSheetUrls(List<String> sheetUrls) {
        this.sheetUrls = sheetUrls;
    }

    public Long getStudentId() {
        return studentId;
    }

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

    public String getSheetPath() {
        return sheetPath;
    }

    public void setSheetPath(String sheetPath) {
        this.sheetPath = sheetPath;
    }

    public Long getExamStartTime() {
        return examStartTime;
    }

    public void setExamStartTime(Long examStartTime) {
        this.examStartTime = examStartTime;
    }

    public Long getExamEndTime() {
        return examEndTime;
    }

    public void setExamEndTime(Long examEndTime) {
        this.examEndTime = examEndTime;
    }

    public Double getObjectiveScore() {
        return objectiveScore;
    }

    public void setObjectiveScore(Double objectiveScore) {
        this.objectiveScore = objectiveScore;
    }

    public Double getSubjectiveScore() {
        return subjectiveScore;
    }

    public void setSubjectiveScore(Double subjectiveScore) {
        this.subjectiveScore = subjectiveScore;
    }

    public String getSubjectiveScoreList() {
        return subjectiveScoreList;
    }

    public void setSubjectiveScoreList(String subjectiveScoreList) {
        this.subjectiveScoreList = subjectiveScoreList;
    }

    public String getObjectiveScoreList() {
        return objectiveScoreList;
    }

    public void setObjectiveScoreList(String objectiveScoreList) {
        this.objectiveScoreList = objectiveScoreList;
    }

    public List<ScoreItem> getScoreList(boolean objective) {
        List<ScoreItem> scoreList = new LinkedList<ScoreItem>();
        try {
            String[] values = StringUtils.split(objective ? objectiveScoreList : subjectiveScoreList, SPLIT);
            for (String value : values) {
                ScoreItem item = ScoreItem.parse(value, objective);
                item.setObjective(objective);
                if (item != null) {
                    scoreList.add(item);
                }
            }
        } catch (Exception e) {
        }
        return scoreList;
    }
    public List<ScoreItem> getScoreList(boolean objective, List<MarkQuestion> questionList) {
        List<ScoreItem> scoreList = new LinkedList<ScoreItem>();
        try {
            String[] values = StringUtils.split(objective ? objectiveScoreList : subjectiveScoreList, SPLIT);
            int i = 0;
            for (String value : values) {
                i++;
                if (questionList.size() < i) {
                    break;
                }
                MarkQuestion question = questionList.get(i - 1);
                if (question.getTotalScore() == null || question.getTotalScore() == 0) {
                    continue;
                }
                ScoreItem item = ScoreItem.parse(value, objective);
                item.setObjective(objective);
                item.setMainNumber(question.getMainNumber());
                item.setTitle(question.getMainTitle());
                item.setTotalScore(question.getTotalScore());
                item.setSubNumber(question.getSubNumber());
                if (item != null) {
                    scoreList.add(item);
                }
            }
        } catch (Exception e) {
        }
        return scoreList;
    }
}
