package com.ssj.service.conch.parents.v2.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.ssj.framework.weixin.util.DateUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * @description
 * @author yrf
 * @time 2019/11/27 11:14
 */
public class StudentWeeklyReportDTO implements Serializable {

    private static final long serialVersionUID = 4221805554749654299L;

    private String vipId;

    @JSONField(serialize = false)
    private String subjectStr;

    @JSONField(serialize = false)
    private String accuracyRateStr;

    private Integer totalKnowledgeNum;
    private Integer masterWellKnowledgeNum;
    private Integer masterInfirmlyKnowledgeNum;
    private Integer notMasteredKnowledgeNum;
    private String beginTime;
    private String endTime;
    private List<LearningScore> learningScoreList;

    public String getVipId() {
        return vipId;
    }

    public void setVipId(String vipId) {
        this.vipId = vipId;
    }

    public String getSubjectStr() {
        return subjectStr;
    }

    public void setSubjectStr(String subjectStr) {
        this.subjectStr = subjectStr;
    }

    public String getAccuracyRateStr() {
        return accuracyRateStr;
    }

    public void setAccuracyRateStr(String accuracyRateStr) {
        this.accuracyRateStr = accuracyRateStr;
    }

    public Integer getTotalKnowledgeNum() {
        return totalKnowledgeNum;
    }

    public void setTotalKnowledgeNum(Integer totalKnowledgeNum) {
        this.totalKnowledgeNum = totalKnowledgeNum;
    }

    public Integer getMasterWellKnowledgeNum() {
        return masterWellKnowledgeNum;
    }

    public void setMasterWellKnowledgeNum(Integer masterWellKnowledgeNum) {
        this.masterWellKnowledgeNum = masterWellKnowledgeNum;
    }

    public Integer getMasterInfirmlyKnowledgeNum() {
        return masterInfirmlyKnowledgeNum;
    }

    public void setMasterInfirmlyKnowledgeNum(Integer masterInfirmlyKnowledgeNum) {
        this.masterInfirmlyKnowledgeNum = masterInfirmlyKnowledgeNum;
    }

    public Integer getNotMasteredKnowledgeNum() {
        return notMasteredKnowledgeNum;
    }

    public void setNotMasteredKnowledgeNum(Integer notMasteredKnowledgeNum) {
        this.notMasteredKnowledgeNum = notMasteredKnowledgeNum;
    }

    public String getBeginTime() {
        Date beginDate = DateUtil.parse_yyyyMMdd(this.beginTime);
        if (beginDate == null) {
            return "";
        }
        return DateUtil.format(beginDate.getTime(), "yyyy.MM.dd");
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        Date endDate = DateUtil.parse_yyyyMMdd(this.endTime);
        if (endDate == null) {
            return "";
        }
        return DateUtil.format(endDate.getTime(), "yyyy.MM.dd");
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public List<LearningScore> getLearningScoreList() {
        if (CollectionUtils.isEmpty(learningScoreList) && StringUtils.isNotBlank(subjectStr) && StringUtils.isNotBlank(accuracyRateStr)) {
            List<String> orderRegulation = Arrays.asList("语文", "数学", "英语");
            learningScoreList = new LinkedList<>();
            String[] subjects = subjectStr.split(",");
            String[] accuracyRates = accuracyRateStr.split(",");
            for (int i = 0; i < subjects.length; i++) {
                learningScoreList.add(new LearningScore(subjects[i], Integer.parseInt(accuracyRates[i])));
            }
            learningScoreList.sort((o1, o2) -> {
                int index1 = orderRegulation.indexOf(o1.getSubject());
                int index2 = orderRegulation.indexOf(o2.getSubject());
                return (index1 == -1 || index2 == -1) ? index2 - index1 : index1 - index2;
            });
        }
        return learningScoreList;
    }

    public void setLearningScoreList(List<LearningScore> learningScoreList) {
        this.learningScoreList = learningScoreList;
    }

    static class LearningScore {
        String subject;
        int learningScore;

        private LearningScore(String subject, int learningScore) {
            this.subject = subject;
            this.learningScore = learningScore;
        }

        public String getSubject() {
            return subject;
        }

        public int getLearningScore() {
            return learningScore;
        }
    }
}
