Skip to content

Commit

Permalink
Merge pull request #379 from caofengbin/feature/支持从任意行添加或复制步骤
Browse files Browse the repository at this point in the history
feat:支持从任意行添加或复制步骤
  • Loading branch information
ZhouYixun authored Sep 4, 2023
2 parents 96a65a9 + 3db19f6 commit 51e7d7e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ public RespModel<CommentPage<StepsDTO>> 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<String> copyStepsIdByCase(@RequestParam(name = "id") int stepId) {
stepsService.copyStepsIdByCase(stepId);

public RespModel<String> 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);
}

Expand All @@ -184,4 +186,33 @@ public RespModel switchStep(@RequestParam(name = "id") int id, @RequestParam(nam
}
}

@WebAspect
@Operation(summary = "将新增的步骤排序到指定的步骤之前或之后", description = "将当前用例的最后一个步骤拖拽到指定步骤之前或之后")
@GetMapping("/stepSortTarget")
public RespModel<String> stepSortTarget(@RequestParam(name = "targetStepId") int targetStepId,
@RequestParam(name = "addToTargetNext", defaultValue = "false")
boolean addToTargetNext) {
StepsDTO stepsDTO = stepsService.findById(targetStepId);
StepSort stepSort = new StepSort();
stepSort.setDirection("up");
stepSort.setCaseId(stepsDTO.getCaseId());
// startId 要设置为当前用例中最大的sort
Integer maxStepSort = stepsService.findMaxStepSort(stepsDTO.getCaseId());
stepSort.setStartId(maxStepSort);
// endId 取决于添加到目标step的前面,还是目标step的后面
if (addToTargetNext) {
Integer nextStepSort = stepsService.findNextStepSort(stepsDTO.getCaseId(), targetStepId);
if (nextStepSort == null) {
// 已经是最后一个step了,直接返回
return new RespModel<>(RespEnum.UPDATE_OK);
} else {
stepSort.setEndId(nextStepSort);
}
} else {
stepSort.setEndId(stepsDTO.getSort());
}
stepsService.sortSteps(stepSort);
return new RespModel<>(RespEnum.UPDATE_OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,27 @@ public interface StepsService extends IService<Steps> {
CommentPage<StepsDTO> 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);

List<PublicStepsAndStepsIdDTO> stepAndIndex(List<StepsDTO> needAllCopySteps);

/**
* 找到指定用例中最后一个步骤的sort
*
* @param castId 用例的id
* @return 最后一个步骤的sort
*/
Integer findMaxStepSort(int castId);

/**
* 找到指定用例的指定步骤,下一个step的sort值
*
* @param castId 目标用例
* @param targetStepId 目标步骤id
* @return 下一个step的sort值
*/
Integer findNextStepSort(int castId, int targetStepId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,9 @@ public CommentPage<StepsDTO> 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));
Expand Down Expand Up @@ -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;
}

Expand All @@ -422,6 +434,30 @@ public Boolean switchStep(int id, int type) {
}
}

@Override
public Integer findMaxStepSort(int castId) {
List<Steps> stepsList = lambdaQuery().eq(Steps::getCaseId, castId)
.orderByDesc(Steps::getSort)
.list();
if (stepsList != null && stepsList.size() > 0) {
return stepsList.get(0).getSort();
} else {
return null;
}
}

@Override
public Integer findNextStepSort(int castId, int targetStepId) {
List<Steps> stepsList = lambdaQuery().eq(Steps::getCaseId, castId)
.orderByAsc(Steps::getSort)
.list();
for (int i = 0; i < stepsList.size(); i++) {
if (stepsList.get(i).getId() == targetStepId) {
return i == stepsList.size() - 1 ? null : stepsList.get(i + 1).getSort();
}
}
return null;
}

/**
* 记录一组步骤中他们所在的位置;ma
Expand Down

0 comments on commit 51e7d7e

Please sign in to comment.