package cn.com.qmth.examcloud.core.questions.service.bean.dto;

import cn.com.qmth.examcloud.core.questions.base.excel.ExcelProperty;
import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author chenken
 * @date 2017年7月18日 上午10:59:49
 * @company QMTH
 * @description 客观题数据--用于Excel导出
 */
public class ObjectiveQuestionStructure implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = -4064781474344761068L;

    /**
     * 课程ID
     */
    private Long courseId;
    /**
     * 课程代码
     */
    @ExcelProperty(name = "课程代码", index = 0)
    private String courseCode;
    /**
     * 课程名称
     */
    @ExcelProperty(name = "课程名称", index = 1)
    private String courseName;

    /**
     * 试卷名称
     */
    @ExcelProperty(name = "试卷名称", index = 2)
    private String paperName;

    /**
     * 试卷类型
     */
    @ExcelProperty(name = "试卷类型", index = 3)
    private String paperType;
    /**
     * 大题号
     */
    @ExcelProperty(name = "大题号", index = 4)
    private Integer sectionNum;
    /**
     * 小题号
     */
    @ExcelProperty(name = "小题号", index = 5)
    private Integer unitNum;
    /**
     * 题目类型
     */
    @ExcelProperty(name = "题目类型", index = 6)
    private String questionType;
    /**
     * 标准答案
     */
    @ExcelProperty(name = "标准答案", index = 7)
    private String answer;
    /**
     * 小题分数
     */
    @ExcelProperty(name = "小题分数", index = 8)
    private Double unitScore;

    public ObjectiveQuestionStructure() {
    }

    public ObjectiveQuestionStructure(PaperExp paperExp, PaperDetailExp paperDetailExp, PaperDetailUnitExp unit, String paperType) {
        this.courseId = Long.valueOf(paperExp.getCourse().getId());
        this.paperType = paperType;
        this.paperName = paperExp.getName();
        this.courseCode = paperExp.getCourseNo();
        this.courseName = paperExp.getCourseName();
        this.sectionNum = paperDetailExp.getNumber();
        this.questionType = unit.getQuestionType().getName();
        this.unitNum = unit.getNumber();
        this.unitScore = unit.getScore();
        if (StringUtils.isNotBlank(unit.getQuestion().getQuesAnswer())) {
            if (unit.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
                if ("正确".equals(unit.getQuestion().getQuesAnswer())) {
                    this.answer = "A";
                } else if ("错误".equals(unit.getQuestion().getQuesAnswer())) {
                    this.answer = "B";
                } else if ("#".equals(unit.getQuestion().getQuesAnswer())) {
                    this.answer = "#";
                }
            } else if (unit.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
                this.answer = unit.getQuestion().getQuesAnswer().replaceAll(",", "");
            } else {
                this.answer = unit.getQuestion().getQuesAnswer();
            }
        }
    }


    public ObjectiveQuestionStructure(PaperExp paperExp, PaperDetailExp paperDetailExp, PaperDetailUnitExp unit) {
        this.courseCode = paperExp.getCourseNo();
        this.courseName = paperExp.getCourseName();
        this.sectionNum = paperDetailExp.getNumber();
        this.questionType = unit.getQuestionType().getName();
        this.unitNum = unit.getNumber();
        this.unitScore = unit.getScore();
        if (StringUtils.isNotBlank(unit.getQuestion().getQuesAnswer())) {
            if (unit.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
                if ("正确".equals(unit.getQuestion().getQuesAnswer())) {
                    this.answer = "A";
                } else if ("错误".equals(unit.getQuestion().getQuesAnswer())) {
                    this.answer = "B";
                } else if ("#".equals(unit.getQuestion().getQuesAnswer())) {
                    this.answer = "#";
                }
            } else if (unit.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
                this.answer = unit.getQuestion().getQuesAnswer().replaceAll(",", "");
            } else {
                this.answer = unit.getQuestion().getQuesAnswer();
            }
        }
    }

    public ObjectiveQuestionStructure(PaperExp paperExp, PaperDetailExp paperDetailExp, Question question) {
        this.courseCode = paperExp.getCourseNo();
        this.courseName = paperExp.getCourseName();
        this.sectionNum = paperDetailExp.getNumber();
        this.questionType = question.getQuestionType().getName();
        this.unitNum = question.getNumber();
        this.unitScore = question.getScore();
        if (StringUtils.isNotBlank(question.getQuesAnswer())) {
            if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
                if ("正确".equals(question.getQuesAnswer())) {
                    this.answer = "A";
                } else if ("错误".equals(question.getQuesAnswer())) {
                    this.answer = "B";
                } else if ("#".equals(question.getQuesAnswer())) {
                    this.answer = "#";
                }
            } else if (question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
                this.answer = question.getQuesAnswer().replaceAll(",", "");
            } else {
                this.answer = question.getQuesAnswer();
            }
        }
    }

    public Long getCourseId() {
        return courseId;
    }

    public void setCourseId(Long courseId) {
        this.courseId = courseId;
    }

    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 getPaperName() {
        return paperName;
    }

    public void setPaperName(String paperName) {
        this.paperName = paperName;
    }

    public String getPaperType() {
        return paperType;
    }

    public void setPaperType(String paperType) {
        this.paperType = paperType;
    }

    public Integer getSectionNum() {
        return sectionNum;
    }

    public void setSectionNum(Integer sectionNum) {
        this.sectionNum = sectionNum;
    }

    public Integer getUnitNum() {
        return unitNum;
    }

    public void setUnitNum(Integer unitNum) {
        this.unitNum = unitNum;
    }

    public String getQuestionType() {
        return questionType;
    }

    public void setQuestionType(String questionType) {
        this.questionType = questionType;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public Double getUnitScore() {
        return unitScore;
    }

    public void setUnitScore(Double unitScore) {
        this.unitScore = unitScore;
    }

}

