更新一下天机学堂的课后作业部分
随缘更新作业部分
题目就不多赘述了
第一部分:处理退款通知,调用service层进行退课处理
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "learning.lesson.refund.queue", durable = "true"),
exchange = @Exchange(name = MqConstants.Exchange.ORDER_EXCHANGE, type = ExchangeTypes.TOPIC),
key = MqConstants.Key.ORDER_REFUND_KEY
))
public void listenLessonRefund(OrderBasicDTO order){
if(order == null || order.getUserId() == null || CollUtils.isEmpty(order.getCourseIds())){
log.error("订单信息不完整,无法处理");
return;
}
lessonService.deleteCourseFromLesson(order.getUserId(),order.getCourseIds().get(0));
}
第二部分进行deleteCourseFromLesson的实现
定义接口:
void deleteCourseFromLesson(Long userId, Long courseIds);
实现接口:(使用的MyBatisPlus的方法)
@Override
public void deleteCourseFromLesson(Long userId, Long courseIds) {
if (userId == null) {
userId = UserContext.getUser();
}
// delete * from learning_lesson where user_id = #{userId} and course_id in (#{courseIds})
remove(buildUserIdAndCourseIdWrapper(userId, courseIds));
}
private LambdaQueryWrapper<LearningLesson> buildUserIdAndCourseIdWrapper(Long userId, Long courseIds) {
return new QueryWrapper<LearningLesson>().lambda()
.eq(LearningLesson::getUserId, userId)
.in(LearningLesson::getCourseId, courseIds);
}
第三部分:
定义用户删除课程的接口以及实现
@DeleteMapping("/{courseId}")
public void deleteCourseFromLesson(@PathVariable("courseId") Long courseId){
lessonService.deleteCourseFromLesson(null,courseId);
}