hjl
2024-06-21 eb048c01b8734cc765ab744b128d0edc18f20beb
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -1,16 +1,12 @@
package com.ruoyi.study.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.study.domain.*;
import com.ruoyi.study.dto.StudyWeekDTO;
import com.ruoyi.study.mapper.TStudyMapper;
import com.ruoyi.study.service.ITGameRecordService;
import com.ruoyi.study.service.ITStudyService;
import com.ruoyi.study.service.ITSubjectService;
import com.ruoyi.study.service.ITUserStudyService;
import com.ruoyi.study.service.*;
import com.ruoyi.study.vo.*;
import org.springframework.stereotype.Service;
@@ -36,38 +32,157 @@
    @Resource
    private ITGameRecordService gameRecordService;
    @Resource
    private TokenService tokenService;
    private ITStudyAnswerService studyAnswerService;
    @Resource
    private ITStudyInductionService studyInductionService;
    @Resource
    private ITStudyLookService studyLookService;
    @Resource
    private ITStudyListenService studyListenService;
    @Resource
    private ITStudyPairService studyPairService;
    @Resource
    private ITGameService gameService;
    @Resource
    private ITStoryListenService storyListenService;
    private final static Map<String, Integer> GAME_DIFFICULTY_MAP = new HashMap<>();
    private final static Map<Integer, Integer> GAME_DIFFICULTY_MAP = new HashMap<>();
    static {
        GAME_DIFFICULTY_MAP.put("1", 0);
        GAME_DIFFICULTY_MAP.put("2", 1);
        GAME_DIFFICULTY_MAP.put(1, 0);
        GAME_DIFFICULTY_MAP.put(2, 1);
    }
    @Override
    public List<StudyWeekDTO> weekList(Integer type, Integer quarter) {
        return baseMapper.weekList(type, quarter);
    }
    @Override
    public TUserStudy studySchedule(String userId, Integer week) {
        return userStudyService.studySchedule(userId, week);
    }
    @Override
    public void checkDifficulty(Integer difficulty, Integer week, TGame game) {
        // 判断用户是否完成上一个等级
        Integer level = GAME_DIFFICULTY_MAP.get(String.valueOf(difficulty));
        if (null == level) {
            throw new GlobalException("游戏等级异常,请重试!");
    public List<StudyWeekDTO> weekList(Integer type, Integer quarter, Integer userId) {
        List<StudyWeekDTO> result = new ArrayList<>();
        // 根据季度和type查询学习配置
        List<TStudy> study = lambdaQuery().eq(TStudy::getQuarter, quarter).eq(TStudy::getType, type)
                .eq(TStudy::getDisabled, 0).orderByAsc(TStudy::getWeek).list();
        for (TStudy item : study) {
            Integer week = item.getWeek();
            String title = item.getTitle();
            Integer id = item.getId();
            // 计算总积分
            int total = 0;
            // 有问有答
            List<TStudyAnswer> answerList = studyAnswerService.lambdaQuery().eq(TStudyAnswer::getStudyId, id)
                    .eq(TStudyAnswer::getDisabled, 0).list();
            Optional<TStudyAnswer> answerOptional = answerList.stream().findAny();
            if (answerOptional.isPresent()) {
                total += answerOptional.get().getIntegral();
            }
            // 归纳判断
            List<TStudyInduction> inductionList = studyInductionService.lambdaQuery().eq(TStudyInduction::getStudyId, id)
                    .eq(TStudyInduction::getDisabled, 0).list();
            Optional<TStudyInduction> inductionOptional = inductionList.stream().findAny();
            if (inductionOptional.isPresent()) {
                total += inductionOptional.get().getIntegral();
            }
            // 看图选音
            List<TStudyLook> lookList = studyLookService.lambdaQuery().eq(TStudyLook::getStudyId, id)
                    .eq(TStudyLook::getDisabled, 0).list();
            Optional<TStudyLook> lookOptional = lookList.stream().findAny();
            if (lookOptional.isPresent()) {
                total += lookOptional.get().getIntegral();
            }
            // 听音选图
            List<TStudyListen> listenList = studyListenService.lambdaQuery().eq(TStudyListen::getStudyId, id)
                    .eq(TStudyListen::getDisabled, 0).list();
            Optional<TStudyListen> listenOptional = listenList.stream().findAny();
            if (listenOptional.isPresent()) {
                total += listenOptional.get().getIntegral();
            }
            // 音图相配
            List<TStudyPair> pairList = studyPairService.lambdaQuery().eq(TStudyPair::getStudyId, id)
                    .eq(TStudyPair::getDisabled, 0).list();
            Optional<TStudyPair> pairOptional = pairList.stream().findAny();
            if (pairOptional.isPresent()) {
                total += pairOptional.get().getIntegral();
            }
            // 自主游戏
            List<TGame> gameList = gameService.lambdaQuery().eq(TGame::getStudyId, id)
                    .eq(TGame::getDisabled, 0).list();
            // 自主游戏-超级听力
            List<String> gameIntegral = gameList.stream().map(TGame::getIntegral).collect(Collectors.toList());
            for (String s : gameIntegral) {
                List<String> list = Arrays.stream(s.split(",")).collect(Collectors.toList());
                total += list.stream().mapToInt(Integer::parseInt).sum();
            }
            // 自主游戏-框架记忆
            List<Integer> gameAnswerIntegral = gameList.stream().map(TGame::getAnswerIntegral).collect(Collectors.toList());
            for (Integer integral : gameAnswerIntegral) {
                if (null != integral) {
                    total += integral;
                }
            }
            // 自主故事
            List<TStoryListen> storyListenList = storyListenService.lambdaQuery().eq(TStoryListen::getStudyId, id)
                    .eq(TStoryListen::getDisabled, 0).list();
            // 自主故事 - 框架记忆
            total += storyListenList.stream().map(TStoryListen::getIntegral).mapToInt(Integer::intValue).sum();
            // 自主故事 - 看图配音
            total += storyListenList.stream().map(TStoryListen::getLookIntegral).mapToInt(Integer::intValue).sum();
            // 判断周目是否可以进入学习
            Boolean canStudy = checkWeekCanStudy(userId, item);
            result.add(new StudyWeekDTO(week, type, quarter, title, total, canStudy));
        }
        // 获取用户游戏进度
        Integer userId = tokenService.getLoginUserStudy().getUserid();
        List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId).eq(TGameRecord::getGameId, game.getId()).list();
        boolean contains = list.stream().map(TGameRecord::getGameDifficulty).collect(Collectors.toList()).contains(level);
        if (!contains) {
            throw new GlobalException("请先完成上一难度再挑战当前难度!");
        return result;
    }
    /**
     * @param userId 用户id
     * @return 当前周目是否学习
     */
    private Boolean checkWeekCanStudy(Integer userId, TStudy study) {
        TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId)
                .eq(TUserStudy::getDisabled, 0).one();
        if (null == userStudy) {
            userStudy = new TUserStudy();
            userStudy.setUserId(userId);
            // 学习周目
            TStudy tStudy = this.lambdaQuery().eq(TStudy::getQuarter, Constants.ONE)
                    .orderByAsc(TStudy::getWeek).last("limit 1").one();
            userStudy.setWeek(tStudy.getWeek());
            userStudy.setDay(Constants.ONE);
            userStudy.setTotalStudy(Constants.ZERO);
            userStudy.setTodayStudy(Constants.ZERO);
            userStudy.setWeekStudy(Constants.ZERO);
            userStudy.setMonthStudy(Constants.ZERO);
            userStudy.setListen(Constants.BURDEN_ONE);
            userStudy.setLook(Constants.BURDEN_ONE);
            userStudy.setInduction(Constants.BURDEN_ONE);
            userStudy.setAnswer(Constants.BURDEN_ONE);
            userStudy.setPair(Constants.BURDEN_ONE);
            userStudyService.save(userStudy);
        }
        // 学习记录所属周目大于当前学习周目,判断为已学习
        return userStudy.getWeek() >= study.getWeek();
    }
    @Override
    public TUserStudy studySchedule(String userId) {
        return userStudyService.studySchedule(userId);
    }
    @Override
    public void checkDifficulty(Integer difficulty, Integer week, TGame game, Integer userid) {
        // 判断用户是否完成上一个等级
        if (!Constants.ZERO.equals(difficulty)) {
            Integer level = GAME_DIFFICULTY_MAP.get(difficulty);
            if (null == level) {
                throw new GlobalException("游戏等级异常,请重试!");
            }
            // 游戏通关率
            String clearanceRate = game.getRate().split(",")[level];
            // 获取用户游戏进度
            List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid)
                    .eq(TGameRecord::getGameId, game.getId())
                    .ge(TGameRecord::getAccuracy, clearanceRate)
                    .eq(TGameRecord::getGameDifficulty, level).list();
            if (list.isEmpty()) {
                throw new GlobalException("请先完成上一难度再挑战当前难度!");
            }
        }
    }
