From fb14703c3af77e956bfd991290847015e26c3d7e Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Mon, 18 Nov 2024 19:02:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/job/ApiScenarioScheduleJob.java | 75 +++++-------------- 1 file changed, 18 insertions(+), 57 deletions(-) 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 382ce21b05..62f7997417 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 @@ -1,18 +1,16 @@ package io.metersphere.api.job; -import io.metersphere.api.domain.ApiScenarioReport; -import io.metersphere.api.dto.ApiScenarioParamConfig; -import io.metersphere.api.dto.ApiScenarioParseTmpParam; -import io.metersphere.api.dto.debug.ApiResourceRunRequest; -import io.metersphere.api.dto.request.MsScenario; -import io.metersphere.api.dto.scenario.ApiScenarioDetail; -import io.metersphere.api.dto.scenario.ApiScenarioParseParam; +import io.metersphere.api.domain.ApiScenario; +import io.metersphere.api.mapper.ApiScenarioMapper; import io.metersphere.api.service.ApiCommonService; import io.metersphere.api.service.ApiExecuteService; import io.metersphere.api.service.scenario.ApiScenarioRunService; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; -import io.metersphere.sdk.constants.*; +import io.metersphere.sdk.constants.ApiExecuteResourceType; +import io.metersphere.sdk.constants.ApiExecuteRunMode; +import io.metersphere.sdk.constants.ExecTaskType; +import io.metersphere.sdk.constants.TaskTriggerMode; import io.metersphere.sdk.dto.api.task.ApiRunModeConfigDTO; import io.metersphere.sdk.dto.api.task.TaskInfo; import io.metersphere.sdk.dto.api.task.TaskItem; @@ -24,8 +22,6 @@ import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.schedule.BaseScheduleJob; import io.metersphere.system.service.BaseTaskHubService; -import io.metersphere.system.uid.IDGenerator; -import org.apache.commons.lang3.StringUtils; import org.quartz.JobExecutionContext; import org.quartz.JobKey; import org.quartz.TriggerKey; @@ -35,40 +31,22 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob { protected void businessExecute(JobExecutionContext context) { ApiExecuteService apiExecuteService = CommonBeanFactory.getBean(ApiExecuteService.class); ApiScenarioRunService apiScenarioRunService = CommonBeanFactory.getBean(ApiScenarioRunService.class); + ApiScenarioMapper apiScenarioMapper = CommonBeanFactory.getBean(ApiScenarioMapper.class); ApiCommonService apiCommonService = CommonBeanFactory.getBean(ApiCommonService.class); ProjectMapper projectMapper = CommonBeanFactory.getBean(ProjectMapper.class); BaseTaskHubService baseTaskHubService = CommonBeanFactory.getBean(BaseTaskHubService.class); ApiRunModeConfigDTO apiRunModeConfigDTO = JSON.parseObject(context.getJobDetail().getJobDataMap().get("config").toString(), ApiRunModeConfigDTO.class); - ApiScenarioDetail apiScenarioDetail = apiScenarioRunService.getForRun(resourceId); - if (apiScenarioDetail == null) { + ApiScenario apiScenario = apiScenarioMapper.selectByPrimaryKey(resourceId); + if (apiScenario == null) { LogUtils.info("当前定时任务的场景已删除 {}", resourceId); return; } - MsScenario msScenario = apiScenarioRunService.getMsScenario(apiScenarioDetail); - ApiScenarioParseParam parseParam = apiScenarioRunService.getApiScenarioParseParam(apiScenarioDetail); - parseParam.setEnvironmentId(apiRunModeConfigDTO.getEnvironmentId()); - parseParam.setGrouped(apiRunModeConfigDTO.getGrouped()); - if (StringUtils.isBlank(apiRunModeConfigDTO.getEnvironmentId())) { - parseParam.setEnvironmentId(apiScenarioDetail.getEnvironmentId()); - parseParam.setGrouped(apiScenarioDetail.getGrouped()); - } - - if (StringUtils.isBlank(apiRunModeConfigDTO.getPoolId())) { - apiRunModeConfigDTO.setPoolId(apiExecuteService.getProjectApiResourcePoolId(apiScenarioDetail.getProjectId())); - } - - msScenario.setResourceId(apiScenarioDetail.getId()); - // 解析生成场景树,并保存临时变量 - ApiScenarioParseTmpParam tmpParam = apiScenarioRunService.parse(msScenario, apiScenarioDetail.getSteps(), parseParam); - - ApiResourceRunRequest runRequest = apiScenarioRunService.getApiResourceRunRequest(msScenario, tmpParam); - - Project project = projectMapper.selectByPrimaryKey(apiScenarioDetail.getProjectId()); + Project project = projectMapper.selectByPrimaryKey(apiScenario.getProjectId()); ExecTask execTask = apiCommonService.newExecTask(project.getId(), userId); execTask.setCaseCount(1L); - execTask.setTaskName(apiScenarioDetail.getName()); + execTask.setTaskName(apiScenario.getName()); execTask.setOrganizationId(project.getOrganizationId()); execTask.setTriggerMode(TaskTriggerMode.SCHEDULE.name()); execTask.setTaskType(ExecTaskType.API_SCENARIO.name()); @@ -76,12 +54,12 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob { ExecTaskItem execTaskItem = apiCommonService.newExecTaskItem(execTask.getId(), project.getId(), userId); execTaskItem.setOrganizationId(project.getOrganizationId()); execTaskItem.setResourceType(ApiExecuteResourceType.API_SCENARIO.name()); - execTaskItem.setResourceId(apiScenarioDetail.getId()); - execTaskItem.setCaseId(apiScenarioDetail.getId()); - execTaskItem.setResourceName(apiScenarioDetail.getName()); + execTaskItem.setResourceId(apiScenario.getId()); + execTaskItem.setCaseId(apiScenario.getId()); + execTaskItem.setResourceName(apiScenario.getName()); baseTaskHubService.insertExecTaskAndDetail(execTask, execTaskItem); - TaskRequestDTO taskRequest = apiScenarioRunService.getTaskRequest(IDGenerator.nextStr(), apiScenarioDetail.getId(), apiScenarioDetail.getProjectId(), ApiExecuteRunMode.SCHEDULE.name()); + TaskRequestDTO taskRequest = apiScenarioRunService.getTaskRequest(null, apiScenario.getId(), apiScenario.getProjectId(), ApiExecuteRunMode.SCHEDULE.name()); TaskInfo taskInfo = taskRequest.getTaskInfo(); TaskItem taskItem = taskRequest.getTaskItem(); taskInfo.getRunModeConfig().setPoolId(apiRunModeConfigDTO.getPoolId()); @@ -89,28 +67,11 @@ public class ApiScenarioScheduleJob extends BaseScheduleJob { taskInfo.setSaveResult(true); taskInfo.setRealTime(false); taskInfo.setUserId(userId); - taskInfo.getRunModeConfig().setEnvironmentId(parseParam.getEnvironmentId()); - taskItem.setRequestCount(tmpParam.getRequestCount().get()); + taskInfo.getRunModeConfig().setEnvironmentId(apiRunModeConfigDTO.getEnvironmentId()); + taskInfo.getRunModeConfig().setGrouped(apiRunModeConfigDTO.getGrouped()); taskItem.setId(execTaskItem.getId()); - ApiScenarioParamConfig parseConfig = apiScenarioRunService.getApiScenarioParamConfig(msScenario.getProjectId(), parseParam, tmpParam.getScenarioParseEnvInfo()); - parseConfig.setTaskItemId(taskItem.getId()); - - // 初始化报告 - ApiScenarioReport scenarioReport = apiScenarioRunService.getScenarioReport(userId); - scenarioReport.setId(taskItem.getReportId()); - scenarioReport.setTriggerMode(TaskTriggerMode.SCHEDULE.name()); - scenarioReport.setRunMode(ApiBatchRunMode.PARALLEL.name()); - scenarioReport.setPoolId(apiRunModeConfigDTO.getPoolId()); - scenarioReport.setEnvironmentId(parseParam.getEnvironmentId()); - scenarioReport.setWaitingTime(apiScenarioRunService.getGlobalWaitTime(parseParam.getScenarioConfig())); - - apiScenarioRunService.initApiScenarioReport(taskItem.getId(), apiScenarioDetail, scenarioReport); - - // 初始化报告步骤 - apiScenarioRunService.initScenarioReportSteps(apiScenarioDetail.getSteps(), taskItem.getReportId()); - - apiExecuteService.execute(runRequest, taskRequest, parseConfig); + apiExecuteService.execute(taskRequest); }