模板方法CV
This commit is contained in:
parent
0be3b9594f
commit
086ccf5f52
@ -77,7 +77,7 @@ public class StageController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping(path="/deleteTasksOrStage/{taskId}")
|
@PostMapping(path="/deleteTasksOrStage/{taskId}")
|
||||||
public CommonResult<Void> deleteTasksOrStage(@NotNull@PathVariable String taskId){
|
public CommonResult<Void> deleteTasksOrStage(@NotNull@PathVariable String taskId){
|
||||||
stageService.deleteStagesOrTask(taskId);
|
stageService.deleteStagesAndTask(taskId);
|
||||||
return CommonResult.success();
|
return CommonResult.success();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,129 @@
|
|||||||
|
package cd.casic.ci.api;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.stage.StageCreateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.stage.StageUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateStageCreateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateStageUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.context.SingletonRunContextResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.stage.StageResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateStageResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateStage;
|
||||||
|
import cd.casic.ci.process.process.service.stage.StageService;
|
||||||
|
import cd.casic.ci.process.process.service.template.TemplateStageService;
|
||||||
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pi.protocol: http
|
||||||
|
* @pi.groupName: 流水线多阶段控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/templateStage")
|
||||||
|
public class TemplateStageController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TemplateStageService stageService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pi.name:创建流水线阶段及任务
|
||||||
|
* @pi.path:/stage/createStage
|
||||||
|
* @pi.methodType:post
|
||||||
|
* @pi.request-type:json
|
||||||
|
* @pi.param: model=stage
|
||||||
|
*/
|
||||||
|
@PostMapping(path="/createStage")
|
||||||
|
public CommonResult<String> createStagesOrTask(@RequestBody TemplateStageCreateReq stage){
|
||||||
|
String taskId = stageService.createStagesOrTask(stage);
|
||||||
|
return CommonResult.success(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pi.name:查询流水线阶段信息
|
||||||
|
* @pi.path:/stage/finAllStage
|
||||||
|
* @pi.methodType:post
|
||||||
|
* @pi.request-type: formdata
|
||||||
|
* @pi.param: name=pipelineId;dataType=string;value=pipelineId;
|
||||||
|
*/
|
||||||
|
@PermitAll
|
||||||
|
@PostMapping(path="/findAllStage/{templateId}")
|
||||||
|
public CommonResult<List<TemplateStageResp>> findAllPipelineTaskOrTask(@NotNull @PathVariable String templateId){
|
||||||
|
List<TemplateStageResp> stageRespList = stageService.findAllStagesTask(templateId);
|
||||||
|
return CommonResult.success(stageRespList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pi.name:更新流水线阶段任务名称Or移动流水线阶段
|
||||||
|
* @pi.path:/stage/createStage
|
||||||
|
* @pi.methodType:post
|
||||||
|
* @pi.request-type:json
|
||||||
|
* @pi.param: model=stage
|
||||||
|
*/
|
||||||
|
@PostMapping(path="/updateStage")
|
||||||
|
public CommonResult<Void> updateStageTask(@RequestBody @Valid @NotNull TemplateStageUpdateReq stage){
|
||||||
|
stageService.updateStagesTask(stage);
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pi.name:删除流水线阶段及任务
|
||||||
|
* @pi.path:/stage/deleteStage
|
||||||
|
* @pi.methodType:post
|
||||||
|
* @pi.request-type: formdata
|
||||||
|
* @pi.param: name=taskId;dataType=string;value=taskId;
|
||||||
|
*/
|
||||||
|
@PostMapping(path="/deleteTasksOrStage/{taskId}")
|
||||||
|
public CommonResult<Void> deleteTasksOrStage(@NotNull@PathVariable String taskId){
|
||||||
|
stageService.deleteStagesAndTask(taskId);
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
// /**
|
||||||
|
// * 复制stage节点
|
||||||
|
// * */
|
||||||
|
// @PostMapping(path="/copyStage/{stageId}")
|
||||||
|
// public CommonResult<Void> copyStage(@NotEmpty@PathVariable String stageId){
|
||||||
|
// stageService.copyStage(stageId);
|
||||||
|
// return CommonResult.success();
|
||||||
|
// }
|
||||||
|
@PostMapping("/deleteFirstStage/{stageId}")
|
||||||
|
public CommonResult<Void> deleteFirstStage(@PathVariable String stageId){
|
||||||
|
stageService.deleteFirstStage(stageId);
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
package cd.casic.ci.api;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.task.TaskUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateTaskUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.task.TasksResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateTasksResp;
|
||||||
|
import cd.casic.ci.process.process.service.task.TaskService;
|
||||||
|
import cd.casic.ci.process.process.service.template.TemplateTaskService;
|
||||||
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/templateTask")
|
||||||
|
public class TemplateTasksController {
|
||||||
|
@Resource
|
||||||
|
private TemplateTaskService taskService;
|
||||||
|
/**
|
||||||
|
* @pi.name:查询任务及任务详情
|
||||||
|
* @pi.path:/tasks/findOneTasksOrTask
|
||||||
|
* @pi.methodType:post
|
||||||
|
* @pi.request-type: formdata
|
||||||
|
* @pi.param: name=taskId;dataType=string;value=taskId;
|
||||||
|
*/
|
||||||
|
@PostMapping(path="/findOneTasksOrTask/{taskId}")
|
||||||
|
public CommonResult<TemplateTasksResp> findOneTasksOrTask(@NotNull @PathVariable String taskId){
|
||||||
|
return CommonResult.success(taskService.getRespById(taskId));
|
||||||
|
}
|
||||||
|
// /**
|
||||||
|
// * 复制task节点
|
||||||
|
// * */
|
||||||
|
// @PostMapping(path="/copyTask/{taskId}")
|
||||||
|
// public CommonResult<Void> copyTask(@NotEmpty @PathVariable String taskId){
|
||||||
|
// taskService.copyTask(taskId);
|
||||||
|
// return CommonResult.success();
|
||||||
|
// }
|
||||||
|
@PostMapping(path="/updateTask")
|
||||||
|
public CommonResult<Boolean> updateTask(@RequestBody TemplateTaskUpdateReq req){
|
||||||
|
Boolean b = taskService.updateTask(req);
|
||||||
|
return CommonResult.success(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package cd.casic.ci.process.dto.req.template;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.task.TaskCreateReq;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TemplateStageCreateReq {
|
||||||
|
// 阶段stageId
|
||||||
|
private String stageId;
|
||||||
|
// 如果需要新增阶段则传这个
|
||||||
|
private Integer stageSort;
|
||||||
|
private TemplateTaskCreateReq task;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package cd.casic.ci.process.dto.req.template;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TemplateStageUpdateReq {
|
||||||
|
// 更新名称
|
||||||
|
private String stageName;
|
||||||
|
// 更新sort
|
||||||
|
private Integer stageSort;
|
||||||
|
private String id;
|
||||||
|
private String pipelineId;
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cd.casic.ci.process.dto.req.template;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TemplateTaskCreateReq {
|
||||||
|
// 第二级stageId,如果没有值则新建第二级stage
|
||||||
|
private String stageId;
|
||||||
|
private String taskName;
|
||||||
|
private String templateId;
|
||||||
|
private String taskType;
|
||||||
|
private Integer taskSort;
|
||||||
|
private Map<String,Object> taskProperties;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cd.casic.ci.process.dto.req.template;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TemplateTaskUpdateReq {
|
||||||
|
// 第二级stageId,如果没有值则新建第二级stage
|
||||||
|
private String id;
|
||||||
|
private String taskName;
|
||||||
|
private String taskType;
|
||||||
|
private Map<String,Object> taskProperties;
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package cd.casic.ci.process.process.converter;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.resp.stage.StageResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateStageResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateStage;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface TemplateStageConverter {
|
||||||
|
TemplateStageConverter INSTANCE = Mappers.getMapper(TemplateStageConverter.class);
|
||||||
|
public TemplateStageResp converter(TemplateStage stage);
|
||||||
|
public List<TemplateStageResp> converter(List<TemplateStage> stage);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cd.casic.ci.process.process.converter;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.resp.task.TasksResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateTasksResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateTask;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface TemplateTaskConverter {
|
||||||
|
TemplateTaskConverter INSTANCE = Mappers.getMapper(TemplateTaskConverter.class);
|
||||||
|
TemplateTasksResp doToResp(TemplateTask task);
|
||||||
|
}
|
@ -31,10 +31,12 @@ public interface StageService extends IService<PipStage> {
|
|||||||
List<PipStage> findAllFirstStagesAndChild(String pipelineId);
|
List<PipStage> findAllFirstStagesAndChild(String pipelineId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除阶段及任务
|
* 删除阶段及任务,如果当前节点是当前阶段最后一个节点,
|
||||||
|
* 会自动删除阶段
|
||||||
|
*
|
||||||
* @param taskId 配置id
|
* @param taskId 配置id
|
||||||
*/
|
*/
|
||||||
void deleteStagesOrTask(String taskId);
|
void deleteStagesAndTask(String taskId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除流水线所有阶段
|
* 删除流水线所有阶段
|
||||||
|
@ -189,7 +189,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteStagesOrTask(String taskId) {
|
public void deleteStagesAndTask(String taskId) {
|
||||||
PipTask taskQuery = new PipTask();
|
PipTask taskQuery = new PipTask();
|
||||||
taskQuery.setId(taskId);
|
taskQuery.setId(taskId);
|
||||||
List<PipTask> taskList = taskService.getTask(taskQuery);
|
List<PipTask> taskList = taskService.getTask(taskQuery);
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package cd.casic.ci.process.process.service.template;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.stage.StageCreateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.stage.StageUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateStageCreateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateStageUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.stage.StageResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateStageResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateStage;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface TemplateStageService extends IService<TemplateStage> {
|
||||||
|
/**
|
||||||
|
* 创建阶段及关联任务
|
||||||
|
* @param stage 阶段信息
|
||||||
|
* @return 阶段id
|
||||||
|
*/
|
||||||
|
String createStagesOrTask(TemplateStageCreateReq stage);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有阶段任务
|
||||||
|
* @param templateId 流水线id
|
||||||
|
* @return 任务
|
||||||
|
*/
|
||||||
|
List<TemplateStageResp> findAllStagesTask(String templateId);
|
||||||
|
List<TemplateStage> findAllFirstStagesAndChild(String templateId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void deleteFirstStage(String stageId);
|
||||||
|
/**
|
||||||
|
* 删除阶段及任务
|
||||||
|
* @param taskId 配置id
|
||||||
|
*/
|
||||||
|
void deleteStagesAndTask(String taskId);
|
||||||
|
|
||||||
|
public void updateStagesTask(TemplateStageUpdateReq stage);
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cd.casic.ci.process.process.service.template;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.task.TaskUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateTaskUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.task.TasksResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateTasksResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateTask;
|
||||||
|
import cd.casic.ci.process.util.WebFrameworkUtils;
|
||||||
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface TemplateTaskService extends IService<TemplateTask> {
|
||||||
|
List<TemplateTask> getTask(TemplateTask pipTask);
|
||||||
|
List<TemplateTask> getTaskByStageIdList(List<String> stageIdList);
|
||||||
|
TemplateTasksResp getRespById(String taskId);
|
||||||
|
public Boolean updateTask(TemplateTaskUpdateReq req);
|
||||||
|
}
|
@ -0,0 +1,368 @@
|
|||||||
|
package cd.casic.ci.process.process.service.template.impl;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.stage.StageUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateStageCreateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateStageUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateTaskCreateReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateStageResp;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.process.converter.TemplateStageConverter;
|
||||||
|
import cd.casic.ci.process.process.dao.template.TemplateStageDao;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateStage;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateTask;
|
||||||
|
import cd.casic.ci.process.process.service.template.TemplateStageService;
|
||||||
|
import cd.casic.ci.process.process.service.template.TemplateTaskService;
|
||||||
|
import cd.casic.ci.process.util.WebFrameworkUtils;
|
||||||
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
@Service
|
||||||
|
public class TemplateStageServiceImpl extends ServiceImpl<TemplateStageDao, TemplateStage> implements TemplateStageService {
|
||||||
|
@Resource
|
||||||
|
private TemplateStageDao stageDao;
|
||||||
|
@Resource
|
||||||
|
private TemplateTaskService templateTaskService;
|
||||||
|
@Resource
|
||||||
|
private TemplateStageConverter stageConverter;
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@Override
|
||||||
|
public String createStagesOrTask(TemplateStageCreateReq stageReq) {
|
||||||
|
String firstStageId = stageReq.getStageId();
|
||||||
|
Integer stageSort = stageReq.getStageSort();
|
||||||
|
TemplateTaskCreateReq task = stageReq.getTask();
|
||||||
|
String taskName = task.getTaskName();
|
||||||
|
String secondStageId = task.getStageId();
|
||||||
|
Map<String,Object> taskProperties = task.getTaskProperties();
|
||||||
|
String taskType = task.getTaskType();
|
||||||
|
Integer taskSort = task.getTaskSort();
|
||||||
|
String templateId = task.getTemplateId();
|
||||||
|
Long loginUserId = WebFrameworkUtils.getLoginUserId();
|
||||||
|
TemplateStage firstStage = null;
|
||||||
|
// 判断是否需要新建阶段,如果没有传第一级tageId而传了sort就是需要创建阶段
|
||||||
|
if (StringUtils.isEmpty(firstStageId)) {
|
||||||
|
// 新建stage
|
||||||
|
firstStage = new TemplateStage();
|
||||||
|
firstStage.setStageName("阶段-"+stageSort);
|
||||||
|
if (stageSort == null) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"参数有误");
|
||||||
|
}
|
||||||
|
firstStage.setStageSort(stageSort);
|
||||||
|
firstStage.setCreateTime(LocalDateTime.now());
|
||||||
|
firstStage.setParentId("-1");
|
||||||
|
firstStage.setTemplateId(templateId);
|
||||||
|
|
||||||
|
firstStage.setCreator(String.valueOf(loginUserId));
|
||||||
|
firstStage.setUpdater(String.valueOf(loginUserId));
|
||||||
|
firstStage.setUpdateTime(LocalDateTime.now());
|
||||||
|
TemplateStage stageQuery = new TemplateStage();
|
||||||
|
stageQuery.setTemplateId(templateId);
|
||||||
|
stageQuery.setParentId("-1");
|
||||||
|
List<TemplateStage> otherStageList = getTemplateStageList(stageQuery);
|
||||||
|
if (!CollectionUtils.isEmpty(otherStageList)) {
|
||||||
|
for (TemplateStage stage : otherStageList) {
|
||||||
|
if (stageSort<=stage.getStageSort()) {
|
||||||
|
stage.setStageSort(stage.getStageSort()+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateBatchById(otherStageList);
|
||||||
|
}
|
||||||
|
save(firstStage);
|
||||||
|
} else {
|
||||||
|
TemplateStage stageQuery = new TemplateStage();
|
||||||
|
stageQuery.setId(firstStageId);
|
||||||
|
stageQuery.setParentId("-1");
|
||||||
|
List<TemplateStage> pipStageList = getTemplateStageList(stageQuery);
|
||||||
|
if (!CollectionUtils.isEmpty(pipStageList)) {
|
||||||
|
firstStage = pipStageList.get(0);
|
||||||
|
} else {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"阶段不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (firstStage == null) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"创建节点失败");
|
||||||
|
}
|
||||||
|
TemplateStage secondStage = null;
|
||||||
|
if (secondStageId==null||taskSort==null) {
|
||||||
|
// 添加并行节点
|
||||||
|
secondStage = new TemplateStage();
|
||||||
|
TemplateStage stageQuery = new TemplateStage();
|
||||||
|
stageQuery.setParentId(firstStage.getId());
|
||||||
|
stageQuery.setTemplateId(templateId);
|
||||||
|
List<TemplateStage> pipStageList = getTemplateStageList(stageQuery);
|
||||||
|
if (CollectionUtils.isEmpty(pipStageList)) {
|
||||||
|
secondStage.setStageSort(1);
|
||||||
|
} else {
|
||||||
|
secondStage.setStageSort(pipStageList.size()+1);
|
||||||
|
}
|
||||||
|
secondStage.setCreateTime(LocalDateTime.now());
|
||||||
|
secondStage.setUpdateTime(LocalDateTime.now());
|
||||||
|
secondStage.setCreator(String.valueOf(loginUserId));
|
||||||
|
secondStage.setParentId(firstStage.getId());
|
||||||
|
secondStage.setTemplateId(templateId);
|
||||||
|
secondStage.setUpdater(String.valueOf(loginUserId));
|
||||||
|
save(secondStage);
|
||||||
|
taskSort=1;
|
||||||
|
secondStageId = secondStage.getId();
|
||||||
|
} else {
|
||||||
|
secondStage = getById(secondStageId);
|
||||||
|
}
|
||||||
|
if (secondStage == null) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"创建节点失败");
|
||||||
|
}
|
||||||
|
List<TemplateTask> taskValues = templateTaskService.getTaskByStageIdList(Arrays.asList(secondStage.getId()));
|
||||||
|
if (!CollectionUtils.isEmpty(taskValues)) {
|
||||||
|
for (TemplateTask taskValue : taskValues) {
|
||||||
|
if (taskValue.getTaskSort()>=taskSort) {
|
||||||
|
taskValue.setTaskSort(taskValue.getTaskSort()+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templateTaskService.updateBatchById(taskValues);
|
||||||
|
}
|
||||||
|
// 保存task
|
||||||
|
TemplateTask pipTask = new TemplateTask();
|
||||||
|
pipTask.setTaskType(taskType);
|
||||||
|
pipTask.setTaskSort(taskSort);
|
||||||
|
pipTask.setStageId(secondStageId);
|
||||||
|
pipTask.setTaskName(taskName);
|
||||||
|
pipTask.setCreateTime(LocalDateTime.now());
|
||||||
|
pipTask.setTaskProperties(taskProperties);
|
||||||
|
pipTask.setTemplateId(templateId);
|
||||||
|
pipTask.setUpdateTime(LocalDateTime.now());
|
||||||
|
pipTask.setCreator(String.valueOf(loginUserId));
|
||||||
|
pipTask.setUpdater(String.valueOf(loginUserId));
|
||||||
|
templateTaskService.save(pipTask);
|
||||||
|
return pipTask.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TemplateStageResp> findAllStagesTask(String pipelineId) {
|
||||||
|
//获取流水线主节点
|
||||||
|
List<TemplateStage> stageMainStage = findAllMainStage(pipelineId);
|
||||||
|
if (stageMainStage.isEmpty()){
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<TemplateStageResp> list = new ArrayList<>();
|
||||||
|
for (TemplateStage stage : stageMainStage) {
|
||||||
|
String stagesId = stage.getId();
|
||||||
|
//获取从节点
|
||||||
|
List<TemplateStage> allSecondStage = findSecondStageAndTask(stagesId);
|
||||||
|
List<TemplateStageResp> stageRespList = stageConverter.converter(allSecondStage);
|
||||||
|
TemplateStageResp stageResp = stageConverter.converter(stage);
|
||||||
|
stageResp.setStageList(stageRespList);
|
||||||
|
list.add(stageResp);
|
||||||
|
}
|
||||||
|
list.sort(Comparator.comparing(TemplateStageResp::getStageSort));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TemplateStage> findAllFirstStagesAndChild(String pipelineId) {
|
||||||
|
//获取流水线主节点
|
||||||
|
List<TemplateStage> stageMainStage = findAllMainStage(pipelineId);
|
||||||
|
if (stageMainStage.isEmpty()){
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
for (TemplateStage stage : stageMainStage) {
|
||||||
|
String stagesId = stage.getId();
|
||||||
|
//获取从节点
|
||||||
|
List<TemplateStage> allStageStage = findSecondStageAndTask(stagesId);
|
||||||
|
stage.setStageList(allStageStage);
|
||||||
|
}
|
||||||
|
stageMainStage.sort(Comparator.comparing(TemplateStage::getStageSort));
|
||||||
|
return stageMainStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteStagesAndTask(String taskId) {
|
||||||
|
TemplateTask taskQuery = new TemplateTask();
|
||||||
|
taskQuery.setId(taskId);
|
||||||
|
List<TemplateTask> taskList = templateTaskService.getTask(taskQuery);
|
||||||
|
if (CollectionUtils.isEmpty(taskList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TemplateTask task = taskList.get(0);
|
||||||
|
templateTaskService.removeById(taskId);
|
||||||
|
// 查询上一级stage下有无其他task 没有则连着stage删除
|
||||||
|
String stageId = task.getStageId();
|
||||||
|
String pipelineId = task.getTemplateId();
|
||||||
|
taskQuery = new TemplateTask();
|
||||||
|
taskQuery.setStageId(stageId);
|
||||||
|
List<TemplateTask> otherTask = templateTaskService.getTask(taskQuery);
|
||||||
|
if (CollectionUtils.isEmpty(otherTask)) {
|
||||||
|
// 删除当前task的父stage,然后判断父stage的父级有无其他子级如果没有就继续删除当前阶段
|
||||||
|
TemplateStage stageQuery = new TemplateStage();
|
||||||
|
stageQuery.setTemplateId(pipelineId);
|
||||||
|
stageQuery.setId(stageId);
|
||||||
|
List<TemplateStage> currStageList = getTemplateStageList(stageQuery);
|
||||||
|
if (CollectionUtils.isEmpty(currStageList)) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"stage不存在");
|
||||||
|
}
|
||||||
|
TemplateStage currStage = currStageList.get(0);
|
||||||
|
deleteStages(stageId);
|
||||||
|
String parentId = currStage.getParentId();
|
||||||
|
stageQuery = new TemplateStage();
|
||||||
|
stageQuery.setParentId(parentId);
|
||||||
|
// 查询同阶段其他二级stage,如果不存在其他stage则删除阶段stage并整理sort值
|
||||||
|
List<TemplateStage> otherStageList = getTemplateStageList(stageQuery);
|
||||||
|
if (CollectionUtils.isEmpty(otherStageList)) {
|
||||||
|
//没有其他并行路径就需要删除当前阶段
|
||||||
|
deleteStages(parentId);
|
||||||
|
} else {
|
||||||
|
for (TemplateStage stage : otherStageList) {
|
||||||
|
if (currStage.getStageSort()<stage.getStageSort()) {
|
||||||
|
stage.setStageSort(stage.getStageSort()-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateBatchById(otherStageList);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (TemplateTask pipTask : otherTask) {
|
||||||
|
if (task.getTaskSort()<pipTask.getTaskSort()) {
|
||||||
|
pipTask.setTaskSort(pipTask.getTaskSort()-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templateTaskService.updateBatchById(otherTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public List<TemplateStage> getTemplateStageList(TemplateStage pipStage){
|
||||||
|
LambdaQueryWrapper<TemplateStage> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(StringUtils.isNotEmpty(pipStage.getId()),TemplateStage::getId,pipStage.getId());
|
||||||
|
wrapper.eq(StringUtils.isNotEmpty(pipStage.getTemplateId()),TemplateStage::getTemplateId,pipStage.getTemplateId());
|
||||||
|
wrapper.eq(StringUtils.isNotEmpty(pipStage.getParentId()),TemplateStage::getParentId,pipStage.getParentId());
|
||||||
|
return stageDao.selectList(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<TemplateStage> findAllMainStage(String pipelineId) {
|
||||||
|
LambdaQueryWrapper<TemplateStage> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(TemplateStage::getTemplateId,pipelineId);
|
||||||
|
wrapper.eq(TemplateStage::getParentId,"-1");
|
||||||
|
return stageDao.selectList(wrapper);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updateStagesTask(TemplateStageUpdateReq stage) {
|
||||||
|
String id = stage.getId();
|
||||||
|
String stageName = stage.getStageName();
|
||||||
|
Integer currStageSort = stage.getStageSort();
|
||||||
|
Long loginUserId = WebFrameworkUtils.getLoginUserId();
|
||||||
|
TemplateStage updateStage = getById(id);
|
||||||
|
if (updateStage==null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateStage.setUpdater(String.valueOf(loginUserId));
|
||||||
|
updateStage.setUpdateTime(LocalDateTime.now());
|
||||||
|
if (currStageSort == null) {
|
||||||
|
updateStage.setStageName(stageName);
|
||||||
|
updateById(updateStage);
|
||||||
|
} else{
|
||||||
|
Integer oldStageSort = updateStage.getStageSort();
|
||||||
|
if (oldStageSort.equals(currStageSort)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TemplateStage query = new TemplateStage();
|
||||||
|
query.setTemplateId(updateStage.getTemplateId());
|
||||||
|
query.setParentId("-1");
|
||||||
|
List<TemplateStage> stageList = getTemplateStageList(query);
|
||||||
|
if (oldStageSort<currStageSort) {
|
||||||
|
// 往右移动
|
||||||
|
for (TemplateStage pipStage : stageList) {
|
||||||
|
if (!pipStage.getId().equals(updateStage.getId())) {
|
||||||
|
if (pipStage.getStageSort()>oldStageSort&&pipStage.getStageSort()<=currStageSort) {
|
||||||
|
pipStage.setStageSort(pipStage.getStageSort()-1);
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
pipStage.setStageSort(currStageSort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 往左移动
|
||||||
|
for (TemplateStage pipStage : stageList) {
|
||||||
|
if (!pipStage.getId().equals(updateStage.getId())) {
|
||||||
|
if (pipStage.getStageSort()<oldStageSort&&pipStage.getStageSort()>=currStageSort) {
|
||||||
|
pipStage.setStageSort(pipStage.getStageSort()+1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pipStage.setStageSort(currStageSort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateBatchById(stageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void deleteStages(String stageId) {
|
||||||
|
stageDao.deleteById(stageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteFirstStage(String stageId) {
|
||||||
|
List<TemplateStage> secondStageAndTask = findSecondStageAndTask(stageId);
|
||||||
|
for (TemplateStage stage : secondStageAndTask) {
|
||||||
|
List<TemplateTask> taskValues = stage.getTaskValues();
|
||||||
|
if (!CollectionUtils.isEmpty(taskValues)) {
|
||||||
|
List<String> taskIdList = taskValues.stream().map(TemplateTask::getId).toList();
|
||||||
|
templateTaskService.removeBatchByIds(taskIdList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> secondStageIdList = secondStageAndTask.stream().map(TemplateStage::getId).toList();
|
||||||
|
removeBatchByIds(secondStageIdList);
|
||||||
|
TemplateStage byId = getById(stageId);
|
||||||
|
List<TemplateStage> allMainStage = findAllMainStage(byId.getTemplateId());
|
||||||
|
List<TemplateStage> updateList = new ArrayList<>(allMainStage.size());
|
||||||
|
for (TemplateStage stage : allMainStage) {
|
||||||
|
if (byId.getStageSort()<stage.getStageSort()) {
|
||||||
|
stage.setStageSort(stage.getStageSort()-1);
|
||||||
|
updateList.add(stage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//如果删除的为最后一个新增阶段,则无需更新前面阶段的sort值
|
||||||
|
if (!CollectionUtils.isEmpty(updateList)){
|
||||||
|
stageDao.updateBatch(updateList);
|
||||||
|
}
|
||||||
|
stageDao.deleteById(stageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<TemplateStage> findSecondStageAndTask(String stagesId){
|
||||||
|
List<TemplateStage> otherStage = findSecondStage(stagesId);
|
||||||
|
List<TemplateStage> list = new ArrayList<>();
|
||||||
|
List<String> stageIdList = otherStage.stream().map(TemplateStage::getId).toList();
|
||||||
|
if (stageIdList.isEmpty()) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"当前阶段下不存在节点");
|
||||||
|
}
|
||||||
|
Map<String, List<TemplateTask>> stageIdTaskMap = templateTaskService.getTaskByStageIdList(stageIdList).stream().collect(Collectors.groupingBy(TemplateTask::getStageId));
|
||||||
|
for (TemplateStage stage : otherStage) {
|
||||||
|
//获取阶段配置及任务
|
||||||
|
String otherId = stage.getId();
|
||||||
|
List<TemplateTask> allStageTask = stageIdTaskMap.get(otherId);
|
||||||
|
allStageTask.sort(Comparator.comparing(TemplateTask::getTaskSort));
|
||||||
|
stage.setTaskValues(allStageTask);
|
||||||
|
list.add(stage);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
// 获取主stage(阶段)下的子stage
|
||||||
|
public List<TemplateStage> findSecondStage(String stageId){
|
||||||
|
LambdaQueryWrapper<TemplateStage> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(TemplateStage::getParentId,stageId);
|
||||||
|
return stageDao.selectList(wrapper);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package cd.casic.ci.process.process.service.template.impl;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.task.TaskUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.req.template.TemplateTaskUpdateReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.task.TasksResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.template.TemplateTasksResp;
|
||||||
|
import cd.casic.ci.process.process.converter.TemplateTaskConverter;
|
||||||
|
import cd.casic.ci.process.process.dao.template.TemplateTaskDao;
|
||||||
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
import cd.casic.ci.process.process.dataObject.template.TemplateTask;
|
||||||
|
import cd.casic.ci.process.process.service.template.TemplateTaskService;
|
||||||
|
import cd.casic.ci.process.util.WebFrameworkUtils;
|
||||||
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TemplateTaskServiceImpl extends ServiceImpl<TemplateTaskDao, TemplateTask> implements TemplateTaskService {
|
||||||
|
@Resource
|
||||||
|
private TemplateTaskDao taskDao;
|
||||||
|
@Resource
|
||||||
|
private TemplateTaskConverter taskConverter;
|
||||||
|
@Override
|
||||||
|
public List<TemplateTask> getTask(TemplateTask task) {
|
||||||
|
LambdaQueryWrapper<TemplateTask> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(StringUtils.isNotEmpty(task.getId()),TemplateTask::getId,task.getId());
|
||||||
|
wrapper.eq(StringUtils.isNotEmpty(task.getTemplateId()),TemplateTask::getTemplateId,task.getTemplateId());
|
||||||
|
wrapper.eq(StringUtils.isNotEmpty(task.getStageId()),TemplateTask::getStageId,task.getStageId());
|
||||||
|
return taskDao.selectList(wrapper);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public List<TemplateTask> getTaskByStageIdList(List<String> stageIdList){
|
||||||
|
LambdaQueryWrapper<TemplateTask> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.in(TemplateTask::getStageId,stageIdList);
|
||||||
|
return taskDao.selectList(wrapper);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public TemplateTasksResp getRespById(String taskId){
|
||||||
|
TemplateTask pipTask = new TemplateTask();
|
||||||
|
pipTask.setId(taskId);
|
||||||
|
List<TemplateTask> taskList = getTask(pipTask);
|
||||||
|
if (CollectionUtils.isEmpty(taskList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return taskConverter.doToResp(taskList.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateTask(TemplateTaskUpdateReq req) {
|
||||||
|
if (StringUtils.isEmpty(req.getId())) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"传入id有问题");
|
||||||
|
}
|
||||||
|
TemplateTask byId = getById(req.getId());
|
||||||
|
if (byId == null) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"task不存在");
|
||||||
|
}
|
||||||
|
String taskName = req.getTaskName();
|
||||||
|
Map<String, Object> taskProperties = req.getTaskProperties();
|
||||||
|
String taskType = req.getTaskType();
|
||||||
|
byId.setTaskProperties(taskProperties);
|
||||||
|
byId.setTaskType(taskType);
|
||||||
|
byId.setTaskName(taskName);
|
||||||
|
byId.setUpdater(WebFrameworkUtils.getLoginUserIdStr());
|
||||||
|
byId.setUpdateTime(LocalDateTime.now());
|
||||||
|
return updateById(byId);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user