@@ -76,16 +191,32 @@
        if (studyListens.isEmpty()) {
            throw new GlobalException("当前学习周目题目数量不足!");
        }
        // 随机获取一组题
        Random rand = new Random();
        TStudyListen data;
        if (studyListens.size() == 1) {
            data = studyListens.get(0);
        } else {
            data = studyListens.get(rand.nextInt(studyListens.size()));
        // 题组信息
        LearnStudyVO learnStudy = new LearnStudyVO();
        String ids = studyListens.stream().map(TStudyListen::getId).map(String::valueOf)
                .collect(Collectors.joining(","));
        learnStudy.setId(ids);
        int total = 0;
        for (TStudyListen data : studyListens) {
            if (null != data) {
                total += data.getIntegral();
            }
        }
        List<TSubject> subjectList = getSubjects(data.getSubject().split(","));
        return new StudyListenResultVO(data, subjectList);
        learnStudy.setIntegral(total);
        // 语音及图片
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyListen studyListen : studyListens) {
            List<String> subjectIds = Arrays.stream(studyListen.getSubject().split(",")).collect(Collectors.toList());
            List<TSubject> list = new ArrayList<>();
            // 图片及语音集合
            for (String id : subjectIds) {
                TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, id)
                        .eq(TSubject::getDisabled, 0).one();
                list.add(data);
            }
            subjectList.add(list);
        }
        return new StudyListenResultVO(learnStudy, subjectList);
    }
    @Override
