@@ -413,28 +413,74 @@ public static List<String> parseSwitchTask(String nodeCode,
413
413
return conditionTaskList ;
414
414
}
415
415
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 ) {
419
421
420
422
SwitchParameters switchParameters =
421
423
completeTaskList .get (Long .toString (taskNode .getCode ())).getSwitchDependency ();
422
424
int resultConditionLocation = switchParameters .getResultConditionLocation ();
423
425
List <SwitchResultVo > conditionResultVoList = switchParameters .getDependTaskList ();
426
+
424
427
List <String > switchTaskList = conditionResultVoList .get (resultConditionLocation ).getNextNode ();
428
+ Set <String > switchNeedWorkCodes = new HashSet <>();
425
429
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 );
427
435
}
428
436
conditionResultVoList .remove (resultConditionLocation );
429
437
for (SwitchResultVo info : conditionResultVoList ) {
430
438
if (CollectionUtils .isEmpty (info .getNextNode ())) {
431
439
continue ;
432
440
}
433
- setTaskNodeSkip (info .getNextNode ().get (0 ), dag , completeTaskList , skipTaskNodeList );
441
+ for (String nextNode : info .getNextNode ()) {
442
+ setSwitchTaskNodeSkip (nextNode , dag , completeTaskList , skipTaskNodeList ,
443
+ switchNeedWorkCodes );
444
+ }
434
445
}
435
446
return switchTaskList ;
436
447
}
437
448
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
+ }
438
484
/**
439
485
* set task node and the post nodes skip flag
440
486
*/
0 commit comments