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 @@