diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java index ebdc556b..8c97e375 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java @@ -161,11 +161,13 @@ public RespModel> searchFindAll(@RequestParam(name = "proj @Operation(summary = "复制步骤", description = "测试用例复制其中一个步骤") @Parameters(value = { @Parameter(name = "id", description = "用例中需要被复制步骤Id"), + @Parameter(name = "toLast", description = "是否拷贝用例到最后一行", example = "true"), }) @GetMapping("/copy/steps") - public RespModel copyStepsIdByCase(@RequestParam(name = "id") int stepId) { - stepsService.copyStepsIdByCase(stepId); - + public RespModel copyStepsIdByCase(@RequestParam(name = "id") int stepId, + @RequestParam(name = "toLast", defaultValue = "true", required = false) + boolean toLast) { + stepsService.copyStepsIdByCase(stepId, toLast); return new RespModel<>(RespEnum.COPY_OK); } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java index d9872b0a..31f7044d 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java @@ -69,7 +69,7 @@ public interface StepsService extends IService { CommentPage searchFindByProjectIdAndPlatform(int projectId, int platform, int page, int pageSize, String searchContent); - Boolean copyStepsIdByCase(Integer stepId); + Boolean copyStepsIdByCase(Integer stepId, boolean toLast); Boolean switchStep(int id, int type); diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java index d0f33a5f..1261774e 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java @@ -348,8 +348,9 @@ public CommentPage searchFindByProjectIdAndPlatform(int projectId, int @Override @Transactional(rollbackFor = Exception.class) - public Boolean copyStepsIdByCase(Integer stepId) { + public Boolean copyStepsIdByCase(Integer stepId, boolean toLast) { Steps steps = stepsMapper.selectById(stepId); + Integer originSortId = steps.getSort(); StepsDTO stepsCopyDTO = stepsService.handleStep(steps.convertTo(), false); save(steps.setId(null).setSort(stepsMapper.findMaxSort() + 1)); @@ -407,6 +408,17 @@ public Boolean copyStepsIdByCase(Integer stepId) { n++; } } + if (!toLast) { + // 插入到当前步骤的下一行,需要做特殊的排序逻辑处理 + StepSort tempStepSort = new StepSort(); + tempStepSort.setCaseId(steps.getCaseId()); + tempStepSort.setDirection("up"); + // 设置start为当前新增的步骤的sort + tempStepSort.setStartId(steps.getSort()); + // 设置end为之前复制出来的步骤的sort + tempStepSort.setEndId(originSortId); + sortSteps(tempStepSort); + } return true; }