diff --git a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/facade/package-info.java b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/facade/package-info.java new file mode 100644 index 0000000..b42d911 --- /dev/null +++ b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/facade/package-info.java @@ -0,0 +1,7 @@ +/** + * DDD Domain层和Infrastructure的粘合剂:通过倒置依赖. + * + *

domain层声明需要基础设施层实现的接口:RPC, DB, Cache, MQ等.

+ *

为了方便产品人员查看领域层代码,梳理业务,统一放在facade package,减少对产品同学的干扰.

+ */ +package org.example.cp.oms.domain.facade; \ No newline at end of file diff --git a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/OrderMain.java b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/OrderMain.java index 4dd90e7..41052e0 100644 --- a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/OrderMain.java +++ b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/OrderMain.java @@ -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; @@ -36,6 +37,7 @@ public class OrderMain implements IOrderMain { private String step; private ProductDelegate productDelegate; + private OrderItemDelegate orderItemDelegate; @Getter private String x1, x2; @@ -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 { diff --git a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/OrderItem.java b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/OrderItem.java index f1270a4..bd9b5dd 100644 --- a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/OrderItem.java +++ b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/OrderItem.java @@ -2,5 +2,16 @@ import org.example.cp.oms.spec.model.vo.IOrderItem; +import java.math.BigDecimal; + +/** + * 订单项. + * + *

每个{@link org.example.cp.oms.domain.model.OrderMain}包含多个订单项.

+ */ public class OrderItem implements IOrderItem { + private String sku; + private Integer quantity; + private String orderLine; + private BigDecimal price; } diff --git a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/OrderItemDelegate.java b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/OrderItemDelegate.java new file mode 100644 index 0000000..919dde0 --- /dev/null +++ b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/OrderItemDelegate.java @@ -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 items; + + private OrderItemDelegate() {} + + public static OrderItemDelegate createWith(@NotNull OrderModelCreator creator) { + OrderItemDelegate delegate = new OrderItemDelegate(); + delegate.items = new ArrayList<>(); + return delegate; + } + + @Override + public List getItems() { + return items; + } +} diff --git a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/Product.java b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/Product.java index cf2158d..18f5c9f 100644 --- a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/Product.java +++ b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/Product.java @@ -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; diff --git a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/ProductDelegate.java b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/ProductDelegate.java index fb5d500..90702a1 100644 --- a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/ProductDelegate.java +++ b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/model/vo/ProductDelegate.java @@ -20,7 +20,6 @@ public static ProductDelegate createWith(@NotNull OrderModelCreator creator) { return delegate; } - @Override public List getProducts() { return products; diff --git a/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/vo/IOrderItemDelegate.java b/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/vo/IOrderItemDelegate.java new file mode 100644 index 0000000..8c79a09 --- /dev/null +++ b/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/vo/IOrderItemDelegate.java @@ -0,0 +1,7 @@ +package org.example.cp.oms.spec.model.vo; + +import java.util.List; + +public interface IOrderItemDelegate { + List getItems(); +}