From f138375f15c072d10335c20ecec9b35f1da78ee4 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期三, 03 七月 2024 16:17:59 +0800 Subject: [PATCH] bug修改 --- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java | 112 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 96 insertions(+), 16 deletions(-) diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java index ab871ee..36683b1 100644 --- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java +++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java @@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -97,15 +98,12 @@ 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); @@ -113,8 +111,13 @@ // 查询出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); } @@ -736,6 +739,7 @@ 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); } return R.ok(studyRecord); } @@ -809,7 +813,7 @@ data.setIsDelete(0); result = result && userPresentRecordService.save(data); } else { - if (System.currentTimeMillis() - record.getPresentTime().getTime() >= 10 * 60 * 1000) { + if (System.currentTimeMillis() - record.getPresentTime().getTime() >= (long) Integer.parseInt(sysSet.getTime()) * 60 * 1000) { // 赠送积分 result = userService.lambdaUpdate() .set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) @@ -820,6 +824,12 @@ 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); @@ -951,6 +961,31 @@ 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)); } /** @@ -1335,7 +1370,8 @@ * 例如:游戏配置的积分是100,他的正确率是50%那么拿50分,下次他再玩这个游戏 正确率是60% 那么他该获得60分 但是上次已经拿了50 所以这次就只给他加10积分 */ Integer userid = loginUserStudy.getUserid(); - TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()).eq(TGame::getDisabled, 0).one(); + TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()) + .eq(TGame::getDisabled, 0).one(); if (null == game) { throw new GlobalException("游戏信息异常!"); } @@ -1348,15 +1384,17 @@ .eq(TIntegralRecord::getGameDifficulty, difficulty).list(); // 本次游戏总共能获取的积分数量 Integer integral; + Integer item = null; if (completeStudy.getGameName().equals(Constants.HEARING)) { // 本次游戏总积分 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) - .eq(TIntegralRecord::getGameDifficulty, null).list(); + .last("and gameDifficulty is null").list(); integral = game.getAnswerIntegral(); } else { throw new GlobalException("该次游戏积分计算异常!"); @@ -1368,7 +1406,7 @@ // 可获得积分不为null时,才添加积分明细记录 if (null != availableIntegral && !Constants.ZERO.equals(availableIntegral)) { add = add && integralRecordService.add(String.valueOf(availableIntegral), - Constants.COMPLETE_GAME, completeStudy.getGameId(), null, difficulty, null); + Constants.COMPLETE_GAME, completeStudy.getGameId(), null, item, null); // 用户账户添加积分 TUser user = userService.getById(userid); user.setIntegral(user.getIntegral() + availableIntegral); @@ -1619,8 +1657,11 @@ 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).list(); + List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery() + .eq(TGameRecord::getUserId, userId) + .eq(TGameRecord::getDisabled, 0) + .orderByDesc(TGameRecord::getCreateTime) + .list(); if (null != studyRecord) { // 学习时长格式转换 Integer todayStudy = studyRecord.getTodayStudy(); @@ -1656,6 +1697,44 @@ // 学习记录 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 + sum) / 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) { int size = studyService.list(new QueryWrapper<TStudy>() @@ -1679,12 +1758,13 @@ 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)); + StudyRecordResultVO studyRecordResultVO = new StudyRecordResultVO(studyRecord, gameRecordList); + return R.ok(studyRecordResultVO); } @GetMapping("/getIntegral") -- Gitblit v1.7.1