1818import java .util .List ;
1919
2020/**
21- * 流程记录构建服务
21+ * 流程节点服务
2222 */
23- class FlowRecordBuilderService {
23+ class FlowNodeService {
2424
25+ private FlowNode nextNode ;
26+ private IFlowOperator nextOperator ;
2527
2628 private final FlowOperatorRepository flowOperatorRepository ;
2729 private final FlowRecordRepository flowRecordRepository ;
@@ -37,34 +39,77 @@ class FlowRecordBuilderService {
3739 private final IFlowOperator createOperator ;
3840
3941
40- public FlowRecordBuilderService (FlowOperatorRepository flowOperatorRepository ,
41- FlowRecordRepository flowRecordRepository ,
42- BindDataSnapshot snapshot ,
43- Opinion opinion ,
44- IFlowOperator createOperator ,
45- IFlowOperator currentOperator ,
46- List <FlowRecord > historyRecords ,
47- FlowWork flowWork ,
48- String processId ,
49- long preId ) {
42+ public FlowNodeService (FlowOperatorRepository flowOperatorRepository ,
43+ FlowRecordRepository flowRecordRepository ,
44+ BindDataSnapshot snapshot ,
45+ Opinion opinion ,
46+ IFlowOperator createOperator ,
47+ IFlowOperator currentOperator ,
48+ List <FlowRecord > historyRecords ,
49+ FlowWork flowWork ,
50+ String processId ,
51+ long preId ){
5052
51- if (createOperator ==null ){
52- throw new IllegalArgumentException ("createOperator is null" );
53- }
54-
55- this .createOperator = createOperator ;
5653 this .flowOperatorRepository = flowOperatorRepository ;
57-
5854 this .flowRecordRepository = flowRecordRepository ;
5955 this .snapshot = snapshot ;
6056 this .opinion = opinion ;
57+ this .createOperator = createOperator ;
6158 this .currentOperator = currentOperator ;
59+ this .historyRecords = historyRecords ;
6260 this .flowWork = flowWork ;
63-
64-
6561 this .processId = processId ;
6662 this .preId = preId ;
67- this .historyRecords = historyRecords ;
63+ }
64+
65+
66+ public void setNextNode (FlowNode nextNode ) {
67+ this .nextNode = nextNode ;
68+ this .nextOperator = currentOperator ;
69+ }
70+
71+
72+ public void loadNextPassNode (FlowNode currentNode ){
73+ this .nextNode = matcherNextNode (currentNode , false );
74+ this .nextOperator = currentOperator ;
75+ }
76+
77+ public void loadDefaultBackNode (long parentRecordId ){
78+ IFlowOperator flowOperator ;
79+ // 拒绝时,默认返回上一个已办节点
80+ FlowRecord preRecord = flowRecordRepository .getFlowRecordById (parentRecordId );
81+ // 只寻找已办节点
82+ while (!preRecord .isDone ()) {
83+ // 继续寻找上一个节点
84+ preRecord = flowRecordRepository .getFlowRecordById (preRecord .getPreId ());
85+ }
86+ // 获取上一个节点的审批者,继续将审批者设置为当前审批者
87+ flowOperator = preRecord .getCurrentOperator ();
88+ FlowNode nextNode = flowWork .getNodeByCode (preRecord .getNodeCode ());
89+ if (nextNode == null ) {
90+ throw new IllegalArgumentException ("next node not found" );
91+ }
92+ this .nextNode = nextNode ;
93+ this .nextOperator = flowOperator ;
94+ }
95+
96+
97+ public void loadCustomBackNode (FlowNode flowNode , long parentRecordId ){
98+ FlowNode nextNode = this .matcherNextNode (flowNode , true );
99+ if (nextNode == null ) {
100+ throw new IllegalArgumentException ("next node not found" );
101+ }
102+ IFlowOperator flowOperator = currentOperator ;
103+ if (nextNode .isAnyOperatorMatcher ()) {
104+ // 如果是任意人员操作时则需要指定为当时审批人员为当前审批人员
105+ FlowRecord preFlowRecord = flowRecordRepository .getFlowRecordById (parentRecordId );
106+ while (preFlowRecord .isTransfer () || !preFlowRecord .getNodeCode ().equals (nextNode .getCode ())) {
107+ preFlowRecord = flowRecordRepository .getFlowRecordById (preFlowRecord .getPreId ());
108+ }
109+ flowOperator = preFlowRecord .getCurrentOperator ();
110+ }
111+ this .nextNode = nextNode ;
112+ this .nextOperator = flowOperator ;
68113 }
69114
70115
@@ -96,6 +141,41 @@ private FlowNode matcherNextNode(FlowNode flowNode, boolean back) {
96141 return flowNodes .get (0 );
97142 }
98143
144+
145+ /**
146+ * 创建流程记录
147+ *
148+ * @return 流程记录
149+ */
150+ public List <FlowRecord > createRecord () {
151+
152+ FlowSession flowSession = new FlowSession (flowWork ,
153+ nextNode ,
154+ createOperator ,
155+ nextOperator ,
156+ snapshot .toBindData (),
157+ opinion ,
158+ historyRecords );
159+
160+ long workId = flowWork .getId ();
161+ List <? extends IFlowOperator > operators = nextNode .loadFlowNodeOperator (flowSession , flowOperatorRepository );
162+ List <FlowRecord > recordList ;
163+ if (operators .isEmpty ()) {
164+ recordList = this .errMatcher (nextNode , nextOperator );
165+ if (recordList .isEmpty ()) {
166+ throw new IllegalArgumentException ("operator not match." );
167+ }
168+ } else {
169+ String recordTitle = nextNode .generateTitle (flowSession );
170+ recordList = new ArrayList <>();
171+ for (IFlowOperator operator : operators ) {
172+ FlowRecord record = nextNode .createRecord (workId ,flowWork .getCode (), processId , preId , recordTitle , createOperator , operator , snapshot );
173+ recordList .add (record );
174+ }
175+ }
176+ return recordList ;
177+ }
178+
99179 /**
100180 * 异常匹配
101181 *
@@ -150,101 +230,17 @@ private List<FlowRecord> errMatcher(FlowNode currentNode, IFlowOperator currentO
150230
151231
152232 /**
153- * 创建流程记录
154- *
155- * @param currentNode 当前节点
156- * @return 流程记录
157- */
158- public List <FlowRecord > createRecord (FlowNode currentNode , IFlowOperator currentOperator ) {
159- return this .createRecord (currentNode ,currentOperator ,null );
160- }
161-
162- /**
163- * 创建流程记录
164- *
165- * @param currentNode 当前节点
166- * @param currentOperator 当前审批人
167- * @param opinion 审批意见
168- * @return 流程记录
169- */
170- public List <FlowRecord > createRecord (FlowNode currentNode , IFlowOperator currentOperator ,Opinion opinion ) {
171- FlowSession flowSession = new FlowSession (flowWork , currentNode , createOperator , currentOperator , snapshot .toBindData (), opinion , historyRecords );
172- long workId = flowWork .getId ();
173- List <? extends IFlowOperator > operators = currentNode .loadFlowNodeOperator (flowSession , flowOperatorRepository );
174- List <FlowRecord > recordList ;
175- if (operators .isEmpty ()) {
176- recordList = this .errMatcher (currentNode , currentOperator );
177- if (recordList .isEmpty ()) {
178- throw new IllegalArgumentException ("operator not match." );
179- }
180- } else {
181- String recordTitle = currentNode .generateTitle (flowSession );
182- recordList = new ArrayList <>();
183- for (IFlowOperator operator : operators ) {
184- FlowRecord record = currentNode .createRecord (workId ,flowWork .getCode (), processId , preId , recordTitle , createOperator , operator , snapshot );
185- recordList .add (record );
186- }
187- }
188- if (!recordList .isEmpty ()){
189- for (FlowRecord record :recordList ){
190- if (opinion !=null ){
191- record .updateOpinion (opinion );
192- }
193- }
194- }
195-
196- return recordList ;
197- }
198-
199-
200- /**
201- * 创建下一个节点
233+ * 下一节点的类型
202234 */
203- public List <FlowRecord > createNextRecord (FlowNode flowNode ) {
204- FlowNode nextNode = this .matcherNextNode (flowNode , false );
205- return this .createRecord (nextNode , currentOperator );
235+ public boolean nextNodeIsCC () {
236+ return nextNode .isCC ();
206237 }
207238
208- /**
209- * 创建自定义的下级别节点
210- */
211- public List <FlowRecord > createCustomBackRecord (FlowNode flowNode , long parentRecordId ) {
212- FlowNode nextNode = this .matcherNextNode (flowNode , true );
213- if (nextNode == null ) {
214- throw new IllegalArgumentException ("next node not found" );
215- }
216- IFlowOperator flowOperator = currentOperator ;
217- if (nextNode .isAnyOperatorMatcher ()) {
218- // 如果是任意人员操作时则需要指定为当时审批人员为当前审批人员
219- FlowRecord preFlowRecord = flowRecordRepository .getFlowRecordById (parentRecordId );
220- while (preFlowRecord .isTransfer () || !preFlowRecord .getNodeCode ().equals (nextNode .getCode ())) {
221- preFlowRecord = flowRecordRepository .getFlowRecordById (preFlowRecord .getPreId ());
222- }
223- flowOperator = preFlowRecord .getCurrentOperator ();
224- }
225- return this .createRecord (nextNode , flowOperator );
226- }
227239
228240 /**
229- * 创建默认拒绝时的流程记录
241+ * 下一节点是否结束节点
230242 */
231- public List <FlowRecord > createDefaultBackRecord (long parentRecordId ) {
232- IFlowOperator flowOperator ;
233- // 拒绝时,默认返回上一个节点
234- FlowRecord preRecord = flowRecordRepository .getFlowRecordById (parentRecordId );
235- // 去除所有的转办的记录
236- while (preRecord .isTransfer ()) {
237- // 继续寻找上一个节点
238- preRecord = flowRecordRepository .getFlowRecordById (preRecord .getPreId ());
239- }
240- // 获取上一个节点的审批者,继续将审批者设置为当前审批者
241- flowOperator = preRecord .getCurrentOperator ();
242- FlowNode nextNode = flowWork .getNodeByCode (preRecord .getNodeCode ());
243- if (nextNode == null ) {
244- throw new IllegalArgumentException ("next node not found" );
245- }
246- return this .createRecord (nextNode , flowOperator );
243+ public boolean nextNodeIsOver (){
244+ return nextNode .isOverNode ();
247245 }
248-
249-
250246}
0 commit comments