From 395f909cf2a153b86175a9ac6bb04cee743ea8a7 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Thu, 25 Jul 2024 10:06:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=9F=A5=E8=AF=A2=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 26 +--- .../CourseLearningRecordController.java | 12 ++ .../records/LearningRecordsController.java | 21 +-- .../model/entity/records/LearningRecords.java | 15 ++- .../model/vo/records/LearningRecordsVo.java | 2 +- .../records/LearningRecordsServiceImpl.java | 125 +++++++++--------- .../records/LearningRecordsService.java | 2 +- 7 files changed, 102 insertions(+), 101 deletions(-) create mode 100644 src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java diff --git a/pom.xml b/pom.xml index c37861b..310834b 100644 --- a/pom.xml +++ b/pom.xml @@ -39,63 +39,49 @@ org.springframework.boot spring-boot-starter-aop - commons-io commons-io 2.11.0 - - org.freemarker freemarker 2.3.28 - org.mybatis.spring.boot mybatis-spring-boot-starter 2.2.2 - com.baomidou mybatis-plus-boot-starter 3.5.2 - - org.apache.poi poi 4.1.2 - org.apache.poi poi-ooxml 4.1.2 - org.apache.poi poi-ooxml-schemas 4.1.2 - - - - com.aliyun.oss aliyun-sdk-oss 3.15.1 - mysql mysql-connector-java @@ -111,20 +97,17 @@ spring-boot-starter-test test - com.github.xiaoymin knife4j-openapi2-spring-boot-starter 4.4.0 - org.apache.commons commons-lang3 - cn.hutool hutool-all @@ -193,20 +176,23 @@ 2.12.5 compile - - cn.afterturn easypoi-spring-boot-starter 4.1.3 - commons-io commons-io 2.8.0 + + + org.redisson + redisson + 3.13.6 + diff --git a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java new file mode 100644 index 0000000..cb67129 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java @@ -0,0 +1,12 @@ +package com.teaching.backend.controller.records; + + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/courselearingRecord") +public class CourseLearningRecordController { + + +} diff --git a/src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java b/src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java index 47de994..8926166 100644 --- a/src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java +++ b/src/main/java/com/teaching/backend/controller/records/LearningRecordsController.java @@ -1,6 +1,7 @@ package com.teaching.backend.controller.records; +import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; @@ -37,17 +38,19 @@ public class LearningRecordsController { public BaseResponse getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, @RequestParam(value = "pagesize", defaultValue = "10") int pagesize, @RequestParam String userId){ + //根据用户查询 + Page page = learningRecordsService.query() + .orderByDesc("time") + .eq("status", "1") + .eq("user_id", userId).page(new Page<>(pagenum, pagesize)); + //获取当前页数据 + List list = page.getRecords(); + List cs= learningRecordsService.getAll(list); - List cs= learningRecordsService.getAll(userId); - List pageCs = new ArrayList<>(); - //当前页面 - for(int i = (pagenum - 1) * pagesize; i < cs.size() && i < (pagenum) * pagesize; i++){ - pageCs.add(cs.get(i)); - } - long total = cs.size(); // 总记录数 + long total = page.getTotal(); // 总记录数 Page pageInfo = new Page<>(pagenum,pagesize,total); - pageInfo.setRecords(pageCs); - pageInfo.setPages((int)(Math.ceil((double) total / pagesize)));//设置总页数 + pageInfo.setRecords(cs); + pageInfo.setPages(page.getPages());//设置总页数 return ResultUtils.success(pageInfo); } diff --git a/src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java b/src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java index 44f7d8c..510f29d 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java +++ b/src/main/java/com/teaching/backend/model/entity/records/LearningRecords.java @@ -2,6 +2,7 @@ package com.teaching.backend.model.entity.records; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -36,7 +37,7 @@ public class LearningRecords { /** * 访问时间 */ - private LocalDateTime accessTime; + private LocalDateTime time; /** * 学习方式:打开; 1,打开过,2未打开 @@ -74,11 +75,11 @@ public class LearningRecords { */ private String type; /** - * 父节点 + * 课程名称 */ - private String parentNode; - - - - + private String coursesName; + /** + * 课程名称 + */ + private int number; } diff --git a/src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java b/src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java index e9b3ab2..345c436 100644 --- a/src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java +++ b/src/main/java/com/teaching/backend/model/vo/records/LearningRecordsVo.java @@ -33,7 +33,7 @@ public class LearningRecordsVo { /** * 资源观看人数 */ - private Long number; + private int number; /** diff --git a/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java index 598b156..5fb69a9 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java @@ -12,7 +12,6 @@ import com.teaching.backend.mapper.records.LearningRecordsMapper; import com.teaching.backend.model.entity.records.LearningRecords; import com.teaching.backend.model.vo.records.LearningRecordsVo; import com.teaching.backend.service.impl.CourseResourcesServiceImpl; -import com.teaching.backend.service.impl.chapter.ChapterServiceImpl; import com.teaching.backend.service.impl.courses.CoursesServiceImpl; import com.teaching.backend.service.records.LearningRecordsService; import org.springframework.beans.BeanUtils; @@ -36,8 +35,8 @@ public class LearningRecordsServiceImpl extends ServiceImpl selectPageList(Page page, LearningRecords model) { @@ -53,76 +52,64 @@ public class LearningRecordsServiceImpl extends ServiceImpl getAll(String userId){ - //格式化时间 + public List getAll(List list){ + List records = new ArrayList<>(); //格式化时间 String strDateFormat = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); - - List list = new ArrayList<>(); - //将学习记录实体转成学习记录Vo实体 - LambdaQueryWrapper lambdaQueryWrapper1 = new LambdaQueryWrapper<>(); - lambdaQueryWrapper1 - .orderByDesc(LearningRecords::getAccessTime) - .eq(LearningRecords::getUserId, userId) - .eq(LearningRecords::getStatus, "1"); -// System.out.println("查询数据库结果为:"+this.list(lambdaQueryWrapper1)); //如果为空-------------------????? - for (LearningRecords learningRecords : this.list(lambdaQueryWrapper1)) { - //查找该用户的学习记录 -// if (learningRecords.getUserId().equals(userId) && learningRecords.getStatus().equals("1")){ - LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------?? - BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式) - //添加时间 - //LocalDateTime转Date - Date date = Date.from(learningRecords.getAccessTime().atZone(ZoneId.systemDefault()).toInstant()); - learningRecordsVo.setTime(sdf.format(date)); - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId()); -// System.out.println(learningRecords.getResourceId()); -// System.out.println("1"); - - String name; - //添加课程名称 - switch (learningRecords.getType()) { - case "4": //如果是资源学习 - learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName());//设置名称 --------------------------------------------待完善 - break; - case "3": //如果是知识点学习记录 -// learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).get()); -// if (knowledgePointService.getById(learningRecords.getCoursesId()) != null){ -// name=knowledgePointService.getById(learningRecords.getCoursesId()).getName(); -// }else { -// name = "查无次记录"; + list.forEach(learningRecords -> { + LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------?? + BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(时间需要转格式) + Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant()); + learningRecordsVo.setTime(sdf.format(date)); +// //统计记录表里有多少人查看过这门资源 +// LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); +// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId()); +// long count = this.count(lambdaQueryWrapper); + learningRecordsVo.setNumber(learningRecords.getNumber()); + //把整合后该用户的学习记录添加到List里 + records.add(learningRecordsVo); + }); +// for (LearningRecords learningRecords : list) { +// //查找该用户的学习记录 +// LearningRecordsVo learningRecordsVo = new LearningRecordsVo();//好像可以拿出去-----------?? +// BeanUtils.copyProperties(learningRecords,learningRecordsVo);//从多传到少(缺少人数,和资源名称,时间需要转格式) +// //添加时间 +// //LocalDateTime转Date +// Date date = Date.from(learningRecords.getTime().atZone(ZoneId.systemDefault()).toInstant()); +// learningRecordsVo.setTime(sdf.format(date)); +// LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); +// lambdaQueryWrapper.eq(LearningRecords::getCoursesId, learningRecords.getCoursesId()); +// String name; +// //添加课程名称 +// switch (learningRecords.getType()) { +// case "4": //如果是资源学习 +// if (courseResourcesService.getById(learningRecords.getCoursesId()) != null){ +// learningRecordsVo.setCoursesName(courseResourcesService.getById(learningRecords.getCoursesId()).getName()); // } -// learningRecordsVo.setCoursesName(knowledgePointService.getById(learningRecords.getCoursesId()).getName()); - //如果对应的资源不存在 - break; - case "2": //如果是章节学习记录 - learningRecordsVo.setCoursesName(chapterService.getById(learningRecords.getCoursesId()).getName()); - //如果对应的资源不存在 - break; - case "1": //如果是课程学习记录 - learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName()); - break; - } - //添加观看人数 - //统计记录表里有多少人查看过这门资源 - long count = this.count(lambdaQueryWrapper); - learningRecordsVo.setNumber(count); - //把整合后该用户的学习记录添加到List里 - list.add(learningRecordsVo); +// break; +// case "1": //如果是课程学习记录 +// if (coursesService.getById(learningRecords.getCoursesId()) != null){ +// learningRecordsVo.setCoursesName(coursesService.getById(learningRecords.getCoursesId()).getName()); +// } +// break; // } - } -// System.out.println("查询后结果:"+list); - return list; +// //添加观看人数 +// //统计记录表里有多少人查看过这门资源 +// long count = this.count(lambdaQueryWrapper); +// learningRecordsVo.setNumber(count); +// //把整合后该用户的学习记录添加到List里 +// records.add(learningRecordsVo); +// } + return records; } /** @@ -148,14 +135,26 @@ public class LearningRecordsServiceImpl extends ServiceImpl list = query().eq("courses_id", coursesId).eq("type", learningRecords.getType()).list(); + int number; + if (list != null){ + number = list.get(0).getNumber() + 1; + learningRecords.setNumber(number); + list.forEach(learningRecords1 -> { + learningRecords1.setNumber(number); + }); + } else { + number = 0; + } + updateBatchById(list); if (count == 0){//如果没有就新增并记录学习方式是打开还是下载 //根据传上来的type设置 // learningRecords.setType(learningRecords.getType()); diff --git a/src/main/java/com/teaching/backend/service/records/LearningRecordsService.java b/src/main/java/com/teaching/backend/service/records/LearningRecordsService.java index d2acb1b..6ab95e7 100644 --- a/src/main/java/com/teaching/backend/service/records/LearningRecordsService.java +++ b/src/main/java/com/teaching/backend/service/records/LearningRecordsService.java @@ -10,7 +10,7 @@ import com.teaching.backend.model.vo.records.LearningRecordsVo; import java.util.List; public interface LearningRecordsService extends IService { - public List getAll(String username); + public List getAll(List list); public String saveRecords(LearningRecords learningRecords); IPage selectPageList(Page page, LearningRecords model);