1010import com .codingapi .flow .manager .NodeStrategyManager ;
1111import com .codingapi .flow .manager .OperatorManager ;
1212import com .codingapi .flow .node .IFlowNode ;
13+ import com .codingapi .flow .node .NodeType ;
1314import com .codingapi .flow .node .nodes .StartNode ;
1415import com .codingapi .flow .operator .IFlowOperator ;
1516import com .codingapi .flow .pojo .request .FlowProcessNodeRequest ;
2122import com .codingapi .flow .session .FlowAdvice ;
2223import com .codingapi .flow .session .FlowSession ;
2324import com .codingapi .flow .workflow .Workflow ;
25+ import lombok .Getter ;
2426
2527import java .util .ArrayList ;
2628import java .util .List ;
@@ -45,6 +47,7 @@ public class FlowProcessNodeService {
4547 // 流程节点记录
4648 private final List <ProcessNode > nodeList ;
4749
50+
4851 public FlowProcessNodeService (FlowProcessNodeRequest request ) {
4952 this .request = request ;
5053 this .currentOperator = RepositoryHolderContext .getInstance ().getOperatorById (request .getOperatorId ());
@@ -55,6 +58,7 @@ public FlowProcessNodeService(FlowProcessNodeRequest request) {
5558 this .loadWorkflow ();
5659 }
5760
61+
5862 private void loadWorkflow () {
5963 String id = this .request .getId ();
6064 if (this .request .isCreateWorkflow ()) {
@@ -104,30 +108,70 @@ public List<ProcessNode> processNodes() {
104108 FlowAdvice .nullFlowAdvice ()
105109 );
106110
107- this .fetchNextNode (flowSession , List .of (this .currentNode ));
111+ NextNodeLoader nextNodeLoader = new NextNodeLoader (this .currentNode );
112+ List <ProcessNode > nextNodes = nextNodeLoader .loadNextNode (flowSession );
108113
109- // 推理后续
110- return nodeList ;
114+ this . nodeList . addAll ( nextNodes );
115+ return this . nodeList ;
111116 }
112117
113118
114- private void fetchNextNode (FlowSession flowSession , List <IFlowNode > nexNodes ) {
115- for (IFlowNode flowNode : nexNodes ) {
116- List <IFlowOperator > operators = null ;
117- if (flowNode .getType ().equals (StartNode .NODE_TYPE )){
118- operators = List .of (flowSession .getCurrentOperator ());
119- }else {
120- NodeStrategyManager nodeStrategyManager = flowNode .strategyManager ();
121- OperatorManager operatorManager = nodeStrategyManager .loadOperators (flowSession );
122- operators = operatorManager .getOperators ();
119+ private class NextNodeLoader {
120+
121+ @ Getter
122+ private final List <ProcessNode > nodeList ;
123+ private final IFlowNode currentNode ;
124+ private final List <String > displayNodeTypes ;
125+
126+ public NextNodeLoader (IFlowNode currentNode ) {
127+ this .currentNode = currentNode ;
128+ this .nodeList = new ArrayList <>();
129+ this .displayNodeTypes = new ArrayList <>();
130+ this .initDisplayNodeTypes ();
131+ }
132+
133+
134+ private void initDisplayNodeTypes () {
135+ this .displayNodeTypes .add (NodeType .START .name ());
136+ this .displayNodeTypes .add (NodeType .END .name ());
137+ this .displayNodeTypes .add (NodeType .APPROVAL .name ());
138+ this .displayNodeTypes .add (NodeType .NOTIFY .name ());
139+ this .displayNodeTypes .add (NodeType .HANDLE .name ());
140+ this .displayNodeTypes .add (NodeType .TRIGGER .name ());
141+ this .displayNodeTypes .add (NodeType .SUB_PROCESS .name ());
142+ }
143+
144+ private void fetchNextNode (FlowSession flowSession , List <IFlowNode > nexNodes ) {
145+ for (IFlowNode flowNode : nexNodes ) {
146+ List <IFlowOperator > operators = null ;
147+ if (flowNode .getType ().equals (StartNode .NODE_TYPE )) {
148+ operators = List .of (flowSession .getCurrentOperator ());
149+ } else {
150+ NodeStrategyManager nodeStrategyManager = flowNode .strategyManager ();
151+ OperatorManager operatorManager = nodeStrategyManager .loadOperators (flowSession );
152+ operators = operatorManager .getOperators ();
153+ }
154+ ProcessNode processNode = new ProcessNode (flowNode , operators );
155+ if (processNode .isFlowNode (this .currentNode )) {
156+ processNode .setCurrentState ();
157+ }
158+ this .nodeList .add (processNode );
159+ List <IFlowNode > nextNodes = workflow .nextNodes (flowNode );
160+ this .fetchNextNode (flowSession .updateSession (flowNode ), nextNodes );
123161 }
124- ProcessNode processNode = new ProcessNode (flowNode ,operators );
125- if (processNode .isFlowNode (this .currentNode )){
126- processNode .setCurrentState ();
162+ }
163+
164+ public List <ProcessNode > loadNextNode (FlowSession flowSession ) {
165+ this .fetchNextNode (flowSession ,List .of (this .currentNode ));
166+
167+ List <ProcessNode > displayNodes = nodeList .stream ().filter (node -> this .displayNodeTypes .contains (node .getNodeType ())).toList ();
168+ List <ProcessNode > processNodeList = new ArrayList <>();
169+ for (ProcessNode node :displayNodes ){
170+ if (!processNodeList .contains (node )){
171+ processNodeList .add (node );
172+ }
127173 }
128- this .nodeList .add (processNode );
129- List <IFlowNode > nextNodes = workflow .nextNodes (flowNode );
130- this .fetchNextNode (flowSession .updateSession (flowNode ), nextNodes );
174+ return processNodeList ;
131175 }
132176 }
133177
0 commit comments