From 9552f43d1acab10a98ceef822cc8d96bcbfc0fa3 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 13 Nov 2024 15:22:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=9C=BA=E6=99=AF=E6=89=A7=E8=A1=8C=E5=8E=86=E5=8F=B2&?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=BB=93=E6=9E=9C=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../definition/ApiReportController.java | 3 +- .../definition/ApiTestCaseController.java | 9 ++- .../scenario/ApiScenarioController.java | 7 +- .../scenario/ApiScenarioReportController.java | 8 ++- .../api/dto/definition/ExecHistoryDTO.java | 48 ++++++++++++++ .../api/mapper/ExtApiScenarioMapper.java | 2 + .../api/mapper/ExtApiScenarioMapper.xml | 48 ++++++++++++++ .../definition/ApiTestCaseService.java | 64 ++++++++----------- .../service/scenario/ApiScenarioService.java | 53 ++++----------- .../TestPlanApiCaseBatchRunService.java | 5 +- .../TestPlanApiScenarioBatchRunService.java | 5 +- 11 files changed, 159 insertions(+), 93 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecHistoryDTO.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java index f9d7197997..c0fc4bdc4e 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java @@ -135,7 +135,8 @@ public class ApiReportController { @GetMapping("/task-report/{id}") @Operation(summary = "系统-任务中心-接口用例执行任务详情-查看") @RequiresPermissions(value = {PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ, - PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ}, logical = Logical.OR) + PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ, + PermissionConstants.PROJECT_API_REPORT_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE}, logical = Logical.OR) public ApiTaskReportDTO viewCaseItemReport(@PathVariable String id) { return apiReportService.viewCaseTaskItemReport(id); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java index a829a9fa6a..0dddc43ce4 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java @@ -167,7 +167,7 @@ public class ApiTestCaseController { public Pager> page(@Validated @RequestBody ApiTestCasePageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString("id")) ? request.getSortString("id") : "pos desc, id desc"); - return PageUtils.setPageInfo(page, apiTestCaseService.page(request, false, true,null)); + return PageUtils.setPageInfo(page, apiTestCaseService.page(request, false, true, null)); } @PostMapping(value = "/statistics") @@ -248,8 +248,11 @@ public class ApiTestCaseController { @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE}) @CheckOwner(resourceId = "#request.getId()", resourceType = "api_test_case") public Pager> getExecuteList(@Validated @RequestBody ExecutePageRequest request) { - Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); + String sort = StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "eti.id desc"; + if (StringUtils.isNotBlank(sort)) { + sort = sort.replace("start_time", "et.create_time"); + } + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort); return PageUtils.setPageInfo(page, apiTestCaseService.getExecuteList(request)); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java index a19acf7433..5ebc9d41f0 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java @@ -274,8 +274,11 @@ public class ApiScenarioController { @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_SCENARIO_READ, PermissionConstants.PROJECT_API_SCENARIO_UPDATE}) @CheckOwner(resourceId = "#request.getId()", resourceType = "api_scenario") public Pager> getExecuteList(@Validated @RequestBody ExecutePageRequest request) { - Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); + String sort = StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "eti.id desc"; + if (StringUtils.isNotBlank(sort)) { + sort = sort.replace("start_time", "et.create_time"); + } + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort); return PageUtils.setPageInfo(page, apiScenarioService.getExecuteList(request)); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java index 9210388b54..66bb5e9850 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java @@ -140,7 +140,8 @@ public class ApiScenarioReportController { @GetMapping("/task-step/{id}") @Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(任务步骤)") @RequiresPermissions(value = {PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ, - PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ}, logical = Logical.OR) + PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ, + PermissionConstants.PROJECT_API_REPORT_READ, PermissionConstants.PROJECT_API_SCENARIO_EXECUTE}, logical = Logical.OR) public ExecTaskDetailDTO viewScenarioItemReport(@PathVariable String id) { return apiScenarioReportService.viewScenarioItemReport(id); } @@ -148,9 +149,10 @@ public class ApiScenarioReportController { @GetMapping("/task-report/{reportId}/{stepId}") @Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(步骤结果)") @RequiresPermissions(value = {PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ, - PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ}, logical = Logical.OR) + PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ, + PermissionConstants.PROJECT_API_REPORT_READ, PermissionConstants.PROJECT_API_SCENARIO_EXECUTE}, logical = Logical.OR) public List getScenarioReportDetail(@PathVariable String reportId, - @PathVariable String stepId) { + @PathVariable String stepId) { return apiScenarioReportService.getDetail(reportId, stepId); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecHistoryDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecHistoryDTO.java new file mode 100644 index 0000000000..709f5970ac --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecHistoryDTO.java @@ -0,0 +1,48 @@ +package io.metersphere.api.dto.definition; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author wx + */ +@Data +public class ExecHistoryDTO implements Serializable { + + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "任务项id") + private String itemId; + + @Schema(description = "任务id") + private String taskId; + + @Schema(description = "执行方式") + private String triggerMode; + + @Schema(description = "执行结果") + private String status; + + @Schema(description = "状态") + private String execStatus; + + @Schema(description = "操作人") + private String createUser; + + @Schema(description = "操作时间") + private Long startTime; + + @Schema(description = "是否集合报告") + private Boolean integrated; + + @Schema(description = "测试计划id") + private String testPlanId; + + @Schema(description = "测试计划Num") + private String testPlanNum; +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java index 934452279f..fd0678cc3a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java @@ -2,6 +2,7 @@ package io.metersphere.api.mapper; import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.dto.ApiResourceBatchRunInfo; +import io.metersphere.api.dto.definition.ExecHistoryDTO; import io.metersphere.api.dto.definition.ExecutePageRequest; import io.metersphere.api.dto.definition.ExecuteReportDTO; import io.metersphere.api.dto.scenario.*; @@ -105,4 +106,5 @@ public interface ExtApiScenarioMapper { List userCreateApiScenarioCount(@Param("projectId") String projectId, @Param("startTime") long startTime, @Param("endTime") long endTime, @Param("userIds") Set userIds); + List selectExecHistory(@Param("request") ExecutePageRequest request); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml index 559a99bb27..ad76028f3f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml @@ -798,4 +798,52 @@ group by api_scenario.create_user; + + + + + + + + + + + and et.integrated in + + + + and eti.result in + + + + and et.trigger_mode in + + + + + + + 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 592d22c2bd..063e198105 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 @@ -58,7 +58,6 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -import java.util.stream.Stream; @Service @Transactional(rollbackFor = Exception.class) @@ -108,6 +107,8 @@ public class ApiTestCaseService extends MoveNodeService { private FunctionalCaseTestMapper functionalCaseTestMapper; @Resource private UserMapper userMapper; + @Resource + private ExtApiScenarioMapper extApiScenarioMapper; private static final String CASE_TABLE = "api_test_case"; @@ -342,6 +343,7 @@ public class ApiTestCaseService extends MoveNodeService { } return returnList; } + private void buildApiTestCaseDTO(List apiCaseLists) { if (CollectionUtils.isNotEmpty(apiCaseLists)) { List userIds = new ArrayList<>(); @@ -569,46 +571,32 @@ public class ApiTestCaseService extends MoveNodeService { } public List getExecuteList(ExecutePageRequest request) { - List executeList = extApiTestCaseMapper.getExecuteList(request); - if (CollectionUtils.isEmpty(executeList)) { - return new ArrayList<>(); - } - Set userSet = executeList.stream() - .flatMap(apiReport -> Stream.of(apiReport.getCreateUser())) - .collect(Collectors.toSet()); - Map userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet)); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); - //执行历史列表 - List reportIds = executeList.stream().map(ExecuteReportDTO::getId).toList(); - Map historyDeletedMap = new HashMap<>(); - if (CollectionUtils.isNotEmpty(reportIds)) { - List historyDeletedList = extApiReportMapper.getHistoryDeleted(reportIds); - historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity())); - } - - Map testPlanIdMap = executeList.stream() - .filter(apiReport -> !StringUtils.equals(apiReport.getTestPlanId(), "NONE")) - .collect(Collectors.toMap(ExecuteReportDTO::getId, ExecuteReportDTO::getTestPlanId)); - List testPlanIds = new ArrayList<>(testPlanIdMap.keySet()); - Map testPlanNumMap = new HashMap<>(); - if (CollectionUtils.isNotEmpty(testPlanIds)) { - List testPlanNameLists = extApiTestCaseMapper.getTestPlanNum(testPlanIds); - testPlanNumMap = testPlanNameLists.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, ExecuteReportDTO::getTestPlanNum)); - } - Map finalHistoryDeletedMap = historyDeletedMap; - Map finalTestPlanNumMap = testPlanNumMap; - executeList.forEach(apiReport -> { - apiReport.setOperationUser(userMap.get(apiReport.getCreateUser())); - Date date = new Date(apiReport.getStartTime()); - apiReport.setNum(sdf.format(date)); - apiReport.setHistoryDeleted(MapUtils.isNotEmpty(finalHistoryDeletedMap) && !finalHistoryDeletedMap.containsKey(apiReport.getId())); - if (MapUtils.isNotEmpty(testPlanIdMap) && testPlanIdMap.containsKey(apiReport.getId())) { - apiReport.setTestPlanNum(StringUtils.join(Translator.get("test_plan"), ": ", finalTestPlanNumMap.get(apiReport.getId()))); - } - }); + List historyList = extApiScenarioMapper.selectExecHistory(request); + List executeList = handleList(historyList); return executeList; } + private List handleList(List historyList) { + List executeReportDTOList = new ArrayList<>(); + if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(historyList)) { + List userIds = historyList.stream().map(ExecHistoryDTO::getCreateUser).toList(); + Map userNameMap = userLoginService.getUserNameMap(userIds); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + historyList.forEach(item -> { + ExecuteReportDTO reportDTO = new ExecuteReportDTO(); + BeanUtils.copyBean(reportDTO, item); + reportDTO.setOperationUser(userNameMap.get(item.getCreateUser())); + reportDTO.setId(item.getItemId()); + reportDTO.setNum(sdf.format(item.getStartTime())); + if (StringUtils.isNotBlank(item.getTestPlanNum())) { + reportDTO.setTestPlanNum(StringUtils.join(Translator.get("test_plan"), ": ", item.getTestPlanNum())); + } + executeReportDTOList.add(reportDTO); + }); + } + return executeReportDTOList; + } + public List operationHistoryList(OperationHistoryRequest request) { return operationHistoryService.listWidthTable(request, CASE_TABLE); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index c9bc8a12a3..ddd20d9549 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -7,6 +7,7 @@ import io.metersphere.api.controller.result.ApiResultCode; import io.metersphere.api.domain.*; import io.metersphere.api.dto.*; import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest; +import io.metersphere.api.dto.definition.ExecHistoryDTO; import io.metersphere.api.dto.definition.ExecutePageRequest; import io.metersphere.api.dto.definition.ExecuteReportDTO; import io.metersphere.api.dto.export.MetersphereApiScenarioExportResponse; @@ -177,6 +178,8 @@ public class ApiScenarioService extends MoveNodeService { public static final String SCHEDULE = "Schedule"; private static final String SCENARIO_TABLE = "api_scenario"; private static final String SCENARIO = "SCENARIO"; + @Resource + private ApiReportRelateTaskMapper apiReportRelateTaskMapper; public List getScenarioPage(ApiScenarioPageRequest request, boolean isRepeat, String testPlanId) { @@ -1002,7 +1005,7 @@ public class ApiScenarioService extends MoveNodeService { * 获取待更新的 ApiScenarioStep 列表 */ public List getApiScenarioSteps(ApiScenarioStepCommonDTO parent, - List steps, List csvSteps) { + List steps, List csvSteps) { if (CollectionUtils.isEmpty(steps)) { return Collections.emptyList(); } @@ -1462,6 +1465,7 @@ public class ApiScenarioService extends MoveNodeService { return getStepBlobByIds(stepIdList).stream() .collect(Collectors.toMap(ApiScenarioStepBlob::getId, blob -> new String(blob.getContent()))); } + public List getStepBlobByIds(List stepIds) { if (CollectionUtils.isEmpty(stepIds)) { return Collections.emptyList(); @@ -1736,9 +1740,9 @@ public class ApiScenarioService extends MoveNodeService { * @param scenarioStepMap 所有场景步骤,key 为场景ID,value 为子步骤列表 */ public List buildStepTree(List steps, - Map> parentStepMap, - Map> scenarioStepMap, - Set stepIdSet) { + Map> parentStepMap, + Map> scenarioStepMap, + Set stepIdSet) { if (CollectionUtils.isEmpty(steps)) { return Collections.emptyList(); } @@ -2377,46 +2381,11 @@ public class ApiScenarioService extends MoveNodeService { } public List getExecuteList(ExecutePageRequest request) { - List executeList = extApiScenarioMapper.getExecuteList(request); - if (CollectionUtils.isEmpty(executeList)) { - return new ArrayList<>(); - } - Set userSet = executeList.stream() - .flatMap(apiReport -> Stream.of(apiReport.getCreateUser())) - .collect(Collectors.toSet()); - //执行历史列表 - List reportIds = executeList.stream().map(ExecuteReportDTO::getId).toList(); - Map historyDeletedMap = new HashMap<>(); - if (CollectionUtils.isNotEmpty(reportIds)) { - List historyDeletedList = extApiScenarioReportMapper.getHistoryDeleted(reportIds); - historyDeletedMap = historyDeletedList.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, Function.identity())); - } - Map testPlanIdMap = executeList.stream() - .filter(apiReport -> !StringUtils.equals(apiReport.getTestPlanId(), "NONE")) - .collect(Collectors.toMap(ExecuteReportDTO::getId, ExecuteReportDTO::getTestPlanId)); - List testPlanIds = new ArrayList<>(testPlanIdMap.keySet()); - Map testPlanNumMap = new HashMap<>(); - if (org.apache.commons.collections.CollectionUtils.isNotEmpty(testPlanIds)) { - List testPlanNameLists = extApiScenarioReportMapper.getTestPlanNum(testPlanIds); - testPlanNumMap = testPlanNameLists.stream().collect(Collectors.toMap(ExecuteReportDTO::getId, ExecuteReportDTO::getTestPlanNum)); - } - - Map userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet)); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); - Map finalHistoryDeletedMap = historyDeletedMap; - Map finalTestPlanNumMap = testPlanNumMap; - executeList.forEach(apiReport -> { - apiReport.setOperationUser(userMap.get(apiReport.getCreateUser())); - Date date = new Date(apiReport.getStartTime()); - apiReport.setNum(sdf.format(date)); - apiReport.setHistoryDeleted(MapUtils.isNotEmpty(finalHistoryDeletedMap) && !finalHistoryDeletedMap.containsKey(apiReport.getId())); - if (MapUtils.isNotEmpty(testPlanIdMap) && testPlanIdMap.containsKey(apiReport.getId())) { - apiReport.setTestPlanNum(StringUtils.join(Translator.get("test_plan"), ": ", finalTestPlanNumMap.get(apiReport.getId()))); - } - }); - return executeList; + return apiTestCaseService.getExecuteList(request); } + + public List operationHistoryList(OperationHistoryRequest request) { return operationHistoryService.listWidthTable(request, SCENARIO_TABLE); } 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 6eaf415161..2277cd353f 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 @@ -117,7 +117,7 @@ public class TestPlanApiCaseBatchRunService { // 初始化任务 ExecTask execTask = initExecTask(testPlanApiCases.size(), project, userId); // 初始化任务项 - initExecTaskItem(testPlanApiCases, userId, project, execTask); + initExecTaskItem(testPlanApiCases, userId, project, execTask, testPlan.getId()); TestPlanCollection finalRootCollection = rootCollection; List finalTestPlanCollections = testPlanCollections; @@ -296,7 +296,7 @@ public class TestPlanApiCaseBatchRunService { return testPlanApiCases; } - private List initExecTaskItem(List apiTestCases, String userId, Project project, ExecTask execTask) { + private List initExecTaskItem(List apiTestCases, String userId, Project project, ExecTask execTask, String testPlanId) { List execTaskItems = new ArrayList<>(apiTestCases.size()); for (TestPlanApiCaseBatchRunDTO apiTestCase : apiTestCases) { ExecTaskItem execTaskItem = apiCommonService.newExecTaskItem(execTask.getId(), project.getId(), userId); @@ -304,6 +304,7 @@ public class TestPlanApiCaseBatchRunService { execTaskItem.setResourceType(ApiExecuteResourceType.TEST_PLAN_API_CASE.name()); execTaskItem.setResourceId(apiTestCase.getId()); execTaskItem.setCaseId(apiTestCase.getCaseId()); + execTaskItem.setTaskOrigin(testPlanId); execTaskItem.setResourceName(apiTestCase.getName()); execTaskItem.setCollectionId(apiTestCase.getTestPlanCollectionId()); execTaskItems.add(execTaskItem); 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 ad8da16a8e..0334db1080 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 @@ -114,7 +114,7 @@ public class TestPlanApiScenarioBatchRunService { ExecTask execTask = initExecTask(testPlanApiScenarios.size(), project, userId); // 初始化任务项 - initExecTaskItem(testPlanApiScenarios, userId, project, execTask); + initExecTaskItem(testPlanApiScenarios, userId, project, execTask, testPlan.getId()); TestPlanCollection finalRootCollection = rootCollection; List finalTestPlanCollections = testPlanCollections; @@ -274,7 +274,7 @@ public class TestPlanApiScenarioBatchRunService { return execTask; } - private List initExecTaskItem(List apiTestCases, String userId, Project project, ExecTask execTask) { + private List initExecTaskItem(List apiTestCases, String userId, Project project, ExecTask execTask, String testPlanId) { List execTaskItems = new ArrayList<>(apiTestCases.size()); for (TestPlanApiScenarioBatchRunDTO testPlanApiScenario : apiTestCases) { ExecTaskItem execTaskItem = apiCommonService.newExecTaskItem(execTask.getId(), project.getId(), userId); @@ -282,6 +282,7 @@ public class TestPlanApiScenarioBatchRunService { execTaskItem.setResourceType(ApiExecuteResourceType.TEST_PLAN_API_SCENARIO.name()); execTaskItem.setResourceId(testPlanApiScenario.getId()); execTaskItem.setCaseId(testPlanApiScenario.getCaseId()); + execTaskItem.setTaskOrigin(testPlanId); execTaskItem.setResourceName(testPlanApiScenario.getName()); execTaskItem.setCollectionId(testPlanApiScenario.getTestPlanCollectionId()); execTaskItems.add(execTaskItem);