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

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.sys.knowledge.domain.KnowDimension;
import com.ssj.bean.sys.situation.domain.LearningSituation;
import com.ssj.bean.sys.situation.domain.LearningSituationSuggest;
import com.ssj.bean.weixin.libmy.domain.LibVip;
import com.ssj.conch.constant.ConchConstants;
import com.ssj.conch.util.enums.GradeEnum;
import com.ssj.dao.sys.situation.dao.ISituationDao;
import com.ssj.dao.sys.situation.dao.LearningConditionDao;
import com.ssj.dao.sys.situation.dao.SituationDao;
import com.ssj.dao.sys.situation.dao.SituationSuggestDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.framework.core.security.exception.CommonException;
import com.ssj.framework.core.security.manager.TokenManager;
import com.ssj.framework.core.util.PropertiesUtil;
import com.ssj.framework.core.util.RedisUtil;
import com.ssj.framework.core.util.ResponseEntity;
import com.ssj.framework.core.util.StringUtil;
import com.ssj.framework.weixin.util.DateUtil;
import com.ssj.service.conch.parents.dto.*;
import com.ssj.service.conch.teacher.request.teacherorg.SubjectLearningSituationReq;
import com.ssj.service.conch.zyb.constant.SuggestTextUtil;
import com.ssj.service.mapper.HomeworkMapper;
import com.ssj.service.sys.knowledge.service.KnowDimensionService;
import com.ssj.service.sys.problem.service.IBanbenDetailService;
import com.ssj.service.sys.situation.constant.SituationConstant;
import com.ssj.service.sys.situation.service.LearningConditionService;
import com.ssj.service.sys.situation.service.LearningSituationService;
import com.ssj.service.sys.situation.service.LearningSituationSuggestService;
import com.ssj.service.weixin.library.service.ILibVipService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Service(version="1.0")
@Transactional
public class LearningSituationServiceImpl extends BaseServiceImpl<LearningSituation, String> implements LearningSituationService {

    private final Logger logger = LoggerFactory.getLogger(LearningSituationServiceImpl.class);

    @Autowired
    private ISituationDao dao;

    @Autowired
    private SituationDao situationDao;

    @Autowired
    private KnowDimensionService knowDimensionService;

    @Autowired
    private ILibVipService vipService;

    @Autowired
    private TokenManager tokenManager;

    @Autowired
    private LearningSituationSuggestService suggestService;
    
    @Autowired
    private SituationSuggestDao suggestDao;
    

    
    @Autowired
    private RedisUtil redisUtil;
    
    @Autowired
    private LearningConditionService conditionService;
    
    @Autowired
    private LearningConditionDao conditionDao;
    
    @Autowired
    private IBanbenDetailService banbenService;
    @Autowired
    private HomeworkMapper homeworkMapper;

    @Override
    public PagingAndSortingRepository<LearningSituation, String> getDao() {
        return dao;
    }

    @Override
    public List<String> getServiceStudentIds() {
        return situationDao.queryAllServiceStudent();
    }
    


    @Override
    public List<LearningSituation> getLearningSituation(String studentId) {
        return dao.findByStudentIdOrStudentIdIsNull(studentId);
    }

    @Override
    public List<LearningSituation> getLearningSituation(String courseName, String studentId) {
        List<LearningSituation> result = null;
        if (StringUtils.isBlank(courseName)){
            result = this.getLearningSituation(studentId);
        } else {
            result = dao.findByCourseNameAndStudentId(courseName, studentId);
        }
        return result;
    }

    @Override
    public LearningSituationDetailDto learningSituationDetail(String vipId, String subject) {
//        LearningSituationDetailDto result = tokenManager.get("learningsituation_" + vipId + "_" + subject, LearningSituationDetailDto.class);
        LearningSituationDetailDto result = null;
        if (result == null) {
            List<LearningSituation> list = this.getLearningSituation(subject, vipId);
            result = new LearningSituationDetailDto();
            result.setKnowledge(this.getKnowledge(list, subject, vipId));
            result.setSkill(this.getSkill(list, subject, vipId));
            result.setKnowledgePoint(this.getKnowledgePoint(list, vipId, subject));
//            tokenManager.set("learningsituation_" + vipId + "_" + subject, result, 24 * 3600);
        }
        return result;
    }

    @Override
    public LearningSituationDetail2Dto learningSituationDetail2(String vipId, String subject) {
//        LearningSituationDetail2Dto result = tokenManager.get("learningsituationV2_" + vipId + "_" + subject, LearningSituationDetail2Dto.class);
        LearningSituationDetail2Dto result = null;
        if (result == null) {
            List<LearningSituation> list = this.getLearningSituation(subject, vipId);
            if (list != null && list.size() > 0) {
                result = new LearningSituationDetail2Dto();
                result.setKnowledge(this.getKnowledge2(list, subject, vipId));
                result.setSkill(this.getSkill2(list, subject, vipId));
                result.setKnowledgePoint(this.getKnowledgePoint2(list, vipId, subject));
                tokenManager.set("learningsituationV2_" + vipId + "_" + subject, result, 24 * 3600);
            }
        }
        return result;
    }

    @Override
    public LearningSituationDetailNewDto learningSituationDetailNew(SubjectLearningSituationReq req) throws CommonException {
        String vipId = req.getVipId();
        LibVip vip = vipService.getById(vipId);
        if (vip == null) {
            throw new CommonException("孩子不存在");
        }

    	Integer semester = req.getSemester();
        if (semester == null || semester < 1 || semester > 2) {
            semester = Integer.parseInt(PropertiesUtil.getValue("semester"));
        }
        String grade = req.getGrade();
        if (StringUtils.isBlank(grade)) {
            grade = vip.getGrade();
        }
        if (StringUtils.isBlank(grade)) {
            throw new CommonException("请先完善孩子年级信息");
        }
        String subject = req.getSubject();
        Integer banben = banbenService.findBanben(subject, vip.getSchool(), grade);
    	List<String> dimeList = conditionService.getDimensionList(GradeEnum.getIndexByGrade(grade), semester, subject, banben);
    	LearningSituationDetailNewDto result = new LearningSituationDetailNewDto();
        result.setKnowledge(this.getKnowledgeNew(subject, vipId, grade, semester, dimeList));
//        result.setSkill(this.getSkillNew(subject, vipId, dimeList));
        result.setKnowledgePoint(this.getKnowledgePointNew(vipId, subject, grade, semester, dimeList));
//        tokenManager.set("learningsituationV2_" + vipId + "_" + subject, result, 24 * 3600);

        result.setHomeworkAccuracyRateList(new ArrayList<>());

        return result.getKnowledge() == null && result.getKnowledgePoint() == null ? null : result;
    }

