From fef6a5762e1654e6c963d913d2c7f2cae101b51b Mon Sep 17 00:00:00 2001 From: you hang <2998465706@qq.com> Date: Thu, 6 Jun 2024 17:34:29 +0800 Subject: [PATCH] =?UTF-8?q?youhang=20kecheng=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teaching/backend/common/PageRequest.java | 32 +++++++++ .../backend/constant/CommonConstant.java | 18 +++++ .../favour/SeCourseFavourController.java | 28 ++++++++ .../CourseFavourQueryRequest.java | 22 ++++++ .../model/vo/favour/CourseFavourDetailVO.java | 72 +++++++++++++++++++ .../service/favour/SeCourseFavourService.java | 18 +++++ .../favour/SeCourseFavourServiceImpl.java | 39 ++++++++++ src/main/resources/application.properties | 1 + src/main/resources/application.yml | 11 +++ 9 files changed, 241 insertions(+) create mode 100644 src/main/java/com/teaching/backend/common/PageRequest.java create mode 100644 src/main/java/com/teaching/backend/constant/CommonConstant.java create mode 100644 src/main/java/com/teaching/backend/model/dto/favour/courseFavour/CourseFavourQueryRequest.java create mode 100644 src/main/java/com/teaching/backend/model/vo/favour/CourseFavourDetailVO.java diff --git a/src/main/java/com/teaching/backend/common/PageRequest.java b/src/main/java/com/teaching/backend/common/PageRequest.java new file mode 100644 index 0000000..2ee532c --- /dev/null +++ b/src/main/java/com/teaching/backend/common/PageRequest.java @@ -0,0 +1,32 @@ +package com.teaching.backend.common; + + +import com.teaching.backend.constant.CommonConstant; +import lombok.Data; + +/** + * 分页请求 + */ +@Data +public class PageRequest { + + /** + * 当前页号 + */ + private int current = 1; + + /** + * 页面大小 + */ + private int pageSize = 10; + + /** + * 排序字段 + */ + private String sortField; + + /** + * 排序顺序(默认升序) + */ + private String sortOrder = CommonConstant.SORT_ORDER_ASC; +} diff --git a/src/main/java/com/teaching/backend/constant/CommonConstant.java b/src/main/java/com/teaching/backend/constant/CommonConstant.java new file mode 100644 index 0000000..568219b --- /dev/null +++ b/src/main/java/com/teaching/backend/constant/CommonConstant.java @@ -0,0 +1,18 @@ +package com.teaching.backend.constant; + +/** + * 通用常量 + */ +public interface CommonConstant { + + /** + * 升序 + */ + String SORT_ORDER_ASC = "ascend"; + + /** + * 降序 + */ + String SORT_ORDER_DESC = " descend"; + +} 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 da34af4..ea2ef1d 100644 --- a/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java +++ b/src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java @@ -1,5 +1,7 @@ package com.teaching.backend.controller.favour; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ResultUtils; @@ -9,9 +11,17 @@ import com.teaching.backend.exception.BusinessException; import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAddRequest; import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAllRequest; import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourListRequest; +import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourQueryRequest; +import com.teaching.backend.model.entity.courses.Courses; +import com.teaching.backend.model.entity.favour.SeCourseFavour; +import com.teaching.backend.model.vo.CoursesVO; +import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; +import com.teaching.backend.service.courses.ICoursesService; import com.teaching.backend.service.favour.SeCourseFavourService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -106,5 +116,23 @@ public class SeCourseFavourController { return ResultUtils.success(result); } + /** + * 分页获取列表(仅管理员) + * + * @return + */ + @PostMapping("/list/page") + public BaseResponse> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) { + long current = courseFavourQueryRequest.getCurrent(); + long size = courseFavourQueryRequest.getPageSize(); + String userId = courseFavourQueryRequest.getUserId(); + List ids = seCourseFavourService.courseList(userId); + QueryWrapper courseQueryWrapper = new QueryWrapper<>(); + courseQueryWrapper.in("id", ids); + Page courseFavourDetailVOPage = seCourseFavourService.listCourseFavourByPage(new Page<>(current, size), courseQueryWrapper); + + return ResultUtils.success(courseFavourDetailVOPage); + } + } diff --git a/src/main/java/com/teaching/backend/model/dto/favour/courseFavour/CourseFavourQueryRequest.java b/src/main/java/com/teaching/backend/model/dto/favour/courseFavour/CourseFavourQueryRequest.java new file mode 100644 index 0000000..377a588 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/favour/courseFavour/CourseFavourQueryRequest.java @@ -0,0 +1,22 @@ +package com.teaching.backend.model.dto.favour.courseFavour; + +import com.teaching.backend.common.PageRequest; +import com.teaching.backend.constant.CommonConstant; +import lombok.Data; + +import java.io.Serializable; + +/** + * 课程点赞请求 + */ +@Data +public class CourseFavourQueryRequest extends PageRequest implements Serializable { + + /** + * 用户 id + */ + private String userId; + + + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/teaching/backend/model/vo/favour/CourseFavourDetailVO.java b/src/main/java/com/teaching/backend/model/vo/favour/CourseFavourDetailVO.java new file mode 100644 index 0000000..27ebf44 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/favour/CourseFavourDetailVO.java @@ -0,0 +1,72 @@ +package com.teaching.backend.model.vo.favour; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.teaching.backend.model.entity.courses.Courses; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.beans.BeanUtils; + +import java.math.BigDecimal; + +/** + * @Author:youhang + * @Date:2024-06-03-11:18 + * @Description: + */ +@TableName(value = "courses") +@Data +public class CourseFavourDetailVO { + + /** + * 内部编号 + */ + private String id; + + /** + * 课程封面 + */ + private String img; + + + /** + * 课程名称 + */ + private String name; + + /** + * 教师id + */ + @ApiModelProperty("教师id") + private String teacher; + + + /** + * 课程学分 + */ + @ApiModelProperty(value = "课程学分", required = true) + private BigDecimal credit; + + /** + * 课程学时 + */ + @ApiModelProperty(value = "课程学时", required = true) + private Integer classhours; + + + /** + * 对象转包装类 + * + * @param course + * @return + */ + public static CourseFavourDetailVO objToVo(Courses course) { + if (course == null) { + return null; + } + CourseFavourDetailVO courseFavourDetailVO = new CourseFavourDetailVO(); + BeanUtils.copyProperties(course, courseFavourDetailVO); + return courseFavourDetailVO; + } + + +} diff --git a/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java b/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java index 1fae7ce..6296c47 100644 --- a/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java +++ b/src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java @@ -1,7 +1,16 @@ package com.teaching.backend.service.favour; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +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.dto.favour.courseFavour.CourseFavourQueryRequest; +import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.favour.SeCourseFavour; +import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; +import org.springframework.web.bind.annotation.RequestBody; import java.util.List; @@ -48,4 +57,13 @@ public interface SeCourseFavourService extends IService { */ List courseList(String userId); + /** + * 某个用户课程列表全部信息 + * + * @param page + * @param queryWrapper + * @return + */ + public Page listCourseFavourByPage(Page page, Wrapper queryWrapper); + } diff --git a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java index 4d9db6e..117b713 100644 --- a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java @@ -1,21 +1,37 @@ package com.teaching.backend.service.impl.favour; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +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.ErrorCode; +import com.teaching.backend.common.ResultUtils; import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.favour.SeCourseFavourMapper; +import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourQueryRequest; +import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.favour.SeCourseFavour; import com.teaching.backend.model.entity.favour.SeKnowFavour; import com.teaching.backend.model.entity.favour.SeResourceFavour; +import com.teaching.backend.model.vo.CoursesVO; +import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; +import com.teaching.backend.service.courses.ICoursesService; import com.teaching.backend.service.favour.SeCourseFavourService; import com.teaching.backend.service.favour.SeKnowFavourService; import com.teaching.backend.service.favour.SeResourceFavourService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -37,6 +53,9 @@ public class SeCourseFavourServiceImpl extends ServiceImpl listCourseFavourByPage(Page page, Wrapper queryWrapper) { + Page coursePage = coursesService.page(page, queryWrapper); + Page courseFavourVOPage = new Page<>(coursePage.getCurrent(), coursePage.getSize(), coursePage.getTotal()); + List courseFavourList = coursePage.getRecords(); + //若数据为空,直接返回 + if (CollUtil.isEmpty(courseFavourList)) { + return courseFavourVOPage; + } + //过滤字段 + List courseFavourDetailVOList = new ArrayList<>(); + for (int i = 0; i < courseFavourList.size(); i++) { + CourseFavourDetailVO courseFavourDetailVO = new CourseFavourDetailVO(); + BeanUtils.copyProperties(courseFavourList.get(i), courseFavourDetailVO); + courseFavourDetailVOList.add(courseFavourDetailVO); + } + courseFavourVOPage.setRecords(courseFavourDetailVOList); + return courseFavourVOPage; + } + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1d0e31a..458c718 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,3 +2,4 @@ teaching-backend.img.path=C:\\Users\\jian\\Desktop\\cc\\teaching-backend\\src\\m teaching-backend.video.path=C:\\Users\\jian\\Desktop\\cc\\teaching-backend\\src\\main\\resources\\static\\video\\ spring.servlet.multipart.max-file-size=10MB spring.servlet.multipart.max-request-size=10MB + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 221233d..75f762d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,3 +19,14 @@ mybatis: - classpath*:com/**/mapper/*.xml +# 接口文档配置 +knife4j: + enable: true + openapi: + title: "111" + version: 1.0 + group: + default: + api-rule: package + api-rule-resources: + - com.teaching.backend.controller