From 2d4735ab24cbc6788c84bd2f89ed93c7f6aae6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E6=99=93=E5=BC=BA?= Date: Thu, 18 May 2023 15:53:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=AC=E5=85=B1=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E8=BF=98=E6=89=A7=E8=A1=8C=20=20&&=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4=E4=B8=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E6=8E=A7=E4=BB=B6=E5=85=83=E7=B4=A0=20&&=20=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E6=AD=A5=E9=AA=A4=E5=88=97=E8=A1=A8=E9=A1=B5=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E6=AD=A5=E9=AA=A4=E4=B9=B1=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/impl/PublicStepsServiceImpl.java | 13 ++----------- .../services/impl/TestCasesServiceImpl.java | 4 ++++ .../services/impl/TestSuitesServiceImpl.java | 12 ++++++++++-- 3 files changed, 16 insertions(+), 13 deletions(-) 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 bf6edcf3..b53633b9 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 @@ -72,21 +72,12 @@ public CommentPage findByProjectId(int projectId, Page page = lambdaQuery().eq(PublicSteps::getProjectId, projectId) .orderByDesc(PublicSteps::getId) .page(pageable); - // 业务join,java层拼接结果,虽然麻烦一点,但sql性能确实能优化 + List publicStepsDTOList = page.getRecords() .stream().map(TypeConverter::convertTo).collect(Collectors.toList()); - Set publicStepsIdSet = publicStepsDTOList.stream().map(PublicStepsDTO::getId).collect(Collectors.toSet()); - if (publicStepsIdSet.isEmpty()) { - return CommentPage.emptyPage(); - } - - // publicStepsId -> StepsDTO - Map> stepsDTOMap = publicStepsMapper.listStepsByPublicStepsIds(publicStepsIdSet) - .stream().collect(Collectors.groupingBy(StepsDTO::getPublicStepsId)); - // 将step填充到public step publicStepsDTOList.forEach( - e -> e.setSteps(stepsService.handleSteps(stepsDTOMap.get(e.getId()), false)) + e -> e.setSteps(findById(e.getId(), false).getSteps()) ); return CommentPage.convertFrom(page, publicStepsDTOList); diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java index ed94ba99..0802319a 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java @@ -91,6 +91,10 @@ public CommentPage findAll(int projectId, int platform, String nam @Transactional public TestCasesDTO findCaseDetail(TestCases testCases) { + if (testCases == null){ + return new TestCasesDTO().setId(0).setName("unknown"); + } + if (testCases.getModuleId() != null && testCases.getModuleId() != 0) { Modules modules = modulesMapper.selectById(testCases.getModuleId()); if (modules != null) { diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java index 1e86535d..a24ff988 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java @@ -295,7 +295,7 @@ public JSONObject getStep(StepsDTO steps) { } publicStepsJson.add(getStep(pubStep)); } - step = (JSONObject) JSONObject.toJSON(steps); + step = (JSONObject) JSONObject.toJSON(steps); step.put("pubSteps", publicStepsJson); return step; @@ -316,7 +316,7 @@ public JSONObject getStep(StepsDTO steps) { // 获取步骤结构树 public JSONObject handleSteps(StepsDTO steps) { - JSONObject stepsJsonObj = (JSONObject) JSONObject.toJSON(steps); + JSONObject stepsJsonObj = (JSONObject) JSONObject.toJSON(steps); if (steps == null) { return stepsJsonObj; } @@ -346,13 +346,21 @@ public JSONObject handleSteps(StepsDTO steps) { } stepsJsonObj.put("text", packagesService.findOne(steps.getProjectId(), steps.getText(), plat)); } + if (CollectionUtils.isEmpty(steps.getChildSteps())) { return stepsJsonObj; } + JSONArray childStepJsonObjs = new JSONArray(); List childSteps = steps.getChildSteps(); + for (StepsDTO childStep : childSteps) { + if (childStep.getDisabled() == 1) { + continue; + } + JSONObject childStepJsonObj = handleSteps(childStep); + childStepJsonObjs.add(childStepJsonObj); } stepsJsonObj.put("childSteps", childStepJsonObjs);