    /**
     * 查询学生作业正确率列表
     * @param vipId 学生
     * @param beginTime 开始时间
     * @param endTime 结束时间
     * @return 正确率列表
     */
    @Override
    public List<HomeworkAccuracyRateDto> getHomeworkAccuracyRateList(String vipId, Date beginTime, Date endTime) {
        String beginTimeStr = DateUtil.format_yyyyMMdd(beginTime) + " 00:00:00";
        String endTimeStr = DateUtil.format_yyyyMMdd(endTime) + " 23:59:59";
        List<HomeworkAccuracyRateDto> homeworkAccuracyRateDtoList = homeworkMapper.findHomeworkAccuracyRateList(vipId, beginTimeStr, endTimeStr);
        Map<String, List<HomeworkAccuracyRateDto>> tempMap = homeworkAccuracyRateDtoList.stream()
                .collect(Collectors.groupingBy(it -> DateUtil.format(it.getDate().getTime(), "MM.dd")));
        List<HomeworkAccuracyRateDto> finalHomeworkAccuracyRateDtoList = new LinkedList<>();
        int flag = 0;
        HomeworkAccuracyRateDto tempHomeworkAccuracyRateDto;
        for (int i = 0; i < 7; i++) {
            tempHomeworkAccuracyRateDto = new HomeworkAccuracyRateDto();
            Date tempTime = DateUtil.addDays(beginTime, i);
            List<HomeworkAccuracyRateDto> tempList = tempMap.get(DateUtil.format(tempTime.getTime(), "MM.dd"));
            if (CollectionUtils.isEmpty(tempList)) {
                tempHomeworkAccuracyRateDto.setDate(tempTime);
                tempHomeworkAccuracyRateDto.setRate(-1);
                finalHomeworkAccuracyRateDtoList.add(tempHomeworkAccuracyRateDto);
                flag++;
                continue;
            }
            int wrongCount = 0;
            int totalCount = 0;
            for (HomeworkAccuracyRateDto homeworkAccuracyRateDto : tempList) {
                wrongCount += Optional.ofNullable(homeworkAccuracyRateDto.getWrongCount()).orElse(0);
                totalCount += Optional.ofNullable(homeworkAccuracyRateDto.getTotalCount()).orElse(0);
            }
            tempHomeworkAccuracyRateDto.setDate(tempList.get(0).getDate());
            int rate = 0;
            if (totalCount > 0) {
                rate = (totalCount - wrongCount) * 100 / totalCount;
            }
            tempHomeworkAccuracyRateDto.setRate(rate);
            finalHomeworkAccuracyRateDtoList.add(tempHomeworkAccuracyRateDto);
        }
        if(flag == 7) {
            //如果7天都没有数据则返回空数据给前端
            finalHomeworkAccuracyRateDtoList = new LinkedList<>();
        }
        return finalHomeworkAccuracyRateDtoList;
    }

    public KnowledgeSkillDto getKnowledgeNew(String subject, String vipId, String grade, Integer semester, List<String> dimeList) {
    	List<LearningSituation> knowList = dao.findByCourseNameAndStudentIdAndType(subject, vipId, ConchConstants.SITUATION_TYPE_KONWLEDGE, semester, grade);
    	List<LearningSituation> avgKnowList = dao.findByCourseNameAndGradeAndSemesterAndTypeAndStudentIdIsNull(subject, grade, semester, ConchConstants.SITUATION_TYPE_KONWLEDGE);
    	KnowledgeSkillDto knowDto = new KnowledgeSkillDto();
    	if(knowList.size() == 0) {
    		return null;
    	}
    	List<Integer> thisMonthTrueCount = new ArrayList<Integer>();
    	List<Integer> overallAvgTrueCount = new ArrayList<Integer>();
    	//放在redis比较好
		knowDto.setDimension(dimeList);
		for(String dimension : knowDto.getDimension()) {
			knowList.forEach(situation -> {
				if(dimension.equals(situation.getDimension())) {
					thisMonthTrueCount.add(situation.getDegreePercent() == 0 ? ConchConstants.SITUATION_DIMENSION_MIN : situation.getDegreePercent());
				}
			});
			//没有维度值则设置默认值
			if(thisMonthTrueCount.size() < knowDto.getDimension().indexOf(dimension) + 1) {
				thisMonthTrueCount.add(ConchConstants.SITUATION_DIMENSION_DEFAULT);
			}
			avgKnowList.forEach(situation -> {
				if(dimension.equals(situation.getDimension())) {
					overallAvgTrueCount.add(situation.getDegreePercent() == 0 ? ConchConstants.SITUATION_DIMENSION_MIN : situation.getDegreePercent());
				}
			});
			//没有维度值则设置默认值
			if(overallAvgTrueCount.size() < knowDto.getDimension().indexOf(dimension) + 1) {
				overallAvgTrueCount.add(ConchConstants.SITUATION_DIMENSION_DEFAULT);
			}
		}
		//学生维度值
		knowDto.setThisMonthTrueCount(thisMonthTrueCount);
		knowDto.setOverallAvgTrueCount(overallAvgTrueCount);
		createKnowledgeDiagnosticAndSuggest(knowDto, knowList);
//		createLearningSuggestNew(knowDto, knowList);
		return knowDto;
	}

	@Override
	public List<LearningSituation> findByCourseNameAndStudentIdAndType(String subject, String vipId, Integer type, Integer semester, String grade){
        return dao.findByCourseNameAndStudentIdAndType(subject, vipId, type, semester, grade);
    }

