diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java index 017613d6..c13b8d2a 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java @@ -82,6 +82,9 @@ public RespModel>> findByProjectId(@RequestParam(name = @Operation(summary = "更新公共步骤信息", description = "新增或更新公共步骤信息") @PutMapping public RespModel save(@Validated @RequestBody PublicStepsDTO publicStepsDTO) { + if (publicStepsService.checkPublicStepRecursion(publicStepsDTO)) { + return new RespModel<>(RespEnum.UPDATE_FAIL, "子步骤中存在对当前公共步骤的引用,请移除掉相关步骤"); + } return new RespModel(RespEnum.UPDATE_OK, publicStepsService.savePublicSteps(publicStepsDTO)); } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java index 0d634d12..ff5306da 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java @@ -31,4 +31,12 @@ public interface PublicStepsService extends IService { * 复制公共用例 */ void copyPublicSetpsIds(int id); + + /** + * 判断公共步骤的子步骤是否存在递归调用的场景 + * + * @param publicStepsDTO 公共步骤bean + * @return true表示出现了递归调用 + */ + boolean checkPublicStepRecursion(PublicStepsDTO publicStepsDTO); } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java index b53633b9..d65d935e 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java @@ -246,4 +246,21 @@ public void copyPublicSetpsIds(int id) { } } + @Override + public boolean checkPublicStepRecursion(PublicStepsDTO publicStepsDTO) { + if (publicStepsDTO.getId() == null) { + return false; + } + if (publicStepsDTO.getSteps() != null && publicStepsDTO.getSteps().size() > 0) { + for (StepsDTO curStepsDTO : publicStepsDTO.getSteps()) { + if (curStepsDTO.getStepType().equals("publicStep")) { + String curText = curStepsDTO.getText(); + if (publicStepsDTO.getId().toString().equals(curText)) { + return true; + } + } + } + } + return false; + } } \ No newline at end of file