部分接口提交
This commit is contained in:
parent
78d0ad8b52
commit
6b3aa6e39c
@ -1,5 +1,7 @@
|
||||
package cd.casic.ci.common.pipeline.resp.task;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ -20,7 +22,7 @@ public class TasksResp {
|
||||
private String taskName;
|
||||
|
||||
//@ApiProperty(name="values",desc="任务")
|
||||
private Object values;
|
||||
private JSONObject taskProperties;
|
||||
|
||||
//@ApiProperty(name="pipeline",desc="流水线id",eg="@selectOne")
|
||||
private String pipelineId;
|
||||
@ -32,7 +34,6 @@ public class TasksResp {
|
||||
private String stageId;
|
||||
|
||||
//@ApiProperty(name="task",desc="任务",eg="@selectOne")
|
||||
private Object task;
|
||||
|
||||
// 执行实例id
|
||||
private String instanceId;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cd.casic.ci.process.process.dataObject.task;
|
||||
|
||||
import lombok.Data;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@Data
|
||||
public class PipTask {
|
||||
@ -19,9 +20,6 @@ public class PipTask {
|
||||
//@ApiProperty(name="taskName",desc="顺序")
|
||||
private String taskName;
|
||||
|
||||
//@ApiProperty(name="values",desc="任务")
|
||||
private Object values;
|
||||
|
||||
//@ApiProperty(name="pipeline",desc="流水线id",eg="@selectOne")
|
||||
private String pipelineId;
|
||||
|
||||
@ -30,9 +28,8 @@ public class PipTask {
|
||||
|
||||
//@ApiProperty(name="stageId",desc="阶段",eg="@selectOne")
|
||||
private String stageId;
|
||||
|
||||
//@ApiProperty(name="task",desc="任务",eg="@selectOne")
|
||||
private Object task;
|
||||
// task节点配置
|
||||
private JSONObject taskProperties;
|
||||
|
||||
// 执行实例id
|
||||
private String instanceId;
|
||||
|
@ -73,7 +73,7 @@ public interface StageService {
|
||||
* @param stagesId 根节点id
|
||||
* @return 从节点列表
|
||||
*/
|
||||
List<PipStage> findOtherStage(String stagesId);
|
||||
List<PipStage> findSecondStage(String stagesId);
|
||||
|
||||
/**
|
||||
* 更新阶段任务
|
||||
|
@ -11,13 +11,21 @@ import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
import cd.casic.ci.process.process.service.stage.StageService;
|
||||
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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jsoup.helper.W3CDom;
|
||||
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cd.casic.ci.process.constant.PipelineFinalConstant.TASK_TYPE_CODE;
|
||||
|
||||
@ -90,7 +98,7 @@ public class StageServiceImpl implements StageService {
|
||||
|
||||
//并行任务
|
||||
if (StringUtils.isNotEmpty(stagesId)&& stageSort == 0){
|
||||
List<PipStage> otherStage = findOtherStage(stagesId);
|
||||
List<PipStage> otherStage = findSecondStage(stagesId);
|
||||
PipStage oneStages = findOneStages(stagesId);
|
||||
PipStage stages = new PipStage();
|
||||
stages.setParentId(stagesId);
|
||||
@ -148,11 +156,34 @@ public class StageServiceImpl implements StageService {
|
||||
|
||||
@Override
|
||||
public List<StageResp> findAllStagesTask(String pipelineId) {
|
||||
return null;
|
||||
//获取流水线主节点
|
||||
List<PipStage> stageMainStage = findAllMainStage(pipelineId);
|
||||
if (stageMainStage.isEmpty()){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<StageResp> list = new ArrayList<>();
|
||||
for (PipStage stage : stageMainStage) {
|
||||
String stagesId = stage.getStageId();
|
||||
//获取从节点
|
||||
List<PipStage> allStageStage = findOtherStageNoTask(stagesId);
|
||||
List<StageResp> stageRespList = allStageStage.stream().map(it -> {
|
||||
StageResp stageResp = new StageResp();
|
||||
BeanUtils.copyProperties(stageResp, it);
|
||||
return stageResp;
|
||||
}).toList();
|
||||
StageResp stageResp = new StageResp();
|
||||
BeanUtils.copyProperties(stage,stageResp);
|
||||
stageResp.setStageList(stageRespList);
|
||||
list.add(stageResp);
|
||||
}
|
||||
list.sort(Comparator.comparing(StageResp::getStageSort));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStagesOrTask(String taskId) {
|
||||
PipTask pipTask = new PipTask();
|
||||
List<PipTask> taskById = taskService.getTask(pipTask);
|
||||
|
||||
}
|
||||
|
||||
@ -163,17 +194,21 @@ public class StageServiceImpl implements StageService {
|
||||
|
||||
@Override
|
||||
public void updateStageName(StageReq stage) {
|
||||
|
||||
LambdaUpdateWrapper<PipStage> wrapper = new LambdaUpdateWrapper<>();
|
||||
if (StringUtils.isEmpty(stage.getStageName())||StringUtils.isEmpty(stage.getStageId())) {
|
||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"阶段Id和名称蹦年为空");
|
||||
}
|
||||
wrapper.eq(PipStage::getStageId,stage.getStageId());
|
||||
wrapper.set(PipStage::getStageName,stage.getStageName());
|
||||
stageDao.update(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PipStage> findAllMainStage(String pipelineId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PipStage> findOtherStage(String stagesId) {
|
||||
return null;
|
||||
LambdaQueryWrapper<PipStage> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PipStage::getPipelineId,pipelineId);
|
||||
wrapper.eq(PipStage::getParentId,"-1");
|
||||
return stageDao.selectList(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -230,4 +265,23 @@ public class StageServiceImpl implements StageService {
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<PipStage> findOtherStageNoTask(String stagesId){
|
||||
List<PipStage> otherStage = findSecondStage(stagesId);
|
||||
List<PipStage> list = new ArrayList<>();
|
||||
for (PipStage stage : otherStage) {
|
||||
//获取阶段配置及任务
|
||||
String otherId = stage.getStageId();
|
||||
List<PipTask> allStageTask = taskService.finAllStageTask(otherId);
|
||||
stage.setTaskValues(allStageTask);
|
||||
list.add(stage);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
// 获取主stage(阶段)下的子stage
|
||||
@Override
|
||||
public List<PipStage> findSecondStage(String stageId){
|
||||
LambdaQueryWrapper<PipStage> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PipStage::getParentId,stageId);
|
||||
return stageDao.selectList(wrapper);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package cd.casic.ci.process.process.service.task;
|
||||
|
||||
import cd.casic.ci.common.pipeline.resp.task.TasksResp;
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public interface TaskService {
|
||||
@ -10,4 +12,6 @@ public interface TaskService {
|
||||
* */
|
||||
public void taskTypeExist(String taskType);
|
||||
public String createTasksOrTask(PipTask tasks);
|
||||
List<PipTask> finAllStageTask(String stageId);
|
||||
List<PipTask> getTask(PipTask pipTask);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import cd.casic.framework.commons.util.util.WebFrameworkUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
@ -96,6 +97,23 @@ public class TaskServiceImpl implements TaskService {
|
||||
createDifferentTask(tasksId,taskType,tasks.getValues());
|
||||
return tasksId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PipTask> finAllStageTask(String stageId) {
|
||||
LambdaQueryWrapper<PipTask> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PipTask::getStageId,stageId);
|
||||
return taskDao.selectList(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PipTask> getTask(PipTask task) {
|
||||
LambdaQueryWrapper<PipTask> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(StringUtils.isNotEmpty(task.getTaskId()),PipTask::getTaskId,task.getTaskId());
|
||||
wrapper.eq(StringUtils.isNotEmpty(task.getPipelineId()),PipTask::getPipelineId,task.getPipelineId());
|
||||
wrapper.eq(StringUtils.isNotEmpty(task.getStageId()),PipTask::getStageId,task.getStageId());
|
||||
return taskDao.selectList(wrapper);
|
||||
}
|
||||
|
||||
void createDifferentTask(String taskId,String taskType,Object values){
|
||||
// TODO
|
||||
}
|
||||
|
@ -56,223 +56,12 @@ public class StageController {
|
||||
@PermitAll
|
||||
@RequestMapping(path="/finAllStage",method = RequestMethod.POST)
|
||||
public CommonResult<List<StageResp>> finAllPipelineTaskOrTask(@NotNull String pipelineId){
|
||||
// List<Stage> tasks = stageService.findAllStagesTask(pipelineId);
|
||||
String taskStr = "[\n" +
|
||||
" {\n" +
|
||||
" \"stageId\": \"36a816ca6cca\",\n" +
|
||||
" \"stageName\": \"源码\",\n" +
|
||||
" \"createTime\": \"2024-11-25 11:09:35\",\n" +
|
||||
" \"pipelineId\": \"a69119cfbbde\",\n" +
|
||||
" \"stageSort\": 1,\n" +
|
||||
" \"parentId\": null,\n" +
|
||||
" \"code\": true,\n" +
|
||||
" \"taskValues\": null,\n" +
|
||||
" \"stageList\": [\n" +
|
||||
" {\n" +
|
||||
" \"stageId\": \"8cde3a5616e9\",\n" +
|
||||
" \"stageName\": \"源码\",\n" +
|
||||
" \"createTime\": \"2024-11-25 11:09:35\",\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"stageSort\": 1,\n" +
|
||||
" \"parentId\": \"36a816ca6cca\",\n" +
|
||||
" \"code\": false,\n" +
|
||||
" \"taskValues\": [\n" +
|
||||
" {\n" +
|
||||
" \"taskId\": \"a68e6052db9f\",\n" +
|
||||
" \"createTime\": \"2024-11-25 11:09:35\",\n" +
|
||||
" \"taskType\": \"git\",\n" +
|
||||
" \"taskSort\": 1,\n" +
|
||||
" \"taskName\": \"通用Git\",\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"postprocessId\": null,\n" +
|
||||
" \"stageId\": \"8cde3a5616e9\",\n" +
|
||||
" \"task\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"stageList\": null,\n" +
|
||||
" \"taskType\": null,\n" +
|
||||
" \"taskId\": null,\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"taskSort\": 0,\n" +
|
||||
" \"parallelName\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"taskType\": null,\n" +
|
||||
" \"taskId\": null,\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"taskSort\": 0,\n" +
|
||||
" \"parallelName\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"stageId\": \"3b1a5fdd9b6c\",\n" +
|
||||
" \"stageName\": \"阶段-2\",\n" +
|
||||
" \"createTime\": \"2025-03-10 14:51:43\",\n" +
|
||||
" \"pipelineId\": \"a69119cfbbde\",\n" +
|
||||
" \"stageSort\": 2,\n" +
|
||||
" \"parentId\": null,\n" +
|
||||
" \"code\": false,\n" +
|
||||
" \"taskValues\": null,\n" +
|
||||
" \"stageList\": [\n" +
|
||||
" {\n" +
|
||||
" \"stageId\": \"f35b1e576e30\",\n" +
|
||||
" \"stageName\": \"并行阶段-2-1\",\n" +
|
||||
" \"createTime\": \"2025-03-10 14:51:43\",\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"stageSort\": 1,\n" +
|
||||
" \"parentId\": \"3b1a5fdd9b6c\",\n" +
|
||||
" \"code\": false,\n" +
|
||||
" \"taskValues\": [\n" +
|
||||
" {\n" +
|
||||
" \"taskId\": \"21a965370481\",\n" +
|
||||
" \"createTime\": \"2025-03-10 14:51:43\",\n" +
|
||||
" \"taskType\": \"maven\",\n" +
|
||||
" \"taskSort\": 1,\n" +
|
||||
" \"taskName\": \"Maven构建\",\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"postprocessId\": null,\n" +
|
||||
" \"stageId\": \"f35b1e576e30\",\n" +
|
||||
" \"task\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"stageList\": null,\n" +
|
||||
" \"taskType\": null,\n" +
|
||||
" \"taskId\": null,\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"taskSort\": 0,\n" +
|
||||
" \"parallelName\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"taskType\": null,\n" +
|
||||
" \"taskId\": null,\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"taskSort\": 0,\n" +
|
||||
" \"parallelName\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"stageId\": \"871c1b69efe0\",\n" +
|
||||
" \"stageName\": \"阶段-3\",\n" +
|
||||
" \"createTime\": \"2025-03-10 14:52:27\",\n" +
|
||||
" \"pipelineId\": \"a69119cfbbde\",\n" +
|
||||
" \"stageSort\": 3,\n" +
|
||||
" \"parentId\": null,\n" +
|
||||
" \"code\": false,\n" +
|
||||
" \"taskValues\": null,\n" +
|
||||
" \"stageList\": [\n" +
|
||||
" {\n" +
|
||||
" \"stageId\": \"63676c8428e6\",\n" +
|
||||
" \"stageName\": \"并行阶段-3-1\",\n" +
|
||||
" \"createTime\": \"2025-03-10 14:52:27\",\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"stageSort\": 1,\n" +
|
||||
" \"parentId\": \"871c1b69efe0\",\n" +
|
||||
" \"code\": false,\n" +
|
||||
" \"taskValues\": [\n" +
|
||||
" {\n" +
|
||||
" \"taskId\": \"b5eaf0832ff1\",\n" +
|
||||
" \"createTime\": \"2025-03-10 14:52:27\",\n" +
|
||||
" \"taskType\": \"liunx\",\n" +
|
||||
" \"taskSort\": 1,\n" +
|
||||
" \"taskName\": \"主机部署\",\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"postprocessId\": null,\n" +
|
||||
" \"stageId\": \"63676c8428e6\",\n" +
|
||||
" \"task\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"taskId\": \"cf756d646758\",\n" +
|
||||
" \"createTime\": \"2025-05-10 14:17:52\",\n" +
|
||||
" \"taskType\": \"script\",\n" +
|
||||
" \"taskSort\": 2,\n" +
|
||||
" \"taskName\": \"执行脚本\",\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"postprocessId\": null,\n" +
|
||||
" \"stageId\": \"63676c8428e6\",\n" +
|
||||
" \"task\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"stageList\": null,\n" +
|
||||
" \"taskType\": null,\n" +
|
||||
" \"taskId\": null,\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"taskSort\": 0,\n" +
|
||||
" \"parallelName\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"stageId\": \"e9e4ac139f7b\",\n" +
|
||||
" \"stageName\": \"并行阶段-3-2\",\n" +
|
||||
" \"createTime\": \"2025-04-30 20:29:23\",\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"stageSort\": 2,\n" +
|
||||
" \"parentId\": \"871c1b69efe0\",\n" +
|
||||
" \"code\": false,\n" +
|
||||
" \"taskValues\": [\n" +
|
||||
" {\n" +
|
||||
" \"taskId\": \"e46283a4b6d1\",\n" +
|
||||
" \"createTime\": \"2025-04-30 20:29:23\",\n" +
|
||||
" \"taskType\": \"script\",\n" +
|
||||
" \"taskSort\": 1,\n" +
|
||||
" \"taskName\": \"执行脚本\",\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"postprocessId\": null,\n" +
|
||||
" \"stageId\": \"e9e4ac139f7b\",\n" +
|
||||
" \"task\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"taskId\": \"40740f834ce8\",\n" +
|
||||
" \"createTime\": \"2025-05-10 14:17:17\",\n" +
|
||||
" \"taskType\": \"script\",\n" +
|
||||
" \"taskSort\": 2,\n" +
|
||||
" \"taskName\": \"执行脚本\",\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"pipelineId\": null,\n" +
|
||||
" \"postprocessId\": null,\n" +
|
||||
" \"stageId\": \"e9e4ac139f7b\",\n" +
|
||||
" \"task\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"stageList\": null,\n" +
|
||||
" \"taskType\": null,\n" +
|
||||
" \"taskId\": null,\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"taskSort\": 0,\n" +
|
||||
" \"parallelName\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"taskType\": null,\n" +
|
||||
" \"taskId\": null,\n" +
|
||||
" \"values\": null,\n" +
|
||||
" \"taskSort\": 0,\n" +
|
||||
" \"parallelName\": null,\n" +
|
||||
" \"instanceId\": null\n" +
|
||||
" }\n" +
|
||||
"]";
|
||||
JSONArray objects = JSON.parseArray(taskStr);
|
||||
List<StageResp> tasks = new ArrayList<>(objects.size());
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
StageResp object = objects.getObject(i, StageResp.class);
|
||||
tasks.add(object);
|
||||
}
|
||||
return CommonResult.success(tasks);
|
||||
List<StageResp> stageRespList = stageService.findAllStagesTask(pipelineId);
|
||||
return CommonResult.success(stageRespList);
|
||||
}
|
||||
|
||||
/**
|
||||
* // TODO 暂时没发现哪里调用
|
||||
* @pi.name:更新流水线阶段任务
|
||||
* @pi.path:/stage/createStage
|
||||
* @pi.methodType:post
|
||||
@ -281,7 +70,7 @@ public class StageController {
|
||||
*/
|
||||
@RequestMapping(path="/updateStage",method = RequestMethod.POST)
|
||||
public CommonResult<Void> updateStageTask(@RequestBody @Valid @NotNull StageReq stage){
|
||||
// stageService.updateStagesTask(stage);
|
||||
stageService.updateStagesTask(stage);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
@ -295,7 +84,7 @@ public class StageController {
|
||||
@PermitAll
|
||||
@RequestMapping(path="/updateStageName",method = RequestMethod.POST)
|
||||
public CommonResult<Void> updateTasksStage(@RequestBody @Valid @NotNull StageReq stage){
|
||||
// stageService.updateStageName(stage);
|
||||
stageService.updateStageName(stage);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
@ -308,7 +97,7 @@ public class StageController {
|
||||
*/
|
||||
@RequestMapping(path="/deleteStage",method = RequestMethod.POST)
|
||||
public CommonResult<Void> deleteTasksOrStage(@NotNull String taskId){
|
||||
// stageService.deleteStagesOrTask(taskId);
|
||||
stageService.deleteStagesOrTask(taskId);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user