复制阶段
This commit is contained in:
parent
13b8c8185e
commit
b71023318b
@ -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);
|
||||
@ -306,8 +303,52 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
@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){
|
||||
|
@ -90,7 +90,8 @@ public class StageController {
|
||||
* */
|
||||
@PostMapping(path="/copyStage")
|
||||
public CommonResult<Void> copyStage(@NotEmpty String stageId){
|
||||
return null;
|
||||
stageService.copyStage(stageId);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user