无关风月
2024-07-01 528d3d8cacc28eccca68a7194f64e451b7ef7d3b
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -67,7 +67,9 @@
            int total = 0;
            List<Integer> dayList = new ArrayList<>();
            // 有问有答
            List<TStudyAnswer> answerList = studyAnswerService.lambdaQuery().eq(TStudyAnswer::getStudyId, id)
            List<TStudyAnswer> answerList = studyAnswerService.lambdaQuery()
                    .eq(TStudyAnswer::getStudyId, id)
                    .eq(TStudyAnswer::getWeek, week)
                    .eq(TStudyAnswer::getDisabled, 0).list();
            for (TStudyAnswer data : answerList) {
                Integer day = data.getDay();
@@ -78,7 +80,9 @@
            }
            dayList.clear();
            // 归纳判断
            List<TStudyInduction> inductionList = studyInductionService.lambdaQuery().eq(TStudyInduction::getStudyId, id)
            List<TStudyInduction> inductionList = studyInductionService.lambdaQuery()
                    .eq(TStudyInduction::getStudyId, id)
                    .eq(TStudyInduction::getWeek, week)
                    .eq(TStudyInduction::getDisabled, 0).list();
            for (TStudyInduction data : inductionList) {
                Integer day = data.getDay();
@@ -89,7 +93,9 @@
            }
            dayList.clear();
            // 看图选音
            List<TStudyLook> lookList = studyLookService.lambdaQuery().eq(TStudyLook::getStudyId, id)
            List<TStudyLook> lookList = studyLookService.lambdaQuery()
                    .eq(TStudyLook::getStudyId, id)
                    .eq(TStudyLook::getWeek, week)
                    .eq(TStudyLook::getDisabled, 0).list();
            for (TStudyLook data : lookList) {
                Integer day = data.getDay();
@@ -100,7 +106,9 @@
            }
            dayList.clear();
            // 听音选图
            List<TStudyListen> listenList = studyListenService.lambdaQuery().eq(TStudyListen::getStudyId, id)
            List<TStudyListen> listenList = studyListenService.lambdaQuery()
                    .eq(TStudyListen::getStudyId, id)
                    .eq(TStudyListen::getWeek, week)
                    .eq(TStudyListen::getDisabled, 0).list();
            for (TStudyListen data : listenList) {
                Integer day = data.getDay();
@@ -111,7 +119,9 @@
            }
            dayList.clear();
            // 音图相配
            List<TStudyPair> pairList = studyPairService.lambdaQuery().eq(TStudyPair::getStudyId, id)
            List<TStudyPair> pairList = studyPairService.lambdaQuery()
                    .eq(TStudyPair::getStudyId, id)
                    .eq(TStudyPair::getWeek, week)
                    .eq(TStudyPair::getDisabled, 0).list();
            for (TStudyPair data : pairList) {
                Integer day = data.getDay();
@@ -123,7 +133,8 @@
            dayList.clear();
            // 自主游戏
            List<TGame> gameList = gameService.lambdaQuery().eq(TGame::getStudyId, id)
                    .eq(TGame::getDisabled, 0).list();
                    .eq(TGame::getDisabled, 0)
                    .eq(TGame::getWeek, week).list();
            // 自主游戏-超级听力
            List<String> gameIntegral = gameList.stream().map(TGame::getIntegral).collect(Collectors.toList());
            for (String s : gameIntegral) {
@@ -138,7 +149,9 @@
                }
            }
            // 自主故事
            List<TStoryListen> storyListenList = storyListenService.lambdaQuery().eq(TStoryListen::getStudyId, id)
            List<TStoryListen> storyListenList = storyListenService.lambdaQuery()
                    .eq(TStoryListen::getStudyId, id)
                    .eq(TStoryListen::getWeek, week)
                    .eq(TStoryListen::getDisabled, 0).list();
            // 自主故事 - 框架记忆
            total += storyListenList.stream().map(TStoryListen::getIntegral).mapToInt(Integer::intValue).sum();
