package com.ruoyi.common.utils.dz;

import com.fasterxml.jackson.annotation.JsonValue;
import com.ruoyi.common.enums.SubjectType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.beanutils.PropertyUtils;

import java.lang.reflect.InvocationTargetException;

@Data
@ApiModel("分科成绩")
public class SubjectScore {
    @ApiModelProperty(value = "物理", example = "80")
    Double physics;
    @ApiModelProperty(value = "历史", example = "80")
    Double history;
    @ApiModelProperty(value = "化学", example = "80")
    Double chemistry;
    @ApiModelProperty(value = "生物", example = "80")
    Double biology;
    @ApiModelProperty(value = "地理", example = "80")
    Double geography;
    @ApiModelProperty(value = "政治", example = "80")
    Double political;
    @ApiModelProperty(value = "语文", example = "80")
    Double chinese;
    @ApiModelProperty(value = "数学", example = "80")
    Double mathematics;
    @ApiModelProperty(value = "英语", example = "80")
    Double english;
    @ApiModelProperty(value = "外语", example = "80")
    Double foreign;
    @ApiModelProperty(value = "技能", example = "80")
    Double skill;

    /** 物化生历政地 语数英外 **/
    public Double getSelectScore(String name) {
        Double totalScore = 0.0;
        for(String ch : name.split("")) {
            SubjectType st = SubjectType.parse(ch);
            try {
                Object val = PropertyUtils.getProperty(this, st.name().toLowerCase());
                totalScore += Double.valueOf(val.toString());
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
        }
        return totalScore;
    }
}
