From eed41fab067b50ef129ab3e4507ca92bfe61b5a4 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 5 Mar 2021 16:17:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=9C=BA=E6=99=AF=E7=94=A8=E4=BE=8B=E6=97=B6?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=89=A7=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/automation/ApiScenarioDTO.java | 5 +++ .../api/service/ApiAutomationService.java | 25 ++++++----- .../base/mapper/ext/ExtApiScenarioMapper.xml | 1 + .../testcase/ApiCaseRelevanceRequest.java | 11 +++++ .../service/TestPlanScenarioCaseService.java | 29 ++++++++----- .../comonents/api/RelevanceScenarioList.vue | 41 ++++++++++++++++++- .../api/TestCaseScenarioRelevance.vue | 20 ++++++--- 7 files changed, 105 insertions(+), 27 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java index 358ca88ea3..b1f9e6e044 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java @@ -13,4 +13,9 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs { private String projectName; private String userName; private List tagNames; + + /** + * 场景跨项目ID + */ + private List projectIds; } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 88fc2242a2..5c99b63cd1 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -654,24 +654,29 @@ public class ApiAutomationService { } public void relevance(ApiCaseRelevanceRequest request) { - List ids = request.getSelectIds(); - if (CollectionUtils.isEmpty(ids)) { + Map> mapping = request.getMapping(); + Map envMap = request.getEnvMap(); + Set set = mapping.keySet(); + if (set.isEmpty()) { return; } - List apiScenarios = selectByIds(ids); - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - - ExtTestPlanScenarioCaseMapper batchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class); - apiScenarios.forEach(scenario -> { + set.forEach(id -> { + Map newEnvMap = new HashMap<>(16); + if (envMap != null && !envMap.isEmpty()) { + List list = mapping.get(id); + list.forEach(l -> { + newEnvMap.put(l, envMap.get(l)); + }); + } TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); testPlanApiScenario.setId(UUID.randomUUID().toString()); - testPlanApiScenario.setApiScenarioId(scenario.getId()); + testPlanApiScenario.setApiScenarioId(id); testPlanApiScenario.setTestPlanId(request.getPlanId()); testPlanApiScenario.setCreateTime(System.currentTimeMillis()); testPlanApiScenario.setUpdateTime(System.currentTimeMillis()); - batchMapper.insertIfNotExists(testPlanApiScenario); + testPlanApiScenario.setEnvironment(JSON.toJSONString(newEnvMap)); + testPlanApiScenarioMapper.insert(testPlanApiScenario); }); - sqlSession.flushStatements(); } public List selectByIds(List ids) { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index 59e9100554..139de4d8d5 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -134,6 +134,7 @@