|
|
|
@ -14,6 +14,7 @@ import cd.casic.ci.process.process.service.task.TaskService;
|
|
|
|
|
import cd.casic.framework.commons.exception.ServiceException;
|
|
|
|
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
|
|
|
|
import cd.casic.framework.commons.util.object.BeanUtils;
|
|
|
|
|
import cd.casic.framework.commons.util.util.WebFrameworkUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
@ -22,6 +23,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
@ -39,7 +41,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|
|
|
|
private TaskService taskService;
|
|
|
|
|
@Resource
|
|
|
|
|
private PipStageDao stageDao;
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@Override
|
|
|
|
|
public String createStagesOrTask(StageCreateReq stageReq) {
|
|
|
|
|
String firstStageId = stageReq.getStageId();
|
|
|
|
@ -49,8 +51,9 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|
|
|
|
String secondStageId = task.getStageId();
|
|
|
|
|
JSONObject taskProperties = task.getTaskProperties();
|
|
|
|
|
String taskType = task.getTaskType();
|
|
|
|
|
String taskSort = task.getTaskSort();
|
|
|
|
|
Integer taskSort = task.getTaskSort();
|
|
|
|
|
String pipelineId = task.getPipelineId();
|
|
|
|
|
Long loginUserId = WebFrameworkUtils.getLoginUserId();
|
|
|
|
|
PipStage firstStage = null;
|
|
|
|
|
// 判断是否需要新建阶段,如果没有传第一级tageId而传了sort就是需要创建阶段
|
|
|
|
|
if (StringUtils.isEmpty(firstStageId)) {
|
|
|
|
@ -64,11 +67,77 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|
|
|
|
firstStage.setCreateTime(LocalDateTime.now());
|
|
|
|
|
firstStage.setParentId("-1");
|
|
|
|
|
firstStage.setPipelineId(pipelineId);
|
|
|
|
|
|
|
|
|
|
firstStage.setCreateUserId(loginUserId);
|
|
|
|
|
firstStage.setUpdateUserId(loginUserId);
|
|
|
|
|
firstStage.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
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
|
|
|
|
|
} 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());
|
|
|
|
|
secondStage.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
secondStage.setCreateUserId(loginUserId);
|
|
|
|
|
secondStage.setParentId(firstStageId);
|
|
|
|
|
secondStage.setPipelineId(pipelineId);
|
|
|
|
|
secondStage.setUpdateUserId(loginUserId);
|
|
|
|
|
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);
|
|
|
|
|
pipTask.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
pipTask.setCreateUserId(loginUserId);
|
|
|
|
|
pipTask.setUpdateUserId(loginUserId);
|
|
|
|
|
taskService.save(pipTask);
|
|
|
|
|
return pipTask.getTaskId();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 更新主节点阶段顺序
|
|
|
|
@ -274,7 +343,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (PipStage stage : allStage) {
|
|
|
|
|
if (stage.isCode()){
|
|
|
|
|
if (stage.getCode()){
|
|
|
|
|
throw new ServiceException(50001,"代码源已存在,无法再次创建。");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|