llllkid commented on code in PR #16939:
URL: 
https://github.com/apache/dolphinscheduler/pull/16939#discussion_r1903949379


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -2118,37 +2118,38 @@ protected void doBatchOperateWorkflowDefinition(User 
loginUser,
                 List<TaskDefinitionLog> taskDefinitionLogs =
                         
taskDefinitionLogDao.queryTaskDefineLogList(workflowTaskRelations);
                 Map<Long, Long> taskCodeMap = new HashMap<>();
-                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) 
{
+                taskDefinitionLogs.forEach(taskDefinitionLog -> {
                     try {
-                        long taskCode = CodeGenerateUtils.genCode();
-                        taskCodeMap.put(taskDefinitionLog.getCode(), taskCode);
-                        taskDefinitionLog.setCode(taskCode);
-                        if 
(TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
-                            final String taskParams = 
taskDefinitionLog.getTaskParams();
-                            final SwitchParameters switchParameters =
-                                    JSONUtils.parseObject(taskParams, 
SwitchParameters.class);
-                            if (switchParameters == null) {
-                                throw new IllegalArgumentException(
-                                        "Switch task params: " + taskParams + 
" is invalid.");
-                            }
-                            SwitchParameters.SwitchResult switchResult = 
switchParameters.getSwitchResult();
-                            
switchResult.getDependTaskList().forEach(switchResultVo -> {
-                                
switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
-                            });
-                            if (switchResult.getNextNode() != null) {
-                                switchResult.setNextNode(
-                                        
taskCodeMap.get(switchResult.getNextNode()));
-                            }
-                            
taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
-                        }
+                        taskCodeMap.put(taskDefinitionLog.getCode(), 
CodeGenerateUtils.genCode());
                     } catch (CodeGenerateException e) {
                         log.error("Generate task definition code error, 
projectCode:{}.", targetProjectCode, e);
                         putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS);
                         throw new 
ServiceException(Status.INTERNAL_SERVER_ERROR_ARGS);
                     }
+                });
+                for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) 
{
+                    
taskDefinitionLog.setCode(taskCodeMap.get(taskDefinitionLog.getCode()));
                     taskDefinitionLog.setProjectCode(targetProjectCode);
                     taskDefinitionLog.setVersion(0);
                     taskDefinitionLog.setName(taskDefinitionLog.getName());
+                    if 
(TaskTypeUtils.isSwitchTask(taskDefinitionLog.getTaskType())) {
+                        final String taskParams = 
taskDefinitionLog.getTaskParams();
+                        final SwitchParameters switchParameters =
+                                JSONUtils.parseObject(taskParams, 
SwitchParameters.class);
+                        if (switchParameters == null) {
+                            throw new IllegalArgumentException(
+                                    "Switch task params: " + taskParams + " is 
invalid.");
+                        }
+                        SwitchParameters.SwitchResult switchResult = 
switchParameters.getSwitchResult();
+                        
switchResult.getDependTaskList().forEach(switchResultVo -> {
+                            
switchResultVo.setNextNode(taskCodeMap.get(switchResultVo.getNextNode()));
+                        });
+                        if (switchResult.getNextNode() != null) {
+                            switchResult.setNextNode(
+                                    
taskCodeMap.get(switchResult.getNextNode()));
+                        }
+                        
taskDefinitionLog.setTaskParams(JSONUtils.toJsonString(switchParameters));
+                    }

Review Comment:
   > Why move this code to here?
   
   I think this is git's display problem, 
   I don't move this code to here, 
   I added `taskDefinitionLogs.forEach` before `for (TaskDefinitionLog 
taskDefinitionLog : taskDefinitionLogs)`, because we need put all new code into 
taskCodeMap before `taskDefinitionLog.setTaskParams`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to