Merge branch 'master' of http://1.14.125.6:3000/mianbin/ops-pro
This commit is contained in:
commit
84cf91df8b
@ -28,6 +28,7 @@ import cd.casic.ci.process.process.service.stage.impl.StageServiceImpl;
|
||||
import cd.casic.ci.process.process.service.task.impl.TaskServiceImpl;
|
||||
import cd.casic.ci.process.process.service.template.impl.TemplateManagerServiceImpl;
|
||||
import cd.casic.ci.process.util.WebFrameworkUtils;
|
||||
import cd.casic.ci.process.util.snowflake.SnowflakeIdentifierGenerator;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
@ -90,6 +91,9 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
||||
@Resource
|
||||
private TargetVersionDao targetVersionDao;
|
||||
|
||||
@Resource
|
||||
private SnowflakeIdentifierGenerator idWork;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String createPipeline(PipelineCreateReq pipelineReq) {
|
||||
@ -106,12 +110,42 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
||||
pipeline.setState(1);
|
||||
|
||||
this.save(pipeline);
|
||||
// 默认模板id,以后数据库迁移需要更换
|
||||
//如果模板id为空,则设置默认模板,只新增初始节点
|
||||
if (StringUtils.isEmpty(pipelineReq.getTemplateId())) {
|
||||
pipelineReq.setTemplateId("732923254863433728");
|
||||
}
|
||||
//根据模板ID初始化
|
||||
if (!ObjectUtils.isEmpty(pipelineReq.getTemplateId())){
|
||||
//新增父级阶段
|
||||
PipStage pipStage = new PipStage();
|
||||
String stageId = idWork.nextUUID(null);
|
||||
pipStage.setId(stageId);
|
||||
pipStage.setStageName("初始阶段");
|
||||
pipStage.setStageSort(1);
|
||||
pipStage.setParentId("-1");
|
||||
pipStage.setPipelineId(pipeline.getId());
|
||||
pipStage.setCode(true);
|
||||
pipStageDao.insert(pipStage);
|
||||
|
||||
//新增子级阶段
|
||||
PipStage childPipStage = new PipStage();
|
||||
String childPipStageId = idWork.nextUUID(null);
|
||||
childPipStage.setId(childPipStageId);
|
||||
childPipStage.setStageName("初始阶段");
|
||||
childPipStage.setStageSort(1);
|
||||
childPipStage.setParentId(pipStage.getId());
|
||||
childPipStage.setPipelineId(pipeline.getId());
|
||||
childPipStage.setCode(true);
|
||||
pipStageDao.insert(childPipStage);
|
||||
|
||||
//新增节点信息
|
||||
PipTask pipTask = new PipTask();
|
||||
pipTask.setStageId(childPipStage.getId());
|
||||
pipTask.setTaskName("初始节点");
|
||||
pipTask.setPipelineId(pipeline.getId());
|
||||
pipTask.setTaskType(pipelineReq.getTargetType());
|
||||
pipTask.setTaskSort(1);
|
||||
pipTask.setTaskProperties(new HashMap<>());
|
||||
pipTaskDao.insert(pipTask);
|
||||
|
||||
}else {
|
||||
//根据模板ID初始化
|
||||
TemplateFindResp template = templateService.findTemplateById(pipelineReq.getTemplateId());
|
||||
|
||||
if (!ObjectUtils.isEmpty(template)){
|
||||
@ -120,7 +154,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
||||
List<TemplateStageResp> stageList = template.getStageList();
|
||||
stageList.forEach(o->{
|
||||
PipStage pipStage = templateConverter.respToStage(o);
|
||||
pipStage.setId(null);
|
||||
pipStage.setId(idWork.nextUUID(null));
|
||||
pipStage.setPipelineId(pipeline.getId());
|
||||
pipStage.setCreateTime(LocalDateTime.now());
|
||||
pipStage.setCreator(String.valueOf(WebFrameworkUtils.getLoginUserId()));
|
||||
@ -138,8 +172,9 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
||||
PipStage childStage = templateConverter.respToStage(j);
|
||||
Map<PipStage,List<PipTask>> stageTaskMap = new HashMap<>();
|
||||
|
||||
childStage.setId(null);
|
||||
childStage.setId(idWork.nextUUID(null));
|
||||
childStage.setPipelineId(pipeline.getId());
|
||||
childStage.setParentId(pipStage.getId());
|
||||
childStage.setCreateTime(LocalDateTime.now());
|
||||
childStage.setCreator(String.valueOf(WebFrameworkUtils.getLoginUserId()));
|
||||
if (j.isCode()){
|
||||
@ -154,7 +189,8 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
||||
List<PipTask> taskList = new ArrayList<>(0);
|
||||
j.getTaskValues().forEach(k->{
|
||||
PipTask pipTask = templateConverter.templateTaskToTask(k);
|
||||
pipTask.setId(null);
|
||||
pipTask.setId(idWork.nextUUID(null));
|
||||
pipTask.setStageId(childStage.getId());
|
||||
pipTask.setPipelineId(pipeline.getId());
|
||||
pipTask.setCreateTime(LocalDateTime.now());
|
||||
pipTask.setCreator(String.valueOf(WebFrameworkUtils.getLoginUserId()));
|
||||
@ -174,31 +210,29 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
||||
pipTaskDao.insertBatch(pipTaskList);
|
||||
|
||||
//清空数组
|
||||
pipStageList.clear();
|
||||
pipTaskList.clear();
|
||||
|
||||
templateCopyPipelineMap.forEach((parentStage, childStages) -> {
|
||||
|
||||
childStages.forEach((childStage, tasks) -> {
|
||||
childStage.setParentId(parentStage.getId());
|
||||
pipStageList.add(childStage);
|
||||
|
||||
tasks.forEach(task -> {
|
||||
task.setStageId(childStage.getId());
|
||||
pipTaskList.add(task);
|
||||
});
|
||||
});
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(pipStageList)){
|
||||
pipStageDao.updateBatch(pipStageList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(pipTaskList)){
|
||||
pipTaskDao.updateBatch(pipTaskList);
|
||||
}
|
||||
// pipStageList.clear();
|
||||
// pipTaskList.clear();
|
||||
//
|
||||
// templateCopyPipelineMap.forEach((parentStage, childStages) -> {
|
||||
//
|
||||
// childStages.forEach((childStage, tasks) -> {
|
||||
// childStage.setParentId(parentStage.getId());
|
||||
// pipStageList.add(childStage);
|
||||
//
|
||||
// tasks.forEach(task -> {
|
||||
// task.setStageId(childStage.getId());
|
||||
// pipTaskList.add(task);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// if (!CollectionUtils.isEmpty(pipStageList)){
|
||||
// pipStageDao.updateBatch(pipStageList);
|
||||
// }
|
||||
// if (!CollectionUtils.isEmpty(pipTaskList)){
|
||||
// pipTaskDao.updateBatch(pipTaskList);
|
||||
// }
|
||||
}
|
||||
|
||||
//TODO 创建对应的鉴权关系
|
||||
//TODO 创建对应的消息分发
|
||||
return pipeline.getId();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user