hjl
2024-06-19 233ab439e38d3040d556f3f6d04492be2a3a6c8d
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -4,8 +4,8 @@
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.CompleteGameDTO;
import com.ruoyi.study.dto.StudyWeekDTO;
import com.ruoyi.study.mapper.TStudyMapper;
import com.ruoyi.study.service.*;
@@ -33,8 +33,6 @@
    private ITSubjectService subjectService;
    @Resource
    private ITGameRecordService gameRecordService;
    @Resource
    private TokenService tokenService;
    @Resource
    private ITStudyAnswerService studyAnswerService;
    @Resource
@@ -72,23 +70,38 @@
            // 有问有答
            List<TStudyAnswer> answerList = studyAnswerService.lambdaQuery().eq(TStudyAnswer::getStudyId, id)
                    .eq(TStudyAnswer::getDisabled, 0).list();
            total += answerList.stream().map(TStudyAnswer::getIntegral).mapToInt(Integer::intValue).sum();
            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();
            total += inductionList.stream().map(TStudyInduction::getIntegral).mapToInt(Integer::intValue).sum();
            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();
            total += lookList.stream().map(TStudyLook::getIntegral).mapToInt(Integer::intValue).sum();
            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();
            total += listenList.stream().map(TStudyListen::getIntegral).mapToInt(Integer::intValue).sum();
            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();
            total += pairList.stream().map(TStudyPair::getIntegral).mapToInt(Integer::intValue).sum();
            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();
@@ -118,23 +131,24 @@
    }
    @Override
    public TUserStudy studySchedule(String userId, Integer week) {
        return userStudyService.studySchedule(userId, week);
    public TUserStudy studySchedule(String userId) {
        return userStudyService.studySchedule(userId);
    }
    @Override
    public void checkDifficulty(Integer difficulty, Integer week, TGame game) {
    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];
            // 获取用户游戏进度
            Integer userId = tokenService.getLoginUserStudy().getUserid();
            List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId)
            List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid)
                    .eq(TGameRecord::getGameId, game.getId())
                    .eq(TGameRecord::getAccuracy, 100)
                    .ge(TGameRecord::getAccuracy, clearanceRate)
                    .eq(TGameRecord::getGameDifficulty, level).list();
            if (list.isEmpty()) {
                throw new GlobalException("请先完成上一难度再挑战当前难度!");
@@ -163,7 +177,6 @@
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyListen studyListen : studyListens) {
            List<String> subjectIds = Arrays.stream(studyListen.getSubject().split(",")).collect(Collectors.toList());
            Collections.shuffle(subjectIds);
            List<TSubject> list = new ArrayList<>();
            // 图片及语音集合
            for (String id : subjectIds) {
@@ -197,7 +210,6 @@
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyLook studyLook : lookList) {
            List<String> subjectIds = Arrays.stream(studyLook.getSubject().split(",")).collect(Collectors.toList());
            Collections.shuffle(subjectIds);
            List<TSubject> list = new ArrayList<>();
            // 图片及语音集合
            for (String id : subjectIds) {
@@ -231,7 +243,6 @@
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyInduction data : inductionList) {
            List<String> subjectIds = Arrays.stream(data.getSubject().split(",")).collect(Collectors.toList());
            Collections.shuffle(subjectIds);
            List<TSubject> subjectLists = new ArrayList<>();
            for (String id : subjectIds) {
                if (id.startsWith("-")) {
@@ -322,7 +333,6 @@
        List<List<TSubject>> subjectList = new ArrayList<>();
        for (TStudyPair data : pair) {
            List<String> subjectIds = Arrays.stream(data.getSubject().split(",")).collect(Collectors.toList());
            Collections.shuffle(subjectIds);
            List<TSubject> subjectLists = new ArrayList<>();
            for (String id : subjectIds) {
                if (id.startsWith("-")) {
@@ -386,15 +396,13 @@
    @Override
    public int computeTotalIntegral(List<String> studyIds, Integer type, Integer accuracy) {
        int sum;
        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 {
                sum = 0;
            }
        } else if (Constants.TWO.equals(type)) {
            List<TStudyLook> list = studyLookService.lambdaQuery().in(TStudyLook::getId, studyIds)
@@ -402,8 +410,6 @@
            Optional<TStudyLook> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            } else {
                sum = 0;
            }
        } else if (Constants.THREE.equals(type)) {
            List<TStudyInduction> list = studyInductionService.lambdaQuery().in(TStudyInduction::getId, studyIds)
@@ -411,8 +417,6 @@
            Optional<TStudyInduction> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            } else {
                sum = 0;
            }
        } else if (Constants.FOUR.equals(type)) {
            List<TStudyAnswer> list = studyAnswerService.lambdaQuery().in(TStudyAnswer::getId, studyIds)
@@ -420,8 +424,6 @@
            Optional<TStudyAnswer> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            } else {
                sum = 0;
            }
        } else if (Constants.FIVE.equals(type)) {
            List<TStudyPair> list = studyPairService.lambdaQuery().in(TStudyPair::getId, studyIds)
@@ -429,8 +431,6 @@
            Optional<TStudyPair> any = list.stream().findAny();
            if (any.isPresent()) {
                sum = any.get().getIntegral();
            } else {
                sum = 0;
            }
        } else {
            throw new GlobalException("题目信息异常!");
@@ -438,4 +438,9 @@
        return (int) (sum * ((double) accuracy / 100));
    }
    @Override
    public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy) {
    }
}