package com.ssj.service.sys.situation.service.impl;

import com.ssj.framework.core.util.SystemResourceLocator;
import com.ssj.service.sys.situation.bo.DimesionCount;
import com.ssj.service.sys.situation.constant.SituationConstant;
import com.ssj.service.sys.situation.service.LearningSituationService;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

public class One2OneSituation extends AbstractKnowledgeSituation {

    public One2OneSituation (String studentId, String courseName) {
        this.studentId = studentId;
        this.courseName = courseName;
        this.learningSituationService = (LearningSituationService) SystemResourceLocator.getBean("learningSituationServiceImpl");
        this.getCalculate();
    }

    @Override
    public void getKnowDimensionCount() {
        //各维度错题数量
        List<Map<String, Object>> wrongList = learningSituationService.get121WrongKnowModuleData(this.studentId, this.courseName,
                SituationConstant.getBeginTime(), SituationConstant.getEndTime());
        //各维度总体数量
        List<Map<String, Object>> totalList = learningSituationService.get121KnowModuleData(this.studentId, this.courseName,
                SituationConstant.getBeginTime(), SituationConstant.getEndTime());
        super.findKnowDimensionCount(wrongList, totalList);
    }

    @Override
    public void getSkillDimensionCount() {
        //错题
        List<String> wrongList = new ArrayList<>();
        List<String> wl = learningSituationService.get121SkillWrongData(this.studentId, this.courseName,
                SituationConstant.getBeginTime(), SituationConstant.getEndTime());
        //先把单个string里的按;分割
        if (wl != null) {
            wl.forEach((str) -> {
                if (StringUtils.isNotBlank(str)){
                    Arrays.asList(str.split(";")).forEach((skill) -> {
                        wrongList.add(skill);
                    });
                }
            });
        }
        //把技能维度变成map, value存储计算的数量
        Map<String, Integer> wrongMap = new HashMap<>();
        wrongList.forEach((skill) -> {
            if (wrongMap.containsKey(skill)) {
                wrongMap.put(skill, wrongMap.get(skill) + 1);
            } else {
                wrongMap.put(skill, 1);
            }
        });

        //总体
        List<String> totalList = new ArrayList<>();
        List<String> tl = learningSituationService.get121SkillData(this.studentId, this.courseName,
                SituationConstant.getBeginTime(), SituationConstant.getEndTime());
        //先把单个string里的按;分割
        if (tl != null) {
            tl.forEach((str) -> {
                if (StringUtils.isNotBlank(str)) {
                    Arrays.asList(str.split(";")).forEach((skill) -> {
                        totalList.add(skill);
                    });
                }
            });
        }
        //把技能维度变成map, value存储计算的数量
        Map<String, Integer> totalMap = new HashMap<>();
        totalList.forEach((skill) -> {
            if (totalMap.containsKey(skill)){
                totalMap.put(skill, totalMap.get(skill) + 1);
            } else {
                totalMap.put(skill, 1);
            }
        });
        super.findSkillDimensionCount(wrongMap, totalMap);
    }

    @Override
    public void getKnowledgeCount() {

    }

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public List<DimesionCount> getKnowList() {
        return knowList;
    }

    public void setKnowList(List<DimesionCount> knowList) {
        this.knowList = knowList;
    }

    public List<DimesionCount> getSkillList() {
        return skillList;
    }

    public void setSkillList(List<DimesionCount> skillList) {
        this.skillList = skillList;
    }

    public int getUnderstandWrongCount() {
        return understandWrongCount;
    }

    public void setUnderstandWrongCount(int understandWrongCount) {
        this.understandWrongCount = understandWrongCount;
    }

    public int getUnderstandTotalCount() {
        return understandTotalCount;
    }

    public void setUnderstandTotalCount(int understandTotalCount) {
        this.understandTotalCount = understandTotalCount;
    }

    public int getMemoryWrongCount() {
        return memoryWrongCount;
    }

    public void setMemoryWrongCount(int memoryWrongCount) {
        this.memoryWrongCount = memoryWrongCount;
    }

    public int getMemoryTotalCount() {
        return memoryTotalCount;
    }

    public void setMemoryTotalCount(int memoryTotalCount) {
        this.memoryTotalCount = memoryTotalCount;
    }

    public int getApplyWrongCount() {
        return applyWrongCount;
    }

    public void setApplyWrongCount(int applyWrongCount) {
        this.applyWrongCount = applyWrongCount;
    }

    public int getApplyTotalCount() {
        return applyTotalCount;
    }

    public void setApplyTotalCount(int applyTotalCount) {
        this.applyTotalCount = applyTotalCount;
    }
}
