文章目录
-
- 概要
- 整体架构流程
- 技术细节
- 小结
概要
需求分析以及接口设计
参数 | 说明 | ||
---|---|---|---|
请求方式 | 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层