    public List<KnowledgePointDto> getKnowledgePointNew(String vipId, String subject, String grade, Integer semester, List<String> dimeList) {
    	List<LearningSituation> pointList = dao.findByCourseNameAndStudentIdAndType(subject, vipId, ConchConstants.SITUATION_TYPE_KONWLEDGE, semester, grade);
    	List<KnowledgePointDto> pointDtoList = new ArrayList<KnowledgePointDto>();
    	if(pointList.size() == 0) {
    		return null;
    	}
    	for(String dimension: dimeList) {
    		LearningSituation situation = pointList.stream().filter(point -> point.getDimension().equals(dimension)).findFirst().orElse(null);
    		if(situation == null) {
    			continue;
    		}
    		KnowledgePointDto pointDto = new KnowledgePointDto();
    		pointDto.setWrongNum(situation.getWrongCount());
    		pointDto.setTotalNum(situation.getTotalCount());
    		pointDto.setPercent(100 - situation.getDegreePercent());
    		List<Map<String, Object>> noList = getNoKnowledgePointDemo(subject, vipId, dimension, situation.getGrade());
    		List<NoKnowledgePointDto> noPointDtos = new ArrayList<NoKnowledgePointDto>();
    		noList.forEach(map -> {
//    			if (StringUtils.isNotBlank((String)(map.get("ydsl")))){
    				NoKnowledgePointDto noDto = new NoKnowledgePointDto() ;
//                    String celebrityStr = ((String)(map.get("ydsl"))).replaceAll("\r\n", "").replaceAll("　", "").trim();
//                    noDto.setCelebrities(Arrays.asList(celebrityStr.split("#N")));
                    noDto.setName((String)(map.get("name")));
                    noPointDtos.add(noDto);
//                }
    		});
    		pointDto.setNoKnowledgePoint(noPointDtos);
    		pointDto.setStyle(dimension);
    		pointDtoList.add(pointDto);
    	}
		return pointDtoList;
	}

    public KnowledgeSkillDto getSkillNew(String subject, String grade, String vipId, List<String> dimeList) {
		List<LearningSituation> skillList = dao.findByCourseNameAndStudentIdAndType(subject, vipId, ConchConstants.SITUATION_TYPE_SKILL, Integer.parseInt(PropertiesUtil.getValue("semester")), grade);
		KnowledgeSkillDto skillDto = new KnowledgeSkillDto();
		if(skillList.size() == 0) {
			return skillDto;
		}
		List<Integer> thisMonthTrueCount = new ArrayList<Integer>();
    	//放在redis比较好
		skillDto.setDimension(dimeList);
		skillDto.getDimension().forEach(dimension -> {
			skillList.forEach(situation -> {
				if(dimension.equals(situation.getDimension())) {
					thisMonthTrueCount.add(situation.getDegreePercent());
				}
			});
			//没有维度值则设置默认值
			if(thisMonthTrueCount.size() < skillDto.getDimension().indexOf(dimension) + 1) {
				thisMonthTrueCount.add(ConchConstants.SITUATION_DIMENSION_DEFAULT);
			}
		});
		//学生维度值
		skillDto.setThisMonthTrueCount(thisMonthTrueCount);
		createSkillDiagnostic(skillDto);
		createLearningSuggestNew(skillDto, skillList);
		return skillDto;
	}

    

	private void createLearningSuggestNew(KnowledgeSkillDto knowDto, List<LearningSituation> knowList) {
		for(LearningSituation situation : knowList) {
			LearningSituationSuggest suggest = suggestDao.findById(situation.getSuggestId());
			if (suggest != null){
                String suggestStr = suggest.getStandard() + suggest.getSuggest();
                if (StringUtil.isNotBlank(suggestStr)){
                	knowDto.addSuggest(situation.getDimension() + "部分如何提升能力?", suggestStr);
                }
            }
			//学习建议只显示三条
			if(knowDto.getLeaningSuggest().size() > 2) {
				return;
			}
		}
	}

	/**
     * 查询维度
     * @param subject
     * @param type
     * @return
     */
    @Override
    public Map<String, String> getDimension (String subject, int type) {
        List<KnowDimension> list = knowDimensionService.findBySubjectAndType(subject, type);
        Map<String, String> result = new HashMap<String, String>();
        if (list != null){
            for (KnowDimension kd : list){
                result.put(kd.getName(), kd.getRemark());
            }
        }
        return result;
    }

