Skip to content

Commit

Permalink
后端接口实现将新增加的步骤,自动添加到指定步骤的上面或下面
Browse files Browse the repository at this point in the history
  • Loading branch information
caofengbin committed Sep 4, 2023
1 parent c5a541e commit 3db19f6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,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 @@ -74,4 +74,22 @@ CommentPage<StepsDTO> searchFindByProjectIdAndPlatform(int projectId, int platfo
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 @@ -434,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 3db19f6

Please sign in to comment.