无关风月
2025-04-11 75942ecc2e438012c5ea876715966ace593565a0
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java
@@ -1,6 +1,5 @@
package com.ruoyi.study.service.impl;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.study.domain.TGame;
@@ -59,12 +58,6 @@
    }
    @Override
    public TUserStudy studySchedule(String userId) {
        LambdaQueryChainWrapper<TUserStudy> wrapper = lambdaQuery().eq(TUserStudy::getUserId, userId);
        return wrapper.eq(TUserStudy::getDisabled, 0).one();
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void resettingStudyRecord(String time) {
        List<TUserStudy> list = lambdaQuery().eq(TUserStudy::getDisabled, 0).list();
@@ -102,37 +95,35 @@
            Integer type = completeStudy.getType();
            if (Constants.ONE.equals(type)) {
                userStudyRecord.setListen(Constants.ONE_HUNDRED);
                userStudyRecord.setLook(Constants.BURDEN_ONE);
                userStudyRecord.setInduction(Constants.BURDEN_ONE);
                userStudyRecord.setAnswer(Constants.BURDEN_ONE);
                userStudyRecord.setPair(Constants.BURDEN_ONE);
            } else if (Constants.TWO.equals(type)) {
                userStudyRecord.setLook(Constants.ONE_HUNDRED);
                userStudyRecord.setInduction(Constants.BURDEN_ONE);
                userStudyRecord.setAnswer(Constants.BURDEN_ONE);
                userStudyRecord.setPair(Constants.BURDEN_ONE);
            } else if (Constants.THREE.equals(type)) {
                userStudyRecord.setInduction(Constants.ONE_HUNDRED);
                userStudyRecord.setAnswer(Constants.BURDEN_ONE);
                userStudyRecord.setPair(Constants.BURDEN_ONE);
            } else if (Constants.FOUR.equals(type)) {
                userStudyRecord.setAnswer(Constants.ONE_HUNDRED);
                userStudyRecord.setPair(Constants.BURDEN_ONE);
            } else if (Constants.FIVE.equals(type)) {
                userStudyRecord.setPair(Constants.ONE_HUNDRED);
            }
            if (userStudyRecord.getLook().equals(Constants.ONE_HUNDRED) &&
                    userStudyRecord.getAnswer().equals(Constants.ONE_HUNDRED) &&
                    userStudyRecord.getPair().equals(Constants.ONE_HUNDRED) &&
                    userStudyRecord.getInduction().equals(Constants.ONE_HUNDRED) &&
                    userStudyRecord.getListen().equals(Constants.ONE_HUNDRED)) {
                // 学习完成,进入下一学习day
                Integer nextDay = DAY_MAP.get(String.valueOf(userStudyRecord.getDay()));
                // type为5并且day为5应该进入游戏日
                if (Constants.FIVE.equals(completeStudy.getDay())) {
                    userStudyRecord.setPair(Constants.ONE_HUNDRED);
                userStudyRecord.setDay(nextDay);
                // 下一day为 6,进入游戏日
                if (nextDay.equals(Constants.SIX)) {
                    // 游戏难度初始化 0(入门难度)
                    userStudyRecord.setGameDifficulty(Constants.ZERO);
                } else {
                    // 重置学习进度
                    userStudyRecord.setListen(Constants.BURDEN_ONE);
                    userStudyRecord.setLook(Constants.BURDEN_ONE);
                    userStudyRecord.setInduction(Constants.BURDEN_ONE);
                    userStudyRecord.setAnswer(Constants.BURDEN_ONE);
                    userStudyRecord.setPair(Constants.BURDEN_ONE);
                }
                userStudyRecord.setDay(nextDay);
            }
        }
        // 更新学习时长
@@ -147,6 +138,11 @@
    @Override
    public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) {
        String answerRate = game.getAnswerRate();
        String rate = game.getRate().split(",")[Constants.TWO];
        // 校验是否完成超级听力
        List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getGameId, game.getId())
                .eq(TGameRecord::getGameDifficulty, Constants.TWO)
                .ge(TGameRecord::getAccuracy, rate).list();
        // 下一周目逻辑
        int quarterItem = 1;
        Map<Integer, List<TStudy>> studyMap = new HashMap<>(8);
@@ -166,13 +162,14 @@
        // 获取当前季度所有周目
        List<TStudy> studyList1 = studyMap.get(quarterItem);
        // 正确率达到通关率
        if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)) {
        if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)
                && !gameRecordList.isEmpty()) {
            // 获取用户超级记忆游戏记录
            TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one();
            for (int i = 0; i < studyList1.size(); i++) {
                TStudy tStudy = studyList1.get(i);
                if (tStudy.getWeek().equals(userStudy.getWeek())) {
                    if (studyList1.size() == 1 || i + 1 == studyList1.size() - 1) {
                    if (studyList1.size() == 1 || i + 1 == studyList1.size()) {
                        // 是否为当前季度最后一周目
                        List<TStudy> studyList2 = studyMap.get(quarterItem + 1);
                        // 下一季度数据为空
@@ -184,6 +181,7 @@
                        TStudy tStudy1 = studyList1.get(i + 1);
                        userStudy.setWeek(tStudy1.getWeek());
                    }
                    break;
                }
            }
            userStudy.setDay(DAY_MAP.get(String.valueOf(userStudy.getDay())));
@@ -198,7 +196,7 @@
    }
    @Override
    public void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy) {
    public void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) {
        // 超级听力通关率
        String answerRate = game.getRate().split(",")[completeStudy.getDifficulty()];
        if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)) {
@@ -212,7 +210,58 @@
                        .ge(TGameRecord::getAccuracy, answerRate)
                        .eq(TGameRecord::getGameDifficulty, completeStudy.getDifficulty()).list();
                if (!list.isEmpty()) {
                    userStudy.setGameDifficulty(GAME_DIFFICULTY_MAP.get(completeStudy.getDifficulty()));
                    Integer integer = GAME_DIFFICULTY_MAP.get(completeStudy.getDifficulty());
                    userStudy.setGameDifficulty(integer);
                }
            } else {
                // 游戏难度为2,进入下一周目学习
                List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getGameId, game.getId())
                        .eq(TGameRecord::getGameName, Constants.MEMORY)
                        .ge(TGameRecord::getAccuracy, game.getAnswerRate()).list();
                // 判断是否完成超级记忆
                if (!gameRecordList.isEmpty()) {
                    int quarterItem = 1;
                    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);
                        // 记录学习季度
                        if (study.getId().equals(game.getStudyId())) {
                            quarterItem = quarter;
                        }
                    }
                    // 获取当前季度所有周目
                    List<TStudy> studyList1 = studyMap.get(quarterItem);
                    // 获取用户超级记忆游戏记录
                    for (int i = 0; i < studyList1.size(); i++) {
                        TStudy tStudy = studyList1.get(i);
                        if (tStudy.getWeek().equals(userStudy.getWeek())) {
                            if (studyList1.size() == 1 || i + 1 == studyList1.size()) {
                                // 是否为当前季度最后一周目
                                List<TStudy> studyList2 = studyMap.get(quarterItem + 1);
                                // 下一季度数据为空
                                if (null != studyList2 && !studyList2.isEmpty()) {
                                    TStudy tStudy1 = studyList2.get(Constants.ZERO);
                                    userStudy.setWeek(tStudy1.getWeek());
                                }
                            } else {
                                TStudy tStudy1 = studyList1.get(i + 1);
                                userStudy.setWeek(tStudy1.getWeek());
                            }
                        }
                    }
                    userStudy.setDay(DAY_MAP.get(String.valueOf(userStudy.getDay())));
                    userStudy.setLook(Constants.BURDEN_ONE);
                    userStudy.setPair(Constants.BURDEN_ONE);
                    userStudy.setInduction(Constants.BURDEN_ONE);
                    userStudy.setListen(Constants.BURDEN_ONE);
                    userStudy.setAnswer(Constants.BURDEN_ONE);
                    userStudy.setGameDifficulty(Constants.ZERO);
                }
            }
            this.updateById(userStudy);