欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > 查询我正在学习的课程

查询我正在学习的课程

2025/5/13 10:33:26 来源:https://blog.csdn.net/Very_a/article/details/143894495  浏览:    关键词:查询我正在学习的课程

文章目录

    • 概要
    • 整体架构流程
    • 技术细节
    • 小结

概要

需求分析以及接口设计

参数

说明

请求方式

GET

请求路径

/lessons/now

请求参数

无参,程序从登录凭证中获取当前用户

返回值

字段名

类型

说明

courseId

String

课程id

courseName

String

课程名称

sections

int

课程总课时数

learnedSections

int

已学习课时数

createTime

LocalDateTime

加入课表时间

expireTime

LocalDateTime

过期时间

courseAmount

long

课表中课程总数

latestSectionName

String

最近一次学习的小节名称

latestSectionIndex

int

最近一次学习的小节序号

可以看到返回值结果与分页查询的课表VO基本类似,因此这里可以复用LearningLessonVO实体,但是需要添加几个字段:

  • courseAmount

  • latestSectionName

  • latestSectionIndex

    其中CataSimpleInfoDTO中就包含了章节信息:

    @Data public class CataSimpleInfoDTO { @ApiModelProperty("目录id") private Long id; @ApiModelProperty("目录名称") private String name; @ApiModelProperty("数字序号,不包含章序号") private Integer cIndex; }

技术细节

1.Controller层

@ApiOperation("查询我正在学习的课程")@GetMapping("/now")public LearningLessonVO queryMyCurrentLesson(){return iLearningLessonService.queryMyCurrentLesson();}

2.Service层:

public LearningLessonVO queryMyCurrentLesson() {//1.获取到用户idLong userId = UserContext.getUser();//2.查询最近一次的学习课程信息(根据userid,status = 1,latest_learn_time倒序排序即可得出)LearningLesson lesson = this.lambdaQuery().eq(LearningLesson::getUserId, userId).eq(LearningLesson::getStatus, LessonStatus.LEARNING).orderByDesc(LearningLesson::getLatestLearnTime).last("limit 1").one();//3.填充voLearningLessonVO vo = new LearningLessonVO();vo.setCourseId(lesson.getCourseId());vo.setCreateTime(lesson.getCreateTime());vo.setExpireTime(lesson.getExpireTime());vo.setLearnedSections(lesson.getLearnedSections());//远程调用course服务CourseFullInfoDTO courseFullInfoDTO = courseClient.getCourseInfoById(lesson.getCourseId(), false, false);vo.setSections(courseFullInfoDTO.getSectionNum());vo.setCourseName(courseFullInfoDTO.getName());Integer courseAmount = Math.toIntExact(this.lambdaQuery().eq(LearningLesson::getUserId, userId).count());vo.setCourseAmount(courseAmount);//远程调用catalogue服务List<Long> latestSectionId = List.of(lesson.getLatestSectionId());List<CataSimpleInfoDTO> cataSimpleInfoDTOList = catalogueClient.batchQueryCatalogue(latestSectionId);CataSimpleInfoDTO cataSimpleInfoDTO = cataSimpleInfoDTOList.get(0);vo.setLatestSectionName(cataSimpleInfoDTO.getName());vo.setLatestSectionIndex(cataSimpleInfoDTO.getCIndex());//4.返回voreturn vo;}

3.Mapper层

效果展示

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词