| | |
| | | package com.ruoyi.study.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.study.domain.TGame; |
| | | import com.ruoyi.study.domain.TGameRecord; |
| | | import com.ruoyi.study.domain.TStudy; |
| | | import com.ruoyi.study.domain.TUserStudy; |
| | | import com.ruoyi.study.dto.CompleteGameDTO; |
| | | import com.ruoyi.study.dto.CompleteStudyDTO; |
| | | import com.ruoyi.study.mapper.TUserStudyMapper; |
| | | import com.ruoyi.study.service.ITGameRecordService; |
| | | import com.ruoyi.study.service.ITUserStudyService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @Service |
| | | public class TUserStudyServiceImpl extends ServiceImpl<TUserStudyMapper, TUserStudy> implements ITUserStudyService { |
| | | |
| | | @Resource |
| | | private ITGameRecordService gameRecordService; |
| | | |
| | | /** |
| | | * 所属day map |
| | | */ |
| | | private static final Map<String, Integer> DAY_MAP = new HashMap<>(12); |
| | | |
| | | /** |
| | | * 所属day map |
| | | */ |
| | | private static final Map<Integer, Integer> GAME_DIFFICULTY_MAP = new HashMap<>(12); |
| | | |
| | | static { |
| | | // 所属day |
| | | DAY_MAP.put(Constants.ONE_STR, Constants.TWO); |
| | | DAY_MAP.put(Constants.TWO_STR, Constants.THREE); |
| | | DAY_MAP.put(Constants.THREE_STR, Constants.FOUR); |
| | | DAY_MAP.put(Constants.FOUR_STR, Constants.FIVE); |
| | | DAY_MAP.put(Constants.FIVE_STR, Constants.ONE); |
| | | // DAY_MAP.put(Constants.SIX_STR, Constants.SEVEN); |
| | | // DAY_MAP.put(Constants.SEVEN_STR, Constants.ONE); |
| | | } |
| | | |
| | | @Override |
| | | public TUserStudy studySchedule(String userId, Integer week) { |
| | | LambdaQueryChainWrapper<TUserStudy> wrapper = lambdaQuery().eq(TUserStudy::getUserId, userId); |
| | | wrapper = null != week ? wrapper.eq(TUserStudy::getWeek, week) : wrapper; |
| | | return wrapper.eq(TUserStudy::getDisabled, 0).one(); |
| | | DAY_MAP.put(Constants.FIVE_STR, Constants.SIX); |
| | | DAY_MAP.put(Constants.SIX_STR, Constants.ONE); |
| | | // 游戏难度 |
| | | GAME_DIFFICULTY_MAP.put(Constants.ZERO, Constants.ONE); |
| | | GAME_DIFFICULTY_MAP.put(Constants.ONE, Constants.TWO); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Boolean exchangeStudyRecord(List<TStudy> studyList, Integer userId, CompleteStudyDTO completeStudy) { |
| | | public Boolean exchangeStudyRecord(TUserStudy userStudyRecord, Integer userId, CompleteStudyDTO completeStudy) { |
| | | Integer studyTime = completeStudy.getStudyTime(); |
| | | // 学习记录 |
| | | TUserStudy userStudyRecord = lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | Integer type = completeStudy.getType(); |
| | | if (Constants.ONE.equals(type)) { |
| | | userStudyRecord.setListen(Constants.ONE_HUNDRED); |
| | | } else if (Constants.TWO.equals(type)) { |
| | | userStudyRecord.setLook(Constants.ONE_HUNDRED); |
| | | } else if (Constants.THREE.equals(type)) { |
| | | userStudyRecord.setInduction(Constants.ONE_HUNDRED); |
| | | } else if (Constants.FOUR.equals(type)) { |
| | | userStudyRecord.setAnswer(Constants.ONE_HUNDRED); |
| | | } else if (Constants.FIVE.equals(type)) { |
| | | // 类型五,说明当前day已经全部完成,更新学习记录的 day |
| | | Integer nextDay = DAY_MAP.get(String.valueOf(userStudyRecord.getDay())); |
| | | userStudyRecord.setDay(nextDay); |
| | | // 学习day已切换更新学习进度及学习时长 |
| | | userStudyRecord.setListen(Constants.ZERO); |
| | | userStudyRecord.setLook(Constants.ZERO); |
| | | userStudyRecord.setInduction(Constants.ZERO); |
| | | userStudyRecord.setAnswer(Constants.ZERO); |
| | | userStudyRecord.setPair(Constants.ZERO); |
| | | // 下一day为 1说明该周目已完成,应更改为下一周目 |
| | | if (Constants.ONE.equals(nextDay)) { |
| | | // 获取下一周目信息 |
| | | int index = -1; |
| | | for (int i = 0; i < studyList.size(); i++) { |
| | | if (studyList.get(i).getWeek().equals(userStudyRecord.getWeek())) { |
| | | index = i; |
| | | break; |
| | | } |
| | | Integer week = userStudyRecord.getWeek(); |
| | | Integer day = userStudyRecord.getDay(); |
| | | if (week.equals(completeStudy.getWeek()) && day.equals(completeStudy.getDay())) { |
| | | Integer type = completeStudy.getType(); |
| | | if (Constants.ONE.equals(type)) { |
| | | userStudyRecord.setListen(Constants.ONE_HUNDRED); |
| | | } else if (Constants.TWO.equals(type)) { |
| | | userStudyRecord.setLook(Constants.ONE_HUNDRED); |
| | | } else if (Constants.THREE.equals(type)) { |
| | | userStudyRecord.setInduction(Constants.ONE_HUNDRED); |
| | | } else if (Constants.FOUR.equals(type)) { |
| | | userStudyRecord.setAnswer(Constants.ONE_HUNDRED); |
| | | } else if (Constants.FIVE.equals(type)) { |
| | | userStudyRecord.setPair(Constants.ONE_HUNDRED); |
| | | } |
| | | if (userStudyRecord.getLook().equals(Constants.ONE_HUNDRED) && |
| | | userStudyRecord.getAnswer().equals(Constants.ONE_HUNDRED) && |
| | | userStudyRecord.getPair().equals(Constants.ONE_HUNDRED) && |
| | | userStudyRecord.getInduction().equals(Constants.ONE_HUNDRED) && |
| | | userStudyRecord.getListen().equals(Constants.ONE_HUNDRED)) { |
| | | // 学习完成,进入下一学习day |
| | | Integer nextDay = DAY_MAP.get(String.valueOf(userStudyRecord.getDay())); |
| | | userStudyRecord.setDay(nextDay); |
| | | // 下一day为 6,进入游戏日 |
| | | if (nextDay.equals(Constants.SIX)) { |
| | | // 游戏难度初始化 0(入门难度) |
| | | userStudyRecord.setGameDifficulty(Constants.ZERO); |
| | | } else { |
| | | // 重置学习进度 |
| | | userStudyRecord.setListen(Constants.BURDEN_ONE); |
| | | userStudyRecord.setLook(Constants.BURDEN_ONE); |
| | | userStudyRecord.setInduction(Constants.BURDEN_ONE); |
| | | userStudyRecord.setAnswer(Constants.BURDEN_ONE); |
| | | userStudyRecord.setPair(Constants.BURDEN_ONE); |
| | | } |
| | | int nextIndex = (index + 1) % studyList.size(); |
| | | TStudy nextStudy = studyList.get(nextIndex); |
| | | // 更新学习进度及学习时长 |
| | | userStudyRecord.setWeek(nextStudy.getWeek()); |
| | | } |
| | | } |
| | | // 更新学习时长 |
| | |
| | | return this.updateById(userStudyRecord); |
| | | } |
| | | |
| | | @Override |
| | | public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) { |
| | | String answerRate = game.getAnswerRate(); |
| | | String rate = game.getRate().split(",")[Constants.TWO]; |
| | | // 校验是否完成超级听力 |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getGameId, game.getId()) |
| | | .eq(TGameRecord::getGameDifficulty, Constants.TWO) |
| | | .ge(TGameRecord::getAccuracy, rate).list(); |
| | | // 下一周目逻辑 |
| | | int quarterItem = 1; |
| | | Map<Integer, List<TStudy>> studyMap = new HashMap<>(8); |
| | | for (TStudy study : studyList) { |
| | | Integer quarter = study.getQuarter(); |
| | | List<TStudy> itemList = studyMap.get(quarter); |
| | | if (null == itemList) { |
| | | itemList = new ArrayList<>(); |
| | | } |
| | | itemList.add(study); |
| | | studyMap.put(quarter, itemList); |
| | | // 记录学习季度 |
| | | if (study.getId().equals(game.getStudyId())) { |
| | | quarterItem = quarter; |
| | | } |
| | | } |
| | | // 获取当前季度所有周目 |
| | | List<TStudy> studyList1 = studyMap.get(quarterItem); |
| | | // 正确率达到通关率 |
| | | if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate) |
| | | && !gameRecordList.isEmpty()) { |
| | | // 获取用户超级记忆游戏记录 |
| | | TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one(); |
| | | for (int i = 0; i < studyList1.size(); i++) { |
| | | TStudy tStudy = studyList1.get(i); |
| | | if (tStudy.getWeek().equals(userStudy.getWeek())) { |
| | | if (studyList1.size() == 1 || i + 1 == studyList1.size()) { |
| | | // 是否为当前季度最后一周目 |
| | | List<TStudy> studyList2 = studyMap.get(quarterItem + 1); |
| | | // 下一季度数据为空 |
| | | if (null != studyList2 && !studyList2.isEmpty()) { |
| | | TStudy tStudy1 = studyList2.get(Constants.ZERO); |
| | | userStudy.setWeek(tStudy1.getWeek()); |
| | | } |
| | | } else { |
| | | TStudy tStudy1 = studyList1.get(i + 1); |
| | | userStudy.setWeek(tStudy1.getWeek()); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | userStudy.setDay(DAY_MAP.get(String.valueOf(userStudy.getDay()))); |
| | | userStudy.setLook(Constants.BURDEN_ONE); |
| | | userStudy.setPair(Constants.BURDEN_ONE); |
| | | userStudy.setInduction(Constants.BURDEN_ONE); |
| | | userStudy.setListen(Constants.BURDEN_ONE); |
| | | userStudy.setAnswer(Constants.BURDEN_ONE); |
| | | userStudy.setGameDifficulty(Constants.ZERO); |
| | | this.updateById(userStudy); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) { |
| | | // 超级听力通关率 |
| | | String answerRate = game.getRate().split(",")[completeStudy.getDifficulty()]; |
| | | if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)) { |
| | | // 获取用户超级记忆游戏记录 |
| | | TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one(); |
| | | // 更新游戏难度学习记录 |
| | | if (!Constants.TWO.equals(userStudy.getGameDifficulty())) { |
| | | // 获取用户游戏进度 |
| | | List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid) |
| | | .eq(TGameRecord::getGameId, game.getId()) |
| | | .ge(TGameRecord::getAccuracy, answerRate) |
| | | .eq(TGameRecord::getGameDifficulty, completeStudy.getDifficulty()).list(); |
| | | if (!list.isEmpty()) { |
| | | Integer integer = GAME_DIFFICULTY_MAP.get(completeStudy.getDifficulty()); |
| | | userStudy.setGameDifficulty(integer); |
| | | } |
| | | } else { |
| | | // 游戏难度为2,进入下一周目学习 |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getGameId, game.getId()) |
| | | .eq(TGameRecord::getGameName, Constants.MEMORY) |
| | | .ge(TGameRecord::getAccuracy, game.getAnswerRate()).list(); |
| | | // 判断是否完成超级记忆 |
| | | if (!gameRecordList.isEmpty()) { |
| | | int quarterItem = 1; |
| | | Map<Integer, List<TStudy>> studyMap = new HashMap<>(8); |
| | | for (TStudy study : studyList) { |
| | | Integer quarter = study.getQuarter(); |
| | | List<TStudy> itemList = studyMap.get(quarter); |
| | | if (null == itemList) { |
| | | itemList = new ArrayList<>(); |
| | | } |
| | | itemList.add(study); |
| | | studyMap.put(quarter, itemList); |
| | | // 记录学习季度 |
| | | if (study.getId().equals(game.getStudyId())) { |
| | | quarterItem = quarter; |
| | | } |
| | | } |
| | | // 获取当前季度所有周目 |
| | | List<TStudy> studyList1 = studyMap.get(quarterItem); |
| | | // 获取用户超级记忆游戏记录 |
| | | for (int i = 0; i < studyList1.size(); i++) { |
| | | TStudy tStudy = studyList1.get(i); |
| | | if (tStudy.getWeek().equals(userStudy.getWeek())) { |
| | | if (studyList1.size() == 1 || i + 1 == studyList1.size()) { |
| | | // 是否为当前季度最后一周目 |
| | | List<TStudy> studyList2 = studyMap.get(quarterItem + 1); |
| | | // 下一季度数据为空 |
| | | if (null != studyList2 && !studyList2.isEmpty()) { |
| | | TStudy tStudy1 = studyList2.get(Constants.ZERO); |
| | | userStudy.setWeek(tStudy1.getWeek()); |
| | | } |
| | | } else { |
| | | TStudy tStudy1 = studyList1.get(i + 1); |
| | | userStudy.setWeek(tStudy1.getWeek()); |
| | | } |
| | | } |
| | | } |
| | | userStudy.setDay(DAY_MAP.get(String.valueOf(userStudy.getDay()))); |
| | | userStudy.setLook(Constants.BURDEN_ONE); |
| | | userStudy.setPair(Constants.BURDEN_ONE); |
| | | userStudy.setInduction(Constants.BURDEN_ONE); |
| | | userStudy.setListen(Constants.BURDEN_ONE); |
| | | userStudy.setAnswer(Constants.BURDEN_ONE); |
| | | userStudy.setGameDifficulty(Constants.ZERO); |
| | | } |
| | | } |
| | | this.updateById(userStudy); |
| | | } |
| | | } |
| | | |
| | | } |