package cn.com.qmth.stmms.biz.report.utils.module;

import org.apache.commons.lang.StringUtils;

import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
import cn.com.qmth.stmms.biz.report.utils.Module;
import cn.com.qmth.stmms.biz.report.utils.QuestionCalculatorProvider;
import cn.com.qmth.stmms.biz.report.utils.ReportContext;
import cn.com.qmth.stmms.biz.report.utils.unit.BaseCalculatorUnit;

/**
 * 按科目+机组维度统计小题指标
 * 
 * @author luoshi
 *
 */
public class SubjectClassQuestionModule extends SubjectQuestionModule implements Module, QuestionCalculatorProvider {

    public SubjectClassQuestionModule(ReportContext context) {
        super(context);
    }

    @Override
    protected void process(ExamStudent student, ExamQuestion question, double score, double totalScore) {
        findCalculator(getKey(question, student.getClassName())).process(score, question.getTotalScore(), totalScore);
    }

    @Override
    public String getKey(ExamQuestion question, Object... parameter) {
        return question.getSubjectCode() + "\t" + parameter[0] + "\t" + question.isObjective() + "\t"
                + StringUtils.trimToEmpty(question.getPaperType()) + "\t" + question.getMainNumber() + "\t"
                + question.getSubNumber();
    }

    @Override
    public BaseCalculatorUnit getCalculator(ExamQuestion question, Object... parameter) {
        return calculators.get(getKey(question, parameter));
    }

    @Override
    public void save() {
        // 暂时不需要保存到数据库
    }

}
