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 746d2e3..6219771 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 @@ -8,6 +8,7 @@ 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; +import org.example.cp.oms.spec.model.vo.IOrderItemDelegate; import org.example.cp.oms.spec.model.vo.IProductDelegate; import javax.validation.constraints.NotNull; @@ -101,7 +102,12 @@ public void setX2(String x2) { @Override public IProductDelegate productDelegate() { - return null; + return productDelegate; + } + + @Override + public IOrderItemDelegate itemDelegate() { + return orderItemDelegate; } @Override diff --git a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/step/submitorder/StockStep.java b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/step/submitorder/StockStep.java index 93e0e1e..32ade85 100644 --- a/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/step/submitorder/StockStep.java +++ b/order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/step/submitorder/StockStep.java @@ -19,7 +19,7 @@ public class StockStep extends SubmitOrderStep { @Override public void execute(@NotNull OrderMain model) throws OrderException { - stockService.occupyStock("SKU098"); + stockService.occupyStock(model); } @Override diff --git a/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/IOrderMain.java b/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/IOrderMain.java index 2b2f973..c870de6 100644 --- a/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/IOrderMain.java +++ b/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/IOrderMain.java @@ -1,6 +1,7 @@ package org.example.cp.oms.spec.model; import io.github.dddplus.api.RequestProfile; +import org.example.cp.oms.spec.model.vo.IOrderItemDelegate; import org.example.cp.oms.spec.model.vo.IProductDelegate; import io.github.dddplus.model.IDomainModel; import lombok.NonNull; @@ -17,6 +18,8 @@ public interface IOrderMain extends IDomainModel { */ IProductDelegate productDelegate(); + IOrderItemDelegate itemDelegate(); + /** * 获取当前的请求参数. */ diff --git a/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/vo/IOrderItem.java b/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/vo/IOrderItem.java index 688e72c..f5b7c4f 100644 --- a/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/vo/IOrderItem.java +++ b/order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/vo/IOrderItem.java @@ -1,4 +1,8 @@ package org.example.cp.oms.spec.model.vo; public interface IOrderItem { + + String getSku(); + Integer getQuantity(); + } diff --git a/order-center-domain-stock/order-center-stock-domain/src/main/java/org/example/oms/d/stock/domain/service/StockService.java b/order-center-domain-stock/order-center-stock-domain/src/main/java/org/example/oms/d/stock/domain/service/StockService.java index 81ab70d..d024aaa 100644 --- a/order-center-domain-stock/order-center-stock-domain/src/main/java/org/example/oms/d/stock/domain/service/StockService.java +++ b/order-center-domain-stock/order-center-stock-domain/src/main/java/org/example/oms/d/stock/domain/service/StockService.java @@ -2,6 +2,8 @@ import io.github.dddplus.annotation.DomainService; import lombok.extern.slf4j.Slf4j; +import org.example.cp.oms.spec.model.IOrderMain; +import org.example.cp.oms.spec.model.vo.IOrderItem; import org.example.oms.d.stock.domain.facade.rpc.IRemoteStockRpc; import org.example.oms.d.stock.spec.StockDomain; import org.example.oms.d.stock.spec.service.IStockService; @@ -16,10 +18,13 @@ public class StockService implements IStockService { private IRemoteStockRpc remoteStockRpc; @Override - public void occupyStock(String sku) { + public void occupyStock(IOrderMain orderMain) { log.info("会通过infrastructure层调用库存中心的RPC接口,执行预占库存动作"); log.info("这里的逻辑,主要是根据不同业务场景组织库存中心RPC的入参,并对返回结果进行处理"); - remoteStockRpc.doOccupy(sku, 5); + for (IOrderItem item : orderMain.itemDelegate().getItems()) { + // 生产环境,看到会批量调用,这里只是演示 + remoteStockRpc.doOccupy(item.getSku(), item.getQuantity()); + } } } diff --git a/order-center-domain-stock/order-center-stock-spec/pom.xml b/order-center-domain-stock/order-center-stock-spec/pom.xml index 43d1ca9..1dd74d0 100644 --- a/order-center-domain-stock/order-center-stock-spec/pom.xml +++ b/order-center-domain-stock/order-center-stock-spec/pom.xml @@ -12,4 +12,12 @@ + + + org.example + cp-oc-spec + ${project.version} + + + diff --git a/order-center-domain-stock/order-center-stock-spec/src/main/java/org/example/oms/d/stock/spec/service/IStockService.java b/order-center-domain-stock/order-center-stock-spec/src/main/java/org/example/oms/d/stock/spec/service/IStockService.java index 1c8b6ec..774a630 100644 --- a/order-center-domain-stock/order-center-stock-spec/src/main/java/org/example/oms/d/stock/spec/service/IStockService.java +++ b/order-center-domain-stock/order-center-stock-spec/src/main/java/org/example/oms/d/stock/spec/service/IStockService.java @@ -1,6 +1,7 @@ package org.example.oms.d.stock.spec.service; import io.github.dddplus.model.IDomainService; +import org.example.cp.oms.spec.model.IOrderMain; // 库存相关的服务,都收敛在库存支撑域,通过领域服务提供给订单核心域调用:JVM内调用, not RPC public interface IStockService extends IDomainService { @@ -8,8 +9,8 @@ public interface IStockService extends IDomainService { /** * 预占预存. * - * @param sku 商品的sku编号 + * @param orderMain core domain提供的领域模型聚合根 */ - void occupyStock(String sku); + void occupyStock(IOrderMain orderMain); }