-
Notifications
You must be signed in to change notification settings - Fork 126
/
OrderMain.java
126 lines (99 loc) · 3 KB
/
OrderMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.example.cp.oms.domain.model;
import lombok.Getter;
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;
import org.example.cp.oms.spec.model.vo.IOrderItemDelegate;
import org.example.cp.oms.spec.model.vo.IProductDelegate;
import javax.validation.constraints.NotNull;
/**
* 订单主档.
*
* <p>注意,它没有实现Serializable,因为它不会网络传递,也不会本地文件存储.</p>
*/
@Getter // 注意:它没有@Setter,是为了封装,包含订单一致性
@Slf4j
public class OrderMain implements IOrderMain {
private Long id;
private String source;
private String customerNo;
private String orderNo;
private String externalNo;
private RequestProfile requestProfile;
@Setter
private String activity;
@Setter
private String step;
private ProductDelegate productDelegate;
private OrderItemDelegate orderItemDelegate;
@Getter
private String x1, x2;
public static OrderMain createWith(@NotNull OrderModelCreator creator) throws OrderException {
log.debug("creating with {}", creator);
return new OrderMain(creator).validate();
}
private OrderMain(OrderModelCreator creator) {
this.id = creator.getId();
this.source = creator.getSource();
this.customerNo = creator.getCustomerNo();
this.externalNo = creator.getExternalNo();
this.requestProfile = creator.getRequestProfile();
this.productDelegate = ProductDelegate.createWith(creator);
this.orderItemDelegate = OrderItemDelegate.createWith(creator);
}
private OrderMain validate() throws OrderException {
// 模型本身的基础校验
return this;
}
@Override
public void assignOrderNo(Object who, String orderNo) {
this.orderNo = orderNo;
}
@Override
public String currentStep() {
return step;
}
@Override
public String currentActivity() {
return activity;
}
@Override
public boolean isColdChain() {
return false;
}
@Override
public boolean isB2B() {
return false;
}
@Override
public void setX1(String x1) {
this.x1 = x1;
}
@Override
public void setX2(String x2) {
this.x2 = x2;
}
@Override
public IProductDelegate productDelegate() {
return productDelegate;
}
@Override
public IOrderItemDelegate itemDelegate() {
return orderItemDelegate;
}
@Override
public RequestProfile requestProfile() {
return requestProfile;
}
@Override
public String customerProvidedOrderNo() {
return externalNo;
}
public String label() {
return "Order(source=" + source + ", customer=" + customerNo + ")";
}
}