From c62e9f81b2072473b084abb30f7c005ed341a336 Mon Sep 17 00:00:00 2001 From: hjl <1657978663@qq.com> Date: 星期四, 06 六月 2024 15:05:34 +0800 Subject: [PATCH] feat: 修复代码冲突 --- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java | 134 +++++++++++++++++++++++++++++++++----------- 1 files changed, 99 insertions(+), 35 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 510ed8e..e1cb646 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 @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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; @@ -10,6 +11,7 @@ import com.ruoyi.study.service.ITStudyService; import com.ruoyi.study.service.ITSubjectService; import com.ruoyi.study.service.ITUserStudyService; +import com.ruoyi.study.vo.*; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -49,8 +51,8 @@ } @Override - public TUserStudy studySchedule(String userId, Integer week, Integer day) { - return userStudyService.studySchedule(userId, week, day); + public TUserStudy studySchedule(String userId, Integer week) { + return userStudyService.studySchedule(userId, week); } @Override @@ -65,65 +67,121 @@ 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("请先完成上一难度再挑战"); + throw new GlobalException("请先完成上一难度再挑战当前难度!"); } } @Override - public Map<String, Object> listenSelectPicture(Integer week, Integer day, List<TStudyListen> studyListens) { + public StudyListenResultVO listenSelectPicture(Integer week, Integer day, List<TStudyListen> studyListens) { + if (studyListens.isEmpty()) { + throw new GlobalException("当前学习周目题目数量不足!"); + } // 随机获取一组题 Random rand = new Random(); - TStudyListen data = studyListens.get(rand.nextInt(studyListens.size())); + TStudyListen data; + if (studyListens.size() == 1) { + data = studyListens.get(0); + } else { + data = studyListens.get(rand.nextInt(studyListens.size())); + } List<TSubject> subjectList = getSubjects(data.getSubject().split(",")); - Map<String, Object> result = new HashMap<>(8); - result.put("data", data); - result.put("subject", subjectList); - return result; + return new StudyListenResultVO(data, subjectList); } @Override - public Map<String, Object> pictureSelectVoice(Integer week, Integer day, List<TStudyLook> lookList) { + public StudyLookResultVO pictureSelectVoice(Integer week, Integer day, List<TStudyLook> lookList) { + if (lookList.isEmpty()) { + throw new GlobalException("当前学习周目题目数量不足!"); + } // 随机获取一组题 Random rand = new Random(); - TStudyLook data = lookList.get(rand.nextInt(lookList.size())); + TStudyLook data; + if (lookList.size() == 1) { + data = lookList.get(0); + } else { + data = lookList.get(rand.nextInt(lookList.size())); + } List<TSubject> subjectList = getSubjects(data.getSubject().split(",")); - Map<String, Object> result = new HashMap<>(8); - result.put("data", data); - result.put("subject", subjectList); - return result; + return new StudyLookResultVO(data, subjectList); } @Override - public Map<String, Object> induceExclude(Integer week, Integer day, List<TStudyInduction> inductionList) { + public StudyInductionResultVO induceExclude(Integer week, Integer day, List<TStudyInduction> inductionList) { + if (inductionList.isEmpty()) { + throw new GlobalException("当前学习周目题目数量不足!"); + } // 随机获取一组题 Random rand = new Random(); - TStudyInduction data = inductionList.get(rand.nextInt(inductionList.size())); - List<TSubject> subjectList = getSubjects(data.getSubject().split(",")); - Map<String, Object> result = new HashMap<>(8); - result.put("data", data); - result.put("subject", subjectList); - return result; + TStudyInduction data; + if (inductionList.size() == 1) { + data = inductionList.get(0); + } else { + data = inductionList.get(rand.nextInt(inductionList.size())); + } + String[] ids = data.getSubject().split(","); + List<TSubject> subjectList = new ArrayList<>(); + for (String id : ids) { + if (id.startsWith("-")) { + id = id.replace("-", ""); + } + subjectList.add(subjectService.getById(id)); + } + return new StudyInductionResultVO(data, subjectList); } @Override - public Map<String, Object> questionsAndAnswers(Integer week, Integer day, List<TStudyAnswer> answerList) { + public StudyAnswerResultVO questionsAndAnswers(Integer week, Integer day, List<TStudyAnswer> answerList) { + if (answerList.isEmpty()) { + throw new GlobalException("当前学习周目题目数量不足!"); + } // 随机获取一组题 Random rand = new Random(); - TStudyAnswer data = answerList.get(rand.nextInt(answerList.size())); + TStudyAnswer data; + TStudyAnswer dataTwo; + if (answerList.size() == 1) { + data = answerList.get(0); + dataTwo = answerList.get(0); + } else { + data = answerList.get(rand.nextInt(answerList.size())); + dataTwo = answerList.get(rand.nextInt(answerList.size())); + } + AnswerVO one = new AnswerVO(); + BeanUtils.copyProperties(data, one); + answerList.remove(data); + AnswerVO two = new AnswerVO(); + BeanUtils.copyProperties(dataTwo, two); // 获取问题题目 和 回答题目 - Map<String, Object> result = new HashMap<>(8); - result.put("data", data); - // todo 有问有答 - return result; + List<String> ids = new ArrayList<>(); + ids.add(String.valueOf(one.getSubject())); + ids.add(String.valueOf(one.getAnswerSubject())); + // 有问有答 + List<TStudyAnswer> answers = new ArrayList<>(); + answers.add(one); + one.setSubjectList(getSubjects(ids.toArray(new String[0]))); + // 第二题信息 + List<String> twoIds = new ArrayList<>(); + answers.add(two); + twoIds.add(String.valueOf(two.getSubject())); + twoIds.add(String.valueOf(two.getAnswerSubject())); + two.setSubjectList(getSubjects(twoIds.toArray(new String[0]))); + return new StudyAnswerResultVO(answers); } @Override - public Map<String, Object> pictureMateVoice(Integer week, Integer day, TStudyPair pair) { - List<TSubject> subjectList = getSubjects(pair.getSubject().split(",")); - Map<String, Object> result = new HashMap<>(8); - result.put("data", pair); - result.put("subject", subjectList); - return result; + public StudyPairResultVO pictureMateVoice(Integer week, Integer day, List<TStudyPair> pair) { + if (pair.isEmpty()) { + throw new GlobalException("当前学习周目题目数量不足!"); + } + // 随机获取一组题 + Random rand = new Random(); + TStudyPair data; + if (pair.size() == 1) { + data = pair.get(0); + } else { + data = pair.get(rand.nextInt(pair.size())); + } + List<TSubject> subjectList = getSubjects(data.getSubject().split(",")); + return new StudyPairResultVO(data, subjectList); } /** @@ -133,7 +191,13 @@ * @return 图片及语音集合 */ private List<TSubject> getSubjects(String[] ids) { - return subjectService.lambdaQuery().in(TSubject::getId, Arrays.asList(ids)).list(); + List<TSubject> list = new ArrayList<>(); + for (String id : ids) { + TSubject data = subjectService.lambdaQuery().eq(TSubject::getId, id) + .eq(TSubject::getDisabled, 0).one(); + list.add(data); + } + return list; } } -- Gitblit v1.7.1