hjl
2024-06-07 3407c10808d75f2f9340a030f90191ecafa055a2
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -1,6 +1,7 @@
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;
@@ -58,16 +59,18 @@
    @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("游戏等级异常,请重试!");
        }
        // 获取用户游戏进度
        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("请先完成上一难度再挑战当前难度!");
        if (!Constants.ZERO.equals(difficulty)) {
            Integer level = GAME_DIFFICULTY_MAP.get(String.valueOf(difficulty));
            if (null == level) {
                throw new GlobalException("游戏等级异常,请重试!");
            }
            // 获取用户游戏进度
            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("请先完成上一难度再挑战当前难度!");
            }
        }
    }