Skip to content

Commit

Permalink
WIP: OrderItem #5
Browse files Browse the repository at this point in the history
  • Loading branch information
funkygao committed Oct 23, 2020
1 parent 646315c commit 7121393
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* DDD Domain层和Infrastructure的粘合剂:通过倒置依赖.
*
* <p>domain层声明需要基础设施层实现的接口:RPC, DB, Cache, MQ等.</p>
* <p>为了方便产品人员查看领域层代码,梳理业务,统一放在facade package,减少对产品同学的干扰.</p>
*/
package org.example.cp.oms.domain.facade;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import io.github.dddplus.api.RequestProfile;
import org.example.cp.oms.domain.model.vo.OrderItemDelegate;
import org.example.cp.oms.spec.exception.OrderException;
import org.example.cp.oms.domain.model.vo.ProductDelegate;
import org.example.cp.oms.spec.model.IOrderMain;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class OrderMain implements IOrderMain {
private String step;

private ProductDelegate productDelegate;
private OrderItemDelegate orderItemDelegate;

@Getter
private String x1, x2;
Expand All @@ -52,6 +54,7 @@ private OrderMain(OrderModelCreator creator) {
this.requestProfile = creator.getRequestProfile();

this.productDelegate = ProductDelegate.createWith(creator);
this.orderItemDelegate = OrderItemDelegate.createWith(creator);
}

private OrderMain validate() throws OrderException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@

import org.example.cp.oms.spec.model.vo.IOrderItem;

import java.math.BigDecimal;

/**
* 订单项.
*
* <p>每个{@link org.example.cp.oms.domain.model.OrderMain}包含多个订单项.</p>
*/
public class OrderItem implements IOrderItem {
private String sku;
private Integer quantity;
private String orderLine;
private BigDecimal price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.example.cp.oms.domain.model.vo;

import org.example.cp.oms.domain.model.OrderModelCreator;
import org.example.cp.oms.spec.model.vo.IOrderItem;
import org.example.cp.oms.spec.model.vo.IOrderItemDelegate;
import org.example.cp.oms.spec.model.vo.IProduct;
import org.example.cp.oms.spec.model.vo.IProductDelegate;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

public class OrderItemDelegate implements IOrderItemDelegate {

private List<OrderItem> items;

private OrderItemDelegate() {}

public static OrderItemDelegate createWith(@NotNull OrderModelCreator creator) {
OrderItemDelegate delegate = new OrderItemDelegate();
delegate.items = new ArrayList<>();
return delegate;
}

@Override
public List<? extends IOrderItem> getItems() {
return items;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
public class Product implements IProduct {
private String code;

void setCode(String code) {
this.code = code;
}

@Override
public String code() {
return code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static ProductDelegate createWith(@NotNull OrderModelCreator creator) {
return delegate;
}


@Override
public List<? extends IProduct> getProducts() {
return products;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.cp.oms.spec.model.vo;

import java.util.List;

public interface IOrderItemDelegate {
List<? extends IOrderItem> getItems();
}

0 comments on commit 7121393

Please sign in to comment.