caishunfeng commented on a change in pull request #8190:
URL: https://github.com/apache/dolphinscheduler/pull/8190#discussion_r791543873



##########
File path: 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java
##########
@@ -555,47 +474,44 @@ private void updateProcessDefiniteVersion(User loginUser, 
Map<String, Object> re
             putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, 
processDefinitionCode);
             return result;
         }
-        List<ProcessTaskRelation> processTaskRelationList = 
processTaskRelationMapper.queryByCode(projectCode, processDefinitionCode, 
preTaskCode, postTaskCode);
+        List<ProcessTaskRelation> processTaskRelationList = 
processTaskRelationMapper.queryByProcessCode(projectCode, 
processDefinitionCode);
         if (CollectionUtils.isEmpty(processTaskRelationList)) {
             putMsg(result, Status.DATA_IS_NULL, "processTaskRelationList");
             return result;
         }
-        if (processTaskRelationList.size() > 1) {
-            putMsg(result, Status.DATA_IS_NOT_VALID, 
"processTaskRelationList");
-            return result;
+        Map<Long, List<ProcessTaskRelation>> taskRelationMap = new HashMap<>();
+        for (ProcessTaskRelation processTaskRelation : 
processTaskRelationList) {
+            taskRelationMap.compute(processTaskRelation.getPostTaskCode(), (k, 
v) -> {
+                if (v == null) {
+                    v = new ArrayList<>();
+                }
+                v.add(processTaskRelation);
+                return v;
+            });
         }
-        ProcessTaskRelation processTaskRelation = 
processTaskRelationList.get(0);
-        int upstreamCount = processTaskRelationMapper.countByCode(projectCode, 
processTaskRelation.getProcessDefinitionCode(),
-            0L, processTaskRelation.getPostTaskCode());
-
-        if (upstreamCount == 0) {
-            putMsg(result, Status.DATA_IS_NULL, "upstreamCount");
+        if (!taskRelationMap.containsKey(postTaskCode)) {
+            putMsg(result, Status.DATA_IS_NULL, "postTaskCode");
             return result;
         }
-        if (upstreamCount > 1) {
-            int delete = 
processTaskRelationMapper.deleteById(processTaskRelation.getId());
-            if (delete == 0) {
-                putMsg(result, Status.DELETE_EDGE_ERROR);
+        if (taskRelationMap.get(postTaskCode).size() > 1) {
+            for (ProcessTaskRelation processTaskRelation : 
taskRelationMap.get(postTaskCode)) {
+                if (processTaskRelation.getPreTaskCode() == preTaskCode) {
+                    int delete = 
processTaskRelationMapper.deleteById(processTaskRelation.getId());
+                    if (delete == 0) {
+                        putMsg(result, Status.DELETE_EDGE_ERROR);
+                        throw new ServiceException(Status.DELETE_EDGE_ERROR);
+                    }
+                    processTaskRelationList.remove(processTaskRelation);
+                }
             }
-            return result;
-        }
-        updateProcessDefiniteVersion(loginUser, result, processDefinition);
-        
processTaskRelation.setProcessDefinitionVersion(processDefinition.getVersion());
-        processTaskRelation.setPreTaskVersion(0);
-        processTaskRelation.setPreTaskCode(0L);
-        Date now = new Date();
-        processTaskRelation.setUpdateTime(now);
-        int update = processTaskRelationMapper.updateById(processTaskRelation);
-        processTaskRelation.setId(0);
-        ProcessTaskRelationLog processTaskRelationLog = new 
ProcessTaskRelationLog(processTaskRelation);
-        processTaskRelationLog.setCreateTime(now);
-        processTaskRelationLog.setOperator(loginUser.getId());
-        processTaskRelationLog.setOperateTime(now);
-        int insert = 
processTaskRelationLogMapper.insert(processTaskRelationLog);
-        if ((update & insert) == 0) {
-            putMsg(result, Status.DELETE_EDGE_ERROR);
-            throw new ServiceException(Status.DELETE_EDGE_ERROR);
+        } else {
+            ProcessTaskRelation processTaskRelation = 
taskRelationMap.get(postTaskCode).get(0);
+            processTaskRelationList.remove(processTaskRelation);
+            processTaskRelation.setPreTaskVersion(0);
+            processTaskRelation.setPreTaskCode(0L);
+            processTaskRelationList.add(processTaskRelation);

Review comment:
       why to add a empty preTask here?

##########
File path: 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessTaskRelationController.java
##########
@@ -101,46 +101,6 @@ public Result createProcessTaskRelation(@ApiIgnore 
@RequestAttribute(value = Con
         return returnDataList(result);
     }
 
-    /**
-     * move task to other processDefinition
-     *
-     * @param loginUser login user info
-     * @param projectCode project code
-     * @param processDefinitionCode process definition code
-     * @param targetProcessDefinitionCode target process definition code
-     * @param taskCode the current task code (the post task code)
-     * @return move result code
-     */
-    @ApiOperation(value = "moveRelation", notes = 
"MOVE_TASK_TO_OTHER_PROCESS_DEFINITION_NOTES")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", 
required = true, type = "Long"),
-        @ApiImplicitParam(name = "processDefinitionCode", value = 
"PROCESS_DEFINITION_CODE", required = true, type = "Long"),
-        @ApiImplicitParam(name = "targetProcessDefinitionCode", value = 
"TARGET_PROCESS_DEFINITION_CODE", required = true, type = "Long"),
-        @ApiImplicitParam(name = "taskCode", value = "TASK_CODE", required = 
true, type = "Long")
-    })
-    @PostMapping(value = "/move")
-    @ResponseStatus(HttpStatus.OK)
-    @ApiException(MOVE_PROCESS_TASK_RELATION_ERROR)
-    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
-    public Result moveTaskProcessRelation(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,

Review comment:
       Is it OK to delete the controller function directly?

##########
File path: 
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessTaskRelationServiceImpl.java
##########
@@ -372,6 +259,21 @@ private void updateProcessDefiniteVersion(User loginUser, 
Map<String, Object> re
         return result;
     }
 
+    private void updateRelation(User loginUser, Map<String, Object> result, 
ProcessDefinition processDefinition,
+                                List<ProcessTaskRelation> 
processTaskRelationList) {
+        updateProcessDefiniteVersion(loginUser, result, processDefinition);
+        List<ProcessTaskRelationLog> relationLogs = 
processTaskRelationList.stream().map(ProcessTaskRelationLog::new).collect(Collectors.toList());
+        int insertResult = processService.saveTaskRelation(loginUser, 
processDefinition.getProjectCode(), processDefinition.getCode(),
+            processDefinition.getVersion(), relationLogs, 
Lists.newArrayList(), Boolean.TRUE);
+        if (insertResult == Constants.EXIT_CODE_SUCCESS) {

Review comment:
       It's better to use another const,  but not `EXIT_CODE_SUCCESS`




-- 
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