创建节点方法

This commit is contained in:
even 2025-05-15 10:08:45 +08:00
parent 81b7533da5
commit 1abd20136a
3 changed files with 63 additions and 8 deletions

View File

@ -9,6 +9,6 @@ public class TaskCreateReq {
private String taskName; private String taskName;
private String pipelineId; private String pipelineId;
private String taskType; private String taskType;
private String taskSort; private Integer taskSort;
private JSONObject taskProperties; private JSONObject taskProperties;
} }

View File

@ -24,13 +24,13 @@ public class PipStage {
private String pipelineId; private String pipelineId;
//@ApiProperty(name="stageSort",desc="阶段顺序") //@ApiProperty(name="stageSort",desc="阶段顺序")
private int stageSort; private Integer stageSort;
//@ApiProperty(name = "parentId",desc="主阶段") //@ApiProperty(name = "parentId",desc="主阶段")
private String parentId; private String parentId;
//@ApiProperty(name = "code",desc="是否是源码") //@ApiProperty(name = "code",desc="是否是源码")
private boolean code = false; private Boolean code = false;
//@ApiProperty(name = "taskValues",desc="阶段任务") //@ApiProperty(name = "taskValues",desc="阶段任务")
@TableField(exist = false) @TableField(exist = false)

View File

@ -22,6 +22,7 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -39,7 +40,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
private TaskService taskService; private TaskService taskService;
@Resource @Resource
private PipStageDao stageDao; private PipStageDao stageDao;
@Transactional(rollbackFor = Exception.class)
@Override @Override
public String createStagesOrTask(StageCreateReq stageReq) { public String createStagesOrTask(StageCreateReq stageReq) {
String firstStageId = stageReq.getStageId(); String firstStageId = stageReq.getStageId();
@ -49,7 +50,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
String secondStageId = task.getStageId(); String secondStageId = task.getStageId();
JSONObject taskProperties = task.getTaskProperties(); JSONObject taskProperties = task.getTaskProperties();
String taskType = task.getTaskType(); String taskType = task.getTaskType();
String taskSort = task.getTaskSort(); Integer taskSort = task.getTaskSort();
String pipelineId = task.getPipelineId(); String pipelineId = task.getPipelineId();
PipStage firstStage = null; PipStage firstStage = null;
// 判断是否需要新建阶段,如果没有传第一级tageId而传了sort就是需要创建阶段 // 判断是否需要新建阶段,如果没有传第一级tageId而传了sort就是需要创建阶段
@ -64,11 +65,65 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
firstStage.setCreateTime(LocalDateTime.now()); firstStage.setCreateTime(LocalDateTime.now());
firstStage.setParentId("-1"); firstStage.setParentId("-1");
firstStage.setPipelineId(pipelineId); firstStage.setPipelineId(pipelineId);
PipStage stageQuery = new PipStage();
stageQuery.setPipelineId(pipelineId);
stageQuery.setParentId("-1");
List<PipStage> otherStageList = getPipStageList(stageQuery);
if (!CollectionUtils.isEmpty(otherStageList)) {
for (PipStage stage : otherStageList) {
if (stageSort<=stage.getStageSort()) {
stage.setStageSort(stage.getStageSort()+1);
}
}
updateBatchById(otherStageList);
}
save(firstStage);
// firstStage // firstStage
} else { } else {
PipStage stageQuery = new PipStage();
stageQuery.setStageId(firstStageId);
List<PipStage> pipStageList = getPipStageList(stageQuery);
if (!CollectionUtils.isEmpty(pipStageList)) {
firstStage = pipStageList.get(0);
}
} }
return null; if (firstStage == null) {
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"创建节点失败");
}
PipStage secondStage = null;
if (secondStageId==null||taskSort==null) {
// 添加并行节点
secondStage = new PipStage();
PipStage stageQuery = new PipStage();
stageQuery.setParentId(firstStageId);
stageQuery.setPipelineId(pipelineId);
List<PipStage> pipStageList = getPipStageList(stageQuery);
if (CollectionUtils.isEmpty(pipStageList)) {
secondStage.setStageSort(1);
} else {
secondStage.setStageSort(pipStageList.size()+1);
}
secondStage.setCreateTime(LocalDateTime.now());
save(secondStage);
taskSort=1;
secondStageId = secondStage.getStageId();
} else {
secondStage = getById(secondStageId);
}
if (secondStage == null) {
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"创建节点失败");
}
// 保存task
PipTask pipTask = new PipTask();
pipTask.setTaskType(taskType);
pipTask.setTaskSort(taskSort);
pipTask.setStageId(secondStageId);
pipTask.setTaskName(taskName);
pipTask.setCreateTime(LocalDateTime.now());
pipTask.setTaskProperties(taskProperties);
pipTask.setPipelineId(pipelineId);
taskService.save(pipTask);
return pipTask.getTaskId();
} }
/** /**
* 更新主节点阶段顺序 * 更新主节点阶段顺序
@ -274,7 +329,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
return; return;
} }
for (PipStage stage : allStage) { for (PipStage stage : allStage) {
if (stage.isCode()){ if (stage.getCode()){
throw new ServiceException(50001,"代码源已存在,无法再次创建。"); throw new ServiceException(50001,"代码源已存在,无法再次创建。");
} }
} }