From 113d266c479a402a3a533d8a72b34c881100f14a Mon Sep 17 00:00:00 2001
From: hjl <1657978663@qq.com>
Date: 星期一, 01 七月 2024 18:27:00 +0800
Subject: [PATCH] fix: 学习端bug

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java |   38 ++++++++++++++++++++++++++++++++++----
 1 files changed, 34 insertions(+), 4 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 870f4eb..322fe1f 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
@@ -111,7 +111,7 @@
                 wrapper.isNotNull("error");
                 List<TStory> list1 = storyService.list(wrapper);
                 for (TStory tStory : list1) {
-                    if (tStory.getError()!=null && (!tStory.equals(""))){
+                    if (tStory.getError() != null && (!tStory.getError().isEmpty())) {
                         tStories.add(tStory);
                     }
                 }
@@ -738,6 +738,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);
     }
@@ -959,6 +960,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 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));
     }
 
     /**
@@ -1630,8 +1656,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();
@@ -1697,9 +1726,10 @@
         studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600));
         return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList));
     }
+
     @PostMapping("/recordManagement/{id}")
     @ApiOperation(value = "游戏测试成绩", tags = {"管理后台-查看用户详情"})
-    public R<StudyRecordResultVO> recordManagement(@PathVariable("id")Integer id) {
+    public R<StudyRecordResultVO> recordManagement(@PathVariable("id") Integer id) {
         // 学习记录
         TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, id)
                 .eq(TUserStudy::getDisabled, 0).one();

--
Gitblit v1.7.1