0724 ljc 新增ai创建流水线接口
This commit is contained in:
parent
52faa190c9
commit
fe6ca78d74
@ -0,0 +1,129 @@
|
|||||||
|
package cd.casic.ci.api;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.pipeline.AiPipelineCreateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.pipeline.PipelineQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.req.pipeline.PipelineReq;
|
||||||
|
import cd.casic.ci.process.dto.req.pipeline.PipelineUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.context.TreeRunContextResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.pipeline.PipelineFindResp;
|
||||||
|
import cd.casic.ci.process.engine.executor.PipelineExecutor;
|
||||||
|
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
|
||||||
|
import cd.casic.ci.process.enums.PiplineTriggerModeEnum;
|
||||||
|
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
|
||||||
|
import cd.casic.ci.process.process.service.pipeline.PipelineService;
|
||||||
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName PipelineController
|
||||||
|
* @Author hopeli
|
||||||
|
* @Date 2025/5/10 10:28
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/aiPipeline")
|
||||||
|
public class AiPipelineController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PipelineService pipelineService;
|
||||||
|
@Resource
|
||||||
|
private PipelineExecutor pipelineExecutor;
|
||||||
|
|
||||||
|
@PermitAll
|
||||||
|
@PostMapping(path="/aiCreatePipeline")
|
||||||
|
public CommonResult<String> aiCreatePipeline(@RequestBody @Valid AiPipelineCreateReq req){
|
||||||
|
|
||||||
|
String pipelineId = pipelineService.aiCreatePipeline(req);
|
||||||
|
|
||||||
|
return CommonResult.success(pipelineId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PermitAll
|
||||||
|
@PostMapping(path="/findPipelineList")
|
||||||
|
public CommonResult<List<PipelineFindResp>> findPipelineList(@RequestBody @Valid PipelineQueryReq pipelineQueryReq){
|
||||||
|
|
||||||
|
List<PipelineFindResp> respList = pipelineService.findPipelineList(pipelineQueryReq);
|
||||||
|
|
||||||
|
return CommonResult.success(respList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PermitAll
|
||||||
|
@PostMapping(path="/findPipelineById")
|
||||||
|
public CommonResult<PipelineFindResp> findPipelineById(@RequestBody @Valid PipelineQueryReq pipelineQueryReq){
|
||||||
|
|
||||||
|
PipelineFindResp resp = pipelineService.findPipelineById(pipelineQueryReq);
|
||||||
|
|
||||||
|
return CommonResult.success(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path="/deletePipeline")
|
||||||
|
public CommonResult<Void> deletePipeline(@RequestBody @Valid PipelineReq req){
|
||||||
|
|
||||||
|
pipelineService.deletePipeline(req);
|
||||||
|
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/updatePipeline")
|
||||||
|
public CommonResult<Void> updatePipeline(@RequestBody @NotNull @Valid PipelineUpdateReq pipeline){
|
||||||
|
|
||||||
|
pipelineService.updatePipeline(pipeline);
|
||||||
|
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findPipelinePage")
|
||||||
|
public CommonResult<PageResult<PipelineFindResp>> findPipelinePage(@RequestBody @NotNull @Valid PipelineQueryReq query){
|
||||||
|
|
||||||
|
PageResult<PipelineFindResp> pipelineRespPage = pipelineService.findPipelinePage(query);
|
||||||
|
|
||||||
|
return CommonResult.success(pipelineRespPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/pipelineClone")
|
||||||
|
public CommonResult<Void> pipelineClone(@RequestBody @Valid PipelineReq req){
|
||||||
|
pipelineService.pipelineClone(req);
|
||||||
|
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
@Resource
|
||||||
|
private HttpServletRequest request;
|
||||||
|
@PostMapping("/executePipeline/{pipelineId}")
|
||||||
|
public CommonResult<PipelineRunContext> executePipeline(@PathVariable("pipelineId") String pipelineId,@RequestParam(required = false,defaultValue = "false") Boolean fromError){
|
||||||
|
PipelineRunContext execute = pipelineExecutor.execute(pipelineId, PiplineTriggerModeEnum.HAND,fromError);
|
||||||
|
return CommonResult.success(execute);
|
||||||
|
}
|
||||||
|
@PostMapping("/getStageRunState/{pipelineId}")
|
||||||
|
public CommonResult<TreeRunContextResp> getPipelineRunState(@PathVariable String pipelineId){
|
||||||
|
return CommonResult.success(pipelineService.getPipelineRunState(pipelineId));
|
||||||
|
}
|
||||||
|
@PostMapping("/traversePipelineContext/{pipelineId}")
|
||||||
|
public CommonResult<PipelineRunContext> traversePipelineContext(@PathVariable("pipelineId") String pipelineId,@RequestParam(required = false,defaultValue = "false") Boolean fromError){
|
||||||
|
pipelineExecutor.traversePipelineContext(pipelineId);
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path="/transformTemplateByPipeline")
|
||||||
|
public CommonResult<Void> transformTemplateByPipeline(@RequestBody @Valid BaseIdReq req){
|
||||||
|
|
||||||
|
pipelineService.transformTemplateByPipeline(req);
|
||||||
|
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package cd.casic.ci.process.dto.req.pipeline;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateFindResp;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HopeLi
|
||||||
|
* @version v1.0
|
||||||
|
* @ClassName AiPipelineCreateReq
|
||||||
|
* @Date: 2025/7/24 18:22
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AiPipelineCreateReq {
|
||||||
|
//流水线名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
//环境id
|
||||||
|
private String envId;
|
||||||
|
|
||||||
|
//分组id
|
||||||
|
private String groupId;
|
||||||
|
|
||||||
|
//流水线类型 1.多任务 2.多阶段
|
||||||
|
private int type;
|
||||||
|
|
||||||
|
//运行状态 1.未运行 2.运行中
|
||||||
|
private int state;
|
||||||
|
|
||||||
|
//项目作用域 1.全局 2.项目
|
||||||
|
private int power;
|
||||||
|
|
||||||
|
//颜色 1~5随机生成
|
||||||
|
private int color;
|
||||||
|
|
||||||
|
//流水线模板id
|
||||||
|
private String templateId;
|
||||||
|
|
||||||
|
//目标id
|
||||||
|
private String targetVersionId;
|
||||||
|
|
||||||
|
//目标类型
|
||||||
|
private String targetType;
|
||||||
|
|
||||||
|
//流水线标签
|
||||||
|
private String pipelineTag;
|
||||||
|
|
||||||
|
//项目id
|
||||||
|
private String projectId;
|
||||||
|
|
||||||
|
//备注
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
//收藏 0.未收藏 1.收藏
|
||||||
|
private int collect;
|
||||||
|
|
||||||
|
//执行人id
|
||||||
|
private String executeUserId;
|
||||||
|
|
||||||
|
//执行时间
|
||||||
|
private LocalDateTime executeTime;
|
||||||
|
|
||||||
|
//流水线触发模式
|
||||||
|
private String pipelineTriggerMode;
|
||||||
|
|
||||||
|
//执行状态
|
||||||
|
private String executeStatus;
|
||||||
|
|
||||||
|
//资源id
|
||||||
|
private String resourceId;
|
||||||
|
|
||||||
|
private TemplateFindResp templateFindResp;
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package cd.casic.ci.process.process.converter;
|
package cd.casic.ci.process.process.converter;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.pipeline.AiPipelineCreateReq;
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineCreateReq;
|
import cd.casic.ci.process.dto.req.pipeline.PipelineCreateReq;
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineUpdateReq;
|
import cd.casic.ci.process.dto.req.pipeline.PipelineUpdateReq;
|
||||||
import cd.casic.ci.process.dto.resp.pipeline.PipelineFindResp;
|
import cd.casic.ci.process.dto.resp.pipeline.PipelineFindResp;
|
||||||
@ -24,4 +25,5 @@ public interface PipelineConverter {
|
|||||||
PipPipeline reqToDO(PipelineUpdateReq req);
|
PipPipeline reqToDO(PipelineUpdateReq req);
|
||||||
List<PipelineFindResp> toRespList(List<PipPipeline> pipPipelines);
|
List<PipelineFindResp> toRespList(List<PipPipeline> pipPipelines);
|
||||||
|
|
||||||
|
PipPipeline aiReqToDO(AiPipelineCreateReq req);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package cd.casic.ci.process.process.service.pipeline;
|
package cd.casic.ci.process.process.service.pipeline;
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineCreateReq;
|
import cd.casic.ci.process.dto.req.pipeline.*;
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineQueryReq;
|
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineReq;
|
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineUpdateReq;
|
|
||||||
import cd.casic.ci.process.dto.resp.context.TreeRunContextResp;
|
import cd.casic.ci.process.dto.resp.context.TreeRunContextResp;
|
||||||
import cd.casic.ci.process.dto.resp.pipeline.PipelineFindResp;
|
import cd.casic.ci.process.dto.resp.pipeline.PipelineFindResp;
|
||||||
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
|
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
|
||||||
@ -42,4 +39,6 @@ public interface PipelineService extends IService<PipPipeline> {
|
|||||||
|
|
||||||
void transformTemplateByPipeline(@Valid BaseIdReq req);
|
void transformTemplateByPipeline(@Valid BaseIdReq req);
|
||||||
Boolean targetVersionInUse(List<String> targetVersionId);
|
Boolean targetVersionInUse(List<String> targetVersionId);
|
||||||
|
|
||||||
|
String aiCreatePipeline(@Valid AiPipelineCreateReq req);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package cd.casic.ci.process.process.service.pipeline.impl;
|
package cd.casic.ci.process.process.service.pipeline.impl;
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineCreateReq;
|
import cd.casic.ci.process.dto.req.pipeline.*;
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineQueryReq;
|
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineReq;
|
|
||||||
import cd.casic.ci.process.dto.req.pipeline.PipelineUpdateReq;
|
|
||||||
import cd.casic.ci.process.dto.req.template.TemplateCreateByDataReq;
|
import cd.casic.ci.process.dto.req.template.TemplateCreateByDataReq;
|
||||||
import cd.casic.ci.process.dto.req.template.TemplateStageCreateByDataReq;
|
import cd.casic.ci.process.dto.req.template.TemplateStageCreateByDataReq;
|
||||||
import cd.casic.ci.process.dto.req.template.TemplateTaskCreateByDataReq;
|
import cd.casic.ci.process.dto.req.template.TemplateTaskCreateByDataReq;
|
||||||
@ -625,6 +622,90 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
|||||||
return pipelineDao.exists(wrapper);
|
return pipelineDao.exists(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String aiCreatePipeline(AiPipelineCreateReq req) {
|
||||||
|
List<PipStage> pipStageList = new ArrayList<>(0);
|
||||||
|
List<PipTask> pipTaskList = new ArrayList<>(0);
|
||||||
|
|
||||||
|
PipPipeline pipeline = pipelineConverter.aiReqToDO(req);
|
||||||
|
|
||||||
|
// 随机颜色
|
||||||
|
int randomNumber = (int)(Math.random() * 5) + 1;
|
||||||
|
pipeline.setColor(randomNumber);
|
||||||
|
|
||||||
|
pipeline.setState(1);
|
||||||
|
|
||||||
|
this.save(pipeline);
|
||||||
|
|
||||||
|
TemplateFindResp template = new TemplateFindResp();
|
||||||
|
if (!ObjectUtils.isEmpty(req.getTemplateId())){
|
||||||
|
//则根据模板进行新增
|
||||||
|
template = templateService.findTemplateById(req.getTemplateId());
|
||||||
|
}else {
|
||||||
|
//则根据ai生成的模板进行新增
|
||||||
|
template = req.getTemplateFindResp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ObjectUtils.isEmpty(template)){
|
||||||
|
|
||||||
|
//新增阶段数据
|
||||||
|
List<TemplateStageResp> stageList = template.getStageList();
|
||||||
|
stageList.forEach(o->{
|
||||||
|
PipStage pipStage = templateConverter.respToStage(o);
|
||||||
|
pipStage.setId(idWork.nextUUID(null));
|
||||||
|
pipStage.setPipelineId(pipeline.getId());
|
||||||
|
if (o.isCode()){
|
||||||
|
pipStage.setCode(true);
|
||||||
|
}else {
|
||||||
|
pipStage.setCode(false);
|
||||||
|
}
|
||||||
|
pipStageList.add(pipStage);
|
||||||
|
|
||||||
|
List<TemplateStageResp> childStageList = o.getStageList();
|
||||||
|
if (!CollectionUtils.isEmpty(childStageList)){
|
||||||
|
//则代表大阶段下存在阶段子节点
|
||||||
|
childStageList.forEach(j->{
|
||||||
|
PipStage childStage = templateConverter.respToStage(j);
|
||||||
|
|
||||||
|
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()){
|
||||||
|
childStage.setCode(true);
|
||||||
|
}else {
|
||||||
|
childStage.setCode(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
pipStageList.add(childStage);
|
||||||
|
|
||||||
|
if (!CollectionUtils.isEmpty(j.getTaskValues())){
|
||||||
|
List<PipTask> taskList = new ArrayList<>(0);
|
||||||
|
j.getTaskValues().forEach(k->{
|
||||||
|
PipTask pipTask = templateConverter.templateTaskToTask(k);
|
||||||
|
pipTask.setId(idWork.nextUUID(null));
|
||||||
|
pipTask.setStageId(childStage.getId());
|
||||||
|
pipTask.setPipelineId(pipeline.getId());
|
||||||
|
pipTask.setCreateTime(LocalDateTime.now());
|
||||||
|
pipTask.setCreator(String.valueOf(WebFrameworkUtils.getLoginUserId()));
|
||||||
|
taskList.add(pipTask);
|
||||||
|
});
|
||||||
|
pipTaskList.addAll(taskList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!CollectionUtils.isEmpty(pipStageList)){
|
||||||
|
pipStageDao.insertBatch(pipStageList);
|
||||||
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(pipTaskList)){
|
||||||
|
pipTaskDao.insertBatch(pipTaskList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pipeline.getId();
|
||||||
|
}
|
||||||
|
|
||||||
private String between(LocalDateTime startTime,LocalDateTime endTime){
|
private String between(LocalDateTime startTime,LocalDateTime endTime){
|
||||||
if (startTime==null||endTime==null) {
|
if (startTime==null||endTime==null) {
|
||||||
return "";
|
return "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user