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 4130315..eac87ef 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 @@ -339,19 +342,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 @@ + + + + + + +