Compare commits
3 Commits
82a0f0d341
...
b71023318b
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b71023318b | ||
![]() |
13b8c8185e | ||
![]() |
f7533f9ff3 |
@ -7,6 +7,7 @@ import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
||||
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@ -81,6 +82,6 @@ public interface StageService extends IService<PipStage> {
|
||||
void deleteStages(String stageId);
|
||||
|
||||
|
||||
void createStagesOrTaskList(@Valid @NotNull List<StageCreateReq> stageList);
|
||||
void copyStage(@NotEmpty String stageId);
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cd.casic.ci.process.process.service.stage.impl;
|
||||
|
||||
import cd.casic.ci.common.pipeline.req.stage.StageCreateReq;
|
||||
import cd.casic.ci.common.pipeline.req.stage.StageReq;
|
||||
import cd.casic.ci.common.pipeline.req.stage.StageUpdateReq;
|
||||
import cd.casic.ci.common.pipeline.req.task.TaskCreateReq;
|
||||
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
||||
|
||||
@ -27,10 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cd.casic.ci.process.constant.PipelineFinalConstant.TASK_TYPE_CODE;
|
||||
@ -84,7 +82,6 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
updateBatchById(otherStageList);
|
||||
}
|
||||
save(firstStage);
|
||||
// firstStage
|
||||
} else {
|
||||
PipStage stageQuery = new PipStage();
|
||||
stageQuery.setStageId(firstStageId);
|
||||
@ -220,7 +217,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
|
||||
@Override
|
||||
public void deleteAllStagesOrTask(String pipelineId) {
|
||||
|
||||
// TODO 删除流水线,不知道要不要
|
||||
}
|
||||
|
||||
public List<PipStage> getPipStageList(PipStage pipStage){
|
||||
@ -305,13 +302,54 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
stageDao.deleteById(stageId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createStagesOrTaskList(List<StageCreateReq> stageList) {
|
||||
if (!ObjectUtils.isEmpty(stageList)){
|
||||
stageList.forEach(this::createStagesOrTask);
|
||||
@Transactional
|
||||
public void copyStage(String stageId) {
|
||||
// 查询当前stage(阶段下所有)
|
||||
PipStage firstStage = getById(stageId);
|
||||
Long loginUserId = WebFrameworkUtils.getLoginUserId();
|
||||
List<PipStage> allMainStage = findAllMainStage(firstStage.getPipelineId());
|
||||
List<PipStage> updateStageList = new ArrayList<>(allMainStage.size());
|
||||
for (PipStage stage : allMainStage) {
|
||||
if (stage.getStageSort()>firstStage.getStageSort()) {
|
||||
stage.setStageSort(stage.getStageSort()+1);
|
||||
updateStageList.add(stage);
|
||||
}
|
||||
}
|
||||
// 保存复制后的阶段,除了id和sort其他都一样
|
||||
firstStage.setStageId(null);
|
||||
firstStage.setStageSort(firstStage.getStageSort()+1);
|
||||
save(firstStage);
|
||||
updateBatchById(updateStageList);
|
||||
// 查询阶段下所有分支
|
||||
List<PipStage> secondStageList = findSecondStage(stageId);
|
||||
if (!CollectionUtils.isEmpty(secondStageList)) {
|
||||
List<String> stageIdList = secondStageList.stream().map(PipStage::getStageId).toList();
|
||||
List<PipTask> taskList = taskService.listByIds(stageIdList);
|
||||
Map<String, List<PipTask>> stageIdMap = taskList.stream().collect(Collectors.groupingBy(PipTask::getStageId));
|
||||
for (PipStage secondStage : secondStageList) {
|
||||
secondStage.setCreateUserId(loginUserId);
|
||||
secondStage.setCreateTime(LocalDateTime.now());
|
||||
secondStage.setUpdateTime(LocalDateTime.now());
|
||||
secondStage.setUpdateUserId(loginUserId);
|
||||
secondStage.setParentId(firstStage.getStageId());
|
||||
String secondStageId = secondStage.getStageId();
|
||||
List<PipTask> childTask = stageIdMap.get(secondStageId);
|
||||
secondStage.setStageId(null);
|
||||
save(secondStage);
|
||||
for (PipTask pipTask : childTask) {
|
||||
pipTask.setStageId(secondStage.getStageId());
|
||||
pipTask.setTaskId(null);
|
||||
pipTask.setCreateUserId(loginUserId);
|
||||
pipTask.setCreateTime(LocalDateTime.now());
|
||||
pipTask.setUpdateTime(LocalDateTime.now());
|
||||
pipTask.setUpdateUserId(loginUserId);
|
||||
}
|
||||
taskService.saveBatch(childTask);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<PipStage> findOtherStageNoTask(String stagesId){
|
||||
List<PipStage> otherStage = findSecondStage(stagesId);
|
||||
|
@ -12,6 +12,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
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.*;
|
||||
@ -84,7 +85,14 @@ public class StageController {
|
||||
stageService.deleteStagesOrTask(taskId);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制stage节点
|
||||
* */
|
||||
@PostMapping(path="/copyStage")
|
||||
public CommonResult<Void> copyStage(@NotEmpty String stageId){
|
||||
stageService.copyStage(stageId);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user