From 883d04c8d038ba0e45c1630f760f4aa642286f45 Mon Sep 17 00:00:00 2001 From: hjl <1657978663@qq.com> Date: 星期三, 22 五月 2024 10:50:48 +0800 Subject: [PATCH] feat: 微信分享更改;接口返回更改;接口参数描述 --- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java | 125 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 124 insertions(+), 1 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 5891770..15966db 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 @@ -1,10 +1,20 @@ package com.ruoyi.study.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ruoyi.study.domain.TStudy; +import com.ruoyi.common.core.exception.GlobalException; +import com.ruoyi.common.security.service.TokenService; +import com.ruoyi.study.domain.*; +import com.ruoyi.study.dto.StudyWeekDTO; import com.ruoyi.study.mapper.TStudyMapper; +import com.ruoyi.study.service.ITGameRecordService; import com.ruoyi.study.service.ITStudyService; +import com.ruoyi.study.service.ITSubjectService; +import com.ruoyi.study.service.ITUserStudyService; import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; /** * <p> @@ -17,4 +27,117 @@ @Service public class TStudyServiceImpl extends ServiceImpl<TStudyMapper, TStudy> implements ITStudyService { + @Resource + private ITUserStudyService userStudyService; + @Resource + private ITSubjectService subjectService; + @Resource + private ITGameRecordService gameRecordService; + @Resource + private TokenService tokenService; + + private final static Map<String, Integer> GAME_DIFFICULTY_MAP = new HashMap<>(); + + static { + GAME_DIFFICULTY_MAP.put("1", 0); + GAME_DIFFICULTY_MAP.put("2", 1); + } + + @Override + public List<StudyWeekDTO> weekList(Integer type, Integer quarter) { + return baseMapper.weekList(type, quarter); + } + + @Override + public TUserStudy studySchedule(String userId, Integer week, Integer day) { + return userStudyService.studySchedule(userId, week, day); + } + + @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("请先完成上一难度再挑战"); + } + } + + @Override + public Map<String, Object> listenSelectPicture(Integer week, Integer day, List<TStudyListen> studyListens) { + // 随机获取一组题 + Random rand = new Random(); + TStudyListen 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; + } + + @Override + public Map<String, Object> pictureSelectVoice(Integer week, Integer day, List<TStudyLook> lookList) { + // 随机获取一组题 + Random rand = new Random(); + TStudyLook 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; + } + + @Override + public Map<String, Object> induceExclude(Integer week, Integer day, List<TStudyInduction> inductionList) { + // 随机获取一组题 + 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; + } + + @Override + public Map<String, Object> questionsAndAnswers(Integer week, Integer day, List<TStudyAnswer> answerList) { + // 随机获取一组题 + Random rand = new Random(); + TStudyAnswer data = answerList.get(rand.nextInt(answerList.size())); + // 获取问题题目 和 回答题目 + Map<String, Object> result = new HashMap<>(8); + List<String> ids = new ArrayList<>(); + ids.add(String.valueOf(data.getSubject())); + ids.add(String.valueOf(data.getAnswerSubject())); + result.put("data", data); + // 有问有答 + result.put("subject", getSubjects(ids.toArray(ids.toArray(new String[0])))); + return result; + } + + @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; + } + + /** + * 根据参数id查询图片及语音 + * + * @param ids 多个id + * @return 图片及语音集合 + */ + private List<TSubject> getSubjects(String[] ids) { + return subjectService.lambdaQuery().in(TSubject::getId, Arrays.asList(ids)).list(); + } + } -- Gitblit v1.7.1