Compare commits
3 Commits
81b7533da5
...
2459515c98
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2459515c98 | ||
![]() |
9e50fea94f | ||
![]() |
1abd20136a |
@ -0,0 +1,8 @@
|
|||||||
|
package cd.casic.ci.common.pipeline.req.stage;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StageUpdateReq {
|
||||||
|
private
|
||||||
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
@ -41,4 +41,7 @@ public class PipStage {
|
|||||||
private List<PipStage> stageList;
|
private List<PipStage> stageList;
|
||||||
// 执行实例id
|
// 执行实例id
|
||||||
private String instanceId;
|
private String instanceId;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
private Long createUserId;
|
||||||
|
private Long updateUserId;
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,7 @@ public class PipTask {
|
|||||||
|
|
||||||
// 执行实例id
|
// 执行实例id
|
||||||
private String instanceId;
|
private String instanceId;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
private Long updateUserId;
|
||||||
|
private Long createUserId;
|
||||||
}
|
}
|
||||||
|
@ -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.ServiceException;
|
||||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
import cd.casic.framework.commons.util.object.BeanUtils;
|
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.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
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.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 +41,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,8 +51,9 @@ 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();
|
||||||
|
Long loginUserId = WebFrameworkUtils.getLoginUserId();
|
||||||
PipStage firstStage = null;
|
PipStage firstStage = null;
|
||||||
// 判断是否需要新建阶段,如果没有传第一级tageId而传了sort就是需要创建阶段
|
// 判断是否需要新建阶段,如果没有传第一级tageId而传了sort就是需要创建阶段
|
||||||
if (StringUtils.isEmpty(firstStageId)) {
|
if (StringUtils.isEmpty(firstStageId)) {
|
||||||
@ -64,11 +67,77 @@ 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);
|
||||||
|
|
||||||
|
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
|
// 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());
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
for (PipStage stage : allStage) {
|
for (PipStage stage : allStage) {
|
||||||
if (stage.isCode()){
|
if (stage.getCode()){
|
||||||
throw new ServiceException(50001,"代码源已存在,无法再次创建。");
|
throw new ServiceException(50001,"代码源已存在,无法再次创建。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user