删除节点方法添加

This commit is contained in:
even 2025-05-14 18:26:22 +08:00
parent 0082a3a5d6
commit 6479e0112d
3 changed files with 65 additions and 5 deletions

View File

@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import org.jsoup.helper.W3CDom;
import org.springframework.core.task.VirtualThreadTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Collections;
@ -182,17 +183,70 @@ public class StageServiceImpl implements StageService {
@Override
public void deleteStagesOrTask(String taskId) {
PipTask pipTask = new PipTask();
// pipTask.set
List<PipTask> taskById = taskService.getTask(pipTask);
PipTask taskQuery = new PipTask();
taskQuery.setTaskId(taskId);
List<PipTask> taskList = taskService.getTask(taskQuery);
if (CollectionUtils.isEmpty(taskList)) {
return;
}
PipTask task = taskList.get(0);
taskService.deleteTaskById(taskId);
// 查询上一级stage下有无其他task 没有则连着stage删除
String stageId = task.getStageId();
String pipelineId = task.getPipelineId();
taskQuery.setTaskId("");
taskQuery.setStageId(stageId);
List<PipTask> otherTask = taskService.getTask(task);
if (CollectionUtils.isEmpty(otherTask)) {
// 删除当前task的父stage然后判断父stage的父级有无其他子集如果没有就继续删除当前阶段
PipStage stageQuery = new PipStage();
stageQuery.setPipelineId(stageId);
List<PipStage> currStageList = getPipStageList(stageQuery);
if (CollectionUtils.isEmpty(currStageList)) {
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"stage不存在");
}
PipStage currStage = currStageList.get(0);
deleteStages(stageId);
String parentId = currStage.getParentId();
stageQuery.setParentId(parentId);
stageQuery.setStageId(null);
// 查询同阶段其他二级stage如果不存在其他stage则删除阶段stage并整理sort值
List<PipStage> otherStageList = getPipStageList(stageQuery);
if (CollectionUtils.isEmpty(otherStageList)) {
//没有其他并行路径就需要删除当前阶段
deleteStages(parentId);
} else {
for (PipStage stage : otherStageList) {
if (currStage.getStageSort()<stage.getStageSort()) {
stage.setStageSort(stage.getStageSort()-1);
}
}
}
} else {
for (PipTask pipTask : otherTask) {
if (task.getTaskSort()<pipTask.getTaskSort()) {
pipTask.setTaskSort(pipTask.getTaskSort()-1);
}
}
}
}
@Override
public void deleteAllStagesOrTask(String pipelineId) {
}
private List<PipStage> getPipStageList(PipStage pipStage){
LambdaQueryWrapper<PipStage> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(StringUtils.isNotEmpty(pipStage.getStageId()),PipStage::getStageId,pipStage.getStageId());
wrapper.eq(StringUtils.isNotEmpty(pipStage.getPipelineId()),PipStage::getPipelineId,pipStage.getPipelineId());
wrapper.eq(StringUtils.isNotEmpty(pipStage.getParentId()),PipStage::getParentId,pipStage.getParentId());
return stageDao.selectList(wrapper);
}
@Override
public void updateStageName(StageReq stage) {
LambdaUpdateWrapper<PipStage> wrapper = new LambdaUpdateWrapper<>();
@ -235,7 +289,7 @@ public class StageServiceImpl implements StageService {
@Override
public void deleteStages(String stageId) {
stageDao.deleteById(stageId);
}
@Override

View File

@ -14,4 +14,5 @@ public interface TaskService {
public String createTasksOrTask(PipTask tasks);
List<PipTask> finAllStageTask(String stageId);
List<PipTask> getTask(PipTask pipTask);
void deleteTaskById(String taskId);
}

View File

@ -94,7 +94,7 @@ public class TaskServiceImpl implements TaskService {
String tasksId = createTasks(tasks);
//创建任务
createDifferentTask(tasksId,taskType,tasks.getValues());
// createDifferentTask(tasksId,taskType,tasks.getValues());
return tasksId;
}
@ -114,6 +114,11 @@ public class TaskServiceImpl implements TaskService {
return taskDao.selectList(wrapper);
}
@Override
public void deleteTaskById(String taskId) {
taskDao.deleteById(taskId);
}
void createDifferentTask(String taskId,String taskType,Object values){
// TODO
}