| | |
| | | update = update && studyRecordService.save(record); |
| | | } |
| | | // 更改学习记录 |
| | | Boolean updateStudyRecord = userStudyService.exchangeStudyRecord(userId, completeStudy); |
| | | 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(update && updateStudyRecord); |
| | | } |
| | | |
| | |
| | | // 学习时长更新 |
| | | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | userStudy.setTotalStudy(userStudy.getTotalStudy() + completeStudy.getUseTime()); |
| | | userStudy.setTodayStudy(userStudy.getTodayStudy() + completeStudy.getUseTime()); |
| | | userStudy.setWeekStudy(userStudy.getWeekStudy() + completeStudy.getUseTime()); |
| | | userStudy.setMonthStudy(userStudy.getMonthStudy() + completeStudy.getUseTime()); |
| | | 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()); |
| | | } |
| | | boolean update = userStudyService.updateById(userStudy); |
| | | return R.ok(add && update); |
| | | } |
| | | |
| | | 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) { |
| | |
| | | // 学习时长更新 |
| | | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime); |
| | | userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime); |
| | | userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime); |
| | | userStudy.setMonthStudy(userStudy.getMonthStudy() + studyTime); |
| | | 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); |
| | | } |
| | | boolean update = userStudyService.updateById(userStudy); |
| | | if (!update) { |
| | | throw new GlobalException("学习时长更新失败!"); |
| | |
| | | // 学习记录 |
| | | 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()); |
| | | 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 + sum) / 3600)); |
| | | // 剩余周目 |
| | | int size = studyService.list(new QueryWrapper<TStudy>() |
| | | .eq("type", 1)).size(); |
| | | studyRecord.setSurplus(size - studyRecord.getWeek()); |
| | | } |
| | | return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); |
| | | } |
| | | |