Skip to content

Commit

Permalink
计划增加 OrderItem #5
Browse files Browse the repository at this point in the history
  • Loading branch information
funkygao committed Oct 23, 2020
1 parent 1f8cca2 commit 646315c
Show file tree
Hide file tree
Showing 61 changed files with 174 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import io.github.dddplus.annotation.Partner;
import io.github.dddplus.ext.IIdentityResolver;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

@Partner(code = FreshPartner.CODE, name = "生鲜业务前台BP")
public class FreshPartner implements IIdentityResolver<IOrderModel> {
public class FreshPartner implements IIdentityResolver<IOrderMain> {
public static final String CODE = "fresh";

@Override
public boolean match(IOrderModel model) {
public boolean match(IOrderMain model) {
return model.getSource().toLowerCase().equals(CODE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import lombok.extern.slf4j.Slf4j;
import org.example.bp.oms.fresh.FreshPartner;
import org.example.cp.oms.spec.ext.IPostPersistExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

@Slf4j
@Extension(code = FreshPartner.CODE, value = "freshPostPersistExt")
public class PostPersitExt implements IPostPersistExt {

@Override
public void afterPersist(IOrderModel model) {
public void afterPersist(IOrderMain model) {
log.info("{} 落库了,我要发个MQ通知我的下游!", model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.example.bp.oms.fresh.FreshPartner;
import org.example.cp.oms.spec.ext.IPresortExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

import javax.validation.constraints.NotNull;

Expand All @@ -13,7 +13,7 @@
public class PresortExt implements IPresortExt {

@Override
public void presort(@NotNull IOrderModel model) {
public void presort(@NotNull IOrderMain model) {
log.info("Fresh里预分拣的结果:{}", new MockInnerClass().getResult());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.example.bp.oms.isv;

import lombok.extern.slf4j.Slf4j;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;
import io.github.dddplus.annotation.Partner;
import io.github.dddplus.ext.IIdentityResolver;
import org.springframework.beans.factory.DisposableBean;

@Partner(code = IsvPartner.CODE, name = "ISV业务前台")
@Slf4j
public class IsvPartner implements IIdentityResolver<IOrderModel>, DisposableBean {
public class IsvPartner implements IIdentityResolver<IOrderMain>, DisposableBean {
public static final String CODE = "ISV";

public IsvPartner() {
Expand All @@ -17,7 +17,7 @@ public IsvPartner() {
}

@Override
public boolean match(IOrderModel model) {
public boolean match(IOrderMain model) {
if (model.getSource() == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import org.example.bp.oms.isv.aop.AutoLogger;
import org.example.cp.oms.spec.exception.OrderErrorReason;
import org.example.cp.oms.spec.exception.OrderException;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

import javax.validation.constraints.NotNull;
import java.util.Map;

@Slf4j
@Extension(code = IsvPartner.CODE, value = "isvCustomModel", name = "ISV前台的订单个性化字段处理逻辑")
public class CustomModelExt implements IModelAttachmentExt<IOrderModel> {
public class CustomModelExt implements IModelAttachmentExt<IOrderMain> {
private static final String KEY_STATION_NO = "_station_contact_";

@Override
@AutoLogger
public void explain(@NotNull RequestProfile source, @NotNull IOrderModel target) {
public void explain(@NotNull RequestProfile source, @NotNull IOrderMain target) {
// 入参里预留了扩展属性
Map<String, String> ext = source.getExt();
// 站点联系人号码,是个性化字段,中台只存储,不负责逻辑:前台来处理逻辑,并告诉中台存储到哪些已预留的字段
Expand All @@ -38,10 +38,10 @@ public void explain(@NotNull RequestProfile source, @NotNull IOrderModel target)
}

@Override
public void explain(@NotNull IOrderModel model) {
public void explain(@NotNull IOrderMain model) {
}

@Override
public void render(@NotNull IOrderModel source, @NotNull ApiResult target) {
public void render(@NotNull IOrderMain source, @NotNull ApiResult target) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.example.bp.oms.isv.aop.AutoLogger;
import org.example.bp.oms.isv.extension.util.WarehouseUtil;
import org.example.cp.oms.spec.ext.IPresortExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

import javax.validation.constraints.NotNull;
import java.io.IOException;
Expand All @@ -22,7 +22,7 @@ public class PresortExt implements IPresortExt {

@Override
@AutoLogger
public void presort(@NotNull IOrderModel model) {
public void presort(@NotNull IOrderMain model) {
log.info("ISV里预分拣的结果:{}", new MockInnerClass().getResult());

// 演示第三方包的使用:guava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.github.dddplus.annotation.Extension;
import org.example.bp.oms.isv.IsvPartner;
import org.example.cp.oms.spec.ext.ISerializableIsolationExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;
import org.example.cp.oms.spec.model.vo.LockEntry;

import javax.validation.constraints.NotNull;
Expand All @@ -13,7 +13,7 @@
public class SerializableIsolationExt implements ISerializableIsolationExt {

@Override
public LockEntry createLockEntry(@NotNull IOrderModel model) {
public LockEntry createLockEntry(@NotNull IOrderMain model) {
return new LockEntry(model.customerProvidedOrderNo(), 50, TimeUnit.MINUTES);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.example.bp.oms.ka;

import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;
import io.github.dddplus.annotation.Partner;
import io.github.dddplus.ext.IIdentityResolver;

@Partner(code = KaPartner.CODE, name = "KA业务前台")
public class KaPartner implements IIdentityResolver<IOrderModel> {
public class KaPartner implements IIdentityResolver<IOrderMain> {
public static final String CODE = "KA";

@Override
public boolean match(IOrderModel model) {
public boolean match(IOrderMain model) {
if (model.getSource() == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import org.example.bp.oms.ka.KaPartner;
import org.example.cp.oms.spec.ext.IAssignOrderNoExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;
import io.github.dddplus.annotation.Extension;
import org.example.cp.oms.spec.resource.IStockRpc;

Expand All @@ -19,7 +19,7 @@ public class AssignOrderNoExt implements IAssignOrderNoExt {
private IStockRpc stockService;

@Override
public void assignOrderNo(@NotNull IOrderModel model) {
public void assignOrderNo(@NotNull IOrderMain model) {
log.info("KA 预占库存 GSM098");
if (!stockService.preOccupyStock("GSM098")) {
throw new RuntimeException("预占库存失败");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.example.bp.oms.ka.KaPartner;
import org.example.cp.oms.spec.ext.IReviseStepsExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

import java.util.List;

Expand All @@ -13,7 +13,7 @@
public class ReviseStepsExt implements IReviseStepsExt {

@Override
public List<String> reviseSteps(IOrderModel model) {
public List<String> reviseSteps(IOrderMain model) {
log.info("KA will not revise subsequent steps");
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import io.github.dddplus.annotation.Extension;
import org.example.cp.oms.spec.ext.ISerializableIsolationExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;
import org.example.cp.oms.spec.model.vo.LockEntry;
import org.example.bp.oms.ka.KaPartner;

Expand All @@ -15,7 +15,7 @@
public class SerializableIsolationExt implements ISerializableIsolationExt {

@Override
public LockEntry createLockEntry(@NotNull IOrderModel model) {
public LockEntry createLockEntry(@NotNull IOrderMain model) {
log.info("KA的锁TTL大一些");
return new LockEntry(model.customerProvidedOrderNo(), 11, TimeUnit.MINUTES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import io.github.dddplus.api.RequestProfile;
import io.github.dddplus.runtime.registry.Container;
import org.example.cp.oms.domain.model.OrderModel;
import org.example.cp.oms.domain.model.OrderMain;
import org.example.cp.oms.domain.model.OrderModelCreator;
import org.example.cp.oms.domain.service.SubmitOrder;
import org.slf4j.MDC;
Expand Down Expand Up @@ -47,7 +47,7 @@ public String submitOrder(@RequestParam(required = false) String type) {
creator.setSource(type);
creator.setCustomerNo("goog"); // if 'home', HomeAppliancePattern will match
creator.setExternalNo("20200987655");
OrderModel model = OrderModel.createWith(creator);
OrderMain model = OrderMain.createWith(creator);

// 调用domain service完成该use case
submitOrder.submit(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
import org.example.cp.oms.domain.CoreDomain;
import org.example.cp.oms.domain.ability.extension.DefaultAssignOrderNoExt;
import org.example.cp.oms.spec.ext.IAssignOrderNoExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;
import io.github.dddplus.annotation.DomainAbility;
import io.github.dddplus.runtime.BaseDomainAbility;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@DomainAbility(domain = CoreDomain.CODE, name = "分配订单号的能力")
public class AssignOrderNoAbility extends BaseDomainAbility<IOrderModel, IAssignOrderNoExt> {
public class AssignOrderNoAbility extends BaseDomainAbility<IOrderMain, IAssignOrderNoExt> {

@Resource
private DefaultAssignOrderNoExt defaultAssignOrderNoExt;

public void assignOrderNo(@NotNull IOrderModel model) {
public void assignOrderNo(@NotNull IOrderMain model) {
firstExtension(model).assignOrderNo(model);
}

@Override
public IAssignOrderNoExt defaultExtension(@NotNull IOrderModel model) {
public IAssignOrderNoExt defaultExtension(@NotNull IOrderMain model) {
return defaultAssignOrderNoExt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import io.github.dddplus.ext.IModelAttachmentExt;
import io.github.dddplus.runtime.BaseDomainAbility;
import org.example.cp.oms.domain.CoreDomain;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

import javax.validation.constraints.NotNull;

@DomainAbility(domain = CoreDomain.CODE)
public class CustomModelAbility extends BaseDomainAbility<IOrderModel, IModelAttachmentExt> {
public class CustomModelAbility extends BaseDomainAbility<IOrderMain, IModelAttachmentExt> {

public void explain(@NotNull IOrderModel model) {
public void explain(@NotNull IOrderMain model) {
firstExtension(model).explain(model.requestProfile(), model);
}

@Override
public IModelAttachmentExt defaultExtension(IOrderModel model) {
public IModelAttachmentExt defaultExtension(IOrderMain model) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.example.cp.oms.domain.CoreDomain;
import org.example.cp.oms.spec.DomainAbilities;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;
import io.github.dddplus.annotation.DomainAbility;
import io.github.dddplus.ext.IDecideStepsExt;
import io.github.dddplus.runtime.BaseDomainAbility;
Expand All @@ -11,14 +11,14 @@
import java.util.List;

@DomainAbility(domain = CoreDomain.CODE, name = "动态决定领域步骤的能力", tags = DomainAbilities.decideSteps)
public class DecideStepsAbility extends BaseDomainAbility<IOrderModel, IDecideStepsExt> {
public class DecideStepsAbility extends BaseDomainAbility<IOrderMain, IDecideStepsExt> {

public List<String> decideSteps(@NotNull IOrderModel model, String activityCode) {
public List<String> decideSteps(@NotNull IOrderMain model, String activityCode) {
return firstExtension(model).decideSteps(model, activityCode);
}

@Override
public IDecideStepsExt defaultExtension(@NotNull IOrderModel model) {
public IDecideStepsExt defaultExtension(@NotNull IOrderMain model) {
// 没有默认的扩展点实现
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
import io.github.dddplus.runtime.BaseDomainAbility;
import org.example.cp.oms.domain.CoreDomain;
import org.example.cp.oms.spec.ext.IPostPersistExt;
import org.example.cp.oms.spec.ext.IPresortExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

import javax.validation.constraints.NotNull;

@DomainAbility(domain = CoreDomain.CODE, name = "落库后的扩展能力")
public class PostPersistAbility extends BaseDomainAbility<IOrderModel, IPostPersistExt> {
public class PostPersistAbility extends BaseDomainAbility<IOrderMain, IPostPersistExt> {

public void afterPersist(@NotNull IOrderModel model) {
public void afterPersist(@NotNull IOrderMain model) {
firstExtension(model).afterPersist(model);
}

@Override
public IPostPersistExt defaultExtension(@NotNull IOrderModel model) {
public IPostPersistExt defaultExtension(@NotNull IOrderMain model) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import io.github.dddplus.runtime.BaseDomainAbility;
import org.example.cp.oms.domain.CoreDomain;
import org.example.cp.oms.spec.ext.IPresortExt;
import org.example.cp.oms.spec.model.IOrderModel;
import org.example.cp.oms.spec.model.IOrderMain;

import javax.validation.constraints.NotNull;

@DomainAbility(domain = CoreDomain.CODE, name = "预分拣的能力")
public class PresortAbility extends BaseDomainAbility<IOrderModel, IPresortExt> {
public class PresortAbility extends BaseDomainAbility<IOrderMain, IPresortExt> {

public void presort(@NotNull IOrderModel model) {
public void presort(@NotNull IOrderMain model) {
firstExtension(model).presort(model);
}

@Override
public IPresortExt defaultExtension(@NotNull IOrderModel model) {
public IPresortExt defaultExtension(@NotNull IOrderMain model) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import io.github.dddplus.annotation.DomainAbility;
import io.github.dddplus.runtime.BaseDomainAbility;
import org.example.cp.oms.domain.CoreDomain;
import org.example.cp.oms.domain.model.OrderModel;
import org.example.cp.oms.domain.model.OrderMain;
import org.example.cp.oms.spec.ext.IReviseStepsExt;

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

@DomainAbility(domain = CoreDomain.CODE)
public class ReviseStepsAbility extends BaseDomainAbility<OrderModel, IReviseStepsExt> {
public class ReviseStepsAbility extends BaseDomainAbility<OrderMain, IReviseStepsExt> {

public List<String> revisedSteps(@NotNull OrderModel model) {
public List<String> revisedSteps(@NotNull OrderMain model) {
// execute ext with timeout 300ms
return firstExtension(model, 300).reviseSteps(model);
}

@Override
public IReviseStepsExt defaultExtension(@NotNull OrderModel model) {
public IReviseStepsExt defaultExtension(@NotNull OrderMain model) {
return null;
}
}
Loading

0 comments on commit 646315c

Please sign in to comment.