@@ -413,28 +413,74 @@ public static List<String> parseSwitchTask(String nodeCode,
413413 return conditionTaskList ;
414414 }
415415
416- private static List <String > skipTaskNode4Switch (TaskNode taskNode , Map <String , TaskNode > skipTaskNodeList ,
417- Map <String , TaskInstance > completeTaskList ,
418- DAG <String , TaskNode , TaskNodeRelation > dag ) {
416+
417+ public static List <String > skipTaskNode4Switch (TaskNode taskNode ,
418+ Map <String , TaskNode > skipTaskNodeList ,
419+ Map <String , TaskInstance > completeTaskList ,
420+ DAG <String , TaskNode , TaskNodeRelation > dag ) {
419421
420422 SwitchParameters switchParameters =
421423 completeTaskList .get (Long .toString (taskNode .getCode ())).getSwitchDependency ();
422424 int resultConditionLocation = switchParameters .getResultConditionLocation ();
423425 List <SwitchResultVo > conditionResultVoList = switchParameters .getDependTaskList ();
426+
424427 List <String > switchTaskList = conditionResultVoList .get (resultConditionLocation ).getNextNode ();
428+ Set <String > switchNeedWorkCodes = new HashSet <>();
425429 if (CollectionUtils .isEmpty (switchTaskList )) {
426- switchTaskList = new ArrayList <>();
430+ return new ArrayList <>();
431+ }
432+ // get all downstream nodes of the branch that the switch node needs to execute
433+ for (String switchTaskCode : switchTaskList ) {
434+ getSwitchNeedWorkCodes (switchTaskCode , dag , switchNeedWorkCodes );
427435 }
428436 conditionResultVoList .remove (resultConditionLocation );
429437 for (SwitchResultVo info : conditionResultVoList ) {
430438 if (CollectionUtils .isEmpty (info .getNextNode ())) {
431439 continue ;
432440 }
433- setTaskNodeSkip (info .getNextNode ().get (0 ), dag , completeTaskList , skipTaskNodeList );
441+ for (String nextNode : info .getNextNode ()) {
442+ setSwitchTaskNodeSkip (nextNode , dag , completeTaskList , skipTaskNodeList ,
443+ switchNeedWorkCodes );
444+ }
434445 }
435446 return switchTaskList ;
436447 }
437448
449+ /**
450+ * get all downstream nodes of the branch that the switch node needs to execute
451+ * @param taskCode
452+ * @param dag
453+ * @param switchNeedWorkCodes
454+ */
455+ public static void getSwitchNeedWorkCodes (String taskCode , DAG <String , TaskNode , TaskNodeRelation > dag ,
456+ Set <String > switchNeedWorkCodes ) {
457+ switchNeedWorkCodes .add (taskCode );
458+ Set <String > subsequentNodes = dag .getSubsequentNodes (taskCode );
459+ if (org .apache .commons .collections .CollectionUtils .isNotEmpty (subsequentNodes )) {
460+ for (String subCode : subsequentNodes ) {
461+ getSwitchNeedWorkCodes (subCode , dag , switchNeedWorkCodes );
462+ }
463+ }
464+ }
465+
466+ private static void setSwitchTaskNodeSkip (String skipNodeCode ,
467+ DAG <String , TaskNode , TaskNodeRelation > dag ,
468+ Map <String , TaskInstance > completeTaskList ,
469+ Map <String , TaskNode > skipTaskNodeList ,
470+ Set <String > switchNeedWorkCodes ) {
471+ // ignore when the node that needs to be skipped exists on the branch that the switch type node needs to execute
472+ if (!dag .containsNode (skipNodeCode ) || switchNeedWorkCodes .contains (skipNodeCode )) {
473+ return ;
474+ }
475+ skipTaskNodeList .putIfAbsent (skipNodeCode , dag .getNode (skipNodeCode ));
476+ Collection <String > postNodeList = dag .getSubsequentNodes (skipNodeCode );
477+ for (String post : postNodeList ) {
478+ TaskNode postNode = dag .getNode (post );
479+ if (isTaskNodeNeedSkip (postNode , skipTaskNodeList )) {
480+ setTaskNodeSkip (post , dag , completeTaskList , skipTaskNodeList );
481+ }
482+ }
483+ }
438484 /**
439485 * set task node and the post nodes skip flag
440486 */
0 commit comments