一、修改课程销量
1、service层
接口:service_edu中CourseService
void updateBuyCountById(String id);
实现:CourseServiceImpl
@Override
public void updateBuyCountById(String id) {
Course course = baseMapper.selectById(id);
course.setBuyCount(course.getBuyCount() + 1);
this.updateById(course);
}
2、controller层
ApiCourseController
@ApiOperation("根据课程id更改销售量")
@GetMapping("inner/update-buy-count/{id}")
public R updateBuyCountById(
@ApiParam(value = "课程id", required = true)
@PathVariable String id){
courseService.updateBuyCountById(id);
return R.ok();
}
二、远程调用接口
1、Feign接口
接口:service_trade 中 EduCourseService
@GetMapping("/api/edu/course/inner/update-buy-count/{id}")
R updateBuyCountById(@PathVariable("id") String id);
2、熔断器
EduCourseServiceFallBack
@Override
public R updateBuyCountById(String id) {
log.error("熔断器被执行");
return R.error();
}
3、RPC调用
OrderServiceImpl
@Transactional(rollbackFor = Exception.class)
@Override
public void updateOrderStatus(Map<String, String> map) {
//更新订单状态
......
//记录支付日志
......
//更新课程销量:有问题直接熔断
eduCourseService.updateBuyCountById(order.getCourseId());
}