5
5
import com .codingapi .springboot .flow .record .FlowRecord ;
6
6
import com .codingapi .springboot .flow .repository .FlowProcessRepository ;
7
7
import com .codingapi .springboot .flow .repository .FlowRecordRepository ;
8
+ import com .codingapi .springboot .flow .repository .FlowWorkRepository ;
8
9
import com .codingapi .springboot .flow .user .IFlowOperator ;
9
10
import lombok .Getter ;
10
11
16
17
public class FlowRecordVerifyService {
17
18
18
19
// constructor params
19
- private final long recordId ;
20
20
@ Getter
21
21
private final IFlowOperator currentOperator ;
22
22
23
23
// register repository
24
24
final FlowRecordRepository flowRecordRepository ;
25
25
final FlowProcessRepository flowProcessRepository ;
26
+ final FlowWorkRepository flowWorkRepository ;
26
27
27
28
// load Object
28
29
@ Getter
29
30
private FlowWork flowWork ;
30
31
@ Getter
31
32
private FlowNode flowNode ;
32
33
@ Getter
33
- private FlowRecord flowRecord ;
34
+ private final FlowRecord flowRecord ;
35
+
36
+ public FlowRecordVerifyService (
37
+ FlowWorkRepository flowWorkRepository ,
38
+ FlowRecordRepository flowRecordRepository ,
39
+ FlowProcessRepository flowProcessRepository ,
40
+ long recordId ,
41
+ IFlowOperator currentOperator ) {
42
+ this .flowWorkRepository = flowWorkRepository ;
43
+ this .flowRecordRepository = flowRecordRepository ;
44
+ this .flowProcessRepository = flowProcessRepository ;
34
45
35
- public FlowRecordVerifyService (FlowRecordRepository flowRecordRepository ,
46
+ this .currentOperator = currentOperator ;
47
+ FlowRecord flowRecord = flowRecordRepository .getFlowRecordById (recordId );
48
+ if (flowRecord == null ) {
49
+ throw new IllegalArgumentException ("flow record not found" );
50
+ }
51
+ this .flowRecord = flowRecord ;
52
+ }
53
+
54
+ public FlowRecordVerifyService (FlowWorkRepository flowWorkRepository ,
55
+ FlowRecordRepository flowRecordRepository ,
36
56
FlowProcessRepository flowProcessRepository ,
37
- long recordId ,
57
+ FlowRecord flowRecord ,
58
+ FlowWork flowWork ,
38
59
IFlowOperator currentOperator ) {
60
+ this .flowWorkRepository = flowWorkRepository ;
39
61
this .flowRecordRepository = flowRecordRepository ;
40
62
this .flowProcessRepository = flowProcessRepository ;
41
63
42
64
this .currentOperator = currentOperator ;
43
- this .recordId = recordId ;
65
+ this .flowRecord = flowRecord ;
66
+ this .flowWork = flowWork ;
44
67
}
45
68
46
69
47
-
48
70
/**
49
- * 校验流程记录是否已提交状态
71
+ * 校验流程记录是否已提交状态
50
72
*/
51
73
public void verifyFlowRecordSubmitState () {
52
74
flowRecord .submitStateVerify ();
@@ -56,13 +78,13 @@ public void verifyFlowRecordSubmitState() {
56
78
* 校验流程是否当前操作者可操作的
57
79
*/
58
80
public void verifyFlowRecordCurrentOperator () {
59
- if (!currentOperator .isFlowManager ()) {
81
+ if (!currentOperator .isFlowManager ()) {
60
82
flowRecord .matcherOperator (currentOperator );
61
83
}
62
84
}
63
85
64
86
/**
65
- * 校验流程是否已审批
87
+ * 校验流程是否已审批
66
88
*/
67
89
public void verifyFlowRecordNotDone () {
68
90
if (flowRecord .isDone ()) {
@@ -72,7 +94,7 @@ public void verifyFlowRecordNotDone() {
72
94
73
95
74
96
/**
75
- * 校验流程是否已审批
97
+ * 校验流程是否已审批
76
98
*/
77
99
public void verifyFlowRecordIsDone () {
78
100
if (!flowRecord .isDone ()) {
@@ -81,20 +103,19 @@ public void verifyFlowRecordIsDone() {
81
103
}
82
104
83
105
84
-
85
106
/**
86
- * 校验流程是否未审批
107
+ * 校验流程是否未审批
87
108
*/
88
109
public void verifyFlowRecordNotTodo () {
89
110
if (flowRecord .isTodo ()) {
90
- if (!flowRecord .isStartRecord ()) {
111
+ if (!flowRecord .isStartRecord ()) {
91
112
throw new IllegalArgumentException ("flow record is todo" );
92
113
}
93
114
}
94
115
}
95
116
96
117
/**
97
- * 校验流程是未审批
118
+ * 校验流程是未审批
98
119
*/
99
120
public void verifyFlowRecordIsTodo () {
100
121
if (!flowRecord .isTodo ()) {
@@ -103,7 +124,7 @@ public void verifyFlowRecordIsTodo() {
103
124
}
104
125
105
126
/**
106
- * 校验流程是否已完成
127
+ * 校验流程是否已完成
107
128
*/
108
129
public void verifyFlowRecordNotFinish () {
109
130
if (flowRecord .isFinish ()) {
@@ -112,7 +133,7 @@ public void verifyFlowRecordNotFinish() {
112
133
}
113
134
114
135
/**
115
- * 校验流程节点是否可编辑
136
+ * 校验流程节点是否可编辑
116
137
*/
117
138
public void verifyFlowNodeEditableState (boolean editable ) {
118
139
// 流程节点不可编辑时,不能保存
@@ -123,41 +144,35 @@ public void verifyFlowNodeEditableState(boolean editable) {
123
144
124
145
125
146
/**
126
- * 校验转办人员不能是当前操作者
147
+ * 校验转办人员不能是当前操作者
127
148
*/
128
149
public void verifyTargetOperatorIsNotCurrentOperator (IFlowOperator targetOperator ) {
129
- if (currentOperator .getUserId () == targetOperator .getUserId ()){
150
+ if (currentOperator .getUserId () == targetOperator .getUserId ()) {
130
151
throw new IllegalArgumentException ("current operator is target operator" );
131
152
}
132
153
}
133
154
134
155
135
156
/**
136
- * 获取流程记录对象
137
- */
138
- public void loadFlowRecord () {
139
- FlowRecord flowRecord = flowRecordRepository .getFlowRecordById (recordId );
140
- if (flowRecord == null ) {
141
- throw new IllegalArgumentException ("flow record not found" );
142
- }
143
- this .flowRecord = flowRecord ;
144
- }
145
-
146
- /**
147
- * 获取流程设计对象
157
+ * 获取流程设计对象
148
158
*/
149
159
public void loadFlowWork () {
150
- FlowWork flowWork = flowProcessRepository .getFlowWorkByProcessId (flowRecord .getProcessId ());
151
- if (flowWork == null ) {
152
- throw new IllegalArgumentException ("flow work not found" );
160
+ if (this .flowWork == null ) {
161
+ FlowWork flowWork = flowProcessRepository .getFlowWorkByProcessId (flowRecord .getProcessId ());
162
+ if (flowWork == null ) {
163
+ flowWork = flowWorkRepository .getFlowWorkByCode (flowRecord .getWorkCode ());
164
+ }
165
+ if (flowWork == null ) {
166
+ throw new IllegalArgumentException ("flow work not found" );
167
+ }
168
+ flowWork .enableValidate ();
169
+ this .flowWork = flowWork ;
153
170
}
154
- flowWork .enableValidate ();
155
- this .flowWork = flowWork ;
156
171
}
157
172
158
173
159
174
/**
160
- * 获取流程节点对象
175
+ * 获取流程节点对象
161
176
*/
162
177
public void loadFlowNode () {
163
178
FlowNode flowNode = flowWork .getNodeByCode (flowRecord .getNodeCode ());
@@ -168,11 +183,11 @@ public void loadFlowNode() {
168
183
}
169
184
170
185
/**
171
- * 标记流程为已读状态
186
+ * 标记流程为已读状态
172
187
*/
173
188
public void setFlowRecordRead () {
174
189
if (currentOperator != null ) {
175
- if (flowRecord .isOperator (currentOperator )) {
190
+ if (flowRecord .isOperator (currentOperator )) {
176
191
if (!flowRecord .isRead ()) {
177
192
flowRecord .read ();
178
193
flowRecordRepository .update (flowRecord );
0 commit comments