完成下单服务的完整流程。

master
Administrator 3 years ago
parent 2ea03363d1
commit c40cb4ddcc

@ -3,6 +3,7 @@ package com.mashibing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author zjw
@ -10,6 +11,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class PlaceOrderStarterApp {
public static void main(String[] args) {

@ -0,0 +1,15 @@
package com.mashibing.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author zjw
* @description
*/
@FeignClient(value = "business")
public interface BusinessClient {
@GetMapping("/notify")
public void notifyBusiness();
}

@ -0,0 +1,15 @@
package com.mashibing.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author zjw
* @description
*/
@FeignClient(value = "coupon")
public interface CouponClient {
@GetMapping("/coupon")
public void coupon();
}

@ -0,0 +1,15 @@
package com.mashibing.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author zjw
* @description
*/
@FeignClient(value = "itemstock")
public interface ItemStockClient {
@GetMapping("/decr")
public void decr();
}

@ -0,0 +1,15 @@
package com.mashibing.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author zjw
* @description
*/
@FeignClient(value = "ordermanage")
public interface OrderManageClient {
@GetMapping("create")
public void create();
}

@ -0,0 +1,15 @@
package com.mashibing.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* @author zjw
* @description
*/
@FeignClient(value = "userpoints")
public interface UserPointsClient {
@GetMapping("/up")
public void up();
}

@ -1,5 +1,7 @@
package com.mashibing.controller;
import com.mashibing.client.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@ -10,22 +12,38 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class PlaceOrderController {
@Autowired
private ItemStockClient itemStockClient;
@Autowired
private OrderManageClient orderManageClient;
@Autowired
private CouponClient couponClient;
@Autowired
private UserPointsClient userPointsClient;
@Autowired
private BusinessClient businessClient;
/**
*
* @return
*/
@GetMapping("/po")
public String po(){
long start = System.currentTimeMillis();
//1、调用库存服务扣除商品库存
itemStockClient.decr();
//2、调用订单服务创建订单
orderManageClient.create();
//3、调用优惠券服务预扣除使用的优惠券
couponClient.coupon();
//4、调用用户积分服务预扣除用户使用的积分
userPointsClient.up();
//5、调用商家服务通知商家用户已下单
businessClient.notifyBusiness();
long end = System.currentTimeMillis();
System.out.println(end - start);
return "place order is ok!";
}

Loading…
Cancel
Save