From e3531d5ee2d14db88bb30b71e5e421f22d28629a Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 21 Oct 2022 17:29:13 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001018291 --user=郭雨琦 --- .../plan/service/TestPlanService.java | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index cda38fbc5f..c6b5fb9d50 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -10,7 +10,6 @@ import io.metersphere.base.mapper.ext.ExtTestPlanReportMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.*; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.*; @@ -574,41 +573,47 @@ public class TestPlanService { } public void caseTestRelevance(PlanCaseRelevanceRequest request, List testCaseIds) { - //同步添加关联的接口和测试用例 - if (request.getChecked()) { - if (!testCaseIds.isEmpty()) { - testCaseIds.forEach(caseId -> { - List list = new ArrayList<>(); - TestCaseTestExample examp = new TestCaseTestExample(); - examp.createCriteria().andTestCaseIdEqualTo(caseId); - if (testCaseTestMapper.countByExample(examp) > 0) { - list = testCaseTestMapper.selectByExample(examp); - } + if (!request.getChecked()) { + return; + } + if (CollectionUtils.isEmpty(testCaseIds)) { + return; + } + List list; + TestCaseTestExample exam = new TestCaseTestExample(); + exam.createCriteria().andTestCaseIdIn(testCaseIds); + list = testCaseTestMapper.selectByExample(exam); + if (CollectionUtils.isEmpty(list)) { + return; + } + List apiCaseIds = new ArrayList<>(); + List scenarioIds = new ArrayList<>(); + List performanceIds = new ArrayList<>(); + buildCaseIdList(list, apiCaseIds, scenarioIds, performanceIds); + startRelevance(request, apiCaseIds, scenarioIds, performanceIds); + } - List apiCaseIds = new ArrayList<>(); - List scenarioIds = new ArrayList<>(); - List performanceIds = new ArrayList<>(); + private void startRelevance(PlanCaseRelevanceRequest request, List apiCaseIds, List scenarioIds, List performanceIds) { + try { + relevanceTestCaseTest(apiCaseIds, request.getPlanId(), planTestPlanApiCaseService::relevanceByTestIds); + relevanceTestCaseTest(scenarioIds, request.getPlanId(), planTestPlanScenarioCaseService::relevanceByTestIds); + relevanceTestCaseTest(performanceIds, request.getPlanId(), planTestPlanLoadCaseService::relevanceByTestIds); + } catch (MSException e) { + LogUtil.error(e); + } + } - for (TestCaseTest l : list) { - if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.performance.name())) { - performanceIds.add(l.getTestId()); - } - if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.api.name())) { - apiCaseIds.add(l.getTestId()); - } - if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.automation.name())) { - scenarioIds.add(l.getTestId()); - } - } - try { - relevanceTestCaseTest(apiCaseIds, request.getPlanId(), planTestPlanApiCaseService::relevanceByTestIds); - relevanceTestCaseTest(scenarioIds, request.getPlanId(), planTestPlanScenarioCaseService::relevanceByTestIds); - relevanceTestCaseTest(performanceIds, request.getPlanId(), planTestPlanLoadCaseService::relevanceByTestIds); - } catch (MSException e) { - LogUtil.error(e); - } - }); + private static void buildCaseIdList(List list, List apiCaseIds, List scenarioIds, List performanceIds) { + for (TestCaseTest l : list) { + if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.performance.name())) { + performanceIds.add(l.getTestId()); + } + if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.api.name())) { + apiCaseIds.add(l.getTestId()); + } + if (StringUtils.equals(l.getTestType(), TestCaseTestStatus.automation.name())) { + scenarioIds.add(l.getTestId()); } } } @@ -1321,7 +1326,7 @@ public class TestPlanService { } public void runReportWithExceptionHandle(TestPlanSimpleReportDTO report, Function getCaseFunc, - BiConsumer setReportCaseFunc) { + BiConsumer setReportCaseFunc) { try { // todo 服务调用失败 setReportCaseFunc.accept(report, getCaseFunc.apply(report));