| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private IUserStudyRecordService studyRecordService; |
| | | @Resource |
| | | private ManagementClient managementClient; |
| | | @Resource |
| | | private ITUserPresentRecordService userPresentRecordService; |
| | | |
| | | @PostMapping("/testAddData") |
| | | @ApiOperation(value = "测试分片", tags = {"测试分片"}) |
| | | public R<Object> testAddData() { |
| | | TIntegralRecord tIntegralRecord = new TIntegralRecord(); |
| | | tIntegralRecord.setIntegral("1"); |
| | | tIntegralRecord.setMethod("1"); |
| | | tIntegralRecord.setUserId(23); |
| | | tIntegralRecord.setGameId(1); |
| | | tIntegralRecord.setGameDifficulty(1); |
| | | tIntegralRecord.setStoryId(1); |
| | | tIntegralRecord.setStoryType(1); |
| | | integralRecordService.save(tIntegralRecord); |
| | | TGameRecord tGameRecord = new TGameRecord(); |
| | | tGameRecord.setUserId(33); |
| | | tGameRecord.setAccuracy(0); |
| | | tGameRecord.setGameName(""); |
| | | tGameRecord.setUseTime(0); |
| | | tGameRecord.setUseTime1(""); |
| | | tGameRecord.setGameId(0); |
| | | tGameRecord.setGameDifficulty(0); |
| | | tGameRecord.setTime(""); |
| | | tGameRecord.setDisabled(false); |
| | | tGameRecord.setCreateBy(""); |
| | | tGameRecord.setCreateTime(new Date()); |
| | | tGameRecord.setUpdateBy(""); |
| | | tGameRecord.setUpdateTime(new Date()); |
| | | gameRecordService.save(tGameRecord); |
| | | TSubjectRecord tSubjectRecord = new TSubjectRecord(); |
| | | tSubjectRecord.setUserId(22); |
| | | tSubjectRecord.setWeek(0); |
| | | tSubjectRecord.setDay(0); |
| | | tSubjectRecord.setBeforeSubject(""); |
| | | tSubjectRecord.setType(0); |
| | | tSubjectRecord.setCompleteSubject(""); |
| | | tSubjectRecord.setAnswerNumber(0); |
| | | tSubjectRecord.setCorrectNumber(0); |
| | | tSubjectRecord.setDisabled(false); |
| | | tSubjectRecord.setCreateBy(""); |
| | | tSubjectRecord.setCreateTime(new Date()); |
| | | tSubjectRecord.setUpdateBy(""); |
| | | tSubjectRecord.setUpdateTime(new Date()); |
| | | subjectRecordService.save(tSubjectRecord); |
| | | TUserPresentRecord tUserPresentRecord = new TUserPresentRecord(); |
| | | tUserPresentRecord.setUserId(44); |
| | | tUserPresentRecord.setPresentTime(new Date()); |
| | | tUserPresentRecord.setIsDelete(0); |
| | | userPresentRecordService.save(tUserPresentRecord); |
| | | |
| | | TUserStudyRecord tUserStudyRecord = new TUserStudyRecord(); |
| | | tUserStudyRecord.setUserId(17); |
| | | tUserStudyRecord.setQuarter(0); |
| | | tUserStudyRecord.setWeek(0); |
| | | tUserStudyRecord.setDay(0); |
| | | tUserStudyRecord.setObtainedIntegral(0); |
| | | tUserStudyRecord.setType(0); |
| | | tUserStudyRecord.setStudyType(0); |
| | | tUserStudyRecord.setStoryId(0); |
| | | studyRecordService.save(tUserStudyRecord); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/storyList") |
| | | // @ApiOperation(value = "配置学习类型选择故事", tags = {"题目管理"}) |
| | |
| | | wrapper.like("type", query.getType()); |
| | | } |
| | | wrapper.eq("state", 1); |
| | | List<TStory> tStories = new ArrayList<>(); |
| | | |
| | | switch (query.getStoryType()) { |
| | | case 2: |
| | | List<TStory> list = storyService.list(wrapper); |
| | | List<TStory> tSubjects = new ArrayList<>(); |
| | | for (TStory tSubject : list) { |
| | | if (!tSubject.getError().isEmpty()) { |
| | | tSubjects.add(tSubject); |
| | | } |
| | | } |
| | | List<TStory> tSubjects = new ArrayList<>(list); |
| | | res.setRecords(tSubjects); |
| | | res.setTotal(tSubjects.size()); |
| | | return R.ok(res); |
| | |
| | | // 查询出error字段不为空的数据 |
| | | wrapper.isNotNull("error"); |
| | | List<TStory> list1 = storyService.list(wrapper); |
| | | res.setRecords(list1); |
| | | res.setTotal(list1.size()); |
| | | for (TStory tStory : list1) { |
| | | if (tStory.getError() != null && (!tStory.getError().isEmpty())) { |
| | | tStories.add(tStory); |
| | | } |
| | | } |
| | | res.setRecords(tStories); |
| | | res.setTotal(tStories.size()); |
| | | return R.ok(res); |
| | | |
| | | } |
| | |
| | | studyId.setAnswerTime(game.getAnswerTime()); |
| | | studyId.setAnswerIntegral(game.getAnswerIntegral()); |
| | | studyId.setAnswerCount(game.getAnswerCount()); |
| | | studyId.setRate(game.getRate()); |
| | | studyId.setAnswerRate(game.getAnswerRate()); |
| | | gameService.updateById(studyId); |
| | | } else { |
| | | TGame tGame = new TGame(); |
| | |
| | | studyPairVO.setIsVip(tStudyPair.getIsVip()); |
| | | pairVOS.add(studyPairVO); |
| | | } |
| | | |
| | | } |
| | | List<TGame> list5 = gameService.list(new QueryWrapper<TGame>() |
| | | .eq("week", week)); |
| | |
| | | gameVO.setAnswerTime(tGame.getAnswerTime()); |
| | | gameVO.setAnswerIntegral(tGame.getAnswerIntegral()); |
| | | gameVO.setAnswerCount(tGame.getAnswerCount()); |
| | | gameVO.setRate(tGame.getRate()); |
| | | gameVO.setAnswerRate(tGame.getAnswerRate()); |
| | | gameVOS.add(gameVO); |
| | | } |
| | | List<TStoryListen> list6 = storyListenService.list(new QueryWrapper<TStoryListen>() |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取当前季度游戏难度 |
| | | */ |
| | | @GetMapping("/userGameDifficulty") |
| | | @ApiOperation(value = "获取当前季度游戏难度", tags = {"学习端-首页"}) |
| | | public R<Integer> userGameDifficulty(@RequestParam Integer week) { |
| | | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); |
| | | if (null == loginStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | Integer userid = loginStudy.getUserid(); |
| | | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | return R.ok(studyService.userGameDifficulty(studyRecord, week)); |
| | | } |
| | | |
| | | /** |
| | | * 首次页面加载时调用,获取学习进度及学习时长等信息 |
| | | * |
| | | * @param week 周目 |
| | |
| | | if (null == loginStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | TUserStudy result = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, loginStudy.getUserid()) |
| | | Integer userid = loginStudy.getUserid(); |
| | | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, loginStudy.getUserid()) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | if (null != result) { |
| | | if (null != studyRecord) { |
| | | // 计算当前周 day 1-5的总进度 |
| | | int computeSchedule = studyService.computeSchedule(result, week); |
| | | result.setComputeSchedule(computeSchedule); |
| | | int computeSchedule = studyService.computeSchedule(studyRecord, week); |
| | | studyRecord.setComputeSchedule(computeSchedule); |
| | | // 学习时长格式转换 |
| | | Integer todayStudy = studyRecord.getTodayStudy(); |
| | | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); |
| | | Integer weekStudy = studyRecord.getWeekStudy(); |
| | | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); |
| | | Integer monthStudy = studyRecord.getMonthStudy(); |
| | | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); |
| | | // 总时长还需计算上游戏测试成绩时长 |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid) |
| | | .eq(TGameRecord::getDisabled, 0).list(); |
| | | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); |
| | | Integer totalStudy = studyRecord.getTotalStudy(); |
| | | studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600)); |
| | | studyRecord = studyService.studySchedule(studyRecord, week); |
| | | // 数据库保存的是已完成的学习进度,返回前端时需要转换为剩余学习进度 |
| | | Integer look = studyRecord.getLook(); |
| | | if (look != 100 && look != -1) { |
| | | studyRecord.setLook(100 - look); |
| | | } |
| | | Integer pair = studyRecord.getPair(); |
| | | if (pair != 100 && pair != -1) { |
| | | studyRecord.setPair(100 - pair); |
| | | } |
| | | Integer answer = studyRecord.getAnswer(); |
| | | if (answer != 100 && answer != -1) { |
| | | studyRecord.setAnswer(100 - answer); |
| | | } |
| | | Integer induction = studyRecord.getInduction(); |
| | | if (induction != 100 && induction != -1) { |
| | | studyRecord.setInduction(100 - induction); |
| | | } |
| | | Integer listen = studyRecord.getListen(); |
| | | if (listen != 100 && listen != -1) { |
| | | studyRecord.setListen(100 - listen); |
| | | } |
| | | } |
| | | return R.ok(result); |
| | | return R.ok(studyRecord); |
| | | } |
| | | |
| | | /** |
| | |
| | | @ApiImplicitParam(value = "季度 首次进入季度quarter默认传1", name = "quarter", dataType = "Integer", required = true) |
| | | }) |
| | | public R<List<StudyWeekDTO>> weekList(@RequestParam(defaultValue = "1") Integer type, @RequestParam Integer quarter) { |
| | | List<StudyWeekDTO> result = studyService.weekList(type, quarter); |
| | | LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); |
| | | if (null == loginUserStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | List<StudyWeekDTO> result = studyService.weekList(type, quarter, loginUserStudy.getUserid()); |
| | | return R.ok(result); |
| | | } |
| | | |
| | |
| | | throw new GlobalException("获取在线时间赠送积分信息失败!"); |
| | | } |
| | | String integral = sysSet.getIntegral(); |
| | | // 计算时间间隔 |
| | | TUserPresentRecord record = userPresentRecordService.lambdaQuery() |
| | | .eq(TUserPresentRecord::getUserId, loginStudy.getUserid()) |
| | | .orderByDesc(TUserPresentRecord::getPresentTime) |
| | | .eq(TUserPresentRecord::getIsDelete, 0).last("limit 1").one(); |
| | | boolean result = true; |
| | | TUser user = userService.lambdaQuery().eq(TUser::getId, loginStudy.getUserid()) |
| | | .eq(TUser::getDisabled, 0).one(); |
| | | boolean update = userService.lambdaUpdate().set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) |
| | | .eq(TUser::getId, loginStudy.getUserid()).update(); |
| | | return R.ok(update); |
| | | if (null == record) { |
| | | // 赠送积分 |
| | | result = userService.lambdaUpdate().set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) |
| | | .eq(TUser::getId, loginStudy.getUserid()).update(); |
| | | // 添加赠送积分记录 |
| | | TUserPresentRecord data = new TUserPresentRecord(); |
| | | data.setUserId(loginStudy.getUserid()); |
| | | data.setPresentTime(new Date()); |
| | | data.setIsDelete(0); |
| | | result = result && userPresentRecordService.save(data); |
| | | } else { |
| | | if (System.currentTimeMillis() - record.getPresentTime().getTime() >= (long) Integer.parseInt(sysSet.getTime()) * 60 * 1000) { |
| | | // 赠送积分 |
| | | result = userService.lambdaUpdate() |
| | | .set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) |
| | | .eq(TUser::getId, loginStudy.getUserid()).update(); |
| | | // 添加赠送积分记录 |
| | | TUserPresentRecord data = new TUserPresentRecord(); |
| | | data.setUserId(loginStudy.getUserid()); |
| | | data.setPresentTime(new Date()); |
| | | data.setIsDelete(0); |
| | | result = result && userPresentRecordService.save(data); |
| | | // 生成积分明细 |
| | | TIntegralRecord integralRecord = new TIntegralRecord(); |
| | | integralRecord.setIntegral(sysSet.getIntegral()); |
| | | integralRecord.setMethod(Constants.ONLINE_DURATION); |
| | | integralRecord.setUserId(loginStudy.getUserid()); |
| | | result = result && integralRecordService.save(integralRecord); |
| | | } |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | // 返回结果 |
| | | SubjectRecordResultVO result; |
| | | if (null != subjectRecord) { |
| | | subjectRecordService.lambdaUpdate().set(TSubjectRecord::getDisabled, 1) |
| | | .eq(TSubjectRecord::getId, subjectRecord.getId()).update(); |
| | | // 题组id |
| | | /*// 题组id |
| | | List<Integer> teamIds = Arrays.stream(subjectRecord.getBeforeSubject().split(",")).map(Integer::parseInt) |
| | | .collect(Collectors.toList()); |
| | | // 题目id |
| | | List<Integer> topicIds = Arrays.stream(subjectRecord.getCompleteSubject().split(",")).map(Integer::parseInt) |
| | | .collect(Collectors.toList()); |
| | | result = new SubjectRecordResultVO(teamIds, topicIds, subjectRecord.getAnswerNumber(), subjectRecord.getCorrectNumber()); |
| | | .collect(Collectors.toList());*/ |
| | | result = new SubjectRecordResultVO(null, null, subjectRecord.getAnswerNumber(), subjectRecord.getCorrectNumber(), subjectRecord.getSchedule()); |
| | | } else { |
| | | result = new SubjectRecordResultVO(); |
| | | result = null; |
| | | } |
| | | subjectRecordService.lambdaUpdate().set(TSubjectRecord::getDisabled, 0) |
| | | .eq(TSubjectRecord::getUserId, loginStudy.getUserid()).update(); |
| | | return R.ok(result); |
| | | } |
| | | |
| | |
| | | if (null == loginStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | // 退出学习如果已经存在中途学习记录,则删除记录,保存新学习记录 |
| | | Integer userid = loginStudy.getUserid(); |
| | | TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery() |
| | | .eq(TSubjectRecord::getUserId, userid) |
| | | .eq(TSubjectRecord::getWeek, exitLearn.getWeek()) |
| | | .eq(TSubjectRecord::getDay, exitLearn.getDay()) |
| | | .eq(TSubjectRecord::getType, exitLearn.getType()) |
| | | .eq(TSubjectRecord::getDisabled, 0) |
| | | .one(); |
| | | if (null != subjectRecord) { |
| | | subjectRecordService.removeById(subjectRecord); |
| | | } |
| | | // 判断当前week和day是否已完成学习 |
| | | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | if (null == userStudy) { |
| | | throw new GlobalException("登录用户学习记录不存在!"); |
| | | userStudy = createUserStudy(userid); |
| | | } |
| | | Integer quarter = exitLearn.getQuarter(); |
| | | Integer week = exitLearn.getWeek(); |
| | | Integer day = exitLearn.getDay(); |
| | | int schedule = exitLearn.getSchedule() - 1; |
| | | if (userStudy.getWeek().equals(exitLearn.getWeek()) && userStudy.getDay().equals(exitLearn.getDay())) { |
| | | // 计算完成率 |
| | | int completionRate = exitLearn.getTopicIds().split(",").length * 5; |
| | | Integer type = exitLearn.getType(); |
| | | // 更新用户学习完成率 |
| | | if (Constants.ONE.equals(type) && userStudy.getListen() < completionRate) { |
| | | // 听音选图 |
| | | userStudy.setListen(completionRate); |
| | | } else if (Constants.TWO.equals(type) && userStudy.getLook() < completionRate) { |
| | | // 看图选音 |
| | | userStudy.setLook(completionRate); |
| | | } else if (Constants.THREE.equals(type) && userStudy.getInduction() < completionRate) { |
| | | // 归纳排除 |
| | | userStudy.setInduction(completionRate); |
| | | } else if (Constants.FOUR.equals(type) && userStudy.getAnswer() < completionRate) { |
| | | // 有问有答 |
| | | userStudy.setAnswer(completionRate); |
| | | } else if (Constants.FIVE.equals(type) && userStudy.getPair() < completionRate) { |
| | | // 音图相配 |
| | | userStudy.setPair(completionRate); |
| | | if (Constants.ONE.equals(type)) { |
| | | if (userStudy.getListen() != 100) { |
| | | if (1 == exitLearn.getSchedule()) { |
| | | userStudy.setListen(Constants.BURDEN_ONE); |
| | | } else { |
| | | // 听音选图 |
| | | List<TStudyListen> studyListens = studyListenService.listenSelectPicture(quarter, week, day); |
| | | int item = 0; |
| | | for (TStudyListen studyListen : studyListens) { |
| | | item += studyListen.getSubject().split(",").length; |
| | | } |
| | | int i = (int) (((double) schedule / item) * 100); |
| | | userStudy.setListen(i); |
| | | } |
| | | } |
| | | } else if (Constants.TWO.equals(type)) { |
| | | if (userStudy.getLook() != 100) { |
| | | if (1 == exitLearn.getSchedule()) { |
| | | userStudy.setLook(Constants.BURDEN_ONE); |
| | | } else { |
| | | // 看图选音 |
| | | List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day); |
| | | if (!lookList.isEmpty()) { |
| | | int item = lookList.size(); |
| | | int i = (int) (((double) schedule / item) * 100); |
| | | userStudy.setLook(i); |
| | | } |
| | | } |
| | | } |
| | | } else if (Constants.THREE.equals(type)) { |
| | | if (userStudy.getInduction() != 100) { |
| | | if (1 == exitLearn.getSchedule()) { |
| | | userStudy.setInduction(Constants.BURDEN_ONE); |
| | | } else { |
| | | // 归纳排除 |
| | | List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day); |
| | | if (!inductionList.isEmpty()) { |
| | | int item = inductionList.size(); |
| | | int i = (int) (((double) schedule / item) * 100); |
| | | userStudy.setInduction(i); |
| | | } |
| | | } |
| | | } |
| | | } else if (Constants.FOUR.equals(type)) { |
| | | if (userStudy.getAnswer() != 100) { |
| | | if (1 == exitLearn.getSchedule()) { |
| | | userStudy.setAnswer(Constants.BURDEN_ONE); |
| | | } else { |
| | | // 有问有答 |
| | | List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day); |
| | | if (answerList.size() % Constants.TWO == Constants.ZERO) { |
| | | int i = (int) (((double) schedule / (answerList.size() / 2)) * 100); |
| | | userStudy.setAnswer(i); |
| | | } |
| | | } |
| | | } |
| | | } else if (Constants.FIVE.equals(type)) { |
| | | if (userStudy.getPair() != 100) { |
| | | if (1 == exitLearn.getSchedule()) { |
| | | userStudy.setPair(Constants.BURDEN_ONE); |
| | | } else { |
| | | // 音图相配 |
| | | List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day); |
| | | if (!pairList.isEmpty()) { |
| | | int item = pairList.size(); |
| | | int i = (int) (((double) schedule / item) * 100); |
| | | userStudy.setPair(i); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 学习时长更新 |
| | |
| | | userStudy.setMonthStudy(userStudy.getMonthStudy() + exitLearn.getStudyTime()); |
| | | userStudyService.updateById(userStudy); |
| | | return R.ok(subjectRecordService.exitLearning(exitLearn, userid)); |
| | | } |
| | | |
| | | /** |
| | | * 退出游戏/故事学习 |
| | | */ |
| | | @GetMapping("/exitGameOrStory") |
| | | @ApiOperation(value = "退出游戏/故事学习", tags = {"学习端-题目"}) |
| | | public R<Boolean> exitGameOrStory(@RequestParam("studyTime") Integer studyTime) { |
| | | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); |
| | | if (null == loginStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | Integer userid = loginStudy.getUserid(); |
| | | // 判断当前week和day是否已完成学习 |
| | | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | if (null == userStudy) { |
| | | userStudy = createUserStudy(userid); |
| | | } |
| | | // 学习时长更新 |
| | | userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime); |
| | | userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime); |
| | | userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime); |
| | | userStudy.setMonthStudy(userStudy.getMonthStudy() + studyTime); |
| | | return R.ok(userStudyService.updateById(userStudy)); |
| | | } |
| | | |
| | | /** |
| | |
| | | // 非会员只能查看非会员题目,会员可以查看所有题目 |
| | | List<TStudyListen> studyListens = studyListenService.listenSelectPicture(quarter, week, day); |
| | | for (TStudyListen studyListen : studyListens) { |
| | | if (studyListen.getIsVip() == 1) { |
| | | if (studyListen.getIsVip() == 0) { |
| | | // 需要会员查看 |
| | | if (!isVip) { |
| | | // 不是会员 |
| | |
| | | // 非会员只能查看非会员题目,会员可以查看所有题目 |
| | | List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day); |
| | | for (TStudyLook studyListen : lookList) { |
| | | if (studyListen.getIsVip() == 1) { |
| | | if (studyListen.getIsVip() == 0) { |
| | | // 需要会员查看 |
| | | if (!isVip) { |
| | | // 不是会员 |
| | |
| | | // 非会员只能查看非会员题目,会员可以查看所有题目 |
| | | List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day); |
| | | for (TStudyInduction studyListen : inductionList) { |
| | | if (studyListen.getIsVip() == 1) { |
| | | if (studyListen.getIsVip() == 0) { |
| | | // 需要会员查看 |
| | | if (!isVip) { |
| | | // 不是会员 |
| | |
| | | // 非会员只能查看非会员题目,会员可以查看所有题目 |
| | | List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day); |
| | | for (TStudyAnswer studyListen : answerList) { |
| | | if (studyListen.getIsVip() == 1) { |
| | | if (studyListen.getIsVip() == 0) { |
| | | // 需要会员查看 |
| | | if (!isVip) { |
| | | // 不是会员 |
| | |
| | | // 非会员只能查看非会员题目,会员可以查看所有题目 |
| | | List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day); |
| | | for (TStudyPair pair : pairList) { |
| | | if (pair.getIsVip() == 1) { |
| | | if (pair.getIsVip() == 0) { |
| | | // 需要会员查看 |
| | | if (!isVip) { |
| | | // 不是会员 |
| | |
| | | */ |
| | | @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("登录失效!"); |
| | |
| | | // 登录用户id |
| | | Integer userId = userStudy.getUserid(); |
| | | // 判断是否已完成该题组 |
| | | boolean update = true; |
| | | boolean update; |
| | | // 清除中途退出记录 |
| | | TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery() |
| | | .eq(TSubjectRecord::getUserId, userId) |
| | | .eq(TSubjectRecord::getWeek, completeStudy.getWeek()) |
| | | .eq(TSubjectRecord::getDay, completeStudy.getDay()) |
| | | .eq(TSubjectRecord::getType, completeStudy.getType()) |
| | | .eq(TSubjectRecord::getDisabled, 0) |
| | | .one(); |
| | | if (null != subjectRecord) { |
| | | subjectRecordService.removeById(subjectRecord); |
| | | } |
| | | List<String> studyIds = Arrays.stream(completeStudy.getStudyIds().split(",")) |
| | | .collect(Collectors.toList()); |
| | | Integer type = completeStudy.getType(); |
| | |
| | | .eq(TUserStudyRecord::getWeek, completeStudy.getWeek()) |
| | | .eq(TUserStudyRecord::getDay, completeStudy.getDay()) |
| | | .eq(TUserStudyRecord::getType, 0) |
| | | .eq(TUserStudyRecord::getStudyType, completeStudy.getType()) |
| | | .eq(TUserStudyRecord::getUserId, userId).list(); |
| | | if (list.isEmpty()) { |
| | | obtainedIntegral = 0; |
| | |
| | | record.setQuarter(completeStudy.getQuarter()); |
| | | record.setWeek(completeStudy.getWeek()); |
| | | record.setDay(completeStudy.getDay()); |
| | | // 学习类型 |
| | | record.setStudyType(completeStudy.getType()); |
| | | record.setObtainedIntegral(integral); |
| | | record.setType(Constants.ZERO); |
| | | update = update && studyRecordService.save(record); |
| | | } |
| | | // 学习配置列表 |
| | | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) |
| | | .orderByAsc(TStudy::getWeek).list(); |
| | | if (studyList.isEmpty()) { |
| | | throw new GlobalException("学习配置列表未配置或数据失效!"); |
| | | } |
| | | // 更改学习记录 |
| | | Boolean updateStudyRecord = userStudyService.exchangeStudyRecord(studyList, userId, completeStudy); |
| | | return R.ok(update && updateStudyRecord); |
| | | TUserStudy userStudyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | if (null == userStudyRecord) { |
| | | userStudyRecord = createUserStudy(userId); |
| | | } |
| | | Boolean updateStudyRecord = userStudyService.exchangeStudyRecord(userStudyRecord, userId, completeStudy); |
| | | 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)); |
| | | } |
| | |
| | | @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) |
| | | }) |
| | | public R<StudyGameMemoryVO> gameMemory(@RequestParam Integer quarter, @RequestParam Integer week) { |
| | | LoginUserParent userStudy = tokenService.getLoginUserStudy(); |
| | | if (null == userStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | TGame game = gameService.gameHearing(quarter, week); |
| | | if (null == game) { |
| | | throw new GlobalException("当前季度该周目暂无配置游戏数据!"); |
| | |
| | | photoList.add(new GameMemoryPhotoVO(tSubject.getId(), tSubject.getImg())); |
| | | voiceList.add(new GameMemoryVoiceVO(tSubject.getId(), tSubject.getCorrect())); |
| | | } |
| | | // 校验超级听力是否通过 |
| | | // studyService.checkClearance(game,userStudy.getUserid()); |
| | | // 框架记忆数量翻倍,前端需要根据数量画格子 |
| | | game.setAnswerCount(game.getAnswerCount() * 2); |
| | | return R.ok(new StudyGameMemoryVO(game, photoList, voiceList)); |
| | |
| | | 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) { |
| | | LoginUserParent userStudy = tokenService.getLoginUserStudy(); |
| | | if (null == userStudy) { |
| | | public R<Integer> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { |
| | | LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); |
| | | if (null == loginUserStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | /* |
| | |
| | | * 并且需要判断如果该游戏用户已获取一部分积分,再次测试后正确率增长,只能获取高于上次正确率的部分积分 |
| | | * 例如:游戏配置的积分是100,他的正确率是50%那么拿50分,下次他再玩这个游戏 正确率是60% 那么他该获得60分 但是上次已经拿了50 所以这次就只给他加10积分 |
| | | */ |
| | | Integer userid = userStudy.getUserid(); |
| | | TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()).eq(TGame::getDisabled, 0).one(); |
| | | Integer userid = loginUserStudy.getUserid(); |
| | | TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()) |
| | | .eq(TGame::getDisabled, 0).one(); |
| | | if (null == game) { |
| | | throw new GlobalException("游戏信息异常!"); |
| | | } |
| | | // 积分明细 |
| | | List<TIntegralRecord> integralRecordList = integralRecordService.lambdaQuery().eq(TIntegralRecord::getUserId, userid) |
| | | .eq(TIntegralRecord::getGameId, game.getId()).eq(TIntegralRecord::getDisabled, 0).list(); |
| | | Integer difficulty = completeStudy.getDifficulty(); |
| | | List<TIntegralRecord> integralRecordList = integralRecordService.lambdaQuery() |
| | | .eq(TIntegralRecord::getUserId, userid) |
| | | .eq(TIntegralRecord::getGameId, game.getId()) |
| | | .eq(TIntegralRecord::getDisabled, 0) |
| | | .eq(TIntegralRecord::getGameDifficulty, difficulty).list(); |
| | | // 本次游戏总共能获取的积分数量 |
| | | Integer integral; |
| | | Integer item = null; |
| | | if (completeStudy.getGameName().equals(Constants.HEARING)) { |
| | | // 本次游戏总积分 |
| | | integral = Integer.parseInt(game.getIntegral().split(",")[completeStudy.getDifficulty()]); |
| | | integral = Integer.parseInt(game.getIntegral().split(",")[difficulty]); |
| | | item = completeStudy.getDifficulty(); |
| | | } else if (completeStudy.getGameName().equals(Constants.MEMORY)) { |
| | | integralRecordList = integralRecordService.lambdaQuery() |
| | | .eq(TIntegralRecord::getUserId, userid) |
| | | .eq(TIntegralRecord::getGameId, game.getId()) |
| | | .eq(TIntegralRecord::getDisabled, 0) |
| | | .last("and gameDifficulty is null").list(); |
| | | integral = game.getAnswerIntegral(); |
| | | } else { |
| | | throw new GlobalException("该次游戏积分计算异常!"); |
| | | } |
| | | Integer accuracy = completeStudy.getAccuracy(); |
| | | if (accuracy >= 100) { |
| | | accuracy = 100; |
| | | } |
| | | int gameAvailableIntegral = (int) (integral * ((double) completeStudy.getAccuracy() / 100)); |
| | | Integer availableIntegral = gameService.countIntegral(userid, game, completeStudy, gameAvailableIntegral, integralRecordList); |
| | | // 游戏测试记录 |
| | | Boolean add = gameRecordService.add(completeStudy); |
| | | // 可获得积分不为null时,才添加积分明细记录 |
| | | if (null != availableIntegral) { |
| | | add = add && integralRecordService.add(String.valueOf(availableIntegral), Constants.COMPLETE_GAME, completeStudy.getGameId(), null); |
| | | if (null != availableIntegral && !Constants.ZERO.equals(availableIntegral)) { |
| | | add = add && integralRecordService.add(String.valueOf(availableIntegral), |
| | | Constants.COMPLETE_GAME, completeStudy.getGameId(), null, item, null); |
| | | // 用户账户添加积分 |
| | | TUser user = userService.getById(userid); |
| | | user.setIntegral(user.getIntegral() + availableIntegral); |
| | | add = add && userService.updateById(user); |
| | | } |
| | | // 学习时长更新 |
| | | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | if (null == userStudy) { |
| | | userStudy = createUserStudy(userid); |
| | | } |
| | | // 学习时长 |
| | | userStudy.setTotalStudy(userStudy.getTotalStudy() + completeStudy.getUseTime()); |
| | | userStudy.setTodayStudy(userStudy.getTodayStudy() + completeStudy.getUseTime()); |
| | | userStudy.setWeekStudy(userStudy.getWeekStudy() + completeStudy.getUseTime()); |
| | | userStudy.setMonthStudy(userStudy.getMonthStudy() + completeStudy.getUseTime()); |
| | | userStudyService.updateById(userStudy); |
| | | // 学习配置列表 |
| | | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) |
| | | .orderByAsc(TStudy::getWeek).list(); |
| | | if (studyList.isEmpty()) { |
| | | throw new GlobalException("学习配置列表未配置或数据失效!"); |
| | | } |
| | | // 超级记忆逻辑 |
| | | if (Constants.MEMORY.equals(completeStudy.getGameName())) { |
| | | // 学习配置列表 |
| | | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) |
| | | .orderByAsc(TStudy::getWeek).list(); |
| | | if (studyList.isEmpty()) { |
| | | throw new GlobalException("学习配置列表未配置或数据失效!"); |
| | | } |
| | | // 超级记忆正确率达到通关率标准,才能进入下一周目学习 |
| | | // 校验是否通关超级听力与超级记忆,通关则学习记录更新为下一周目 |
| | | userStudyService.checkRate(game, userid, completeStudy, studyList); |
| | | return R.ok(add && completeStudy.getAccuracy() >= Integer.parseInt(game.getAnswerRate())); |
| | | } else { |
| | | // 超级听力需根据正确率判断是否允许进入下一难度 |
| | | userStudyService.gameHearing(game, userid, completeStudy); |
| | | String rate = game.getRate().split(",")[completeStudy.getDifficulty()]; |
| | | return R.ok(add && completeStudy.getAccuracy() >= Integer.parseInt(rate)); |
| | | userStudyService.gameHearing(game, userid, completeStudy, studyList); |
| | | } |
| | | return R.ok(availableIntegral); |
| | | } |
| | | |
| | | private TUserStudy createUserStudy(Integer userid) { |
| | | TUserStudy userStudy = new TUserStudy(); |
| | | userStudy.setUserId(userid); |
| | | // 学习周目 |
| | | TStudy tStudy = studyService.lambdaQuery().eq(TStudy::getQuarter, Constants.ONE) |
| | | .orderByAsc(TStudy::getWeek).last("limit 1").one(); |
| | | userStudy.setWeek(tStudy.getWeek()); |
| | | userStudy.setDay(Constants.ONE); |
| | | userStudy.setTotalStudy(Constants.ZERO); |
| | | userStudy.setTodayStudy(Constants.ZERO); |
| | | userStudy.setWeekStudy(Constants.ZERO); |
| | | userStudy.setMonthStudy(Constants.ZERO); |
| | | userStudy.setListen(Constants.BURDEN_ONE); |
| | | userStudy.setLook(Constants.BURDEN_ONE); |
| | | userStudy.setInduction(Constants.BURDEN_ONE); |
| | | userStudy.setAnswer(Constants.BURDEN_ONE); |
| | | userStudy.setPair(Constants.BURDEN_ONE); |
| | | userStudyService.save(userStudy); |
| | | return userStudy; |
| | | } |
| | | |
| | | private List<String> getSubjectId(Integer week) { |
| | |
| | | @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(); |
| | |
| | | Integer userId = loginUserStudy.getUserid(); |
| | | Boolean result = true; |
| | | // 学习时长更新 |
| | | TStudy study = studyService.lambdaQuery().eq(TStudy::getId, storyListen.getStudyId()) |
| | | .eq(TStudy::getDisabled, 0).one(); |
| | | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | if (null == userStudy) { |
| | | userStudy = createUserStudy(userId); |
| | | } |
| | | userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime); |
| | | userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime); |
| | | userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime); |
| | |
| | | throw new GlobalException("学习时长更新失败!"); |
| | | } |
| | | // 根据故事类型不同,逻辑处理 |
| | | int sum = 0; |
| | | if (Constants.ONE.equals(type)) { |
| | | if (null == accuracy) { |
| | | throw new GlobalException("自主故事-看图配音正确率异常!"); |
| | | } |
| | | if (accuracy >= 100) { |
| | | accuracy = 100; |
| | | } |
| | | // 看图配音模式,也需要根据游戏正确率计算积分 |
| | | int integral = storyListen.getLookIntegral() * (accuracy / 100); |
| | | double d = (double) accuracy / 100; |
| | | int integral = (int) (storyListen.getLookIntegral() * d); |
| | | int obtainedIntegral; |
| | | // 看图配音已获取积分数量 |
| | | List<TUserStudyRecord> list = studyRecordService.lambdaQuery() |
| | | .eq(TUserStudyRecord::getStoryId, storyId) |
| | | .eq(TUserStudyRecord::getType, 1) |
| | | .eq(TUserStudyRecord::getQuarter, study.getQuarter()) |
| | | .eq(TUserStudyRecord::getWeek, storyListen.getWeek()) |
| | | .eq(TUserStudyRecord::getUserId, userId).list(); |
| | | if (list.isEmpty()) { |
| | | obtainedIntegral = 0; |
| | |
| | | .mapToInt(Integer::intValue).sum(); |
| | | } |
| | | // 可获得积分计算 |
| | | if (integral > obtainedIntegral) { |
| | | int i = integral - obtainedIntegral; |
| | | if (i > 0) { |
| | | TUserStudyRecord data = new TUserStudyRecord(); |
| | | data.setUserId(userId); |
| | | data.setObtainedIntegral(integral - obtainedIntegral); |
| | | data.setObtainedIntegral(i); |
| | | data.setType(Constants.ONE); |
| | | data.setStoryId(storyId); |
| | | data.setQuarter(study.getQuarter()); |
| | | data.setWeek(storyListen.getWeek()); |
| | | result = studyRecordService.save(data); |
| | | sum = i; |
| | | // 添加积分明细记录 |
| | | result = integralRecordService.add(String.valueOf(sum), |
| | | Constants.COMPLETE_STORY, null, storyId, null, Constants.ZERO); |
| | | TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); |
| | | // 添加积分 |
| | | user.setIntegral(user.getIntegral() + sum); |
| | | result = result && userService.updateById(user); |
| | | } |
| | | } else { |
| | | // 超级记忆只有首次才能获取积分 |
| | | TIntegralRecord integralRecord = integralRecordService.lambdaQuery() |
| | | .eq(TIntegralRecord::getUserId, userId) |
| | | .eq(TIntegralRecord::getStoryId, storyId) |
| | | .eq(TIntegralRecord::getDisabled, 0).one(); |
| | | .eq(TIntegralRecord::getDisabled, 0) |
| | | .eq(TIntegralRecord::getStoryType, Constants.ONE) |
| | | .one(); |
| | | if (null == integralRecord) { |
| | | // 添加积分明细记录 |
| | | result = integralRecordService.add(String.valueOf(storyListen.getIntegral()), |
| | | Constants.COMPLETE_STORY, null, storyId); |
| | | Constants.COMPLETE_STORY, null, storyId, null, Constants.ONE); |
| | | TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); |
| | | // 添加积分 |
| | | user.setIntegral(user.getIntegral() + storyListen.getIntegral()); |
| | | result = result && userService.updateById(user); |
| | | sum = storyListen.getIntegral(); |
| | | } |
| | | } |
| | | return R.ok(result); |
| | | return R.ok(sum); |
| | | } |
| | | |
| | | @GetMapping("/studyRecord") |
| | |
| | | // 学习记录 |
| | | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | // 学习时长格式转换 |
| | | Integer todayStudy = studyRecord.getTodayStudy(); |
| | | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); |
| | | Integer weekStudy = studyRecord.getWeekStudy(); |
| | | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); |
| | | Integer monthStudy = studyRecord.getMonthStudy(); |
| | | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); |
| | | // 总时长还需计算上游戏测试成绩时长 |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId) |
| | | .eq(TGameRecord::getDisabled, 0).list(); |
| | | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); |
| | | Integer totalStudy = studyRecord.getTotalStudy(); |
| | | studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600)); |
| | | // 剩余周目 |
| | | int size = studyService.list(new QueryWrapper<TStudy>() |
| | | .eq("type", 1)).size(); |
| | | studyRecord.setSurplus(size - studyRecord.getWeek()); |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery() |
| | | .eq(TGameRecord::getUserId, userId) |
| | | .eq(TGameRecord::getDisabled, 0) |
| | | .orderByDesc(TGameRecord::getCreateTime) |
| | | .list(); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); |
| | | if (null != studyRecord) { |
| | | // 学习时长格式转换 |
| | | Integer todayStudy = studyRecord.getTodayStudy(); |
| | | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); |
| | | Integer weekStudy = studyRecord.getWeekStudy(); |
| | | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); |
| | | Integer monthStudy = studyRecord.getMonthStudy(); |
| | | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); |
| | | // 游戏总时长 |
| | | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); |
| | | Integer totalStudy = studyRecord.getTotalStudy(); |
| | | studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); |
| | | for (TGameRecord tGameRecord : gameRecordList) { |
| | | tGameRecord.setTime(simpleDateFormat.format(tGameRecord.getCreateTime())); |
| | | } |
| | | // 剩余周目 |
| | | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) |
| | | .eq(TStudy::getType, Constants.ONE) |
| | | .orderByAsc(TStudy::getWeek).list(); |
| | | int size = studyService.residueWeek(studyRecord, studyList); |
| | | studyRecord.setSurplus(size); |
| | | } |
| | | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "游戏测试成绩", tags = {"家长端-游戏测试成绩"}) |
| | | public R<StudyRecordResultVO> record() { |
| | | LoginUserParent loginUser1 = tokenService.getLoginUser1(); |
| | | System.err.println("用户登录信息:" + loginUser1); |
| | | if (loginUser1 == null) { |
| | | return R.tokenError("登陆失效,请重新登录"); |
| | | } |
| | |
| | | |
| | | // 学习记录 |
| | | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | // 总时长还需计算上游戏测试成绩时长 |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery() |
| | | .eq(TGameRecord::getUserId, userId) |
| | | .eq(TGameRecord::getDisabled, 0) |
| | | .orderByDesc(TGameRecord::getCreateTime) |
| | | .list(); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); |
| | | if (null != studyRecord) { |
| | | // 学习时长格式转换 |
| | | Integer todayStudy = studyRecord.getTodayStudy(); |
| | | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); |
| | | Integer weekStudy = studyRecord.getWeekStudy(); |
| | | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); |
| | | Integer monthStudy = studyRecord.getMonthStudy(); |
| | | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); |
| | | // 游戏总时长 |
| | | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); |
| | | for (TGameRecord tGameRecord : gameRecordList) { |
| | | tGameRecord.setTime(simpleDateFormat.format(tGameRecord.getCreateTime())); |
| | | } |
| | | Integer totalStudy = studyRecord.getTotalStudy(); |
| | | studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); |
| | | // 剩余周目 |
| | | List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) |
| | | .eq(TStudy::getType, Constants.ONE) |
| | | .orderByAsc(TStudy::getWeek).list(); |
| | | int size = studyService.residueWeek(studyRecord, studyList); |
| | | studyRecord.setSurplus(size); |
| | | } |
| | | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); |
| | | } |
| | | |
| | | @PostMapping("/recordManagement/{id}") |
| | | @ApiOperation(value = "游戏测试成绩", tags = {"管理后台-查看用户详情"}) |
| | | public R<StudyRecordResultVO> recordManagement(@PathVariable("id") Integer id) { |
| | | // 学习记录 |
| | | TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, id) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | // 查询剩余周目 |
| | | if (studyRecord != null) { |
| | |
| | | TUserStudy tUserStudy = new TUserStudy(); |
| | | tUserStudy.setSurplus(studyService.list(new QueryWrapper<TStudy>() |
| | | .eq("type", 1)).size()); |
| | | tUserStudy.setTodayStudy(Constants.ZERO); |
| | | tUserStudy.setTotalStudy(Constants.ZERO); |
| | | tUserStudy.setWeekStudy(Constants.ZERO); |
| | | tUserStudy.setMonthStudy(Constants.ZERO); |
| | | studyRecord = tUserStudy; |
| | | } |
| | | // 学习时长格式转换 |
| | |
| | | Integer monthStudy = studyRecord.getMonthStudy(); |
| | | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); |
| | | // 总时长还需计算上游戏测试成绩时长 |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId) |
| | | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, id) |
| | | .eq(TGameRecord::getDisabled, 0).list(); |
| | | int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); |
| | | Integer totalStudy = studyRecord.getTotalStudy(); |
| | | studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600)); |
| | | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); |
| | | studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); |
| | | StudyRecordResultVO studyRecordResultVO = new StudyRecordResultVO(studyRecord, gameRecordList); |
| | | return R.ok(studyRecordResultVO); |
| | | } |
| | | |
| | | @GetMapping("/getIntegral") |
| | | @ApiOperation(value = "获取剩余积分", tags = {"家长端-获取剩余积分"}) |
| | | public R<Integer> getIntegral() { |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Integer userId = tokenService.getLoginUser1().getUserid(); |
| | | return R.ok(userService.getById(userId).getIntegral()); |
| | | } |
| | |
| | | if (tokenService.getLoginUserStudy() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | return R.ok(integralRecordService.integralDetail(new Page<>(pageNum, pageSize), tokenService.getLoginUserStudy().getUserid(), time)); |
| | | IPage<TIntegralRecord> page = integralRecordService.integralDetail(new Page<>(pageNum, pageSize), |
| | | tokenService.getLoginUserStudy().getUserid(), time); |
| | | for (TIntegralRecord record : page.getRecords()) { |
| | | if (!record.getIntegral().startsWith("-")) { |
| | | record.setIntegral("+" + record.getIntegral()); |
| | | } |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | @GetMapping("/integralDetailParent") |
| | |
| | | public R<IPage<TIntegralRecord>> integralDetailParent(String time, |
| | | @RequestParam("pageNum") Integer pageNum, |
| | | @RequestParam("pageSize") Integer pageSize) { |
| | | System.err.println("页码" + pageNum); |
| | | System.err.println("页数" + pageSize); |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | return R.ok(integralRecordService.integralDetail(new Page<>(pageNum, pageSize), tokenService.getLoginUser1().getUserid(), time)); |
| | | IPage<TIntegralRecord> page = integralRecordService.integralDetail(new Page<>(pageNum, pageSize), |
| | | tokenService.getLoginUser1().getUserid(), time); |
| | | for (TIntegralRecord record : page.getRecords()) { |
| | | if (!record.getIntegral().startsWith("-")) { |
| | | record.setIntegral("+" + record.getIntegral()); |
| | | } |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | /** |
| | |
| | | public R<Boolean> addIntegralDetail(@RequestParam("integral") String integral, @RequestParam("method") String method) { |
| | | // 当前登录用户 |
| | | LoginUserParent userStudy = tokenService.getLoginUserStudy(); |
| | | // 生成积分明细信息 |
| | | TIntegralRecord integralRecord = new TIntegralRecord(); |
| | | integralRecord.setIntegral(integral); |
| | | integralRecord.setMethod(method); |
| | | integralRecord.setUserId(userStudy.getUserid()); |
| | | integralRecord.setDisabled(Boolean.FALSE); |
| | | integralRecord.setCreateBy(userStudy.getPhone()); |
| | | integralRecord.setCreateTime(new Date()); |
| | | integralRecord.setUpdateBy(userStudy.getPhone()); |
| | | integralRecord.setUpdateTime(new Date()); |
| | | return R.ok(integralRecordService.save(integralRecord)); |
| | | } |
| | | |
| | | @GetMapping("/addIntegralDetailParent") |
| | | // @ApiOperation(value = "添加-积分明细", tags = {"添加-积分明细"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "积分数量", name = "integral", dataType = "Integer", required = true), |
| | | @ApiImplicitParam(value = "变动源(完成学习、完成游戏...)", name = "method", dataType = "String", required = true) |
| | | }) |
| | | public R<Boolean> addIntegralDetailParent(@RequestParam("integral") String integral, @RequestParam("method") String method) { |
| | | // 当前登录用户 |
| | | LoginUserParent userStudy = tokenService.getLoginUser1(); |
| | | // 生成积分明细信息 |
| | | TIntegralRecord integralRecord = new TIntegralRecord(); |
| | | integralRecord.setIntegral(integral); |
| | |
| | | return R.ok(userService.updateById(user)); |
| | | } |
| | | |
| | | @GetMapping("/exchangeIntegralParent") |
| | | // @ApiOperation(value = "用户积分变动", tags = {"用户积分变动"}) |
| | | public R<Boolean> exchangeIntegralParent(@RequestParam("integral") Integer integral, @RequestParam("method") String method) { |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | TUser user = userService.getById(tokenService.getLoginUser1().getUserid()); |
| | | if (Constants.BURDEN.equals(method)) { |
| | | user.setIntegral(user.getIntegral() - integral); |
| | | } else { |
| | | user.setIntegral(user.getIntegral() + integral); |
| | | } |
| | | return R.ok(userService.updateById(user)); |
| | | } |
| | | |
| | | @GetMapping("/exchangeIntegral1") |
| | | // @ApiOperation(value = "用户积分变动", tags = {"用户积分变动"}) |
| | | public R<Boolean> exchangeIntegral1(@RequestParam("integral") Integer integral, @RequestParam("method") String method) { |