    /**
     * 学情知识维度模块
     * @param list
     * @param subject
     * @param vipId
     * @return
     */
    private KnowledgeSkillDto getKnowledge (List<LearningSituation> list, String subject, String vipId){
        KnowledgeSkillDto result = new KnowledgeSkillDto();
        //知识维度
        Map<String, String> dimensions = this.getDimension(subject, 0);
        result.setDimension(new ArrayList<>(dimensions.keySet()));

        if (list != null) {
            //学生的知识维度
     //       List<String> rmDimension = new ArrayList<>();
            List<LearningSituation> knowledges = list.stream().filter(learningSituation ->
                    learningSituation.getType() == 1).collect(Collectors.toList());
            result.getDimension().forEach(dimension -> {
                LearningSituation learningSituation = knowledges.stream().filter(
                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
                if (learningSituation == null){
                    result.addThisCount(100);
                } else {
                    if (learningSituation.getTotalCount() != null && learningSituation.getWrongCount() != 0
                            && learningSituation.getWrongCount() != null && learningSituation.getWrongCount() != 0){
                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
                        result.addThisCount(score);
                    } else {
                        result.addThisCount(100);
                    }
                }
            });

            //整体知识维度
//            List<LearningSituation> totalKnow = list.stream().filter(learningSituation ->
//                    learningSituation.getType() == 3).collect(Collectors.toList());
//            result.getDimension().forEach(dimension -> {
//                LearningSituation learningSituation = totalKnow.stream().filter(
//                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
//                if (learningSituation == null){
//                    result.addAvgCount(100);
//                } else {
//                    if (learningSituation.getTotalCount() != null && learningSituation.getTotalCount() != 0){
//                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
//                        result.addAvgCount(score);
//                    } else {
//                        result.addAvgCount(100);
//                    }
//                }
//            });

            //不影响线上
            result.getDimension().forEach(dimension -> {
                result.addLastCount(100);
                result.addAvgCount(100);
            });

            this.createKnowledgeDiagnostic(result);
            this.createLearningSuggest(result, vipId);
        }

        return result;
    }

    /**
     * 学情知识维度模块
     * @param list
     * @param subject
     * @param vipId
     * @return
     */
    private KnowledgeSkillDto getKnowledge2 (List<LearningSituation> list, String subject, String vipId){
        if (list == null || list.size() == 0){
            return null;
        }
        List<LearningSituation> knowledges = list.stream().filter(learningSituation ->
                learningSituation.getType() == 1).collect(Collectors.toList());

        if (knowledges != null && knowledges.size() > 0) {
            KnowledgeSkillDto result = new KnowledgeSkillDto();
            //知识维度
            result.setDimension(SituationConstant.getKnows().get(subject));
            result.getDimension().forEach(dimension -> {
                LearningSituation learningSituation = knowledges.stream().filter(
                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
                if (learningSituation == null){
                    result.addThisCount(0);
                } else {
                    if (learningSituation.getTotalCount() != null && learningSituation.getTotalCount() != 0){
                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
                        result.addThisCount(score);
                    } else {
                        result.addThisCount(0);
                    }
                }
            });


            //整体知识维度
            List<LearningSituation> totalKnow = list.stream().filter(learningSituation ->
                    learningSituation.getType() == 3).collect(Collectors.toList());
            result.getDimension().forEach(dimension -> {
                LearningSituation learningSituation = totalKnow.stream().filter(
                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
                if (learningSituation == null){
                    result.addAvgCount(0);
                } else {
                    if (learningSituation.getTotalCount() != null && learningSituation.getTotalCount() != 0){
                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
                        result.addAvgCount(score);
                    } else {
                        result.addAvgCount(0);
                    }
                }
            });

            this.createKnowledgeDiagnostic(result);
            this.createLearningSuggestV1(result, subject, vipId, 1);
            return result;
        }
        return null;

    }

    /**
     *  学情技能维度模块
     * @param list
     * @param subject
     * @param vipId
     * @return
     */
    private KnowledgeSkillDto getSkill (List<LearningSituation> list, String subject, String vipId){
        if (list == null || list.size() == 0){
            return null;
        }
        KnowledgeSkillDto result = null;
        List<LearningSituation> skill = list.stream().filter(learningSituation ->
                learningSituation.getType() == 2).collect(Collectors.toList());
        if (skill != null && skill.size() > 0) {
            //学生的技能维度
            result = new KnowledgeSkillDto();
            //技能维度
            Map<String, String> dimensions = this.getDimension(subject, 1);
            result.setDimension(new ArrayList<>(dimensions.keySet()));
            KnowledgeSkillDto finalResult = result;
            result.getDimension().forEach(dimension -> {
                LearningSituation learningSituation = skill.stream().filter(
                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
                if (learningSituation == null){
                    finalResult.addThisCount(100);
                } else {
                    if (learningSituation.getTotalCount() != null && learningSituation.getTotalCount() != 0
                            && learningSituation.getWrongCount() != null && learningSituation.getWrongCount() != 0){
                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
                        finalResult.addThisCount(score);
                    } else {
                        finalResult.addThisCount(100);
                    }
                }
            });

            //整体技能维度
//            List<LearningSituation> totalSkill = list.stream().filter(learningSituation ->
//                    learningSituation.getType() == 4).collect(Collectors.toList());
//            result.getDimension().forEach(dimension -> {
//                LearningSituation learningSituation = totalSkill.stream().filter(
//                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
//                if (learningSituation == null){
//                    result.addAvgCount(100);
//                } else {
//                    if (learningSituation.getTotalCount() != null && learningSituation.getTotalCount() != 0){
//                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
//                        result.addAvgCount(score);
//                    } else {
//                        result.addAvgCount(100);
//                    }
//                }
//            });

            //不影响线上
            KnowledgeSkillDto finalResult1 = result;
            result.getDimension().forEach(dimension -> {
                finalResult1.addLastCount(100);
                finalResult1.addAvgCount(100);
            });

            this.createSkillDiagnostic(result);
            this.createLearningSuggest(result, vipId);
        }


        return result;
    }


    /**
     *  学情技能维度模块
     * @param list
     * @param subject
     * @param vipId
     * @return
     */
    private KnowledgeSkillDto getSkill2 (List<LearningSituation> list, String subject, String vipId){
        if (list == null || list.size() == 0){
            return null;
        }
        List<LearningSituation> skill = list.stream().filter(learningSituation ->
                learningSituation.getType() == 2).collect(Collectors.toList());
        if (skill != null && skill.size() > 0) {
            //学生的技能维度
            KnowledgeSkillDto result = new KnowledgeSkillDto();
            //技能维度
            Map<String, String> dimensions = this.getDimension(subject, 1);
            result.setDimension(new ArrayList<>(dimensions.keySet()));

            KnowledgeSkillDto finalResult = result;
            result.getDimension().forEach(dimension -> {
                LearningSituation learningSituation = skill.stream().filter(
                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
                if (learningSituation == null){
                    finalResult.addThisCount(0);
                } else {
                    if (learningSituation.getTotalCount() != null && learningSituation.getTotalCount() != 0){
                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
                        finalResult.addThisCount(score);
                    } else {
                        finalResult.addThisCount(0);
                    }
                }
            });

            //整体技能维度
            List<LearningSituation> totalSkill = list.stream().filter(learningSituation ->
                    learningSituation.getType() == 4).collect(Collectors.toList());
            KnowledgeSkillDto finalResult1 = result;
            result.getDimension().forEach(dimension -> {
                LearningSituation learningSituation = totalSkill.stream().filter(
                        ls -> ls.getRemark().equals(dimension)).findFirst().orElse(null);
                if (learningSituation == null){
                    finalResult1.addAvgCount(0);
                } else {
                    if (learningSituation.getTotalCount() != null && learningSituation.getTotalCount() != 0){
                        int score = 100 - (int)(learningSituation.getWrongCount() * 1.0 /learningSituation.getTotalCount() * 100);
                        finalResult1.addAvgCount(score);
                    } else {
                        finalResult1.addAvgCount(0);
                    }
                }
            });

            this.createSkillDiagnostic(result);
            this.createLearningSuggestV1(result, subject, vipId, 2);
            return result;
        }
        return null;
    }



    /**
     * 生成知识维度诊断说明
     */
    private void createKnowledgeDiagnostic (KnowledgeSkillDto data) {
        List<String> goodDimension = new ArrayList<>();
        List<String> middleDimension = new ArrayList<>();
        List<String> badDimension = new ArrayList<>();
        List<String> advanceDimension = new ArrayList<>();
        List<String> interirotyDimension = new ArrayList<>();
        List<Integer> basic = data.getThisMonthTrueCount();
        List<String> dimension = data.getDimension();
        for (int i = 0; i < basic.size(); i++){
            if (basic.get(i).intValue() > 85){
                goodDimension.add(dimension.get(i));
            } else if (basic.get(i).intValue() > 65){
                middleDimension.add(dimension.get(i));
            } else if (basic.get(i).intValue() >= 0){
                badDimension.add(dimension.get(i));
            }
        }
        /**
         * 去掉所有人平均值 by young.du
         */
        for (int i = 0; i < dimension.size(); i ++){
            if (data.getThisMonthTrueCount().get(i) >= 0 && data.getOverallAvgTrueCount().get(i) >= 0){
                if (data.getThisMonthTrueCount().get(i) > data.getOverallAvgTrueCount().get(i)){
                    advanceDimension.add(dimension.get(i));
                } else {
                    interirotyDimension.add(dimension.get(i));
                }
            }
        }

        data.setDiagnostic(this.dataIntoSuggest(goodDimension, middleDimension, badDimension, advanceDimension, interirotyDimension));
    }
    
    private void createKnowledgeDiagnosticAndSuggest (KnowledgeSkillDto knowDto, List<LearningSituation> list) {
        List<String> goodDimension = new ArrayList<>();
        List<String> middleDimension = new ArrayList<>();
        List<String> badDimension = new ArrayList<>();
        List<String> advanceDimension = new ArrayList<>();
        List<String> interirotyDimension = new ArrayList<>();
        for(String dimension : knowDto.getDimension()) {
        	LearningSituation situation = list.stream().filter(obj -> obj.getDimension().equals(dimension)).findFirst().orElse(null);
        	if(situation == null) {
        		continue;
        	}
        	if (situation.getDegreePercent() > 85){
                goodDimension.add(situation.getDimension());
            } else if (situation.getDegreePercent() > 65){
                middleDimension.add(situation.getDimension());
            } else if (situation.getDegreePercent() >= 0){
        		badDimension.add(situation.getDimension());
            }
        }
        knowDto.setDiagnostic(this.dataIntoSuggestNew(goodDimension, middleDimension, badDimension, advanceDimension, interirotyDimension));
        List<String> needSuggestList = new ArrayList<String>();
        if(badDimension.size() > 0) {
        	needSuggestList.addAll(badDimension);
        } else if(middleDimension.size() > 0) {
        	needSuggestList.addAll(middleDimension);
        } else if(goodDimension.size() < 4){
        	needSuggestList.addAll(goodDimension);
        } else {
        	needSuggestList.add(goodDimension.get(0));
        	needSuggestList.add(goodDimension.get(1));
        	needSuggestList.add(goodDimension.get(2));
        }
        for(String dimension : needSuggestList) {
        	LearningSituation situation = list.stream().filter(obj -> obj.getDimension().equals(dimension)).findFirst().orElse(null);
//        	if(situation == null || Strings.isNullOrEmpty(situation.getSuggestId())) {
//        		continue;
//        	}
			LearningSituationSuggest suggest = suggestDao.findById(situation.getSuggestId());
			if (suggest != null){
                String suggestStr = suggest.getStandard() + suggest.getSuggest();
                if (StringUtil.isNotBlank(suggestStr)){
                	knowDto.addSuggest(situation.getDimension() + "部分如何提升能力?", suggestStr);
                }
            }
		}
    }

    /**
     * 把数据转成语句
     * @param good
     * @param middle
     * @param bad
     * @param advantage
     * @param inferiority
     * @return
     */
    private String dataIntoSuggest (List<String> good, List<String> middle, List<String> bad, List<String> advantage, List<String> inferiority) {
        StringBuilder sb = new StringBuilder();
        if(good.size()>0){
            sb.append("发现你已经熟练掌握了"+String.join("、", good)+"。");
        }
        if(middle.size()>0){
            sb.append("在"+String.join("、", middle)+"上，你能达到基本熟练的水平，能够完成比较基础的题目。");
        }
        if(bad.size()>0){
            sb.append("在"+String.join("、", bad)+"上，你还不够熟练，存在着比较多的失误。");
        }
        if(advantage.size()>0){
            sb.append("另外我们发现，和同龄人相比，你在"+String.join("、", advantage)+"上占有明显优势。");
        }
        if(inferiority.size()>0){
            sb.append("要注意的是，你的"+String.join("、", inferiority)+"低于同龄伙伴的平均水平，平时要加强这些知识模块的学习。");
        }
        return StringUtil.isNotBlank(sb.toString()) ? "根据我们对你的观察，"+ sb.toString(): "" ;
    }
    
    private String dataIntoSuggestNew (List<String> good, List<String> middle, List<String> bad, List<String> advantage, List<String> inferiority) {
        StringBuilder sb = new StringBuilder();
        if(good.size()>0){
            sb.append("发现你已经熟练掌握了"+String.join("、", good)+"。");
        }
        if(middle.size()>0){
            sb.append("在"+String.join("、", middle)+"上，你能达到基本熟练的水平，能够完成比较基础的题目。");
        }
        if(bad.size()>0){
            sb.append("在"+String.join("、", bad)+"上，你还不够熟练，存在着比较多的失误。");
        }
        return StringUtil.isNotBlank(sb.toString()) ? "根据我们对你的观察，"+ sb.toString(): "" ;
    }

    /**
     * 生成学习建议
     */
    private void createLearningSuggest (KnowledgeSkillDto data, String vipId) {
        List<String> dimension = data.getDimension();
        LibVip vip = vipService.getById(vipId);
        if (vip == null) {
            return;
        }
        if (StringUtil.isBlank(vip.getGrade())){
            logger.error("该学生没有年级");
            vip.setGrade("二年级");
        }
        String temp = null;
//        for (int i = 0; i < dimension.size(); i ++){
        // 建议最多三条 by young.du on 2019/04/24
    	for (int i = 0; i < 3; i ++){
            if (data.getThisMonthTrueCount().get(i) >=  0){
                temp = SuggestTextUtil.getSuggest(dimension.get(i), data.getThisMonthTrueCount().get(i), vip.getGrade());
                if (StringUtil.isNotBlank(temp)){
                    data.addSuggest(dimension.get(i) + "部分如何提升能力?", temp);
                }
            }
        }
    }

    /**
     * 生成学习建议
     * @param data
     * @param vipId
     * @param type
     */
    private void createLearningSuggestV1 (KnowledgeSkillDto data, String subject, String vipId, int type){
        List<String> dimension = data.getDimension();
        LibVip vip = vipService.getById(vipId);
        if (vip == null) {
            return;
        }
        if (StringUtil.isBlank(vip.getGrade())){
            logger.error("该学生没有年级");
            vip.setGrade("二年级");
        }
        String temp = null;
        for (int i = 0; i < dimension.size(); i ++){
            if (data.getThisMonthTrueCount().get(i) >=  0){
                LearningSituationSuggest suggest = null;
                if (type == 1){
                    suggest = suggestService.findStandardAndSuggest(subject, type, dimension.get(i), vip.getGrade(), data.getThisMonthTrueCount().get(i));
                } else  {
                    suggest = suggestService.findStandardAndSuggest(subject, type, dimension.get(i), vip.getGrade(), data.getThisMonthTrueCount().get(i) - data.getOverallAvgTrueCount().get(i));
                }
                if (suggest != null){
                    temp = suggest.getStandard() + suggest.getSuggest();
                    if (StringUtil.isNotBlank(temp)){
                        data.addSuggest(dimension.get(i) + "部分如何提升能力?", temp);
                    }
                }
            }
        }
    }

    /**
     * 生成技能维度诊断说明
     * @param data
     */
    private void createSkillDiagnostic (KnowledgeSkillDto data) {
        List<String> goodDimension = new ArrayList<>();
        List<String> middleDimension = new ArrayList<>();
        List<String> badDimension = new ArrayList<>();
        List<String> advanceDimension = new ArrayList<>();
        List<String> interirotyDimension = new ArrayList<>();
        List<Integer> basic = data.getThisMonthTrueCount();
        List<String> dimension = data.getDimension();
        for (int i = 0; i < basic.size(); i++){
            if (basic.get(i).intValue() > 85){
                goodDimension.add(dimension.get(i));
            } else if (basic.get(i).intValue() > 65){
                middleDimension.add(dimension.get(i));
            } else if (basic.get(i).intValue() > 0){
                badDimension.add(dimension.get(i));
            }
        }
		/**
		 * 去掉所有人平均值by young.du
		 */
//        for (int i = 0; i < dimension.size(); i++){
//            if (data.getThisMonthTrueCount().get(i) > 0 && data.getOverallAvgTrueCount().get(i) > 0) {
//                if (data.getThisMonthTrueCount().get(i) > data.getOverallAvgTrueCount().get(i)) {
//                    advanceDimension.add(dimension.get(i));
//                } else {
//                    interirotyDimension.add(dimension.get(i));
//                }
//            }
//        }

        data.setDiagnostic(this.skillDataIntoSuggest(goodDimension, middleDimension, badDimension, advanceDimension, interirotyDimension));
    }


    /**
     * 技能维度把数据转成语句
     * @param good
     * @param middle
     * @param bad
     * @param advantage
     * @param inferiority
     * @return
     */
    private String skillDataIntoSuggest (List<String> good, List<String> middle, List<String> bad, List<String> advantage, List<String> inferiority) {
        StringBuilder sb = new StringBuilder();
        if(good.size()>0){
            sb.append("你已经熟练掌握了"+String.join("、", good)+"。");
        }
        if(middle.size()>0){
            sb.append("在"+String.join("、", middle)+"在学科技能方面，你已经熟练掌握了");
        }
        if(bad.size()>0){
            sb.append("在"+String.join("、", bad)+"上，你还不够熟练，存在着比较多的失误。");
        }
//        if(advantage.size()>0){
//            sb.append("另外我们发现，和同龄人相比，你在"+String.join("、", advantage)+"上占有明显优势。");
//        }
//        if(inferiority.size()>0){
//            sb.append("要注意的是，你的"+String.join("、", inferiority)+"低于同龄伙伴的平均水平，平时要加强这些知识模块的学习。");
//        }
        return StringUtil.isNotBlank(sb.toString()) ? "在学科技能方面，"+sb.toString() :"";
    }

    /**
     * 查询知识点掌握情况
     * @param vipId
     * @param subject
     * @return
     */
    public List<KnowledgePointDto> getKnowledgePoint (List<LearningSituation> list, String vipId, String subject){
        List<KnowledgePointDto> result = new ArrayList<>();
        KnowledgePointDto memoryKnowledge = new KnowledgePointDto("记忆知识点"),
                understandKnowledge = new KnowledgePointDto("理解知识点"),
                applyKnowledge = new  KnowledgePointDto("运用知识点");

        list.forEach(ls -> {
            if (ls.getType().intValue() == 5) {
                applyKnowledge.setWrongNum(ls.getWrongCount());
                applyKnowledge.setTotalNum(ls.getTotalCount());
                applyKnowledge.calculatePercent();
            } else if (ls.getType().intValue() == 6){
                understandKnowledge.setWrongNum(ls.getWrongCount());
                understandKnowledge.setTotalNum(ls.getTotalCount());
                understandKnowledge.calculatePercent();
            } else if (ls.getType().intValue() == 7){
                memoryKnowledge.setWrongNum(ls.getWrongCount());
                memoryKnowledge.setTotalNum(ls.getTotalCount());
                memoryKnowledge.calculatePercent();
            }
        });

        //未掌握知识点
        List<Map<String, Object>> noList = this.getNoKnowledgePoint(subject, vipId);
        if (noList != null) {
            List<Map<String, Object>> memList = noList.stream().filter(map -> "1".equals((String)map.get("memorize"))).collect(Collectors.toList());
            memList.forEach(map -> {
                this.addNoGraspKnowledgePoint(memoryKnowledge, (String)map.get("name"), (String)map.get("ydsl"));
            });
            List<Map<String, Object>> underList = noList.stream().filter(map -> "1".equals((String)map.get("understanding"))).collect(Collectors.toList());
            underList.forEach(map -> {
                this.addNoGraspKnowledgePoint(understandKnowledge, (String)map.get("name"), (String)map.get("ydsl"));
            });
            List<Map<String, Object>> applyList = noList.stream().filter(map -> "1".equals((String)map.get("apply"))).collect(Collectors.toList());
            underList.forEach(map -> {
                this.addNoGraspKnowledgePoint(applyKnowledge, (String)map.get("name"), (String)map.get("ydsl"));
            });
        }

        result.add(applyKnowledge);
        result.add(understandKnowledge);
        result.add(memoryKnowledge);
        return result;
    }


    /**
     * 查询知识点掌握情况
     * @param vipId
     * @param subject
     * @return
     */
    public Map<String, KnowledgePointDto> getKnowledgePoint2 (List<LearningSituation> list, String vipId, String subject){
        Map<String, KnowledgePointDto> result = new HashMap<>();
        KnowledgePointDto memoryKnowledge = new KnowledgePointDto("记忆知识点"),
                understandKnowledge = new KnowledgePointDto("理解知识点"),
                applyKnowledge = new  KnowledgePointDto("运用知识点");

        list.forEach(ls -> {
            if (ls.getType().intValue() == 5) {
                applyKnowledge.setWrongNum(ls.getWrongCount());
                applyKnowledge.setTotalNum(ls.getTotalCount());
                applyKnowledge.calculatePercent();
            } else if (ls.getType().intValue() == 6){
                understandKnowledge.setWrongNum(ls.getWrongCount());
                understandKnowledge.setTotalNum(ls.getTotalCount());
                understandKnowledge.calculatePercent();
            } else if (ls.getType().intValue() == 7){
                memoryKnowledge.setWrongNum(ls.getWrongCount());
                memoryKnowledge.setTotalNum(ls.getTotalCount());
                memoryKnowledge.calculatePercent();
            }
        });

        //未掌握知识点
        List<Map<String, Object>> noList = this.getNoKnowledgePoint(subject, vipId);
        if (noList != null) {
            List<Map<String, Object>> memList = noList.stream().filter(map -> "1".equals((String)map.get("memorize"))).collect(Collectors.toList());
            memList.forEach(map -> {
                this.addNoGraspKnowledgePoint(memoryKnowledge, (String)map.get("name"), (String)map.get("ydsl"));
            });
            List<Map<String, Object>> underList = noList.stream().filter(map -> "1".equals((String)map.get("understanding"))).collect(Collectors.toList());
            underList.forEach(map -> {
                this.addNoGraspKnowledgePoint(understandKnowledge, (String)map.get("name"), (String)map.get("ydsl"));
            });
            List<Map<String, Object>> applyList = noList.stream().filter(map -> "1".equals((String)map.get("apply"))).collect(Collectors.toList());
            underList.forEach(map -> {
                this.addNoGraspKnowledgePoint(applyKnowledge, (String)map.get("name"), (String)map.get("ydsl"));
            });
        }

        boolean isNotData = true;
        if (applyKnowledge.getNoKnowledgePoint().size() > 0){
            result.put("apply", applyKnowledge);
            isNotData = false;
        }
        if (understandKnowledge.getNoKnowledgePoint().size() > 0){
            result.put("understand", understandKnowledge);
            isNotData = false;
        }
        if (memoryKnowledge.getNoKnowledgePoint().size() > 0){
            result.put("remember", memoryKnowledge);
            isNotData = false;
        }
        if (isNotData) result = null;
        return result;
    }
    
    @Override
    public List<Map<String, Object>> getNoKnowledgePointDemo(String subject, String vipId, String dimension, String grade) {
        //作业未掌握知识点
        List<Map<String, Object>> workKnowledge = situationDao.getHomeworkWrongDetailDemo(vipId, subject, dimension, grade);
        //授课未掌握的知识点
//        List<Map<String, Object>> one2oneKnowledge = situationDao.getOne2OneWrongDetailDemo(vipId, subject, dimension);
        //合并
//        workKnowledge.addAll(one2oneKnowledge);
        return workKnowledge;
    }

    @Override
    public List<Map<String, Object>> getNoKnowledgePoint(String subject, String vipId) {
        //作业未掌握知识点
        List<Map<String, Object>> workKnowledge = situationDao.getHomeworkWrongDetail(vipId, subject,
                SituationConstant.getBeginTime(), SituationConstant.getEndTime());

        //授课未掌握的知识点
        List<Map<String, Object>> one2oneKnowledge = situationDao.getOne2OneWrongDetail(vipId, subject,
                SituationConstant.getBeginTime(), SituationConstant.getEndTime());
        //合并
        workKnowledge.addAll(one2oneKnowledge);
        return workKnowledge;
    }

    /**
     * 添加未掌握知识点
     * @param data
     * @param knowName
     * @param celebrityStr
     */
    private void addNoGraspKnowledgePoint (KnowledgePointDto data, String knowName, String celebrityStr) {
        NoKnowledgePointDto temp  = null;
        NoKnowledgePointDto nkpData = data.getNoKnowledgePoint().stream().filter(nkp -> nkp.getName().equals(knowName)).findFirst().orElse(null);
        if (nkpData == null){
            temp = new NoKnowledgePointDto();
            temp.setName(knowName);
            if (StringUtils.isNotBlank(celebrityStr)){
                celebrityStr = celebrityStr.replaceAll("\r\n", "").replaceAll("　", "").trim();
                temp.setCelebrities(Arrays.asList(celebrityStr.split("#N")));
            }
            data.addNoKnowPoint(temp);
        }
    }

    /**
     * 计算最后的得数，用100减去前面的值
     * @param list
     * @return
     */
    private Integer lastCount (List<Integer> list) {
        int result = 100;
        if (list.size() > 0){
            for (Integer count : list) {
                result -= count.intValue();
            }
        }
        return result;
    }

    @Override
    public List<KnowDimension> findKnowDimesion() {
        return situationDao.findKnowDimesion();
    }

    public List<Map<String, Object>> findKnowledgeDimesion() {
        List<Map<String, Object>> result = new ArrayList<>();
        List<Map<String, Object>> temp = null;
        //语文
        temp = situationDao.findChineseKnowledgeDimension();
        result.addAll(temp);
        temp = situationDao.findKnowledgeDimesion("数学");
        result.addAll(temp);
        temp = situationDao.findKnowledgeDimesion("英语");
        result.addAll(temp);
        return result;
    }

    @Override
    public List<Map<String, Object>> getHomeworkKnowModuleData(String vipId, String subject, String beginTime, String endTime, int type) {
        List<Map<String, Object>> result = null;
        if ("语文".equals(subject)){
            result = situationDao.getChineseHomeworkKnowModuleData(vipId, subject, beginTime, endTime, type);
        } else {
            result = situationDao.getHomeworkKnowModuleData(vipId, subject, beginTime, endTime, type);
        }
        return result;
    }

    @Override
    public List<Map<String, Object>> getHomeworkKnowClassData(String vipId, String subject, String beginTime, String endTime, int type) {
        return situationDao.getHomeworkKnowClassData(vipId, subject, beginTime, endTime, type);
    }

    @Override
    public List<String> get121SkillWrongData(String vipId, String subject, String beginTime, String endTime) {
        return situationDao.get121SkillWrongData(vipId, subject, beginTime, endTime);
    }

    @Override
    public List<String> get121SkillData(String vipId, String subject, String beginTime, String endTime) {
        return situationDao.get121SkillData(vipId, subject, beginTime, endTime);
    }

    @Override
    public List<Map<String, Object>> get121WrongKnowModuleData(String vipId, String subject, String beginTime, String endTime) {
        return situationDao.get121WrongKnowModuleData(vipId, subject, beginTime, endTime);
    }

    @Override
    public List<Map<String, Object>> get121KnowModuleData(String vipId, String subject, String beginTIme, String endTime) {
        return situationDao.get121KnowModuleData(vipId, subject, beginTIme, endTime);
    }

    @Override
    public void truncateTable() {
        dao.truncateTable();
    }

    @Override
    public List<Map<String, Object>> getHomeworkKnowHowModuleData(String vipId, String subject, String beginTime, String endTime, int type) {
        List<Map<String, Object>> result = null;
        if ("语文".equals(subject)){
            result = situationDao.getChineseHomeworkKnowHowModuleData(vipId, subject, beginTime, endTime, type);
        } else {
            result = situationDao.getHomeworkKnowHowModuleData(vipId, subject, beginTime, endTime, type);
        }
        return result;
    }

    @Override
    public List<Map<String, Object>> getHomeworkWrongKnowHowClassData(String vipId, String subject, String beginTime, String endTime) {
        return situationDao.getHomeworkWrongKnowHowClassData(vipId, subject, beginTime, endTime);
    }

    @Override
    public List<Map<String, Object>> getHomeworkAllKnowHowClassData(String vipId, String subject, String beginTime, String endTime) {
        return situationDao.getHomeworkAllKnowHowClassData(vipId, subject, beginTime, endTime);
    }
    
    public ResponseEntity learningSituationHistory(String vipId, String subject) {
        ResponseEntity responseEntity = new ResponseEntity();
        Map<String,Object> data=new HashMap<>();
        LibVip vip = vipService.getById(vipId);
        if (vip == null) {
            return responseEntity.failure("用户不存在");
        }
        String grade = vip.getGrade();
        Integer banben = banbenService.findBanben(subject, vip.getSchool(), grade);
        if (StringUtils.isBlank(grade)) {
            return responseEntity.failure("请先完善孩子年级信息");
        }

        List<LearningSituationHistory> hisList = new ArrayList<LearningSituationHistory>();
        List<LearningSituation> situations = conditionDao.queryHistoryByVipIdAndSubject(vipId, subject);
        for(GradeEnum gradeEnum : GradeEnum.values()) {
            if(GradeEnum.getIndexByGrade(grade) < GradeEnum.getIndexByGrade(gradeEnum.getGrade())) {
    			continue;
    		}
    		for(int i = 1; i < 3; i ++ ) {
//    			List<LearningSituation> situations = conditionDao.queryHistoryByVipIdAndSubject(vipId, subject, gradeEnum.getGrade(), i);
    			List<String> dimensionList = conditionService.getDimensionList(GradeEnum.getIndexByGrade(gradeEnum.getGrade()), i, subject, banben);
    			if(dimensionList == null || dimensionList.size() == 0) {
    				continue;
    			}
    			LearningSituationHistory history = new LearningSituationHistory();
    			history.setGrade(gradeEnum.getGrade());
    			history.setSemester(i);
    			history.setDimensionList(dimensionList);
    			List<LearningSituation> list = situations.stream().filter( 
    					n -> n.getStudentId() != null && gradeEnum.getGrade().equals(n.getGrade()) && history.getSemester().equals(n.getSemester())
    					&& subject.equals(n.getCourseName())).collect(Collectors.toList());
    			if(list == null || list.size() == 0) {
    				continue;
    			}
    			history.setCountList(getSituationCountByOrder(list, dimensionList));
    			List<LearningSituation> avglist = situations.stream().filter( 
    					n -> n.getStudentId() == null && gradeEnum.getGrade().equals(n.getGrade()) && history.getSemester().equals(n.getSemester())
    					&& subject.equals(n.getCourseName())).collect(Collectors.toList());
    			history.setAvgCountList(getSituationCountByOrder(avglist, dimensionList));
    			hisList.add(history);

    		}
    	}
        data.put("historyList",hisList);
       return  responseEntity.success(data,"成功");


    }
    
    public List<Integer> getSituationCountByOrder(List<LearningSituation> situations, List<String> dimensionList){
    	List<Integer> countList = new ArrayList<Integer>();
    	for(String dimension: dimensionList) {
    		LearningSituation situation = situations.stream().filter( single -> single.getDimension().equals(dimension)).findFirst().orElse(null);
    		if(situation != null && situation.getDegreePercent() != null) {
    			countList.add(situation.getDegreePercent() == 0 ? ConchConstants.SITUATION_DIMENSION_MIN : situation.getDegreePercent());
    		} else {
    			countList.add(ConchConstants.SITUATION_DIMENSION_DEFAULT);
    		}
    	}
    	return countList;
    }
}