@@ -93,16 +224,36 @@
        if (lookList.isEmpty()) {
            throw new GlobalException("当前学习周目题目数量不足!");
        }
        // 随机获取一组题
        Random rand = new Random();
        TStudyLook data;
        if (lookList.size() == 1) {
            data = lookList.get(0);
        } else {
            data = lookList.get(rand.nextInt(lookList.size()));
        // 题组信息
        LearnStudyVO learnStudy = new LearnStudyVO();
        String ids = lookList.stream().map(TStudyLook::getId).map(String::valueOf)
                .collect(Collectors.joining(","));
        learnStudy.setId(ids);
        int total = 0;
        for (TStudyLook data : lookList) {
            if (null != data) {
                total += data.getIntegral();
            }
        }
        List<TSubject> subjectList = getSubjects(data.getSubject().split(","));
        return new StudyLookResultVO(data, subjectList);
        learnStudy.setIntegral(total);
        // 语音及图片
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyLook studyLook : lookList) {
            List<String> sortList = Arrays.stream(studyLook.getSort().split(",")).collect(Collectors.toList());
            List<String> subjectIds = Arrays.stream(studyLook.getSubject().split(",")).collect(Collectors.toList());
            List<TSubject> list = new ArrayList<>();
            // 图片及语音集合
            for (int i = 0; i < subjectIds.size(); i++) {
                TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, subjectIds.get(i))
                        .eq(TSubject::getDisabled, 0).one();
                data.setSort(Integer.parseInt(sortList.get(i)));
                list.add(data);
            }
            // 根据顺序排序
            list.sort(Comparator.comparingInt(TSubject::getSort));
            subjectList.add(list);
        }
        return new StudyLookResultVO(learnStudy, subjectList);
    }
    @Override
