| | |
| | | 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.*; |
| | |
| | | private ITSubjectService subjectService; |
| | | @Resource |
| | | private ITGameRecordService gameRecordService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private ITStudyAnswerService studyAnswerService; |
| | | @Resource |
| | |
| | | // 有问有答 |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @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("请先完成上一难度再挑战当前难度!"); |
| | |
| | | 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) { |
| | |
| | | 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) { |
| | |
| | | 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("-")) { |
| | |
| | | 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("-")) { |
| | |
| | | |
| | | @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) |
| | |
| | | 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) |
| | |
| | | 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) |
| | |
| | | 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) |
| | |
| | | Optional<TStudyPair> any = list.stream().findAny(); |
| | | if (any.isPresent()) { |
| | | sum = any.get().getIntegral(); |
| | | } else { |
| | | sum = 0; |
| | | } |
| | | } else { |
| | | throw new GlobalException("题目信息异常!"); |
| | |
| | | return (int) (sum * ((double) accuracy / 100)); |
| | | } |
| | | |
| | | @Override |
| | | public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy) { |
| | | |
| | | } |
| | | |
| | | } |