From e8d40880a23a5f0fd136b5ad2397f0f853095942 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 30 Jul 2024 09:11:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E8=AF=BE=E7=A8=8B=E5=89=8D?= =?UTF-8?q?=E5=9B=9B=E7=9A=84=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/courses/CoursesController.java | 4 +- .../favour/SeCourseFavourController.java | 2 +- .../CourseLearningRecordController.java | 23 ++++++++++- .../controller/umsAdmin/ReportController.java | 2 +- .../records/CourseLearningRecordMapper.java | 7 ++++ .../model/entity/courses/StudentCourses.java | 4 +- .../service/courses/ICoursesService.java | 3 +- .../impl/courses/CoursesServiceImpl.java | 37 ++++++++++++------ .../CourseLearningRecordServiceImpl.java | 39 ++++++++++++++++++- .../records/ICourseLearningRecordService.java | 4 ++ .../mapper/CourseLearningRecordMapper.xml | 32 +++++++++++++++ 11 files changed, 134 insertions(+), 23 deletions(-) create mode 100644 src/main/resources/mapper/CourseLearningRecordMapper.xml diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 419691c..07fb7f2 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -142,8 +142,8 @@ public class CoursesController { @ApiOperation("查询学生列表") @PostMapping("/studentList") - public CommonResult> getStudentList(CourseQuery courseQuery){ - HashSet umsStudentList = coursesService.queryStudentList(courseQuery); + public CommonResult> getStudentList(CourseQuery courseQuery){ + LinkedHashSet umsStudentList = coursesService.queryStudentList(courseQuery); return CommonResult.success(umsStudentList); } diff --git a/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java b/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java index 05dde6a..5a61c49 100644 --- a/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java +++ b/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java @@ -102,7 +102,7 @@ public class SeCourseFavourController { public CommonResult newCollect(@RequestParam String userId) { CoursesVO newCoursesVO = seCourseFavourService.queryNewCollect(userId); if (newCoursesVO == null){ - CommonResult.failed(); + CommonResult.failed("用户或角色错误"); } return CommonResult.success(newCoursesVO); } diff --git a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java index 63a3f0d..808cb8e 100644 --- a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java @@ -1,18 +1,24 @@ package com.teaching.backend.controller.records; +import com.teaching.backend.common.CommonResult; +import com.teaching.backend.model.vo.courses.CoursesVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.service.impl.records.CourseLearningRecordServiceImpl; -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @RestController +@Api(tags = "学习记录接口") +@Slf4j @RequestMapping("/api/courselearingrecord") public class CourseLearningRecordController { @Resource @@ -51,4 +57,17 @@ public class CourseLearningRecordController { return courseLearningRecordService.removeCoursesRecords(ids); } + /** + * 个人中心课程列表 + * @return + */ + @ApiOperation("查询前4的课程") + @PostMapping("/courseList") + public CommonResult> courseList(@RequestParam String userId) { + List coursesVOList = courseLearningRecordService.queryCourseList(userId); + if (coursesVOList == null){ + CommonResult.failed("用户或角色错误"); + } + return CommonResult.success(coursesVOList); + } } diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java index 99a7d8c..15b86c9 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java @@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController -@Api(tags = "ReportController") +@Api(tags = "主页访问数据接口") @RequestMapping("/api/report") @Slf4j public class ReportController { diff --git a/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java b/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java index 20b8386..602a416 100644 --- a/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java +++ b/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java @@ -4,6 +4,8 @@ package com.teaching.backend.mapper.records; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.teaching.backend.model.entity.records.CourseLearningRecord; +import java.util.List; + /** *

* Mapper 接口 @@ -14,4 +16,9 @@ import com.teaching.backend.model.entity.records.CourseLearningRecord; */ public interface CourseLearningRecordMapper extends BaseMapper { + CourseLearningRecord selectNewRecord(String student); + + List selectMaxNumber(); + + List selectMaxCourseId(String userId); } diff --git a/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java b/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java index b3125f7..a91a9a0 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java @@ -12,7 +12,7 @@ import lombok.experimental.Accessors; /** *

- * + * *

* * @author zjh @@ -31,7 +31,7 @@ public class StudentCourses implements Serializable { private Long id; /** - * 学生的username + * 学生的userId */ private String student; diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index 11156c8..9a06641 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -12,6 +12,7 @@ import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; import javax.servlet.http.HttpServletResponse; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -45,5 +46,5 @@ public interface ICoursesService extends IService { Map getPagePageSize2(int page, int pageSize); - HashSet queryStudentList(CourseQuery courseQuery); + LinkedHashSet queryStudentList(CourseQuery courseQuery); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index f815edd..3a69179 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -12,6 +12,7 @@ import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.mapper.courses.*; +import com.teaching.backend.mapper.records.CourseLearningRecordMapper; import com.teaching.backend.mapper.records.LearningRecordsMapper; import com.teaching.backend.mapper.umsAdmin.UmsStudentMapper; import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; @@ -20,6 +21,7 @@ import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.courses.*; +import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.model.entity.records.LearningRecords; import com.teaching.backend.model.entity.umsAdmin.UmsStudent; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; @@ -88,9 +90,10 @@ public class CoursesServiceImpl extends ServiceImpl impl ObjectiveContentKnowMapper objectiveContentKnowMapper; @Autowired private LearningRecordsMapper learningRecordsMapper; - @Autowired private AddNeoKnowByCourse addNeoKnowByCourse; + @Autowired + CourseLearningRecordMapper courseLearningRecordMapper; @Override @@ -341,19 +344,29 @@ public class CoursesServiceImpl extends ServiceImpl impl } @Override - public HashSet queryStudentList(CourseQuery courseQuery) { - PageDTO queryCourses = queryCourses(courseQuery); - List coursesList = queryCourses.getList(); - List courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); - HashSet studentNameList = new HashSet<>(); - for (String courseId : courseIds) { - List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); - for (StudentCourses studentUsername : studentUsernames) { - UmsStudent umsStudent = umsStudentMapper.selectByUserId(Integer.valueOf(studentUsername.getStudent())); - studentNameList.add(umsStudent); + public LinkedHashSet queryStudentList(CourseQuery courseQuery) { + String roleId = umsUserMapper.getbyIdRoleId(courseQuery.getUserId()); + if (roleId.equals("1")){ + PageDTO queryCourses = queryCourses(courseQuery); + List coursesList = queryCourses.getList(); + List courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); + LinkedHashSet studentNameList = new LinkedHashSet<>(); + for (String courseId : courseIds) { + List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); + List courseLearningRecordList = new ArrayList<>(); + for (StudentCourses studentUsername : studentUsernames) { + CourseLearningRecord courseLearningRecord = courseLearningRecordMapper.selectNewRecord(studentUsername.getStudent()); + courseLearningRecordList.add(courseLearningRecord); + } + courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList()); + for (CourseLearningRecord courseLearningRecord : courseLearningRecordList) { + UmsStudent umsStudent = umsStudentMapper.selectByUserId(Integer.valueOf(courseLearningRecord.getUserId())); + studentNameList.add(umsStudent); + } } + return studentNameList; } - return studentNameList; + throw new BusinessException(400,"只有老师才有此功能"); } @Override diff --git a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java index 425d74c..b8e4809 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java @@ -1,19 +1,22 @@ package com.teaching.backend.service.impl.records; - - import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.mapper.courses.CoursesMapper; import com.teaching.backend.mapper.records.CourseLearningRecordMapper; import com.teaching.backend.model.entity.courses.CourseLearningNumber; +import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; +import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.model.vo.records.CourseLearningRecordsVo; import com.teaching.backend.service.impl.courses.CourseLearningNumberServiceImpl; import com.teaching.backend.service.impl.courses.CoursesServiceImpl; +import com.teaching.backend.model.vo.courses.CoursesVO; import com.teaching.backend.service.records.ICourseLearningRecordService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -39,6 +42,13 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl saveCoursesRecords(CourseLearningRecord courseLearningRecord) { //课程id @@ -108,4 +118,29 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl queryCourseList(String userId) { + String roleId = umsUserMapper.getbyIdRoleId(userId); + List coursesList = new ArrayList<>(); + if (roleId.equals("1")){ + List courseIds = courseLearningRecordMapper.selectMaxNumber(); + for (String courseId : courseIds) { + Courses courses = coursesMapper.selectById(courseId); + coursesList.add(courses); + } + List coursesVOList = BeanUtil.copyToList(coursesList, CoursesVO.class); + return coursesVOList; + } else if (roleId.equals("2")) { + List courseIdList = courseLearningRecordMapper.selectMaxCourseId(userId); + for (String courseId : courseIdList) { + Courses courses = coursesMapper.selectById(courseId); + coursesList.add(courses); + } + List coursesVOList = BeanUtil.copyToList(coursesList, CoursesVO.class); + return coursesVOList; + }else { + return null; + } + } } diff --git a/src/main/java/com/teaching/backend/service/records/ICourseLearningRecordService.java b/src/main/java/com/teaching/backend/service/records/ICourseLearningRecordService.java index 62b940c..686d4d0 100644 --- a/src/main/java/com/teaching/backend/service/records/ICourseLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/ICourseLearningRecordService.java @@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.model.entity.records.CourseLearningRecord; +import com.teaching.backend.model.vo.courses.CoursesVO; + +import java.util.List; import java.util.List; @@ -24,4 +27,5 @@ public interface ICourseLearningRecordService extends IService removeCoursesRecords(List ids); + List queryCourseList(String userId); } diff --git a/src/main/resources/mapper/CourseLearningRecordMapper.xml b/src/main/resources/mapper/CourseLearningRecordMapper.xml new file mode 100644 index 0000000..65d9f52 --- /dev/null +++ b/src/main/resources/mapper/CourseLearningRecordMapper.xml @@ -0,0 +1,32 @@ + + + + + + +