| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @Override |
| | | public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) { |
| | | String answerRate = game.getAnswerRate(); |
| | | // 下一周目逻辑 |
| | | 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)) { |
| | | // 获取用户超级记忆游戏记录 |
| | | TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one(); |
| | | Integer nextDay = DAY_MAP.get(String.valueOf(userStudy.getDay())); |
| | | userStudy.setDay(nextDay); |
| | | if (Constants.ONE.equals(nextDay)) { |
| | | // 获取下一周目信息 |
| | | int index = -1; |
| | | for (int i = 0; i < studyList.size(); i++) { |
| | | if (studyList.get(i).getWeek().equals(userStudy.getWeek())) { |
| | | index = i; |
| | | break; |
| | | for (int i = 0; i < studyList1.size(); i++) { |
| | | TStudy tStudy = studyList1.get(i); |
| | | if (tStudy.getWeek().equals(userStudy.getWeek())) { |
| | | // 是否为当前季度最后一周目 |
| | | if (i + 1 == studyList1.size() - 1) { |
| | | List<TStudy> studyList2 = studyMap.get(quarterItem + 1); |
| | | // 下一季度数据为空 |
| | | if (null != studyList2 && !studyList2.isEmpty()) { |
| | | TStudy tStudy1 = studyList2.get(Constants.ZERO); |
| | | tStudy.setWeek(tStudy1.getWeek()); |
| | | } |
| | | } else { |
| | | TStudy tStudy1 = studyList1.get(i + 1); |
| | | userStudy.setWeek(tStudy1.getWeek()); |
| | | } |
| | | } |
| | | int nextIndex = (index + 1) % studyList.size(); |
| | | TStudy nextStudy = studyList.get(nextIndex); |
| | | // 更新学习进度及学习时长 |
| | | userStudy.setWeek(nextStudy.getWeek()); |
| | | } |
| | | this.updateById(userStudy); |
| | | } |