分页查询我的课表

文章目录

概要

需求分析以及接口设计

技术细节

1.Controller层:

java 复制代码
private final ILearningLessonService iLearningLessonService;

    /**
     * 分页查询我的课表
     * @param pageQuery
     * @return
     */
    @ApiOperation("分页查询我的课表")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery pageQuery){
        return iLearningLessonService.queryMyLessons(pageQuery);
    }

2.Service层:

java 复制代码
/**
     * 分页查询我的课表
     * @param pageQuery
     * @return
     */
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery pageQuery) {
        //1.获取用户id
        Long userId = UserContext.getUser();
        //2.分页查询课程信息
        Page<LearningLesson> page = lambdaQuery()
                .eq(LearningLesson::getUserId, userId)
                .page(pageQuery.toMpPage("latest_learn_time", false));
        List<LearningLesson> records = page.getRecords();
        if (CollUtils.isEmpty(records)){
            return PageDTO.empty(page);
        }
        //3.将po封装成vo
        //3.1远程调用课程服务查询课程信息,获取剩余字段
        Set<Long> ids = records.stream().map(LearningLesson::getCourseId).collect(Collectors.toSet());
        List<CourseSimpleInfoDTO> courseInfoList = courseClient.getSimpleInfoList(ids);
        if (courseInfoList.isEmpty()){
            throw new BizIllegalException("课程不存在");
        }
        //将课程信息转为map,以便循环时一一对应课表的信息
        Map<Long, CourseSimpleInfoDTO> cInfoDTOMap = courseInfoList.stream().collect(Collectors.toMap(CourseSimpleInfoDTO::getId, c -> c));

        ArrayList<LearningLessonVO> learningLessonVOS = new ArrayList<>();
        for (LearningLesson lesson : records) {
            //3.2遍历课表循环每个课程进行封装
            LearningLessonVO learningLessonVO = BeanUtils.copyBean(lesson, LearningLessonVO.class);
            //3.3填充剩余字段
            //通过key(课程id)获取到该课程的详细信息
            CourseSimpleInfoDTO courseSimpleInfoDTO = cInfoDTOMap.get(lesson.getCourseId());
            learningLessonVO.setCourseName(courseSimpleInfoDTO.getName());
            learningLessonVO.setCourseCoverUrl(courseSimpleInfoDTO.getCoverUrl());
            learningLessonVO.setSections(courseSimpleInfoDTO.getSectionNum());

            learningLessonVOS.add(learningLessonVO);
        }
        //4.返回
        return PageDTO.of(page,learningLessonVOS);
    }

效果展示

相关推荐
lb29177 小时前
在window上安装orcale数据库流程(快速,简洁)
数据库
IT小盘7 小时前
09-使用Redis保存大模型多轮对话上下文
数据库·redis·缓存
秋田君7 小时前
QT_QT布局常用类QSplitter窗口分割类与QDockWidget窗口停靠类
开发语言·数据库·qt
小果因子实验室8 小时前
策略研究--qmt实现新股自动申购卖出策略
数据库
用户91366296220128 小时前
ViewModelScope 简介与使用
java
上海安当技术8 小时前
老系统零改造接入:旁路代理统一认证实战
java·servlet·架构·kubernetes·jenkins
Darling噜啦啦8 小时前
从零实战Milvus向量数据库:用RAG打造你的AI日记助手
数据库
Zane19948 小时前
Lock 接口与 AQS 核心原理:手写理解一把可重入锁是怎么运作的
java·后端
Full Stack Developme8 小时前
SpringBoot 整合 Druid 并列出参数清单
java·spring boot·后端
caishenzhibiao8 小时前
顺势交易矩阵主图 同花顺期货通指标
java·c语言·c#