In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Interface design of multi-branches of the same business
Scene description
For example, in the downstream system, when receiving planned orders from the source system, there are many kinds of orders, such as purchase orders, sales orders, transfer orders, pre-sale orders, etc., if the differences between these orders are relatively large, multiple tables need to be built separately, so the background interface needs to be designed.
Next, follow the steps to directly paste the code case.
Step 1: create an interface that defines how to receive orders
Public interface OrderRepeaterServiceI {
Result receiveOrder (ReceiveProductOrder order)
}
Step 2: define the implementation class of the interface, 2 @ Servicebr/ > @ Servicebr/ > @ Override
System.out.println ("purchase order execution Branch.")
Return null
}
@ Service
Public class SaleOrderServiceImpl implements OrderRepeaterServiceI {@ Overridebr/ > @ Override
System.out.println ("sales order execution Branch.")
Return null
}
}
Step 3: define the distributor service @ Servicebr/ > @ Service
@ Resourceprivate OrderRepeaterServiceI purchaseOrderServiceImpl;@Resourceprivate 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 ("order type unknown exception.") } return Result.successWithData ("success");}
}
Step 4: define the controller @ Controllerbr/ > @ Controller of the receiving source system
Public class OrderApiController {
Private static final Logger logger = Logger.getLogger (OrderSapApiController.class); @ Resourceprivate OrderRepeaterService orderRepeaterService;@RequestMapping (value = "/ testService") @ ResponseBodypublic 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 ("Interface Test exception.") Return Result.errorWithData (Test exception);}}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.