分页查询我的课表

文章目录

概要

需求分析以及接口设计

技术细节

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);
    }

效果展示

相关推荐
鹿角片ljp1 分钟前
力扣136.只出现一次的数字-异或和HashMap
java·数据结构·算法·leetcode
weixin_395448917 分钟前
下位机&yolov11输出
java·服务器·前端
freejackman20 分钟前
持续集成-Jenkins 基础教程
java·python·ci/cd·自动化·jenkins·持续部署·持续集成
PythonFun24 分钟前
如何在WPS实现平行语料库简易检索
数据库·wps
ruxshui25 分钟前
Inceptor/hive中整数类型分桶键数据倾斜问题及优化方案
大数据·数据库·sql
OnYoung26 分钟前
Python生成器(Generator)与Yield关键字:惰性求值之美
jvm·数据库·python
雨中飘荡的记忆34 分钟前
Spring AI + MCP:从入门到实战
java·人工智能·spring
Albert Tan39 分钟前
Oracle EBS 12.2.14双应用节点应用补丁-ADOP
数据库·oracle
callJJ39 分钟前
Docker 代码沙箱与容器池技术详解
java·运维·docker·容器·oj系统·代码沙箱
wangmengxxw39 分钟前
SpringAI-mcp-入门案例
java·服务器·前端·大模型·springai·mcp