File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed
cp-oc-domain/src/main/java/org/example/cp/oms/domain
cp-oc-spec/src/main/java/org/example/cp/oms/spec/exception Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ curl -XPOST http://localhost:9090/reload?plugin=isv # plugin hot reloading
5252- [ 前台对中台的步骤编排] ( order-center-bp-ka/src/main/java/org/example/bp/oms/ka/extension/DecideStepsExt.java )
5353 - [ 动态的步骤编排] ( order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/step/submitorder/BasicStep.java )
5454- [ 扩展属性通过扩展点的实现] ( order-center-bp-isv/src/main/java/org/example/bp/oms/isv/extension/CustomModelExt.java )
55+ - [ 业务约束规则的显式化] ( order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/specification/ProductNotEmptySpec.java )
56+ - [ 如何使用] ( order-center-cp/cp-oc-domain/src/main/java/org/example/cp/oms/domain/ability/extension/DefaultAssignOrderNoExt.java )
5557- [ 中台统一定义,兼顾前台个性化的错误码机制] ( order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/exception/OrderException.java )
5658- [ 中台特色的领域模型] ( order-center-cp/cp-oc-spec/src/main/java/org/example/cp/oms/spec/model/IOrderMain.java )
5759 - spec jar里定义受限的领域模型输出给业务前台:通过接口,而不是类
Original file line number Diff line number Diff line change 11package org .example .cp .oms .domain .ability .extension ;
22
33import io .github .dddplus .annotation .Extension ;
4+ import lombok .extern .slf4j .Slf4j ;
5+ import org .example .cp .oms .domain .specification .ProductNotEmptySpec ;
46import org .example .cp .oms .spec .ext .IAssignOrderNoExt ;
57import org .example .cp .oms .spec .model .IOrderMain ;
68
9+ import javax .annotation .Resource ;
710import javax .validation .constraints .NotNull ;
811
912@ Extension (code = IAssignOrderNoExt .DefaultCode , value = "defaultAssignOrderNoExt" )
13+ @ Slf4j
1014public class DefaultAssignOrderNoExt implements IAssignOrderNoExt {
1115
16+ @ Resource
17+ private ProductNotEmptySpec productNotEmptySpec ;
18+
1219 @ Override
1320 public void assignOrderNo (@ NotNull IOrderMain model ) {
21+ // 演示调用业务约束的使用:把implicit business rules变成explicit
22+ if (!productNotEmptySpec .isSatisfiedBy (model )) {
23+ log .warn ("Spec:{} not satisfied" , productNotEmptySpec );
24+ //throw new OrderException(OrderErrorReason.SubmitOrder.ProductEmpty);
25+ }
1426
1527 }
1628}
Original file line number Diff line number Diff line change 1+ package org .example .cp .oms .domain .specification ;
2+
3+ import io .github .dddplus .annotation .Specification ;
4+ import io .github .dddplus .specification .ISpecification ;
5+ import io .github .dddplus .specification .Notification ;
6+ import org .example .cp .oms .spec .model .IOrderMain ;
7+
8+ // 之前的implicit business rules,现在变成了explicit rules
9+ @ Specification ("产品项不能空" )
10+ public class ProductNotEmptySpec implements ISpecification <IOrderMain > {
11+
12+ @ Override
13+ public boolean isSatisfiedBy (IOrderMain candidate , Notification notification ) {
14+ if (candidate .productDelegate ().getProducts () == null || candidate .productDelegate ().getProducts ().isEmpty ()) {
15+ return false ;
16+ }
17+
18+ return true ;
19+ }
20+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ public interface OrderErrorReason {
55 enum SubmitOrder implements OrderErrorSpec {
66 OrderConcurrentNotAllowed ("101" , "同一个订单不允许并发" ),
77 InvalidExtenalNo ("102" , "非法的外部单号" ),
8+ ProductEmpty ("103" , "产品为空" ),
89 ;
910
1011 private final String code ;
You can’t perform that action at this time.
0 commit comments