@@ -149,6 +162,88 @@
            result.add(new StudyWeekDTO(week, type, quarter, title, total, canStudy));
        }
        return result;
    }
    @Override
    public TUserStudy studySchedule(TUserStudy studyRecord, Integer week) {
        // 剩余周目
        List<TStudy> studyList = this.lambdaQuery().eq(TStudy::getDisabled, 0)
                .eq(TStudy::getType, Constants.ONE)
                .orderByAsc(TStudy::getWeek).list();
        // 已学习到的周目
        Integer studyWeek = studyRecord.getWeek();
        // 学习到的季度
        Integer studyQuarter = 1;
        // 当前所点击进入的周目所属季度
        Integer currentQuarter = 1;
        // 根据季度分组封装
        Map<Integer, List<TStudy>> integerListMap = getIntegerListMap(studyList);
        for (Map.Entry<Integer, List<TStudy>> map : integerListMap.entrySet()) {
            List<TStudy> list = map.getValue();
            for (TStudy study : list) {
                Integer itemWeek = study.getWeek();
                if (studyWeek.equals(itemWeek)) {
                    studyQuarter = map.getKey();
                    break;
                }
            }
            for (TStudy study : list) {
                Integer itemWeek = study.getWeek();
                if (week.equals(itemWeek)) {
                    currentQuarter = map.getKey();
                    break;
                }
            }
        }
        // 已学习季度 大于当前周目所属季度,所有学习均已完成
        if (studyQuarter > currentQuarter) {
            studyRecord.setWeek(week);
            studyRecord.setDay(Constants.SIX);
            studyRecord.setListen(Constants.ONE_HUNDRED);
            studyRecord.setLook(Constants.ONE_HUNDRED);
            studyRecord.setInduction(Constants.ONE_HUNDRED);
            studyRecord.setAnswer(Constants.ONE_HUNDRED);
            studyRecord.setPair(Constants.ONE_HUNDRED);
            studyRecord.setGameDifficulty(Constants.TWO);
            studyRecord.setComputeSchedule(Constants.ONE_HUNDRED);
        } else if (studyQuarter < currentQuarter) {
            studyRecord.setWeek(week);
            studyRecord.setDay(Constants.ONE);
            studyRecord.setListen(Constants.BURDEN_ONE);
            studyRecord.setLook(Constants.BURDEN_ONE);
            studyRecord.setInduction(Constants.BURDEN_ONE);
            studyRecord.setAnswer(Constants.BURDEN_ONE);
            studyRecord.setPair(Constants.BURDEN_ONE);
            studyRecord.setGameDifficulty(null);
            studyRecord.setComputeSchedule(Constants.ZERO);
        } else {
            List<TStudy> tStudies = integerListMap.get(studyQuarter);
            List<Integer> weekList = tStudies.stream().map(TStudy::getWeek).collect(Collectors.toList());
            int i = weekList.indexOf(studyWeek);
            int i1 = weekList.indexOf(week);
            if (i > i1) {
                studyRecord.setWeek(week);
                studyRecord.setDay(Constants.SIX);
                studyRecord.setListen(Constants.ONE_HUNDRED);
                studyRecord.setLook(Constants.ONE_HUNDRED);
                studyRecord.setInduction(Constants.ONE_HUNDRED);
                studyRecord.setAnswer(Constants.ONE_HUNDRED);
                studyRecord.setPair(Constants.ONE_HUNDRED);
                studyRecord.setGameDifficulty(Constants.TWO);
                studyRecord.setComputeSchedule(Constants.ONE_HUNDRED);
            } else if (i < i1) {
                studyRecord.setWeek(week);
                studyRecord.setDay(Constants.ONE);
                studyRecord.setListen(Constants.BURDEN_ONE);
                studyRecord.setLook(Constants.BURDEN_ONE);
                studyRecord.setInduction(Constants.BURDEN_ONE);
                studyRecord.setAnswer(Constants.BURDEN_ONE);
                studyRecord.setPair(Constants.BURDEN_ONE);
                studyRecord.setGameDifficulty(null);
                studyRecord.setComputeSchedule(Constants.ZERO);
            }
        }
        return studyRecord;
    }
    /**
@@ -179,11 +274,6 @@
        }
        // 学习记录所属周目大于当前学习周目,判断为已学习
        return userStudy.getWeek() >= study.getWeek();
    }
    @Override
    public TUserStudy studySchedule(String userId) {
        return userStudyService.studySchedule(userId);
    }
    @Override
@@ -453,8 +543,6 @@
            itemList.add(study);
            studyMap.put(quarter, itemList);
        }
        // 临时判断参数
        boolean itemBool = false;
        // 学习进度所属季度
        int studyQuarter = 1;
        // 当前进入周目所属季度
@@ -618,6 +706,71 @@
        // 已学习到的周目
        Integer studyWeek = studyRecord.getWeek();
        // 根据季度分组封装
        Map<Integer, List<TStudy>> itemMap = getIntegerListMap(studyList);
        // 计算已学习周目
        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);
                    // 并且超级听力难度2已通过
                    TStudy study = this.lambdaQuery().eq(TStudy::getWeek, studyRecord.getWeek())
                            .eq(TStudy::getDisabled, 0)
                            .one();
                    TGame game = gameService.lambdaQuery()
                            .eq(TGame::getStudyId, study.getId())
                            .eq(TGame::getDisabled, 0)
                            .eq(TGame::getWeek, study.getWeek())
                            .one();
                    if (null != game) {
                        String rate = game.getRate().split(",")[2];
                        List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery()
                                .eq(TGameRecord::getGameDifficulty, Constants.TWO)
                                .ge(TGameRecord::getAccuracy, rate)
                                .eq(TGameRecord::getUserId, studyRecord.getUserId())
                                .eq(TGameRecord::getGameId, game.getId())
                                .list();
                        if (gameRecordList.isEmpty()) {
                            isStudy = false;
                        }
                        List<TGameRecord> recordList = gameRecordService.lambdaQuery()
                                .ge(TGameRecord::getAccuracy, game.getAnswerRate())
                                .eq(TGameRecord::getUserId, studyRecord.getUserId())
                                .eq(TGameRecord::getGameId, game.getId())
                                .last("and gameDifficulty is null")
                                .list();
                        if (recordList.isEmpty()) {
                            isStudy = false;
                        }
                    }
                    if (isStudy) {
                        residueWeek++;
                    }
                    v = true;
                    break;
                } else {
                    residueWeek++;
                }
            }
            if (v) {
                break;
            }
        }
        return studyList.size() - residueWeek;
    }
    private Map<Integer, List<TStudy>> getIntegerListMap(List<TStudy> studyList) {
        Map<Integer, List<TStudy>> studyMap = new HashMap<>(8);
        for (TStudy study : studyList) {
            Integer quarter = study.getQuarter();
@@ -640,37 +793,7 @@
            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;
        return itemMap;
    }
    @Override