@@ -110,23 +261,55 @@
        if (inductionList.isEmpty()) {
            throw new GlobalException("当前学习周目题目数量不足!");
        }
        // 随机获取一组题
        Random rand = new Random();
        TStudyInduction data;
        if (inductionList.size() == 1) {
            data = inductionList.get(0);
        } else {
            data = inductionList.get(rand.nextInt(inductionList.size()));
        }
        String[] ids = data.getSubject().split(",");
        List<TSubject> subjectList = new ArrayList<>();
        for (String id : ids) {
            if (id.startsWith("-")) {
                id = id.replace("-", "");
        // 题组信息
        LearnStudyVO learnStudy = new LearnStudyVO();
        String ids = inductionList.stream().map(TStudyInduction::getId).map(String::valueOf)
                .collect(Collectors.joining(","));
        learnStudy.setId(ids);
        int total = 0;
        for (TStudyInduction data : inductionList) {
            if (null != data) {
                total += data.getIntegral();
            }
            subjectList.add(subjectService.getById(id));
        }
        return new StudyInductionResultVO(data, subjectList);
        learnStudy.setIntegral(total);
        // 语音及图片
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyInduction data : inductionList) {
            List<String> subjectIds = Arrays.stream(data.getSubject().split(",")).collect(Collectors.toList());
            List<TSubject> subjectLists = new ArrayList<>();
            // 第一组题 固定下标为0,1,2的题
            for (int i = 0; i < Constants.THREE; i++) {
                String id = subjectIds.get(i);
                if (!id.startsWith("-")) {
                    subjectLists.add(subjectService.getById(id));
                }
            }
            for (int i = 0; i < Constants.THREE; i++) {
                String id = subjectIds.get(i);
                if (id.startsWith("-")) {
                    id = id.replace("-", "");
                    subjectLists.add(subjectService.getById(id));
                }
            }
            // 第二组题,固定下标为3,4的题
            for (int i = Constants.THREE; i < Constants.FIVE; i++) {
                String id = subjectIds.get(i);
                if (!id.startsWith("-")) {
                    subjectLists.add(subjectService.getById(id));
                }
            }
            for (int i = Constants.THREE; i < Constants.FIVE; i++) {
                String id = subjectIds.get(i);
                if (id.startsWith("-")) {
                    id = id.replace("-", "");
                    subjectLists.add(subjectService.getById(id));
                }
            }
            subjectLists.add(subjectService.getById(subjectIds.get(subjectIds.size() - 1).replace("-", "")));
            subjectList.add(subjectLists);
        }
        return new StudyInductionResultVO(learnStudy, subjectList);
    }
    @Override
@@ -134,37 +317,68 @@
        if (answerList.isEmpty()) {
            throw new GlobalException("当前学习周目题目数量不足!");
        }
        // 随机获取一组题
        Random rand = new Random();
        TStudyAnswer data;
        TStudyAnswer dataTwo;
        if (answerList.size() == 1) {
            data = answerList.get(0);
            dataTwo = answerList.get(0);
        } else {
            data = answerList.get(rand.nextInt(answerList.size()));
            dataTwo = answerList.get(rand.nextInt(answerList.size()));
        // 题组信息
        LearnStudyVO learnStudy = new LearnStudyVO();
        String ids = answerList.stream().map(TStudyAnswer::getId).map(String::valueOf)
                .collect(Collectors.joining(","));
        learnStudy.setId(ids);
        int total = 0;
        for (TStudyAnswer data : answerList) {
            if (null != data) {
                total += data.getIntegral();
            }
        }
        AnswerVO one = new AnswerVO();
        BeanUtils.copyProperties(data, one);
        answerList.remove(data);
        AnswerVO two = new AnswerVO();
        BeanUtils.copyProperties(dataTwo, two);
        // 获取问题题目 和 回答题目
        List<String> ids = new ArrayList<>();
        ids.add(String.valueOf(one.getSubject()));
        ids.add(String.valueOf(one.getAnswerSubject()));
        // 有问有答
        List<TStudyAnswer> answers = new ArrayList<>();
        answers.add(one);
        one.setSubjectList(getSubjects(ids.toArray(new String[0])));
        // 第二题信息
        List<String> twoIds = new ArrayList<>();
        answers.add(two);
        twoIds.add(String.valueOf(two.getSubject()));
        twoIds.add(String.valueOf(two.getAnswerSubject()));
        two.setSubjectList(getSubjects(twoIds.toArray(new String[0])));
        return new StudyAnswerResultVO(answers);
        learnStudy.setIntegral(total);
        // 题目语音及图片信息
        List<List<QuestionsAnswersSubjectVO>> subjectList = new ArrayList<>();
        for (int i = 0; i < answerList.size(); i += Constants.TWO) {
            List<QuestionsAnswersSubjectVO> voList = new ArrayList<>();
            // 一组题目为四道题,
            TStudyAnswer one = answerList.get(i);
            TStudyAnswer two = answerList.get(i + 1);
            voAdd(voList, one);
            voAdd(voList, two);
            subjectList.add(voList);
        }
        return new StudyAnswerResultVO(learnStudy, subjectList);
    }
    private void voAdd(List<QuestionsAnswersSubjectVO> voList, TStudyAnswer one) {
        // 第一道题问题及答案
        Integer subject = one.getSubject();
        Integer answerSubject = one.getAnswerSubject();
        // 问题题目信息
        QuestionsAnswersSubjectVO oneVO = new QuestionsAnswersSubjectVO();
        TSubject one1 = subjectService.lambdaQuery().eq(TSubject::getId, subject)
                .eq(TSubject::getDisabled, 0).one();
        copyProperties(one1, oneVO);
        // 回答题目信息
        QuestionsAnswersSubjectVO twoVO = new QuestionsAnswersSubjectVO();
        TSubject two1 = subjectService.lambdaQuery().eq(TSubject::getId, answerSubject)
                .eq(TSubject::getDisabled, 0).one();
        copyProperties(two1, twoVO);
        // 判断第一组题目的问题题目及回答题目,哪个是答案
        if (Constants.ZERO.equals(one.getIsAnswer())) {
            oneVO.setIsQuestion(1);
            twoVO.setIsQuestion(0);
        } else {
            oneVO.setIsQuestion(0);
            twoVO.setIsQuestion(1);
        }
        voList.add(oneVO);
        voList.add(twoVO);
    }
    private void copyProperties(TSubject subject, QuestionsAnswersSubjectVO vo) {
        vo.setId(subject.getId());
        vo.setName(subject.getName());
        vo.setEnglish(subject.getEnglish());
        vo.setType(subject.getType());
        vo.setState(subject.getState());
        vo.setImg(subject.getImg());
        vo.setCorrect(subject.getCorrect());
        vo.setError(subject.getError());
        vo.setSort(subject.getSort());
    }
    @Override
