From 3db19f6fbe9f91983222073d281977e58d7be3b6 Mon Sep 17 00:00:00 2001 From: caofengbin <1050430934@qq.com> Date: Mon, 4 Sep 2023 14:27:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=B0=86=E6=96=B0=E5=A2=9E=E5=8A=A0=E7=9A=84=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=EF=BC=8C=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0=E5=88=B0?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E6=AD=A5=E9=AA=A4=E7=9A=84=E4=B8=8A=E9=9D=A2?= =?UTF-8?q?=E6=88=96=E4=B8=8B=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StepsController.java | 29 +++++++++++++++++++ .../controller/services/StepsService.java | 18 ++++++++++++ .../services/impl/StepsServiceImpl.java | 24 +++++++++++++++ 3 files changed, 71 insertions(+) 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 8c97e375..d6f6eed4 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 @@ -186,4 +186,33 @@ public RespModel switchStep(@RequestParam(name = "id") int id, @RequestParam(nam } } + @WebAspect + @Operation(summary = "将新增的步骤排序到指定的步骤之前或之后", description = "将当前用例的最后一个步骤拖拽到指定步骤之前或之后") + @GetMapping("/stepSortTarget") + public RespModel 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); + } + } 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 31f7044d..8da5b099 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 @@ -74,4 +74,22 @@ CommentPage searchFindByProjectIdAndPlatform(int projectId, int platfo Boolean switchStep(int id, int type); List stepAndIndex(List 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); + } 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 1261774e..03d2f5d7 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 @@ -434,6 +434,30 @@ public Boolean switchStep(int id, int type) { } } + @Override + public Integer findMaxStepSort(int castId) { + List 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 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