samedi 29 août 2015

Java Rest API for order management for a ecommerce platform

order item table

order_id
order_item_id
quantity
unit_price
shipping_price
business_id
workflow_id
delivery_id
item_id

Orders table

order_id
billing_address_id
shipping_address_id
payment_mode
total_price
shipping_price
customer_id 
business_id

If the order contains multiple items from multiple seller, I have to group items by seller and create one order each for each seller.

eg:

item 1 => Seller 1

item 2 => Seller 1

item 3 => seller 2

item 4 => seller 3

I should now create three orders

order1 => Seller 1 => item 1 and item 2

order2 => Seller 2 => item 3

order3 => Seller 3 => item 4

The client sends a single request in the following format

Order details (such as payment mode, total cart value etc...)

List of items in the order (this list consists of items from all 3 sellers)

Order Processing system is a java rest API.

I do the following to create an order.

  1. Segregate items based on seller.
  2. In transaction mode , create 3 orders in batch mode(using jdbc) This query returns the order ids that were just created using PreparedStatement.RETURN_GENERATED_KEYS
  3. Query the table again to find which order id is mapped to which business id.
  4. Finally inserting into the order items table (after mapping the item to the order id got from step 3) and update as a batch.

This process is pretty complex. And I am wondering if there is a better way to handle this scenario.

Aucun commentaire:

Enregistrer un commentaire