@@ -172,32 +386,166 @@
        if (pair.isEmpty()) {
            throw new GlobalException("当前学习周目题目数量不足!");
        }
        // 随机获取一组题
        Random rand = new Random();
        TStudyPair data;
        if (pair.size() == 1) {
            data = pair.get(0);
        } else {
            data = pair.get(rand.nextInt(pair.size()));
        // 题组信息
        LearnStudyVO learnStudy = new LearnStudyVO();
        String ids = pair.stream().map(TStudyPair::getId).map(String::valueOf)
                .collect(Collectors.joining(","));
        learnStudy.setId(ids);
        int total = 0;
        for (TStudyPair data : pair) {
            if (null != data) {
                total += data.getIntegral();
            }
        }
        List<TSubject> subjectList = getSubjects(data.getSubject().split(","));
        return new StudyPairResultVO(data, subjectList);
        learnStudy.setIntegral(total);
        // 语音及图片
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyPair data : pair) {
            List<String> subjectIds = Arrays.stream(data.getSubject().split(",")).collect(Collectors.toList());
            List<TSubject> subjectLists = new ArrayList<>();
            for (String id : subjectIds) {
                if (id.startsWith("-")) {
                    id = id.replace("-", "");
                }
                subjectLists.add(subjectService.getById(id));
            }
            subjectList.add(subjectLists);
        }
        return new StudyPairResultVO(learnStudy, subjectList);
    }
    /**
     * 根据参数id查询图片及语音
     *
     * @param ids 多个id
     * @return 图片及语音集合
     */
    private List<TSubject> getSubjects(String[] ids) {
        List<TSubject> list = new ArrayList<>();
        for (String id : ids) {
            TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, id)
                    .eq(TSubject::getDisabled, 0).one();
            list.add(data);
    @Override
    public int computeSchedule(TUserStudy result, Integer week) {
        // 基础学习进度
        Integer day = result.getDay();
        // 默认进度为 0
        int defaultSchedule;
        // week以超过当前week,进度为 100%
        if (result.getWeek() > week) {
            defaultSchedule = 100;
        } else {
            // 根据day初始化学习进度
            if (Constants.ONE.equals(day)) {
                defaultSchedule = 0;
            } else if (Constants.TWO.equals(day)) {
                defaultSchedule = 20;
            } else if (Constants.THREE.equals(day)) {
                defaultSchedule = 40;
            } else if (Constants.FOUR.equals(day)) {
                defaultSchedule = 60;
            } else if (Constants.FIVE.equals(day)) {
                defaultSchedule = 80;
            } else {
                defaultSchedule = 0;
            }
        }
        return list;
        return defaultSchedule;
    }
    @Override
    public int computeTotalIntegral(List<String> studyIds, Integer type, Integer accuracy) {
        int sum = 0;
        if (Constants.ONE.equals(type)) {
            List<TStudyListen> list = studyListenService.lambdaQuery().in(TStudyListen::getId, studyIds)
                    .eq(TStudyListen::getDisabled, 0).list();
            Optional<TStudyListen> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            }
        } else if (Constants.TWO.equals(type)) {
            List<TStudyLook> list = studyLookService.lambdaQuery().in(TStudyLook::getId, studyIds)
                    .eq(TStudyLook::getDisabled, 0).list();
            Optional<TStudyLook> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            }
        } else if (Constants.THREE.equals(type)) {
            List<TStudyInduction> list = studyInductionService.lambdaQuery().in(TStudyInduction::getId, studyIds)
                    .eq(TStudyInduction::getDisabled, 0).list();
            Optional<TStudyInduction> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            }
        } else if (Constants.FOUR.equals(type)) {
            List<TStudyAnswer> list = studyAnswerService.lambdaQuery().in(TStudyAnswer::getId, studyIds)
                    .eq(TStudyAnswer::getDisabled, 0).list();
            Optional<TStudyAnswer> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            }
        } else if (Constants.FIVE.equals(type)) {
            List<TStudyPair> list = studyPairService.lambdaQuery().in(TStudyPair::getId, studyIds)
                    .eq(TStudyPair::getDisabled, 0).list();
            Optional<TStudyPair> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            }
        } else {
            throw new GlobalException("题目信息异常!");
        }
        return (int) (sum * ((double) accuracy / 100));
    }
    @Override
    public int residueWeek(TUserStudy studyRecord, List<TStudy> studyList) {
        // 已学习周目
        int residueWeek = 0;
        // 已学习到的周目
        Integer studyWeek = studyRecord.getWeek();
        // 根据季度分组封装
        Map<Integer, List<TStudy>> studyMap = new HashMap<>(8);
        for (TStudy study : studyList) {
            Integer quarter = study.getQuarter();
            List<TStudy> itemList = studyMap.get(quarter);
            if (null == itemList) {
                itemList = new ArrayList<>();
            }
            itemList.add(study);
            studyMap.put(quarter, itemList);
        }
        // 顺序排序
        Map<Integer, List<TStudy>> itemMap = new HashMap<>(8);
        List<Integer> keyList = new ArrayList<>();
        for (Map.Entry<Integer, List<TStudy>> map : studyMap.entrySet()) {
            Integer key = map.getKey();
            keyList.add(key);
        }
        Collections.sort(keyList);
        for (Integer key : keyList) {
            List<TStudy> itemList = studyMap.get(key);
            itemMap.put(key, itemList);
        }
        // 计算已学习周目
        boolean v = false;
        for (Map.Entry<Integer, List<TStudy>> map : itemMap.entrySet()) {
            List<TStudy> list = map.getValue();
            for (int i = 0; i < list.size(); i++) {
                TStudy item = list.get(i);
                if (item.getWeek().equals(studyWeek)) {
                    Integer listen = studyRecord.getListen();
                    Integer answer = studyRecord.getAnswer();
                    Integer look = studyRecord.getLook();
                    Integer induction = studyRecord.getInduction();
                    Integer pair = studyRecord.getPair();
                    Integer gameDifficulty = studyRecord.getGameDifficulty();
                    // 听音选图、看图选音、音图相配、有问有答、归纳排除的进度是否 100%,并且超级听力的游戏难度是否为2
                    boolean isStudy = Constants.ONE_HUNDRED.equals(listen) && Constants.ONE_HUNDRED.equals(look) &&
                            Constants.ONE_HUNDRED.equals(induction) && Constants.ONE_HUNDRED.equals(pair) &&
                            Constants.ONE_HUNDRED.equals(answer) && Constants.TWO.equals(gameDifficulty);
                    if (isStudy) {
                        residueWeek++;
                    }
                    v = true;
                    break;
                } else {
                    residueWeek++;
                }
            }
            if (v) {
                break;
            }
        }
        return studyList.size() - residueWeek;
    }
}