您好,登錄后才能下訂單哦!
場景說明
比如處于下游的系統,在接收源系統的計劃訂單的時候,因訂單的種類比較多,例如:采購訂單、銷售訂單、調撥訂單、預售訂單等待,如果這些訂單的差異比較大,需要分開建多個表,這樣后臺接口就需要設計一番了。
下面就按步驟直接貼代碼案例
第一步: 創建一個接口,定義接收訂單的方法;
public interface OrderRepeaterServiceI {
Result receiveOrder(ReceiveProductOrder order);
}
第二步: 定義接口的實現類,2個@Service
br/>@Service
br/>@Override
System.out.println("采購訂單執行分支...");
return null;
}
@Service
public class SaleOrderServiceImpl implements OrderRepeaterServiceI {@Override
br/>@Override
System.out.println("銷售訂單執行分支...");
return null;
}
}
第三步: 定義分發器服務@Service
br/>@Service
@Resource
private OrderRepeaterServiceI purchaseOrderServiceImpl;
@Resource
private OrderRepeaterServiceI saleOrderServiceImpl;
public Result receiveOrder(String orderType, ReceiveProductOrder order) throws Exception {
OrderRepeaterServiceI orderService = null;
switch (orderType) {
case "10" : orderService = purchaseOrderServiceImpl;break;
case "20" : orderService = saleOrderServiceImpl;break;
}
if (orderService != null) {
orderService.receiveOrder(order);
} else {
throw new RuntimeException("訂單類型未知異常.");
}
return Result.successWithData("成功");
}
}
第四步: 定義接收源系統的控制器@Controller
br/>@Controller
public class OrderApiController {
private static final Logger logger = Logger.getLogger(OrderSapApiController.class);
@Resource
private OrderRepeaterService orderRepeaterService;
@RequestMapping(value = "/testService")
@ResponseBody
public Result testService(String orderType) {
try {
ReceiveProductOrder order = new ReceiveProductOrder();
order.setOrderTypeCode("10");
order.setRelatedDocCode("SO18031610001");
return orderRepeaterService.receiveOrder(orderType, order);
} catch (Exception e) {
logger.error("接口測試異常.");
return Result.errorWithData("測試異常");
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。