Merge branch 'master' of 39.106.16.162:/home/git/teaching-backend/teaching-backend

master
yh 4 months ago
commit e20d575436
  1. 4
      src/main/java/com/teaching/backend/controller/courses/CoursesController.java
  2. 2
      src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java
  3. 23
      src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java
  4. 2
      src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java
  5. 7
      src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java
  6. 2
      src/main/java/com/teaching/backend/model/entity/courses/StudentCourses.java
  7. 3
      src/main/java/com/teaching/backend/service/courses/ICoursesService.java
  8. 21
      src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java
  9. 39
      src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java
  10. 4
      src/main/java/com/teaching/backend/service/records/ICourseLearningRecordService.java
  11. 32
      src/main/resources/mapper/CourseLearningRecordMapper.xml

@ -142,8 +142,8 @@ public class CoursesController {
@ApiOperation("查询学生列表") @ApiOperation("查询学生列表")
@PostMapping("/studentList") @PostMapping("/studentList")
public CommonResult<HashSet<UmsStudent>> getStudentList(CourseQuery courseQuery){ public CommonResult<LinkedHashSet<UmsStudent>> getStudentList(CourseQuery courseQuery){
HashSet<UmsStudent> umsStudentList = coursesService.queryStudentList(courseQuery); LinkedHashSet<UmsStudent> umsStudentList = coursesService.queryStudentList(courseQuery);
return CommonResult.success(umsStudentList); return CommonResult.success(umsStudentList);
} }

@ -102,7 +102,7 @@ public class SeCourseFavourController {
public CommonResult<CoursesVO> newCollect(@RequestParam String userId) { public CommonResult<CoursesVO> newCollect(@RequestParam String userId) {
CoursesVO newCoursesVO = seCourseFavourService.queryNewCollect(userId); CoursesVO newCoursesVO = seCourseFavourService.queryNewCollect(userId);
if (newCoursesVO == null){ if (newCoursesVO == null){
CommonResult.failed(); CommonResult.failed("用户或角色错误");
} }
return CommonResult.success(newCoursesVO); return CommonResult.success(newCoursesVO);
} }

@ -1,18 +1,24 @@
package com.teaching.backend.controller.records; 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.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.filter.ValidateParams;
import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.model.entity.records.CourseLearningRecord;
import com.teaching.backend.service.impl.records.CourseLearningRecordServiceImpl; import com.teaching.backend.service.impl.records.CourseLearningRecordServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@RestController @RestController
@Api(tags = "学习记录接口")
@Slf4j
@RequestMapping("/api/courselearingrecord") @RequestMapping("/api/courselearingrecord")
public class CourseLearningRecordController { public class CourseLearningRecordController {
@Resource @Resource
@ -51,4 +57,17 @@ public class CourseLearningRecordController {
return courseLearningRecordService.removeCoursesRecords(ids); return courseLearningRecordService.removeCoursesRecords(ids);
} }
/**
* 个人中心课程列表
* @return
*/
@ApiOperation("查询前4的课程")
@PostMapping("/courseList")
public CommonResult<List<CoursesVO>> courseList(@RequestParam String userId) {
List<CoursesVO> coursesVOList = courseLearningRecordService.queryCourseList(userId);
if (coursesVOList == null){
CommonResult.failed("用户或角色错误");
}
return CommonResult.success(coursesVOList);
}
} }

@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController
@Api(tags = "ReportController") @Api(tags = "主页访问数据接口")
@RequestMapping("/api/report") @RequestMapping("/api/report")
@Slf4j @Slf4j
public class ReportController { public class ReportController {

@ -4,6 +4,8 @@ package com.teaching.backend.mapper.records;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.model.entity.records.CourseLearningRecord;
import java.util.List;
/** /**
* <p> * <p>
* Mapper 接口 * Mapper 接口
@ -14,4 +16,9 @@ import com.teaching.backend.model.entity.records.CourseLearningRecord;
*/ */
public interface CourseLearningRecordMapper extends BaseMapper<CourseLearningRecord> { public interface CourseLearningRecordMapper extends BaseMapper<CourseLearningRecord> {
CourseLearningRecord selectNewRecord(String student);
List<String> selectMaxNumber();
List<String> selectMaxCourseId(String userId);
} }

@ -31,7 +31,7 @@ public class StudentCourses implements Serializable {
private Long id; private Long id;
/** /**
* 学生的username * 学生的userId
*/ */
private String student; private String student;

@ -12,6 +12,7 @@ import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -45,5 +46,5 @@ public interface ICoursesService extends IService<Courses> {
Map<String, Object> getPagePageSize2(int page, int pageSize); Map<String, Object> getPagePageSize2(int page, int pageSize);
HashSet<UmsStudent> queryStudentList(CourseQuery courseQuery); LinkedHashSet<UmsStudent> queryStudentList(CourseQuery courseQuery);
} }

@ -12,6 +12,7 @@ import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException; import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.mapper.chapter.ChapterMapper;
import com.teaching.backend.mapper.courses.*; 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.records.LearningRecordsMapper;
import com.teaching.backend.mapper.umsAdmin.UmsStudentMapper; import com.teaching.backend.mapper.umsAdmin.UmsStudentMapper;
import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; 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.dto.courses.PageDTO;
import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.chapter.Chapter;
import com.teaching.backend.model.entity.courses.*; 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.records.LearningRecords;
import com.teaching.backend.model.entity.umsAdmin.UmsStudent; import com.teaching.backend.model.entity.umsAdmin.UmsStudent;
import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher;
@ -88,9 +90,10 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
ObjectiveContentKnowMapper objectiveContentKnowMapper; ObjectiveContentKnowMapper objectiveContentKnowMapper;
@Autowired @Autowired
private LearningRecordsMapper learningRecordsMapper; private LearningRecordsMapper learningRecordsMapper;
@Autowired @Autowired
private AddNeoKnowByCourse addNeoKnowByCourse; private AddNeoKnowByCourse addNeoKnowByCourse;
@Autowired
CourseLearningRecordMapper courseLearningRecordMapper;
@Override @Override
@ -339,20 +342,30 @@ public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> impl
} }
@Override @Override
public HashSet<UmsStudent> queryStudentList(CourseQuery courseQuery) { public LinkedHashSet<UmsStudent> queryStudentList(CourseQuery courseQuery) {
String roleId = umsUserMapper.getbyIdRoleId(courseQuery.getUserId());
if (roleId.equals("1")){
PageDTO<CoursesVO> queryCourses = queryCourses(courseQuery); PageDTO<CoursesVO> queryCourses = queryCourses(courseQuery);
List<CoursesVO> coursesList = queryCourses.getList(); List<CoursesVO> coursesList = queryCourses.getList();
List<String> courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); List<String> courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList());
HashSet<UmsStudent> studentNameList = new HashSet<>(); LinkedHashSet<UmsStudent> studentNameList = new LinkedHashSet<>();
for (String courseId : courseIds) { for (String courseId : courseIds) {
List<StudentCourses> studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); List<StudentCourses> studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId);
List<CourseLearningRecord> courseLearningRecordList = new ArrayList<>();
for (StudentCourses studentUsername : studentUsernames) { for (StudentCourses studentUsername : studentUsernames) {
UmsStudent umsStudent = umsStudentMapper.selectByUserId(Integer.valueOf(studentUsername.getStudent())); 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); studentNameList.add(umsStudent);
} }
} }
return studentNameList; return studentNameList;
} }
throw new BusinessException(400,"只有老师才有此功能");
}
@Override @Override
public List<CoursesVO> getPagePageSize(int page, int pageSize) { public List<CoursesVO> getPagePageSize(int page, int pageSize) {

@ -1,19 +1,22 @@
package com.teaching.backend.service.impl.records; package com.teaching.backend.service.impl.records;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.ResultUtils; import com.teaching.backend.common.ResultUtils;
import com.teaching.backend.mapper.courses.CoursesMapper;
import com.teaching.backend.mapper.records.CourseLearningRecordMapper; import com.teaching.backend.mapper.records.CourseLearningRecordMapper;
import com.teaching.backend.model.entity.courses.CourseLearningNumber; 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.entity.records.CourseLearningRecord;
import com.teaching.backend.model.vo.records.CourseLearningRecordsVo; import com.teaching.backend.model.vo.records.CourseLearningRecordsVo;
import com.teaching.backend.service.impl.courses.CourseLearningNumberServiceImpl; import com.teaching.backend.service.impl.courses.CourseLearningNumberServiceImpl;
import com.teaching.backend.service.impl.courses.CoursesServiceImpl; import com.teaching.backend.service.impl.courses.CoursesServiceImpl;
import com.teaching.backend.model.vo.courses.CoursesVO;
import com.teaching.backend.service.records.ICourseLearningRecordService; import com.teaching.backend.service.records.ICourseLearningRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -39,6 +42,13 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl<CourseLearningR
private CourseLearningNumberServiceImpl courseLearningNumberService; private CourseLearningNumberServiceImpl courseLearningNumberService;
@Resource @Resource
private CoursesServiceImpl coursesService; private CoursesServiceImpl coursesService;
@Autowired
private UmsUserMapper umsUserMapper;
@Autowired
private CourseLearningRecordMapper courseLearningRecordMapper;
@Autowired
private CoursesMapper coursesMapper;
@Override @Override
public BaseResponse<String> saveCoursesRecords(CourseLearningRecord courseLearningRecord) { public BaseResponse<String> saveCoursesRecords(CourseLearningRecord courseLearningRecord) {
//课程id //课程id
@ -108,4 +118,29 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl<CourseLearningR
// removeBatchByIds(list); // removeBatchByIds(list);
return ResultUtils.success("删除成功!"); return ResultUtils.success("删除成功!");
} }
@Override
public List<CoursesVO> queryCourseList(String userId) {
String roleId = umsUserMapper.getbyIdRoleId(userId);
List<Courses> coursesList = new ArrayList<>();
if (roleId.equals("1")){
List<String> courseIds = courseLearningRecordMapper.selectMaxNumber();
for (String courseId : courseIds) {
Courses courses = coursesMapper.selectById(courseId);
coursesList.add(courses);
}
List<CoursesVO> coursesVOList = BeanUtil.copyToList(coursesList, CoursesVO.class);
return coursesVOList;
} else if (roleId.equals("2")) {
List<String> courseIdList = courseLearningRecordMapper.selectMaxCourseId(userId);
for (String courseId : courseIdList) {
Courses courses = coursesMapper.selectById(courseId);
coursesList.add(courses);
}
List<CoursesVO> coursesVOList = BeanUtil.copyToList(coursesList, CoursesVO.class);
return coursesVOList;
}else {
return null;
}
}
} }

