22
33import com .codingapi .flow .action .IFlowAction ;
44import com .codingapi .flow .action .actions .PassAction ;
5+ import com .codingapi .flow .cache .FlowOperatorLocalThreadCache ;
56import com .codingapi .flow .exception .FlowNotFoundException ;
67import com .codingapi .flow .form .FormData ;
78import com .codingapi .flow .manager .ActionManager ;
@@ -94,30 +95,31 @@ private IFlowOperator loadRecordOperator(long operatorId) {
9495 return flowOperator ;
9596 }
9697
97- private void fetchFlowRecordOperatorList (){
98+ private void fetchFlowRecordOperatorList () {
9899 List <Long > operatorIds = new ArrayList <>();
99100
100- for (FlowRecord flowRecord : this .recordList ){
101- if (!operatorIds .contains (flowRecord .getCreateOperatorId ())){
101+ for (FlowRecord flowRecord : this .recordList ) {
102+ if (!operatorIds .contains (flowRecord .getCreateOperatorId ())) {
102103 operatorIds .add (flowRecord .getCreateOperatorId ());
103104 }
104- if (!operatorIds .contains (flowRecord .getCurrentOperatorId ())){
105+ if (!operatorIds .contains (flowRecord .getCurrentOperatorId ())) {
105106 operatorIds .add (flowRecord .getCurrentOperatorId ());
106107 }
107- if (!operatorIds .contains (flowRecord .getSubmitOperatorId ())){
108+ if (!operatorIds .contains (flowRecord .getSubmitOperatorId ())) {
108109 operatorIds .add (flowRecord .getSubmitOperatorId ());
109110 }
110111 }
111112
112113 List <IFlowOperator > operatorList = this .repositoryHolder .findOperatorByIds (operatorIds );
113- if (operatorList != null && !operatorList .isEmpty ()){
114- for (IFlowOperator operator : operatorList ){
114+ if (operatorList != null && !operatorList .isEmpty ()) {
115+ for (IFlowOperator operator : operatorList ) {
115116 this .recordOperatorMap .put (operator .getUserId (), operator );
116117 }
117118 }
118119 }
119120
120121 public List <ProcessNode > processNodes () {
122+ FlowOperatorLocalThreadCache .getInstance ().clear ();
121123 // load history data
122124 if (this .flowRecord != null ) {
123125 this .loadHistoryData ();
@@ -151,9 +153,6 @@ private void loadEndNode(boolean finish) {
151153 }
152154
153155
154-
155-
156-
157156 private List <FlowRecord > loadLatestRecords () {
158157 List <FlowRecord > flowRecords = new ArrayList <>();
159158 for (FlowRecord flowRecord : this .recordList ) {
@@ -169,7 +168,11 @@ private void loadNextData() {
169168 if (this .flowRecord == null ) {
170169 IFlowNode currentNode = this .workflow .getStartNode ();
171170 IFlowOperator currentOperator = this .loadRecordOperator (this .request .getOperatorId ());
172- FlowSession flowSession = this .buildFlowSession (currentNode , currentOperator , currentOperator , currentOperator , 0 );
171+ FlowSession flowSession = this .buildFlowSession (null , currentNode , currentOperator , currentOperator , currentOperator , 0 );
172+ List <FlowRecord > flowRecords = currentNode .generateCurrentRecords (flowSession );
173+ FlowRecord startRecord = flowRecords .get (0 );
174+ flowSession .setCurrentRecord (startRecord );
175+
173176 this .addFlowNode (currentNode , flowSession );
174177 this .fetchFlowNode (flowSession );
175178 } else {
@@ -181,19 +184,21 @@ private void loadNextData() {
181184 IFlowOperator createOperator = this .loadRecordOperator (todoRecord .getCreateOperatorId ());
182185 IFlowOperator submitOperator = this .loadRecordOperator (todoRecord .getSubmitOperatorId ());
183186
184- FlowSession flowSession = this .buildFlowSession (currentNode , currentOperator , createOperator , submitOperator , todoRecord .getWorkRuntimeId ());
187+ FlowSession flowSession = this .buildFlowSession (todoRecord , currentNode , currentOperator , createOperator , submitOperator , todoRecord .getWorkRuntimeId ());
185188 this .fetchFlowNode (flowSession );
186189 }
187190 }
188191 }
189192 }
190193
191194
192- private FlowSession buildFlowSession (IFlowNode currentNode ,
193- IFlowOperator currentOperator ,
194- IFlowOperator createdOperator ,
195- IFlowOperator submitOperator ,
196- long backupId ) {
195+ private FlowSession buildFlowSession (
196+ FlowRecord flowRecord ,
197+ IFlowNode currentNode ,
198+ IFlowOperator currentOperator ,
199+ IFlowOperator createdOperator ,
200+ IFlowOperator submitOperator ,
201+ long backupId ) {
197202 ActionManager actionManager = currentNode .actionManager ();
198203 IFlowAction flowAction = actionManager .getAction (PassAction .class );
199204 FormData formData = new FormData (this .workflow .getForm ());
@@ -208,7 +213,7 @@ private FlowSession buildFlowSession(IFlowNode currentNode,
208213 currentNode ,
209214 flowAction ,
210215 formData ,
211- this . flowRecord ,
216+ flowRecord ,
212217 new ArrayList <>(),
213218 backupId ,
214219 FlowAdvice .nullFlowAdvice ()
0 commit comments