diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java b/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java index 5e428651f8..7f5dd8312b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/job/ApiScenarioScheduleJob.java @@ -102,7 +102,7 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob { scenarioReport.setEnvironmentId(parseParam.getEnvironmentId()); scenarioReport.setWaitingTime(apiScenarioRunService.getGlobalWaitTime(parseParam.getScenarioConfig())); - apiScenarioRunService.initApiReport(apiScenarioDetail, scenarioReport); + apiScenarioRunService.initApiReport(taskItem.getId(), apiScenarioDetail, scenarioReport); // 初始化报告步骤 apiScenarioRunService.initScenarioReportSteps(apiScenarioDetail.getSteps(), taskItem.getReportId()); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java index a7097d5138..8f971da6a9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java @@ -65,14 +65,27 @@ public class ApiReportService { private EnvironmentGroupMapper environmentGroupMapper; @Resource private ApiReportNoticeService apiReportNoticeService; + @Resource + private ApiReportRelateTaskMapper apiReportRelateTaskMapper; @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertApiReport(ApiReport report) { apiReportMapper.insertSelective(report); } + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) + public void insertApiReport(ApiReport report, ApiReportRelateTask taskRelation) { + apiReportMapper.insertSelective(report); + apiReportRelateTaskMapper.insertSelective(taskRelation); + } + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertApiReport(List reports, List records) { + this.insertApiReport(reports, records, null); + } + + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) + public void insertApiReport(List reports, List records, List taskRelations) { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); if (CollectionUtils.isNotEmpty(reports)) { ApiReportMapper reportMapper = sqlSession.getMapper(ApiReportMapper.class); @@ -86,6 +99,13 @@ public class ApiReportService { subList.forEach(detailMapper::insertSelective); }); } + + if (CollectionUtils.isNotEmpty(taskRelations)) { + ApiReportRelateTaskMapper taskRelationMapper = sqlSession.getMapper(ApiReportRelateTaskMapper.class); + SubListUtils.dealForSubList(taskRelations, 1000, subList -> { + subList.forEach(taskRelationMapper::insertSelective); + }); + } sqlSession.flushStatements(); if (sqlSessionFactory != null) { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java index 7de9bc2a05..8892f12bc9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseBatchRunService.java @@ -107,7 +107,7 @@ public class ApiTestCaseBatchRunService { if (runModeConfig.isIntegratedReport()) { // 初始化集成报告 - initIntegratedReport(runModeConfig, userId, request.getProjectId()); + initIntegratedReport(execTask.getId(), runModeConfig, userId, request.getProjectId()); } // 先初始化集成报告,设置好报告ID,再初始化执行队列 @@ -178,16 +178,16 @@ public class ApiTestCaseBatchRunService { ApiRunModeConfigDTO runModeConfig = getRunModeConfig(request); - if (runModeConfig.isIntegratedReport()) { - // 初始化集成报告 - initIntegratedReport(runModeConfig, ids, userId, request.getProjectId()); - } - Project project = projectMapper.selectByPrimaryKey(request.getProjectId()); // 初始化任务 ExecTask execTask = initExecTask(ids, runModeConfig, project, userId); + if (runModeConfig.isIntegratedReport()) { + // 初始化集成报告 + initIntegratedReport(execTask.getId(), runModeConfig, ids, userId, request.getProjectId()); + } + // 分批查询 SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> { List apiTestCases = getOrderApiTestCases(subIds, runModeConfig); @@ -197,7 +197,7 @@ public class ApiTestCaseBatchRunService { .collect(Collectors.toMap(ExecTaskItem::getResourceId, ExecTaskItem::getId)); // 初始化报告,返回用例和报告的 map - Map caseReportMap = initParallelReport(runModeConfig, apiTestCases, userId); + Map caseReportMap = initParallelReport(resourceExecTaskItemMap, runModeConfig, apiTestCases, userId); List taskItems = new ArrayList<>(subIds.size()); @@ -254,7 +254,7 @@ public class ApiTestCaseBatchRunService { return apiTestCases; } - private Map initParallelReport(ApiRunModeConfigDTO runModeConfig, List apiTestCases, String userId) { + private Map initParallelReport(Map resourceExecTaskItemMap, ApiRunModeConfigDTO runModeConfig, List apiTestCases, String userId) { // 先初始化所有报告 if (runModeConfig.isIntegratedReport()) { // 获取集成报告ID @@ -263,7 +263,7 @@ public class ApiTestCaseBatchRunService { return null; } else { // 初始化非集成报告 - List apiTestCaseRecords = initApiReport(runModeConfig, apiTestCases, userId); + List apiTestCaseRecords = initApiReport(resourceExecTaskItemMap, runModeConfig, apiTestCases, userId); return apiTestCaseRecords.stream() .collect(Collectors.toMap(ApiTestCaseRecord::getApiTestCaseId, ApiTestCaseRecord::getApiReportId)); } @@ -308,7 +308,7 @@ public class ApiTestCaseBatchRunService { * @param ids * @return */ - private ApiReport initIntegratedReport(ApiRunModeConfigDTO runModeConfig, List ids, String userId, String projectId) { + private ApiReport initIntegratedReport(String taskId, ApiRunModeConfigDTO runModeConfig, List ids, String userId, String projectId) { ApiReport apiReport = getApiReport(runModeConfig, userId); apiReport.setName(runModeConfig.getCollectionReport().getReportName() + "_" + DateUtils.getTimeString(System.currentTimeMillis())); apiReport.setIntegrated(true); @@ -320,7 +320,13 @@ public class ApiTestCaseBatchRunService { record.setApiTestCaseId(id); return record; }).toList(); - apiReportService.insertApiReport(List.of(apiReport), records); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiReport.getId()); + apiReportRelateTask.setTaskResourceId(taskId); + + apiReportService.insertApiReport(List.of(apiReport), records, List.of(apiReportRelateTask)); // 设置集成报告执行参数 runModeConfig.getCollectionReport().setReportId(apiReport.getId()); return apiReport; @@ -332,12 +338,18 @@ public class ApiTestCaseBatchRunService { * @param runModeConfig * @return */ - private ApiReport initIntegratedReport(ApiRunModeConfigDTO runModeConfig, String userId, String projectId) { + private ApiReport initIntegratedReport(String taskId, ApiRunModeConfigDTO runModeConfig, String userId, String projectId) { ApiReport apiReport = getApiReport(runModeConfig, userId); apiReport.setName(runModeConfig.getCollectionReport().getReportName() + "_" + DateUtils.getTimeString(System.currentTimeMillis())); apiReport.setIntegrated(true); apiReport.setProjectId(projectId); - apiReportService.insertApiReport(apiReport); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiReport.getId()); + apiReportRelateTask.setTaskResourceId(taskId); + + apiReportService.insertApiReport(apiReport, apiReportRelateTask); // 设置集成报告执行参数 runModeConfig.getCollectionReport().setReportId(apiReport.getId()); return apiReport; @@ -381,7 +393,7 @@ public class ApiTestCaseBatchRunService { reportId = runModeConfig.getCollectionReport().getReportId() + IDGenerator.nextStr(); } else { // 独立报告,执行到当前任务时初始化报告 - reportId = initApiReport(runModeConfig, List.of(apiTestCase), queue.getUserId()).getFirst().getApiReportId(); + reportId = initApiReport(Map.of(apiTestCase.getId(), taskItemId), runModeConfig, List.of(apiTestCase), queue.getUserId()).getFirst().getApiReportId(); } if (apiTestCase == null) { @@ -428,10 +440,12 @@ public class ApiTestCaseBatchRunService { * @param apiTestCases * @return */ - public List initApiReport(ApiRunModeConfigDTO runModeConfig, List apiTestCases, String userId) { + public List initApiReport(Map resourceExecTaskItemMap, + ApiRunModeConfigDTO runModeConfig, List apiTestCases, String userId) { List apiReports = new ArrayList<>(); List apiTestCaseRecords = new ArrayList<>(); List apiReportSteps = new ArrayList<>(); + List apiReportRelateTasks = new ArrayList<>(); for (ApiTestCase apiTestCase : apiTestCases) { // 初始化报告 ApiReport apiReport = getApiReport(runModeConfig, apiTestCase, userId); @@ -440,8 +454,15 @@ public class ApiTestCaseBatchRunService { ApiTestCaseRecord apiTestCaseRecord = apiTestCaseService.getApiTestCaseRecord(apiTestCase, apiReport); apiTestCaseRecords.add(apiTestCaseRecord); apiReportSteps.add(getApiReportStep(apiTestCase, apiReport.getId(), 1)); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiReport.getId()); + apiReportRelateTask.setTaskResourceId(resourceExecTaskItemMap.get(apiTestCase.getId())); + apiReportRelateTasks.add(apiReportRelateTask); } - apiReportService.insertApiReport(apiReports, apiTestCaseRecords); + + apiReportService.insertApiReport(apiReports, apiTestCaseRecords, apiReportRelateTasks); apiReportService.insertApiReportStep(apiReportSteps); return apiTestCaseRecords; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index 9ff3017aaa..b98a9a6585 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -760,7 +760,7 @@ public class ApiTestCaseService extends MoveNodeService { } // 初始化报告 - initApiReport(apiTestCase, reportId, poolId, userId); + initApiReport(taskItem.getId(), apiTestCase, reportId, poolId, userId); return doExecute(taskRequest, runRequest, apiTestCase.getApiDefinitionId(), apiTestCase.getEnvironmentId()); } @@ -861,7 +861,7 @@ public class ApiTestCaseService extends MoveNodeService { * @param userId * @return */ - public ApiTestCaseRecord initApiReport(ApiTestCase apiTestCase, String reportId, String poolId, String userId) { + public ApiTestCaseRecord initApiReport(String taskItemId, ApiTestCase apiTestCase, String reportId, String poolId, String userId) { // 初始化报告 ApiReport apiReport = getApiReport(apiTestCase, reportId, poolId, userId); @@ -869,9 +869,15 @@ public class ApiTestCaseService extends MoveNodeService { // 创建报告和用例的关联关系 ApiTestCaseRecord apiTestCaseRecord = getApiTestCaseRecord(apiTestCase, apiReport); - apiReportService.insertApiReport(List.of(apiReport), List.of(apiTestCaseRecord)); + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(reportId); + apiReportRelateTask.setTaskResourceId(taskItemId); + + apiReportService.insertApiReport(List.of(apiReport), List.of(apiTestCaseRecord), List.of(apiReportRelateTask)); //初始化步骤 apiReportService.insertApiReportStep(List.of(getApiReportStep(apiTestCase.getId(), apiTestCase.getName(), reportId, 1L))); + return apiTestCaseRecord; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java index 92502eebb3..b88c733cee 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioBatchRunService.java @@ -1,9 +1,6 @@ package io.metersphere.api.service.scenario; -import io.metersphere.api.domain.ApiScenario; -import io.metersphere.api.domain.ApiScenarioRecord; -import io.metersphere.api.domain.ApiScenarioReport; -import io.metersphere.api.domain.ApiScenarioReportStep; +import io.metersphere.api.domain.*; import io.metersphere.api.dto.scenario.ApiScenarioBatchRunRequest; import io.metersphere.api.dto.scenario.ApiScenarioDetail; import io.metersphere.api.mapper.ApiScenarioMapper; @@ -115,7 +112,7 @@ public class ApiScenarioBatchRunService { // 初始化集成报告 if (runModeConfig.isIntegratedReport()) { - initIntegratedReport(runModeConfig, userId, request.getProjectId()); + initIntegratedReport(execTask.getId(), runModeConfig, userId, request.getProjectId()); } // 先初始化集成报告,设置好报告ID,再初始化执行队列 @@ -136,8 +133,12 @@ public class ApiScenarioBatchRunService { // 集合报告初始化一级步骤 initApiScenarioReportStep(apiScenarios, reportId); } else { + // 初始化任务项 + Map resourceExecTaskItemMap = execTaskItems + .stream() + .collect(Collectors.toMap(ExecTaskItem::getResourceId, ExecTaskItem::getId)); // 非集合报告,初始化独立报告,执行时初始化步骤 - initScenarioReport(runModeConfig, apiScenarios, userId); + initScenarioReport(resourceExecTaskItemMap, runModeConfig, apiScenarios, userId); } // 初始化队列项 apiBatchRunBaseService.initExecutionQueueDetails(queue.getQueueId(), execTaskItems); @@ -165,26 +166,27 @@ public class ApiScenarioBatchRunService { if (runModeConfig.isIntegratedReport()) { // 初始化集成报告 - initIntegratedReport(runModeConfig, userId, request.getProjectId()); + initIntegratedReport(execTask.getId(), runModeConfig, userId, request.getProjectId()); } // 分批查询 SubListUtils.dealForSubList(ids, TASK_BATCH_SIZE, subIds -> { List apiScenarios = getOrderScenarios(subIds, runModeConfig); Map caseReportMap = null; - if (runModeConfig.isIntegratedReport()) { - // 集合报告初始化一级步骤 - initApiScenarioReportStep(apiScenarios, runModeConfig.getCollectionReport().getReportId()); - } else { - // 非集合报告,初始化独立报告,执行时初始化步骤 - caseReportMap = initScenarioReport(runModeConfig, apiScenarios, userId); - } // 初始化任务项 Map resourceExecTaskItemMap = initExecTaskItem(subIds, apiScenarios, userId, project, execTask) .stream() .collect(Collectors.toMap(ExecTaskItem::getResourceId, ExecTaskItem::getId)); + if (runModeConfig.isIntegratedReport()) { + // 集合报告初始化一级步骤 + initApiScenarioReportStep(apiScenarios, runModeConfig.getCollectionReport().getReportId()); + } else { + // 非集合报告,初始化独立报告,执行时初始化步骤 + caseReportMap = initScenarioReport(resourceExecTaskItemMap, runModeConfig, apiScenarios, userId); + } + List taskItems = new ArrayList<>(ids.size()); for (ApiScenario apiScenario : apiScenarios) { @@ -302,12 +304,18 @@ public class ApiScenarioBatchRunService { * @param runModeConfig * @return */ - private ApiScenarioReport initIntegratedReport(ApiRunModeConfigDTO runModeConfig, String userId, String projectId) { + private ApiScenarioReport initIntegratedReport(String taskId, ApiRunModeConfigDTO runModeConfig, String userId, String projectId) { ApiScenarioReport apiScenarioReport = getScenarioReport(runModeConfig, userId); apiScenarioReport.setName(runModeConfig.getCollectionReport().getReportName() + "_" + DateUtils.getTimeString(System.currentTimeMillis())); apiScenarioReport.setIntegrated(true); apiScenarioReport.setProjectId(projectId); - apiScenarioReportMapper.insertSelective(apiScenarioReport); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiScenarioReport.getId()); + apiReportRelateTask.setTaskResourceId(taskId); + + apiScenarioReportService.insertApiScenarioReport(apiScenarioReport, apiReportRelateTask); // 设置集成报告执行参数 runModeConfig.getCollectionReport().setReportId(apiScenarioReport.getId()); return apiScenarioReport; @@ -345,7 +353,7 @@ public class ApiScenarioBatchRunService { reportId = runModeConfig.getCollectionReport().getReportId() + IDGenerator.nextStr(); } else { // 独立报告,执行到当前任务时初始化报告 - reportId = initScenarioReport(runModeConfig, apiScenario, queue.getUserId()).getApiScenarioReportId(); + reportId = initScenarioReport(queueDetail.getTaskItemId(), runModeConfig, apiScenario, queue.getUserId()).getApiScenarioReportId(); } TaskRequestDTO taskRequest = getTaskRequestDTO(apiScenario.getProjectId(), queue.getRunModeConfig()); @@ -379,9 +387,11 @@ public class ApiScenarioBatchRunService { return apiBatchRunBaseService.setBatchRunTaskInfoParam(runModeConfig, taskInfo); } - public Map initScenarioReport(ApiRunModeConfigDTO runModeConfig, List apiScenarios, String userId) { + public Map initScenarioReport(Map resourceExecTaskItemMap, ApiRunModeConfigDTO runModeConfig, + List apiScenarios, String userId) { List apiScenarioReports = new ArrayList<>(apiScenarios.size()); List apiScenarioRecords = new ArrayList<>(apiScenarios.size()); + List apiReportRelateTasks = new ArrayList<>(); for (ApiScenario apiScenario : apiScenarios) { // 初始化报告 ApiScenarioReport apiScenarioReport = getScenarioReport(runModeConfig, apiScenario, userId); @@ -390,8 +400,13 @@ public class ApiScenarioBatchRunService { // 创建报告和用例的关联关系 ApiScenarioRecord apiScenarioRecord = apiScenarioRunService.getApiScenarioRecord(apiScenario, apiScenarioReport); apiScenarioRecords.add(apiScenarioRecord); + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiScenarioReport.getId()); + apiReportRelateTask.setTaskResourceId(resourceExecTaskItemMap.get(apiScenario.getId())); + apiReportRelateTasks.add(apiReportRelateTask); } - apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords); + apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords, apiReportRelateTasks); return apiScenarioRecords.stream().collect(Collectors.toMap(ApiScenarioRecord::getApiScenarioId, ApiScenarioRecord::getApiScenarioReportId)); } @@ -402,13 +417,19 @@ public class ApiScenarioBatchRunService { * @param apiScenario * @return */ - public ApiScenarioRecord initScenarioReport(ApiRunModeConfigDTO runModeConfig, ApiScenario apiScenario, String userId) { + public ApiScenarioRecord initScenarioReport(String taskItemId, ApiRunModeConfigDTO runModeConfig, ApiScenario apiScenario, String userId) { // 初始化报告 ApiScenarioReport apiScenarioReport = getScenarioReport(runModeConfig, apiScenario, userId); apiScenarioReport.setId(IDGenerator.nextStr()); // 创建报告和用例的关联关系 ApiScenarioRecord apiScenarioRecord = apiScenarioRunService.getApiScenarioRecord(apiScenario, apiScenarioReport); - apiScenarioReportService.insertApiScenarioReport(List.of(apiScenarioReport), List.of(apiScenarioRecord)); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiScenarioReport.getId()); + apiReportRelateTask.setTaskResourceId(taskItemId); + + apiScenarioReportService.insertApiScenarioReport(List.of(apiScenarioReport), List.of(apiScenarioRecord), List.of(apiReportRelateTask)); return apiScenarioRecord; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java index acf8318c00..00cbb75e75 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java @@ -53,6 +53,8 @@ public class ApiScenarioReportService { @Resource private ApiScenarioReportMapper apiScenarioReportMapper; @Resource + private ApiReportRelateTaskMapper apiReportRelateTaskMapper; + @Resource private ApiScenarioReportLogService apiScenarioReportLogService; @Resource private ExtApiScenarioReportDetailBlobMapper extApiScenarioReportDetailBlobMapper; @@ -72,8 +74,19 @@ public class ApiScenarioReportService { private static final int MAX = 50000; private static final int BATCH_SIZE = 1000; + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) + public void insertApiScenarioReport(ApiScenarioReport report, ApiReportRelateTask taskRelation) { + apiScenarioReportMapper.insertSelective(report); + apiReportRelateTaskMapper.insertSelective(taskRelation); + } + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertApiScenarioReport(List reports, List records) { + this.insertApiScenarioReport(reports, records, null); + } + + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) + public void insertApiScenarioReport(List reports, List records, List taskRelations) { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); if (CollectionUtils.isNotEmpty(reports)) { ApiScenarioReportMapper reportMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); @@ -87,6 +100,12 @@ public class ApiScenarioReportService { subList.forEach(detailMapper::insertSelective); }); } + if (CollectionUtils.isNotEmpty(taskRelations)) { + ApiReportRelateTaskMapper taskRelationMapper = sqlSession.getMapper(ApiReportRelateTaskMapper.class); + SubListUtils.dealForSubList(taskRelations, 1000, subList -> { + subList.forEach(taskRelationMapper::insertSelective); + }); + } sqlSession.flushStatements(); if (sqlSessionFactory != null) { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioRunService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioRunService.java index ed4fb9728f..beee09a33c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioRunService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioRunService.java @@ -247,7 +247,7 @@ public class ApiScenarioRunService { scenarioReport.setEnvironmentId(parseParam.getEnvironmentId()); scenarioReport.setWaitingTime(getGlobalWaitTime(parseParam.getScenarioConfig())); - initApiReport(apiScenario, scenarioReport); + initApiReport(taskItem.getId(), apiScenario, scenarioReport); // 初始化报告步骤 initScenarioReportSteps(steps, taskItem.getReportId()); @@ -476,7 +476,7 @@ public class ApiScenarioRunService { * @param apiScenario * @return */ - public ApiScenarioRecord initApiReport(ApiScenario apiScenario, ApiScenarioReport scenarioReport) { + public ApiScenarioRecord initApiReport(String taskItemId, ApiScenario apiScenario, ApiScenarioReport scenarioReport) { // 初始化报告 scenarioReport.setName(apiScenario.getName() + "_" + DateUtils.getTimeString(System.currentTimeMillis())); scenarioReport.setProjectId(apiScenario.getProjectId()); @@ -484,7 +484,12 @@ public class ApiScenarioRunService { // 创建报告和用例的关联关系 ApiScenarioRecord scenarioRecord = getApiScenarioRecord(apiScenario, scenarioReport); - apiScenarioReportService.insertApiScenarioReport(List.of(scenarioReport), List.of(scenarioRecord)); + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(scenarioReport.getId()); + apiReportRelateTask.setTaskResourceId(taskItemId); + + apiScenarioReportService.insertApiScenarioReport(List.of(scenarioReport), List.of(scenarioRecord), List.of(apiReportRelateTask)); return scenarioRecord; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java index 53249bbf4c..e1e1c2e2a1 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiCaseService.java @@ -1,9 +1,6 @@ package io.metersphere.plan.service; -import io.metersphere.api.domain.ApiReport; -import io.metersphere.api.domain.ApiReportStep; -import io.metersphere.api.domain.ApiTestCase; -import io.metersphere.api.domain.ApiTestCaseRecord; +import io.metersphere.api.domain.*; import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.api.mapper.ExtApiTestCaseMapper; import io.metersphere.api.service.ApiBatchRunBaseService; @@ -146,7 +143,7 @@ public class PlanRunTestPlanApiCaseService { ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(collection); // 初始化报告,返回用例和报告的 map - Map caseReportMap = initApiReport(runModeConfig, testPlanReportApiCases, apiCaseMap, userId); + Map caseReportMap = initApiReport(resourceTaskItemMap, runModeConfig, testPlanReportApiCases, apiCaseMap, userId); List taskItems = new ArrayList<>(testPlanReportApiCases.size()); @@ -210,7 +207,7 @@ public class PlanRunTestPlanApiCaseService { ApiTestCase apiTestCase = apiTestCaseMapper.selectByPrimaryKey(testPlanReportApiCase.getApiCaseId()); // 独立报告,执行到当前任务时初始化报告 - String reportId = initApiReport(runModeConfig, List.of(testPlanReportApiCase), Map.of(apiTestCase.getId(), apiTestCase), queue.getUserId()).get(resourceId); + String reportId = initApiReport(Map.of(apiTestCase.getId(), queueDetail.getTaskItemId()), runModeConfig, List.of(testPlanReportApiCase), Map.of(apiTestCase.getId(), apiTestCase), queue.getUserId()).get(resourceId); TaskRequestDTO taskRequest = testPlanApiCaseBatchRunService.getTaskRequestDTO(reportId, testPlanReportApiCase.getId(), apiTestCase, runModeConfig); taskRequest.getTaskInfo().setTaskId(queue.getTaskId()); taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name()); @@ -229,13 +226,15 @@ public class PlanRunTestPlanApiCaseService { * @param runModeConfig * @return */ - public Map initApiReport(ApiRunModeConfigDTO runModeConfig, List testPlanReportApiCases, + public Map initApiReport(Map resourceExecTaskItemMap, + ApiRunModeConfigDTO runModeConfig, List testPlanReportApiCases, Map caseMap, String userId) { Map resourceReportMap = new HashMap<>(); List apiReports = new ArrayList<>(); List apiTestCaseRecords = new ArrayList<>(); List apiReportSteps = new ArrayList<>(); + List apiReportRelateTasks = new ArrayList<>(); for (TestPlanReportApiCase testPlanReportApiCase : testPlanReportApiCases) { ApiTestCase apiTestCase = caseMap.get(testPlanReportApiCase.getApiCaseId()); @@ -253,8 +252,14 @@ public class PlanRunTestPlanApiCaseService { apiTestCaseRecords.add(apiTestCaseRecord); apiReportSteps.add(testPlanApiCaseBatchRunService.getApiReportStep(testPlanReportApiCase.getId(), apiTestCase.getName(), apiReport.getId(), 1)); resourceReportMap.put(testPlanReportApiCase.getId(), apiReport.getId()); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiReport.getId()); + apiReportRelateTask.setTaskResourceId(resourceExecTaskItemMap.get(apiReport.getId())); + apiReportRelateTasks.add(apiReportRelateTask); } - apiReportService.insertApiReport(apiReports, apiTestCaseRecords); + apiReportService.insertApiReport(apiReports, apiTestCaseRecords, apiReportRelateTasks); apiReportService.insertApiReportStep(apiReportSteps); return resourceReportMap; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java index 4cd5a7b363..053f335420 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/PlanRunTestPlanApiScenarioService.java @@ -1,5 +1,6 @@ package io.metersphere.plan.service; +import io.metersphere.api.domain.ApiReportRelateTask; import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenarioRecord; import io.metersphere.api.domain.ApiScenarioReport; @@ -135,7 +136,7 @@ public class PlanRunTestPlanApiScenarioService { .forEach(execTaskItem -> resourceTaskItemMap.put(execTaskItem.getResourceId(), execTaskItem.getId())); }); - Map scenarioReportMap = initReport(testPlanReportApiScenarios, runModeConfig, userId); + Map scenarioReportMap = initReport(resourceTaskItemMap, testPlanReportApiScenarios, runModeConfig, userId); List taskItems = testPlanReportApiScenarios.stream() .map(item -> { TaskItem taskItem = apiExecuteService.getTaskItem(scenarioReportMap.get(item.getId()), item.getId()); @@ -152,7 +153,9 @@ public class PlanRunTestPlanApiScenarioService { return false; } - private Map initReport(List testPlanReportApiScenarios, ApiRunModeConfigDTO runModeConfig, String userId) { + private Map initReport(Map resourceExecTaskItemMap, + List testPlanReportApiScenarios, + ApiRunModeConfigDTO runModeConfig, String userId) { List apiScenarios = new ArrayList<>(testPlanReportApiScenarios.size()); @@ -165,13 +168,17 @@ public class PlanRunTestPlanApiScenarioService { .collect(Collectors.toMap(ApiScenario::getId, Function.identity())); // 初始化独立报告,执行时初始化步骤 - return initScenarioReport(runModeConfig, testPlanReportApiScenarios, apiScenarioMap, userId); + return initScenarioReport(resourceExecTaskItemMap, runModeConfig, testPlanReportApiScenarios, apiScenarioMap, userId); } - public Map initScenarioReport(ApiRunModeConfigDTO runModeConfig, List testPlanReportApiScenarios, + public Map initScenarioReport(Map resourceExecTaskItemMap, + ApiRunModeConfigDTO runModeConfig, + List testPlanReportApiScenarios, Map apiScenarioMap, String userId) { List apiScenarioReports = new ArrayList<>(testPlanReportApiScenarios.size()); List apiScenarioRecords = new ArrayList<>(testPlanReportApiScenarios.size()); + List apiReportRelateTasks = new ArrayList<>(); + Map resourceReportMap = new HashMap<>(); String projectId = ""; for (TestPlanReportApiScenario testPlanReportApiScenario : testPlanReportApiScenarios) { @@ -191,8 +198,14 @@ public class PlanRunTestPlanApiScenarioService { scenarioRecord.setApiScenarioReportId(apiScenarioReport.getId()); apiScenarioRecords.add(scenarioRecord); resourceReportMap.put(testPlanReportApiScenario.getId(), apiScenarioReport.getId()); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiScenario.getId()); + apiReportRelateTask.setTaskResourceId(resourceExecTaskItemMap.get(apiScenario.getId())); + apiReportRelateTasks.add(apiReportRelateTask); } - apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords); + apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords, apiReportRelateTasks); return resourceReportMap; } @@ -239,7 +252,7 @@ public class PlanRunTestPlanApiScenarioService { ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey(testPlanReportApiScenario.getApiScenarioId()); // 独立报告,执行到当前任务时初始化报告 - String reportId = initScenarioReport(runModeConfig, List.of(testPlanReportApiScenario), Map.of(apiScenario.getId(), apiScenario), queue.getUserId()).get(resourceId); + String reportId = initScenarioReport(Map.of(testPlanReportApiScenario.getId(), queueDetail.getTaskItemId()), runModeConfig, List.of(testPlanReportApiScenario), Map.of(apiScenario.getId(), apiScenario), queue.getUserId()).get(resourceId); TaskRequestDTO taskRequest = testPlanApiScenarioBatchRunService.getTaskRequestDTO(apiScenario.getProjectId(), queue.getRunModeConfig()); TaskItem taskItem = apiExecuteService.getTaskItem(reportId, queueDetail.getResourceId()); taskItem.setId(queueDetail.getTaskItemId()); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java index 99e14d5340..545b33c6bf 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java @@ -1,9 +1,6 @@ package io.metersphere.plan.service; -import io.metersphere.api.domain.ApiReport; -import io.metersphere.api.domain.ApiReportStep; -import io.metersphere.api.domain.ApiTestCase; -import io.metersphere.api.domain.ApiTestCaseRecord; +import io.metersphere.api.domain.*; import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.api.mapper.ExtApiTestCaseMapper; import io.metersphere.api.service.ApiBatchRunBaseService; @@ -259,11 +256,11 @@ public class TestPlanApiCaseBatchRunService { Project project, String userId) { - // 初始化报告,返回用例和报告的 map - Map caseReportMap = initApiReport(runModeConfig, testPlanApiCases, project.getId(), userId); - Map resourceTaskItemMap = getResourceTaskItemMap(taskId, testPlanApiCases); + // 初始化报告,返回用例和报告的 map + Map caseReportMap = initApiReport(resourceTaskItemMap, runModeConfig, testPlanApiCases, project.getId(), userId); + List taskItems = new ArrayList<>(testPlanApiCases.size()); // 这里ID顺序和队列的ID顺序保持一致 @@ -403,7 +400,7 @@ public class TestPlanApiCaseBatchRunService { TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId); // 独立报告,执行到当前任务时初始化报告 - String reportId = initApiReport(runModeConfig, List.of(BeanUtils.copyBean(new TestPlanApiCaseBatchRunDTO(), testPlanApiCase)), + String reportId = initApiReport(Map.of(apiTestCase.getId(), queueDetail.getTaskItemId()), runModeConfig, List.of(BeanUtils.copyBean(new TestPlanApiCaseBatchRunDTO(), testPlanApiCase)), testPlan.getProjectId(), queue.getUserId()).get(testPlanApiCase.getId()); TaskRequestDTO taskRequest = getTaskRequestDTO(reportId, testPlanApiCase.getId(), apiTestCase, runModeConfig); taskRequest.getTaskInfo().setTaskId(queue.getTaskId()); @@ -446,10 +443,11 @@ public class TestPlanApiCaseBatchRunService { * @param runModeConfig * @return */ - public Map initApiReport(ApiRunModeConfigDTO runModeConfig, List testPlanApiCases, + public Map initApiReport(Map resourceExecTaskItemMap, ApiRunModeConfigDTO runModeConfig, List testPlanApiCases, String projectId, String userId) { List apiReports = new ArrayList<>(); List apiTestCaseRecords = new ArrayList<>(); + List apiReportRelateTasks = new ArrayList<>(); List apiReportSteps = new ArrayList<>(); Map resourceReportMap = new HashMap<>(); @@ -462,8 +460,14 @@ public class TestPlanApiCaseBatchRunService { apiTestCaseRecords.add(apiTestCaseRecord); apiReportSteps.add(getApiReportStep(testPlanApiCase.getId(), testPlanApiCase.getName(), apiReport.getId(), 1)); resourceReportMap.put(testPlanApiCase.getId(), apiReport.getId()); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiReport.getId()); + apiReportRelateTask.setTaskResourceId(resourceExecTaskItemMap.get(apiReport.getId())); + apiReportRelateTasks.add(apiReportRelateTask); } - apiReportService.insertApiReport(apiReports, apiTestCaseRecords); + apiReportService.insertApiReport(apiReports, apiTestCaseRecords, apiReportRelateTasks); apiReportService.insertApiReportStep(apiReportSteps); return resourceReportMap; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java index db0ba0fb01..739083a015 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java @@ -786,7 +786,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { } // 初始化报告 - initApiReport(apiTestCase, testPlanApiCase, reportId, runModeConfig, userId); + initApiReport(taskItem.getId(), apiTestCase, testPlanApiCase, reportId, runModeConfig, userId); return apiExecuteService.execute(taskRequest); } @@ -811,7 +811,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { * * @return */ - public ApiTestCaseRecord initApiReport(ApiTestCase apiTestCase, TestPlanApiCase testPlanApiCase, String reportId, ApiRunModeConfigDTO runModeConfig, String userId) { + public ApiTestCaseRecord initApiReport(String taskItemId, ApiTestCase apiTestCase, TestPlanApiCase testPlanApiCase, String reportId, ApiRunModeConfigDTO runModeConfig, String userId) { // 初始化报告 ApiReport apiReport = apiTestCaseService.getApiReport(apiTestCase, reportId, runModeConfig.getPoolId(), userId); apiReport.setEnvironmentId(runModeConfig.getEnvironmentId()); @@ -820,7 +820,12 @@ public class TestPlanApiCaseService extends TestPlanResourceService { // 创建报告和用例的关联关系 ApiTestCaseRecord apiTestCaseRecord = apiTestCaseService.getApiTestCaseRecord(apiTestCase, apiReport); - apiReportService.insertApiReport(List.of(apiReport), List.of(apiTestCaseRecord)); + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiReport.getId()); + apiReportRelateTask.setTaskResourceId(taskItemId); + + apiReportService.insertApiReport(List.of(apiReport), List.of(apiTestCaseRecord), List.of(apiReportRelateTask)); //初始化步骤 apiReportService.insertApiReportStep(List.of(getApiReportStep(testPlanApiCase, apiTestCase, reportId))); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java index 9216bf82c6..f4398737b5 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java @@ -1,5 +1,6 @@ package io.metersphere.plan.service; +import io.metersphere.api.domain.ApiReportRelateTask; import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenarioRecord; import io.metersphere.api.domain.ApiScenarioReport; @@ -265,10 +266,10 @@ public class TestPlanApiScenarioBatchRunService { Project project, String userId) { - Map scenarioReportMap = initReport(testPlanApiScenarios, runModeConfig, project.getId(), userId); - Map resourceTaskItemMap = getResourceTaskItemMap(taskId, testPlanApiScenarios); + Map scenarioReportMap = initReport(resourceTaskItemMap, testPlanApiScenarios, runModeConfig, project.getId(), userId); + List taskItems = testPlanApiScenarios.stream() .map(testPlanApiScenario -> { String id = testPlanApiScenario.getId(); @@ -329,10 +330,12 @@ public class TestPlanApiScenarioBatchRunService { return execTaskItems; } - public Map initReport(List testPlanApiScenarios, - ApiRunModeConfigDTO runModeConfig, String projectId, String userId) { + public Map initReport(Map resourceExecTaskItemMap, + List testPlanApiScenarios, + ApiRunModeConfigDTO runModeConfig, String projectId, String userId) { List apiScenarioReports = new ArrayList<>(testPlanApiScenarios.size()); List apiScenarioRecords = new ArrayList<>(testPlanApiScenarios.size()); + List apiReportRelateTasks = new ArrayList<>(testPlanApiScenarios.size()); Map resourceReportMap = new HashMap<>(); for (TestPlanApiScenarioBatchRunDTO testPlanApiScenario : testPlanApiScenarios) { // 初始化报告 @@ -343,8 +346,14 @@ public class TestPlanApiScenarioBatchRunService { ApiScenarioRecord apiScenarioRecord = apiScenarioRunService.getApiScenarioRecord(testPlanApiScenario.getApiScenarioId(), apiScenarioReport); apiScenarioRecords.add(apiScenarioRecord); resourceReportMap.put(testPlanApiScenario.getId(), apiScenarioReport.getId()); + + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiScenarioReport.getId()); + apiReportRelateTask.setTaskResourceId(resourceExecTaskItemMap.get(apiScenarioReport.getId())); + apiReportRelateTasks.add(apiReportRelateTask); } - apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords); + apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords, apiReportRelateTasks); return resourceReportMap; } @@ -362,7 +371,7 @@ public class TestPlanApiScenarioBatchRunService { TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId); // 独立报告,执行到当前任务时初始化报告 - String reportId = initScenarioReport(runModeConfig, BeanUtils.copyBean(new TestPlanApiScenarioBatchRunDTO(), testPlanApiScenario), testPlan.getId(), queue.getUserId()) + String reportId = initScenarioReport(queueDetail.getTaskItemId(), runModeConfig, BeanUtils.copyBean(new TestPlanApiScenarioBatchRunDTO(), testPlanApiScenario), testPlan.getId(), queue.getUserId()) .getApiScenarioReportId(); TaskRequestDTO taskRequest = getTaskRequestDTO(apiScenario.getProjectId(), queue.getRunModeConfig()); @@ -444,13 +453,18 @@ public class TestPlanApiScenarioBatchRunService { * @param testPlanApiScenario * @return */ - public ApiScenarioRecord initScenarioReport(ApiRunModeConfigDTO runModeConfig, TestPlanApiScenarioBatchRunDTO testPlanApiScenario, String projectId, String userId) { + public ApiScenarioRecord initScenarioReport(String taskItemId, ApiRunModeConfigDTO runModeConfig, TestPlanApiScenarioBatchRunDTO testPlanApiScenario, String projectId, String userId) { // 初始化报告 ApiScenarioReport apiScenarioReport = getScenarioReport(runModeConfig, testPlanApiScenario, projectId, userId); apiScenarioReport.setId(IDGenerator.nextStr()); // 创建报告和用例的关联关系 ApiScenarioRecord apiScenarioRecord = apiScenarioRunService.getApiScenarioRecord(testPlanApiScenario.getApiScenarioId(), apiScenarioReport); - apiScenarioReportService.insertApiScenarioReport(List.of(apiScenarioReport), List.of(apiScenarioRecord)); + // 创建报告和任务的关联关系 + ApiReportRelateTask apiReportRelateTask = new ApiReportRelateTask(); + apiReportRelateTask.setReportId(apiScenarioReport.getId()); + apiReportRelateTask.setTaskResourceId(taskItemId); + + apiScenarioReportService.insertApiScenarioReport(List.of(apiScenarioReport), List.of(apiScenarioRecord), List.of(apiReportRelateTask)); return apiScenarioRecord; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java index a9ef9302f9..8298d55433 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java @@ -379,7 +379,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { scenarioReport.setPoolId(runModeConfig.getPoolId()); scenarioReport.setEnvironmentId(runModeConfig.getEnvironmentId()); scenarioReport.setTestPlanScenarioId(testPlanApiScenario.getId()); - apiScenarioRunService.initApiReport(apiScenario, scenarioReport); + apiScenarioRunService.initApiReport(taskItem.getId(), apiScenario, scenarioReport); return apiExecuteService.execute(taskRequest); }