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

import java.util.*;

import com.ssj.bean.sys.knowledge.domain.KnowDimension;
import com.ssj.framework.weixin.util.DateUtil;
import com.ssj.framework.core.util.SystemResourceLocator;
import com.ssj.service.sys.situation.service.LearningSituationService;

public class SituationConstant{
    /**
     * 知识点维度list
     */
    private static  Map<String, List<String>> knows = new HashMap<>();

    /**
     * 技能维度list
     */
    private static   Map<String, List<String>> skills = new HashMap<>();

    /**
     * 学情开始时间
     */
    private static   String beginTime = "0";

    /**
     * 学情结束时间
     */
    private static String endTime = "0";



    private static void initKnowAndSkill (){
        knows = new HashMap<>();
        skills = new HashMap<>();
        LearningSituationService learningSituationService = (LearningSituationService) SystemResourceLocator.getBean(LearningSituationService.class);
        List<KnowDimension> list = learningSituationService.findKnowDimesion();
        if (list != null){
            //知识维度
            List<Map<String, Object>> knowList = learningSituationService.findKnowledgeDimesion();
            knowList.stream().forEach((map) -> {
                if (knows.containsKey((String)map.get("course_name"))) {
                    knows.get((String)map.get("course_name")).add((String)map.get("module"));
                } else {
                    List<String> temp = new ArrayList<>();
                    temp.add((String)map.get("module"));
                    knows.put((String)map.get("course_name"), temp);
                }
            });

            //技能维度
            list.stream().filter( (kd) -> (kd.getType() == 1)).forEach((kd) -> {
                if (skills.containsKey(kd.getCourseName())) {
                    skills.get(kd.getCourseName()).add(kd.getName());
                } else {
                    List<String> temp = new ArrayList<>();
                    temp.add(kd.getName());
                    skills.put(kd.getCourseName(), temp);
                }
            });
        }
    }

    public static Map<String, List<String>> getKnows() {
        if (knows == null || knows.size() == 0){
            initKnowAndSkill();
        }
        return knows;
    }


    public static Map<String, List<String>> getSkills() {
        if (skills == null || skills.size() == 0){
            initKnowAndSkill();
        }
        return skills;
    }


    public static String getBeginTime() {
        return beginTime;
    }

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

    public static String getEndTime() {
        //实时获取结束时间,格式yyyy-MM-dd
        return DateUtil.format_yyyyMMdd(DateUtil.addDays(new Date(), 1));
    }
}
