From eed4e2af4645f1dfc3abc047a86e90ad8fe149b3 Mon Sep 17 00:00:00 2001 From: hjl <1657978663@qq.com> Date: 星期四, 20 六月 2024 18:04:24 +0800 Subject: [PATCH] fix: 学习端bug --- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java | 172 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 110 insertions(+), 62 deletions(-) diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java index ffcf068..5e15dec 100644 --- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java +++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java @@ -3,8 +3,6 @@ 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; import com.ruoyi.study.domain.*; import com.ruoyi.study.dto.StudyWeekDTO; import com.ruoyi.study.mapper.TStudyMapper; @@ -34,8 +32,6 @@ @Resource private ITGameRecordService gameRecordService; @Resource - private TokenService tokenService; - @Resource private ITStudyAnswerService studyAnswerService; @Resource private ITStudyInductionService studyInductionService; @@ -58,7 +54,7 @@ } @Override - public List<StudyWeekDTO> weekList(Integer type, Integer quarter) { + public List<StudyWeekDTO> weekList(Integer type, Integer quarter, Integer userId) { List<StudyWeekDTO> result = new ArrayList<>(); // 根据季度和type查询学习配置 List<TStudy> study = lambdaQuery().eq(TStudy::getQuarter, quarter).eq(TStudy::getType, type) @@ -72,23 +68,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(); @@ -112,29 +123,62 @@ total += storyListenList.stream().map(TStoryListen::getIntegral).mapToInt(Integer::intValue).sum(); // 自主故事 - 看图配音 total += storyListenList.stream().map(TStoryListen::getLookIntegral).mapToInt(Integer::intValue).sum(); - result.add(new StudyWeekDTO(week, type, quarter, title, total)); + // 判断周目是否可以进入学习 + Boolean canStudy = checkWeekCanStudy(userId, item); + result.add(new StudyWeekDTO(week, type, quarter, title, total, canStudy)); } return result; } - @Override - public TUserStudy studySchedule(String userId, Integer week) { - return userStudyService.studySchedule(userId, week); + /** + * @param userId 用户id + * @return 当前周目是否学习 + */ + private Boolean checkWeekCanStudy(Integer userId, TStudy study) { + TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) + .eq(TUserStudy::getDisabled, 0).one(); + if (null == userStudy) { + userStudy = new TUserStudy(); + userStudy.setUserId(userId); + // 学习周目 + TStudy tStudy = this.lambdaQuery().eq(TStudy::getQuarter, Constants.ONE) + .orderByAsc(TStudy::getWeek).last("limit 1").one(); + userStudy.setWeek(tStudy.getWeek()); + userStudy.setDay(Constants.ONE); + userStudy.setTotalStudy(Constants.ZERO); + userStudy.setTodayStudy(Constants.ZERO); + userStudy.setWeekStudy(Constants.ZERO); + userStudy.setMonthStudy(Constants.ZERO); + userStudy.setListen(Constants.BURDEN_ONE); + userStudy.setLook(Constants.BURDEN_ONE); + userStudy.setInduction(Constants.BURDEN_ONE); + userStudy.setAnswer(Constants.BURDEN_ONE); + userStudy.setPair(Constants.BURDEN_ONE); + userStudyService.save(userStudy); + } + // 学习记录所属周目大于当前学习周目,判断为已学习 + return userStudy.getWeek() >= study.getWeek(); } @Override - public void checkDifficulty(Integer difficulty, Integer week, TGame game) { + public TUserStudy studySchedule(String userId) { + return userStudyService.studySchedule(userId); + } + + @Override + 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 +207,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) { @@ -196,15 +239,18 @@ // 语音及图片 List<List<TSubject>> subjectList = new ArrayList<>(); for (TStudyLook studyLook : lookList) { + List<String> sortList = Arrays.stream(studyLook.getSort().split(",")).collect(Collectors.toList()); List<String> subjectIds = Arrays.stream(studyLook.getSubject().split(",")).collect(Collectors.toList()); - Collections.shuffle(subjectIds); List<TSubject> list = new ArrayList<>(); // 图片及语音集合 - for (String id : subjectIds) { - TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, id) + for (int i = 0; i < subjectIds.size(); i++) { + TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, subjectIds.get(i)) .eq(TSubject::getDisabled, 0).one(); + data.setSort(Integer.parseInt(sortList.get(i))); list.add(data); } + // 根据顺序排序 + list.sort(Comparator.comparingInt(TSubject::getSort)); subjectList.add(list); } return new StudyLookResultVO(learnStudy, subjectList); @@ -231,14 +277,36 @@ 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("-")) { - id = id.replace("-", ""); + // 第一组题 固定下标为0,1,2的题 + for (int i = 0; i < Constants.THREE; i++) { + String id = subjectIds.get(i); + if (!id.startsWith("-")) { + subjectLists.add(subjectService.getById(id)); } - subjectLists.add(subjectService.getById(id)); } + for (int i = 0; i < Constants.THREE; i++) { + String id = subjectIds.get(i); + if (id.startsWith("-")) { + id = id.replace("-",""); + subjectLists.add(subjectService.getById(id)); + } + } + // 第二组题,固定下标为3,4的题 + for (int i = Constants.THREE; i < Constants.FIVE; i++) { + String id = subjectIds.get(i); + if (!id.startsWith("-")) { + subjectLists.add(subjectService.getById(id)); + } + } + for (int i = Constants.THREE; i < Constants.FIVE; i++) { + String id = subjectIds.get(i); + if (id.startsWith("-")) { + id = id.replace("-",""); + subjectLists.add(subjectService.getById(id)); + } + } + subjectLists.add(subjectService.getById(subjectIds.get(subjectIds.size() - 1).replace("-",""))); subjectList.add(subjectLists); } return new StudyInductionResultVO(learnStudy, subjectList); @@ -283,12 +351,12 @@ QuestionsAnswersSubjectVO oneVO = new QuestionsAnswersSubjectVO(); TSubject one1 = subjectService.lambdaQuery().eq(TSubject::getId, subject) .eq(TSubject::getDisabled, 0).one(); - BeanUtils.copyProperties(one1, oneVO); + copyProperties(one1, oneVO); // 回答题目信息 QuestionsAnswersSubjectVO twoVO = new QuestionsAnswersSubjectVO(); TSubject two1 = subjectService.lambdaQuery().eq(TSubject::getId, answerSubject) .eq(TSubject::getDisabled, 0).one(); - BeanUtils.copyProperties(two1, twoVO); + copyProperties(two1, twoVO); // 判断第一组题目的问题题目及回答题目,哪个是答案 if (Constants.ZERO.equals(one.getIsAnswer())) { oneVO.setIsQuestion(0); @@ -299,6 +367,18 @@ } voList.add(oneVO); voList.add(twoVO); + } + + private void copyProperties(TSubject subject, QuestionsAnswersSubjectVO vo) { + vo.setId(subject.getId()); + vo.setName(subject.getName()); + vo.setEnglish(subject.getEnglish()); + vo.setType(subject.getType()); + vo.setState(subject.getState()); + vo.setImg(subject.getImg()); + vo.setCorrect(subject.getCorrect()); + vo.setError(subject.getError()); + vo.setSort(subject.getSort()); } @Override @@ -322,7 +402,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("-")) { @@ -338,11 +417,6 @@ @Override public int computeSchedule(TUserStudy result, Integer week) { // 基础学习进度 - Integer listen = result.getListen(); - Integer look = result.getLook(); - Integer induction = result.getInduction(); - Integer answer = result.getAnswer(); - Integer pair = result.getPair(); Integer day = result.getDay(); // 默认进度为 0 int defaultSchedule; @@ -364,37 +438,19 @@ } else { defaultSchedule = 0; } - // 进度学习完成度计算总学习进度 - if (!Constants.ZERO.equals(listen) && !Constants.BURDEN_ONE.equals(listen)) { - defaultSchedule += 4 * (100 / listen); - } - if (!Constants.ZERO.equals(look) && !Constants.BURDEN_ONE.equals(look)) { - defaultSchedule += 4 * (100 / look); - } - if (!Constants.ZERO.equals(induction) && !Constants.BURDEN_ONE.equals(induction)) { - defaultSchedule += 4 * (100 / induction); - } - if (!Constants.ZERO.equals(answer) && !Constants.BURDEN_ONE.equals(answer)) { - defaultSchedule += 4 * (100 / answer); - } - if (!Constants.ZERO.equals(pair) && !Constants.BURDEN_ONE.equals(pair)) { - defaultSchedule += 4 * (100 / pair); - } } return defaultSchedule; } @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 +458,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 +465,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 +472,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 +479,6 @@ Optional<TStudyPair> any = list.stream().findAny(); if (any.isPresent()) { sum = any.get().getIntegral(); - } else { - sum = 0; } } else { throw new GlobalException("题目信息异常!"); -- Gitblit v1.7.1