@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.model.entity.records.CourseLearningRecord;
import com.teaching.backend.model.vo.courses.CoursesVO;
import java.util.List;
import java.util.List; import java.util.List;
@ -24,4 +27,5 @@ public interface ICourseLearningRecordService extends IService<CourseLearningRec
BaseResponse<String> removeCoursesRecords(List<Long> ids); BaseResponse<String> removeCoursesRecords(List<Long> ids);
List<CoursesVO> queryCourseList(String userId);
} }

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.teaching.backend.mapper.records.CourseLearningRecordMapper">
<select id="selectNewRecord" resultType="com.teaching.backend.model.entity.records.CourseLearningRecord">
SELECT
*
FROM
course_learning_record clr
WHERE
clr.user_id = #{student}
ORDER BY
times
DESC LIMIT 1;
</select>
<select id="selectMaxNumber" resultType="java.lang.String">
SELECT
cln.course_id courseId
FROM
course_learning_number cln
ORDER BY
number
DESC LIMIT 4;
</select>
<select id="selectMaxCourseId" resultType="java.lang.String" parameterType="java.lang.String">
SELECT course_id, COUNT(*) as frequency
FROM course_learning_record
WHERE user_id = #{userId}
GROUP BY course_id
ORDER BY frequency DESC
LIMIT 4;
</select>
</mapper>
Loading…
Cancel
Save