package cn.com.qmth.stmms.biz.report.model;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 
 * @Description: 统计配置项
 * @author ting.yin
 * @date 2019年6月18日
 */
@Component
public class SasConfigItem {

    // 及格分数
    @Value("${sas.passScore}")
    private Double passScore;

    // 优秀分数
    @Value("${sas.excellentScore}")
    private Double excellentScore;

    // 区分度优
    @Value("${sas.discriminationExcellentValue}")
    private Double discriminationExcellentValue;

    // 区分度良
    @Value("${sas.discriminationGoodValue}")
    private Double discriminationGoodValue;

    // 区分度可
    @Value("${sas.discriminationGeneralValue}")
    private Double discriminationGeneralValue;

    // 区分度差
    @Value("${sas.discriminationBadValue}")
    private Double discriminationBadValue;

    // 难度高
    @Value("${sas.difficultyHighValue}")
    private Double difficultyHighValue;

    // 难度中
    @Value("${sas.difficultyMiddleValue}")
    private Double difficultyMiddleValue;

    // 难度低
    @Value("${sas.difficultyLowValue}")
    private Double difficultyLowValue;

    // 高分段
    @Value("${sas.highValue}")
    private Double highValue;

    // 低分段
    @Value("${sas.lowValue}")
    private Double lowValue;

    public SasConfigItem() {

    }

    public SasConfigItem(String text) {
        text = StringUtils.trimToEmpty(text);
        try {
            JSONObject jsonObject = JSONObject.fromObject(text);
            passScore = jsonObject.getDouble("passScore");
            excellentScore = jsonObject.getDouble("excellentScore");
            discriminationExcellentValue = jsonObject.getDouble("discriminationExcellentValue");
            discriminationGoodValue = jsonObject.getDouble("discriminationGoodValue");
            discriminationGeneralValue = jsonObject.getDouble("discriminationGeneralValue");
            discriminationBadValue = jsonObject.getDouble("discriminationBadValue");
            difficultyHighValue = jsonObject.getDouble("difficultyHighValue");
            difficultyMiddleValue = jsonObject.getDouble("difficultyMiddleValue");
            difficultyLowValue = jsonObject.getDouble("difficultyLowValue");
            highValue = jsonObject.getDouble("highValue");
            lowValue = jsonObject.getDouble("lowValue");
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid SasConfigItem init text:" + text);
        }
    }

    public static SasConfigItem parse(SasConfigItem configItem, String text) {
        SasConfigItem item = new SasConfigItem(text);
        if (item.getDifficultyHighValue() != null) {
            configItem.setDifficultyHighValue(item.getDifficultyHighValue());
        }
        if (item.getDifficultyLowValue() != null) {
            configItem.setDifficultyLowValue(item.getDifficultyLowValue());
        }
        if (item.getDifficultyMiddleValue() != null) {
            configItem.setDifficultyMiddleValue(item.getDifficultyMiddleValue());
        }
        if (item.getDiscriminationBadValue() != null) {
            configItem.setDiscriminationBadValue(item.getDiscriminationBadValue());
        }
        if (item.getDiscriminationExcellentValue() != null) {
            configItem.setDiscriminationExcellentValue(item.getDiscriminationExcellentValue());
        }
        if (item.getDiscriminationGoodValue() != null) {
            configItem.setDiscriminationGoodValue(item.getDiscriminationGoodValue());
        }
        if (item.getDiscriminationGeneralValue() != null) {
            configItem.setDiscriminationGeneralValue(item.getDiscriminationGeneralValue());
        }
        if (item.getHighValue() != null) {
            configItem.setHighValue(item.getHighValue());
        }
        if (item.getLowValue() != null) {
            configItem.setLowValue(item.getLowValue());
        }
        if (item.getExcellentScore() != null) {
            configItem.setExcellentScore(item.getExcellentScore());
        }
        if (item.getPassScore() != null) {
            configItem.setPassScore(item.getPassScore());
        }
        return configItem;
    }

    public Double getPassScore() {
        return passScore;
    }

    public void setPassScore(Double passScore) {
        this.passScore = passScore;
    }

    public Double getExcellentScore() {
        return excellentScore;
    }

    public void setExcellentScore(Double excellentScore) {
        this.excellentScore = excellentScore;
    }

    public Double getDiscriminationExcellentValue() {
        return discriminationExcellentValue;
    }

    public void setDiscriminationExcellentValue(Double discriminationExcellentValue) {
        this.discriminationExcellentValue = discriminationExcellentValue;
    }

    public Double getDiscriminationGoodValue() {
        return discriminationGoodValue;
    }

    public void setDiscriminationGoodValue(Double discriminationGoodValue) {
        this.discriminationGoodValue = discriminationGoodValue;
    }

    public Double getDiscriminationGeneralValue() {
        return discriminationGeneralValue;
    }

    public void setDiscriminationGeneralValue(Double discriminationGeneralValue) {
        this.discriminationGeneralValue = discriminationGeneralValue;
    }

    public Double getDiscriminationBadValue() {
        return discriminationBadValue;
    }

    public void setDiscriminationBadValue(Double discriminationBadValue) {
        this.discriminationBadValue = discriminationBadValue;
    }

    public Double getDifficultyHighValue() {
        return difficultyHighValue;
    }

    public void setDifficultyHighValue(Double difficultyHighValue) {
        this.difficultyHighValue = difficultyHighValue;
    }

    public Double getDifficultyMiddleValue() {
        return difficultyMiddleValue;
    }

    public void setDifficultyMiddleValue(Double difficultyMiddleValue) {
        this.difficultyMiddleValue = difficultyMiddleValue;
    }

    public Double getDifficultyLowValue() {
        return difficultyLowValue;
    }

    public void setDifficultyLowValue(Double difficultyLowValue) {
        this.difficultyLowValue = difficultyLowValue;
    }

    public Double getHighValue() {
        return highValue;
    }

    public void setHighValue(Double highValue) {
        this.highValue = highValue;
    }

    public Double getLowValue() {
        return lowValue;
    }

    public void setLowValue(Double lowValue) {
        this.lowValue = lowValue;
    }

}
