| | |
| | | */ |
| | | @PostMapping("/completeLearning") |
| | | @ApiOperation(value = "完成学习", tags = {"学习端-听-自主学习"}) |
| | | public R<Boolean> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { |
| | | public R<Integer> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { |
| | | LoginUserParent userStudy = tokenService.getLoginUserStudy(); |
| | | if (null == userStudy) { |
| | | return R.tokenError("登录失效!"); |
| | |
| | | userStudyRecord = createUserStudy(userId); |
| | | } |
| | | Boolean updateStudyRecord = userStudyService.exchangeStudyRecord(userStudyRecord, userId, completeStudy); |
| | | return R.ok(update && updateStudyRecord); |
| | | return R.ok(sum > obtainedIntegral ? sum - obtainedIntegral : 0); |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new GlobalException("当前周目下day1 - day5题目不足!"); |
| | | } |
| | | // 根据游戏设置数量获取图片及语音 |
| | | List<String> subjectData = getData(game, newSubjectId); |
| | | List<String> subjectData = getData(game, newSubjectId, 1); |
| | | List<TSubject> subjectList = getSubjectList(subjectData); |
| | | return R.ok(new StudyGameResultVO(game, subjectList)); |
| | | } |
| | |
| | | throw new GlobalException("当前周目下day1 - day5题目不足!"); |
| | | } |
| | | // 根据游戏设置数量获取图片及语音 |
| | | return getData(game, newSubjectId); |
| | | return getData(game, newSubjectId, 2); |
| | | } |
| | | |
| | | private List<String> getData(TGame game, List<String> newSubjectId) { |
| | | private List<String> getData(TGame game, List<String> newSubjectId, int num) { |
| | | List<String> subjectData = new ArrayList<>(); |
| | | Random random = new Random(); |
| | | // 获取列表大小 |
| | | int dataSize = newSubjectId.size(); |
| | | // 生成随机索引并获取数据 |
| | | for (int i = 0; i < game.getCount(); i++) { |
| | | int index; |
| | | if (1 == num) { |
| | | index = game.getCount(); |
| | | } else { |
| | | index = game.getAnswerCount(); |
| | | } |
| | | for (int i = 0; i < index; i++) { |
| | | // 生成随机索引 |
| | | int randomIndex = random.nextInt(dataSize); |
| | | // 获取对应的数据并加入结果列表 |
| | |
| | | */ |
| | | @PostMapping("/gameAchievement") |
| | | @ApiOperation(value = "完成游戏-记录游戏测试成绩", tags = {"学习端-听-自主游戏"}) |
| | | public R<Boolean> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { |
| | | public R<Integer> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { |
| | | LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); |
| | | if (null == loginUserStudy) { |
| | | return R.tokenError("登录失效!"); |
| | |
| | | userStudy.setTodayStudy(userStudy.getTodayStudy() + completeStudy.getUseTime()); |
| | | userStudy.setWeekStudy(userStudy.getWeekStudy() + completeStudy.getUseTime()); |
| | | userStudy.setMonthStudy(userStudy.getMonthStudy() + completeStudy.getUseTime()); |
| | | boolean update = userStudyService.updateById(userStudy); |
| | | userStudyService.updateById(userStudy); |
| | | // 超级记忆逻辑 |
| | | if (Constants.MEMORY.equals(completeStudy.getGameName())) { |
| | | // 学习配置列表 |
| | |
| | | String rate = game.getRate().split(",")[completeStudy.getDifficulty()]; |
| | | add = add && completeStudy.getAccuracy() >= Integer.parseInt(rate); |
| | | } |
| | | return R.ok(add && update); |
| | | return R.ok(availableIntegral); |
| | | } |
| | | |
| | | private TUserStudy createUserStudy(Integer userid) { |
| | |
| | | @ApiImplicitParam(value = "正确率", name = "accuracy", dataType = "Integer"), |
| | | @ApiImplicitParam(value = "学习时长(秒)", name = "studyTime", dataType = "Integer", required = true) |
| | | }) |
| | | public R<Boolean> completeStory(@RequestParam Integer storyId, @RequestParam Integer type, |
| | | public R<Integer> completeStory(@RequestParam Integer storyId, @RequestParam Integer type, |
| | | Integer accuracy, @RequestParam Integer studyTime) { |
| | | TStoryListen storyListen = storyListenService.lambdaQuery().eq(TStoryListen::getId, storyId) |
| | | .eq(TStoryListen::getDisabled, 0).one(); |
| | |
| | | throw new GlobalException("学习时长更新失败!"); |
| | | } |
| | | // 根据故事类型不同,逻辑处理 |
| | | int sum = 0; |
| | | if (Constants.ONE.equals(type)) { |
| | | if (null == accuracy) { |
| | | throw new GlobalException("自主故事-看图配音正确率异常!"); |
| | |
| | | data.setType(Constants.ONE); |
| | | data.setStoryId(storyId); |
| | | result = studyRecordService.save(data); |
| | | sum = integral - obtainedIntegral; |
| | | } |
| | | } else { |
| | | // 超级记忆只有首次才能获取积分 |
| | |
| | | // 添加积分 |
| | | user.setIntegral(user.getIntegral() + storyListen.getIntegral()); |
| | | result = result && userService.updateById(user); |
| | | sum = storyListen.getIntegral(); |
| | | } |
| | | } |
| | | return R.ok(result); |
| | | return R.ok(sum); |
| | | } |
| | | |
| | | @GetMapping("/studyRecord") |
| | |
| | | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) |
| | | .eq(TStudy::getType, Constants.ONE) |
| | | .orderByAsc(TStudy::getWeek).list(); |
| | | int size = studyService.residueWeek(studyRecord,studyList); |
| | | int size = studyService.residueWeek(studyRecord, studyList); |
| | | studyRecord.setSurplus(size); |
| | | } |
| | | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); |