From 6b96492c540e24cc29d55573c5816df808279825 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期三, 10 七月 2024 16:10:17 +0800
Subject: [PATCH] 分表

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java |  191 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 165 insertions(+), 26 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 e5bbfb6..cce4183 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
@@ -1,4 +1,5 @@
 package com.ruoyi.study.controller;
+import java.util.Date;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -21,11 +22,13 @@
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.jetbrains.annotations.TestOnly;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -82,6 +85,67 @@
     @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 = {"题目管理"})
     public R<PageInfo<TStory>> storyList(@RequestBody ChoiceStory query) {
@@ -111,7 +175,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 +802,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);
     }
@@ -872,8 +937,6 @@
         } else {
             result = null;
         }
-        subjectRecordService.lambdaUpdate().set(TSubjectRecord::getDisabled, 0)
-                .eq(TSubjectRecord::getUserId, loginStudy.getUserid()).update();
         return R.ok(result);
     }
 
@@ -909,46 +972,47 @@
                 for (TStudyListen studyListen : studyListens) {
                     item += studyListen.getSubject().split(",").length;
                 }
-                int i = (int) ((double) (exitLearn.getTopicIds().split(",").length / item) * 100);
+                int i = (int) (((double) schedule / item) * 100);
                 if (i > userStudy.getListen()) {
-                    userStudy.setListen(100 - i);
+                    userStudy.setListen(i);
                 }
             } else if (Constants.TWO.equals(type)) {
                 // 看图选音
                 List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day);
-                if (!lookList.isEmpty()) {
-                    int item = lookList.size();
-                    int i = (int) ((double) (schedule / item)) * 100;
-                    if (i > userStudy.getLook()) {
-                        userStudy.setLook(100 - i);
-                    }
+                int item = 0;
+                for (TStudyLook studyLook : lookList) {
+                    item += studyLook.getSubject().split(",").length;
+                }
+                int i = (int) (((double) schedule / item) * 100);
+                if (i > userStudy.getLook()) {
+                    userStudy.setLook(i);
                 }
             } else if (Constants.THREE.equals(type)) {
                 // 归纳排除
                 List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day);
                 if (!inductionList.isEmpty()) {
                     int item = inductionList.size();
-                    int i = (int) ((double) (schedule / item)) * 100;
+                    int i = (int) (((double) schedule / item) * 100);
                     if (i > userStudy.getInduction()) {
-                        userStudy.setInduction(100 - i);
+                        userStudy.setInduction(i);
                     }
                 }
             } else if (Constants.FOUR.equals(type)) {
                 // 有问有答
                 List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day);
                 if (answerList.size() % Constants.TWO == Constants.ZERO) {
-                    int i = (int) ((double) (schedule / (answerList.size() / 2))) * 100;
+                    int i = (int) (((double) schedule / (answerList.size() / 2)) * 100);
                     if (i > userStudy.getAnswer()) {
-                        userStudy.setAnswer(100 - i);
+                        userStudy.setAnswer(i);
                     }
                 }
             } else if (Constants.FIVE.equals(type)) {
                 // 音图相配
                 List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day);
                 int item = pairList.size();
-                int i = (int) ((double) (schedule / item)) * 100;
+                int i = (int) (((double) schedule / item) * 100);
                 if (i > userStudy.getPair()) {
-                    userStudy.setPair(100 - i);
+                    userStudy.setPair(i);
                 }
             }
         }
@@ -959,6 +1023,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));
     }
 
     /**
@@ -1630,8 +1719,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();
@@ -1643,7 +1735,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.setTotalStudy(Math.round((float) (totalStudy) / 3600));
             // 剩余周目
             List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0)
                     .eq(TStudy::getType, Constants.ONE)
@@ -1666,6 +1758,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) / 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) {
@@ -1690,17 +1820,21 @@
         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());
     }
@@ -1745,12 +1879,17 @@
     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);
     }
 
     /**

--
Gitblit v1.7.1