From 90e71f7e62211a33ba0f71396cb619e6c4002b37 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 7 Nov 2022 15:42:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3case=E5=85=B3=E7=B3=BB=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【【接口测试】接口CASE引用关系查看】 https://www.tapd.cn/55049933/prong/stories/view/1155049933001009305 --- .../api/dto/ApiProjectRequest.java | 12 + .../api/dto/DeleteCheckResult.java | 3 + .../api/dto/QueryReferenceRequest.java | 5 +- .../api/dto/automation/ApiScenarioDTO.java | 2 + .../api/dto/automation/TestPlanDTO.java | 1 + .../base/mapper/ext/ExtApiProjectMapper.java | 12 + .../base/mapper/ext/ExtApiProjectMapper.xml | 26 ++ .../base/mapper/ext/ExtApiScenarioMapper.java | 2 +- .../base/mapper/ext/ExtApiScenarioMapper.xml | 39 ++- .../ext/ExtApiScenarioReferenceIdMapper.java | 2 + .../ext/ExtApiScenarioReferenceIdMapper.xml | 14 + .../plan/ext/ExtTestPlanApiCaseMapper.java | 4 + .../plan/ext/ExtTestPlanApiCaseMapper.xml | 53 ++- .../ext/ExtTestPlanApiScenarioMapper.java | 1 + .../plan/ext/ExtTestPlanApiScenarioMapper.xml | 12 + .../ext/ExtTestPlanScenarioCaseMapper.java | 9 +- .../definition/ApiDefinitionController.java | 10 +- .../controller/ext/ExtProjectController.java | 13 +- .../plan/TestPlanApiCaseController.java | 12 +- .../scenario/ApiScenarioController.java | 5 - .../definition/ApiDefinitionService.java | 24 +- .../definition/ApiTestCaseService.java | 81 +++-- .../ext/ExtProjectApplicationService.java | 16 + .../service/plan/TestPlanApiCaseService.java | 27 +- .../service/scenario/ApiScenarioService.java | 79 +++-- .../resources/i18n/messages_en_US.properties | 3 +- .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + api-test/frontend/src/api/definition.js | 8 +- api-test/frontend/src/api/scenario.js | 4 - .../automation/scenario/ApiScenarioList.vue | 100 +++--- .../automation/scenario/ReferenceView.vue | 95 ------ .../scenario/ScenarioDeleteConfirm.vue | 55 ++++ .../scenario/ScenarioExtendBtns.vue | 7 +- .../components/list/ApiCaseSimpleList.vue | 131 ++++---- .../components/list/ApiDeleteConfirm.vue | 105 ++++++ .../definition/components/list/ApiList.vue | 2 +- .../components/reference/ApiExtendBtns.vue | 9 +- .../components/reference/ReferenceView.vue | 128 -------- .../components/reference/ShowReference.vue | 304 ++++++++++++++++++ api-test/frontend/src/i18n/lang/en-US.js | 10 +- api-test/frontend/src/i18n/lang/zh-CN.js | 8 + api-test/frontend/src/i18n/lang/zh-TW.js | 8 + 43 files changed, 989 insertions(+), 454 deletions(-) create mode 100644 api-test/backend/src/main/java/io/metersphere/api/dto/ApiProjectRequest.java create mode 100644 api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java create mode 100644 api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml delete mode 100644 api-test/frontend/src/business/automation/scenario/ReferenceView.vue create mode 100644 api-test/frontend/src/business/automation/scenario/ScenarioDeleteConfirm.vue create mode 100644 api-test/frontend/src/business/definition/components/list/ApiDeleteConfirm.vue delete mode 100644 api-test/frontend/src/business/definition/components/reference/ReferenceView.vue create mode 100644 api-test/frontend/src/business/definition/components/reference/ShowReference.vue diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/ApiProjectRequest.java b/api-test/backend/src/main/java/io/metersphere/api/dto/ApiProjectRequest.java new file mode 100644 index 0000000000..e578e04584 --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/ApiProjectRequest.java @@ -0,0 +1,12 @@ +package io.metersphere.api.dto; + +import io.metersphere.request.ProjectRequest; +import lombok.Data; + +import java.util.List; + +@Data +public class ApiProjectRequest extends ProjectRequest { + private List workspaceIds; + +} diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/DeleteCheckResult.java b/api-test/backend/src/main/java/io/metersphere/api/dto/DeleteCheckResult.java index bb299bccb5..4caa846571 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/DeleteCheckResult.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/DeleteCheckResult.java @@ -14,4 +14,7 @@ import java.util.List; public class DeleteCheckResult { boolean deleteFlag; List checkMsg; + int refCount; + int scenarioCount; + int planCount; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/QueryReferenceRequest.java b/api-test/backend/src/main/java/io/metersphere/api/dto/QueryReferenceRequest.java index 0caaafdd4b..25e7e32963 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/QueryReferenceRequest.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/QueryReferenceRequest.java @@ -1,13 +1,16 @@ package io.metersphere.api.dto; +import io.metersphere.request.BaseQueryRequest; import lombok.Getter; import lombok.Setter; @Getter @Setter -public class QueryReferenceRequest { +public class QueryReferenceRequest extends BaseQueryRequest { private String scenarioId; private String apiId; private String loadId; private String projectId; + private String workspaceId; + private String id; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java index 543848a28b..5bb3c8fe60 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java @@ -33,4 +33,6 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs { private String env; private Map environmentMap; private String creator; + private String workspaceName; + private String workspaceId; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanDTO.java index 8afdd6a032..4f57df22db 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanDTO.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/TestPlanDTO.java @@ -34,4 +34,5 @@ public class TestPlanDTO extends TestPlanWithBLOBs { * 定时任务下一次执行时间 */ private Long scheduleExecuteTime; + private String workspaceName; } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java new file mode 100644 index 0000000000..c1f3d090fd --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.java @@ -0,0 +1,12 @@ +package io.metersphere.base.mapper.ext; + +import io.metersphere.api.dto.ApiProjectRequest; +import io.metersphere.dto.ProjectDTO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ExtApiProjectMapper { + List getUserProject(@Param("proRequest") ApiProjectRequest request); + +} diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml new file mode 100644 index 0000000000..5a822b60ac --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiProjectMapper.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java index fd9cdadcfc..d13e325553 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java @@ -32,7 +32,7 @@ public interface ExtApiScenarioMapper { List selectByIds(@Param("ids") String ids, @Param("order") String order); - List selectReference(@Param("request") ApiScenarioRequest request); + List selectReference(@Param("request") ApiScenarioRequest request); int removeToGcByExample(ApiScenarioExampleWithOperation example); diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index 4976b78aa6..142a7bb98f 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -460,18 +460,41 @@ ORDER BY FIND_IN_SET(id, ${order}) - + select a.id, a.name , a.num,p.name AS projectName, a.update_time, a.create_time, + w.name AS workspaceName, p.workspace_id AS workspaceId, p.id AS projectId from api_scenario a + LEFT JOIN project p ON a.project_id = p.id + LEFT JOIN `workspace` w ON p.workspace_id = w.id - - AND project.workspace_id = #{request.workspaceId} + a.status != 'Trash' + + and a.id in + + #{id} + - - AND api_scenario_module_id = #{request.moduleId} + + + + + + and a.project_id in + + #{value} + + + + and p.workspace_id in + + #{value} + + + + + - and status != 'Trash' - and scenario_definition like CONCAT('%', #{request.id},'%') and id != #{request.id} + update api_scenario diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java index d8e945a7e8..29e96d4328 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.java @@ -6,4 +6,6 @@ import java.util.List; public interface ExtApiScenarioReferenceIdMapper { List selectUrlByProjectId(String projectId); + + List selectReferenceIdByIds(List ids); } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml index 367a4dec05..b45cded606 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReferenceIdMapper.xml @@ -12,5 +12,19 @@ AND latest = 1) AND reference_id IS NOT NULL + \ No newline at end of file diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java index ea8e6ed2e7..41d5ee20bc 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java @@ -55,6 +55,10 @@ public interface ExtTestPlanApiCaseMapper { List selectByIdsAndStatusIsNotTrash(@Param("ids") List ids); + List selectNameByIdIn(@Param("ids") List ids); + String selectProjectId(String id); + + List selectByRefIds(@Param("ids") List ids); } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml index 13cd416037..56e7b5b32b 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml @@ -479,8 +479,13 @@ + + diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.java index 6c35c1bfec..9a99d8c32b 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.java @@ -10,4 +10,5 @@ public interface ExtTestPlanApiScenarioMapper { List selectPlanByIdsAndStatusIsNotTrash(@Param("ids") List ids); + List selectByScenarioIds(@Param("ids") List ids); } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.xml index ba49768352..e876b20297 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiScenarioMapper.xml @@ -26,4 +26,16 @@ #{v} + diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java index 934e179bbb..85706cdec2 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanScenarioCaseMapper.java @@ -1,10 +1,12 @@ package io.metersphere.base.mapper.plan.ext; +import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.TestPlanFailureScenarioDTO; import io.metersphere.api.dto.automation.TestPlanScenarioRequest; import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; import io.metersphere.base.domain.TestPlanApiScenario; + import io.metersphere.dto.PlanReportCaseDTO; import org.apache.ibatis.annotations.Param; @@ -22,9 +24,9 @@ public interface ExtTestPlanScenarioCaseMapper { List getNotRelevanceCaseIds(String planId, List relevanceProjectIds); - List selectIds(@Param("request") TestPlanScenarioRequest request); + List selectIds(@Param("request")TestPlanScenarioRequest request); - List selectByIds(@Param("ids") String ids, @Param("order") String order); + List selectByIds(@Param("ids")String ids ,@Param("order")String order ); List selectLegalDataByTestPlanId(String planId); @@ -32,7 +34,7 @@ public interface ExtTestPlanScenarioCaseMapper { List getFailureList(@Param("planId") String planId, @Param("status") String status); - List getFailureListByIds(@Param("ids") Collection ids, @Param("status") String status); + List getFailureListByIds(@Param("ids") Collection ids,@Param("status") String status); List getUnderwaySteps(@Param("ids") List underwayIds); @@ -46,5 +48,6 @@ public interface ExtTestPlanScenarioCaseMapper { Long getLastOrder(@Param("planId") String planId, @Param("baseOrder") Long baseOrder); + List selectNameByIdIn(List ids); String selectProjectId(String testPlanId); } diff --git a/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java b/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java index 365356a891..a7d302f01f 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java @@ -3,8 +3,8 @@ package io.metersphere.controller.definition; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.*; +import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioRequest; -import io.metersphere.api.dto.automation.ReferenceDTO; import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.definition.request.assertions.document.DocumentElement; @@ -262,9 +262,11 @@ public class ApiDefinitionController { apiDefinitionService.deleteSchedule(request); } - @PostMapping("/get-reference") - public ReferenceDTO getReference(@RequestBody ApiScenarioRequest request) { - return apiDefinitionService.getReference(request); + @PostMapping("/get-reference/{goPage}/{pageSize}") + public Pager> getReference(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) { + apiDefinitionService.getReferenceIds(request); + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, apiDefinitionService.getReference(request)); } @PostMapping("/batch/edit") diff --git a/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java b/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java index 09c0c4b07f..48347864f2 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/ext/ExtProjectController.java @@ -2,6 +2,7 @@ package io.metersphere.controller.ext; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import io.metersphere.api.dto.ApiProjectRequest; import io.metersphere.commons.constants.PermissionConstants; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; @@ -11,12 +12,7 @@ import io.metersphere.service.BaseCheckPermissionService; import io.metersphere.service.BaseProjectService; import io.metersphere.service.ext.ExtProjectApplicationService; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Collection; @@ -58,4 +54,9 @@ public class ExtProjectController { public void updateCurrentUserByResourceId(@PathVariable String resourceId) { extProjectApplicationService.updateCurrentUserByResourceId(resourceId); } + + @PostMapping("/list/related") + public List getUserProject(@RequestBody ApiProjectRequest request) { + return extProjectApplicationService.getUserProject(request); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java index 644e37b5ee..83d2aeff5b 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java @@ -2,10 +2,11 @@ package io.metersphere.controller.plan; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import io.metersphere.api.dto.QueryReferenceRequest; +import io.metersphere.api.dto.automation.TestPlanDTO; +import io.metersphere.api.dto.automation.TestPlanFailureApiDTO; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.plan.TestPlanApiCaseBatchRequest; -import io.metersphere.api.dto.automation.TestPlanFailureApiDTO; -import io.metersphere.service.plan.TestPlanApiCaseService; import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogModule; import io.metersphere.commons.constants.PermissionConstants; @@ -15,6 +16,7 @@ import io.metersphere.dto.MsExecResponseDTO; import io.metersphere.dto.RunModeConfigDTO; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.request.ResetOrderRequest; +import io.metersphere.service.plan.TestPlanApiCaseService; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.*; @@ -185,4 +187,10 @@ public class TestPlanApiCaseController { testPlanApiCaseService.buildApiResponse(cases); return cases; } + + @PostMapping("/get-reference/{goPage}/{pageSize}") + public Pager> getReference(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryReferenceRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, testPlanApiCaseService.getReference(request)); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java b/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java index 054e796201..35d309f3c9 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/scenario/ApiScenarioController.java @@ -273,11 +273,6 @@ public class ApiScenarioController { apiAutomationService.batchUpdateEnv(request); } - @PostMapping("/getReference") - public ReferenceDTO getReference(@RequestBody ApiScenarioRequest request) { - return apiAutomationService.getReference(request); - } - @PostMapping("/scenario/plan") public String addScenarioToPlan(@RequestBody SaveApiPlanRequest request) { return apiAutomationService.addScenarioToPlan(request); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 96e058736d..8587e1fdc1 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -8,8 +8,8 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.github.ningyu.jmeter.plugin.dubbo.sample.ProviderService; import io.metersphere.api.dto.*; +import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioRequest; -import io.metersphere.api.dto.automation.ReferenceDTO; import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.definition.*; @@ -1908,14 +1908,20 @@ public class ApiDefinitionService { } - public ReferenceDTO getReference(ApiScenarioRequest request) { - ReferenceDTO dto = new ReferenceDTO(); - dto.setScenarioList(extApiScenarioMapper.selectReference(request)); - QueryReferenceRequest planRequest = new QueryReferenceRequest(); - planRequest.setApiId(request.getId()); - planRequest.setProjectId(request.getProjectId()); - dto.setTestPlanList(extTestPlanApiCaseMapper.selectTestPlanByRelevancy(planRequest)); - return dto; + public List getReference(ApiScenarioRequest request) { + if (CollectionUtils.isEmpty(request.getIds())) { + return new ArrayList<>(); + } else { + return extApiScenarioMapper.selectReference(request); + } + } + + public void getReferenceIds(ApiScenarioRequest request) { + ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample(); + example.createCriteria().andReferenceIdEqualTo(request.getId()).andReferenceTypeEqualTo(MsTestElementConstants.REF.name()); + List scenarioReferenceIds = apiScenarioReferenceIdMapper.selectByExample(example); + List scenarioIds = scenarioReferenceIds.stream().map(ApiScenarioReferenceId::getApiScenarioId).collect(Collectors.toList()); + request.setIds(scenarioIds); } public void editApiBath(ApiBatchRequest request) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java index 231a1be680..71e978f79e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java @@ -16,6 +16,7 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.*; +import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.enums.ApiTestDataStatus; @@ -36,12 +37,12 @@ import io.metersphere.service.BaseUserService; import io.metersphere.service.ServiceUtils; import io.metersphere.service.ext.ExtFileAssociationService; import io.metersphere.service.plan.TestPlanApiCaseService; -import io.metersphere.service.scenario.ApiScenarioReferenceIdService; import io.metersphere.xpack.api.service.ApiCaseBatchSyncService; import io.metersphere.xpack.api.service.ApiTestCaseSyncService; import io.metersphere.xpack.version.service.ProjectVersionService; import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.comparators.FixedOrderComparator; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; @@ -83,8 +84,6 @@ public class ApiTestCaseService { @Resource private EsbApiParamService esbApiParamService; @Resource - private ApiScenarioReferenceIdService apiScenarioReferenceIdService; - @Resource private ExtApiScenarioMapper extApiScenarioMapper; @Resource private ApiTestEnvironmentMapper apiTestEnvironmentMapper; @@ -108,6 +107,10 @@ public class ApiTestCaseService { private ApiScenarioReferenceIdMapper apiScenarioReferenceIdMapper; @Resource private TestPlanApiCaseService testPlanApiCaseService; + @Resource + private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; + @Resource + private ExtApiScenarioReferenceIdMapper extApiScenarioReferenceIdMapper; private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; @@ -966,54 +969,63 @@ public class ApiTestCaseService { } public DeleteCheckResult checkDeleteData(ApiTestBatchRequest request) { + DeleteCheckResult result = new DeleteCheckResult(); List deleteIds = request.getIds(); if (request.isSelectAll()) { deleteIds = this.getAllApiCaseIdsByFrontedSelect(request.getFilters(), request.getModuleIds(), request.getName(), request.getProjectId(), request.getProtocol(), request.getUnSelectIds(), request.getStatus(), request.getApiDefinitionId(), request.getCombine()); } - DeleteCheckResult result = new DeleteCheckResult(); - List checkMsgList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(deleteIds)) { - List apiScenarioReferenceIdList = apiScenarioReferenceIdService.findByReferenceIdsAndRefType(deleteIds, MsTestElementConstants.REF.name()); + //场景引用 + List apiScenarioReferenceIdList = extApiScenarioReferenceIdMapper.selectReferenceIdByIds(deleteIds); + Map> scenarioDic = new HashMap<>(); if (CollectionUtils.isNotEmpty(apiScenarioReferenceIdList)) { - Map> scenarioDic = new HashMap<>(); apiScenarioReferenceIdList.forEach(item -> { - String refreceID = item.getReferenceId(); + String referenceId = item.getReferenceId(); String scenarioId = item.getApiScenarioId(); - if (scenarioDic.containsKey(refreceID)) { - scenarioDic.get(refreceID).add(scenarioId); + if (scenarioDic.containsKey(referenceId)) { + scenarioDic.get(referenceId).add(scenarioId); } else { List list = new ArrayList<>(); list.add(scenarioId); - scenarioDic.put(refreceID, list); + scenarioDic.put(referenceId, list); } }); - - for (Map.Entry> entry : scenarioDic.entrySet()) { - String refreceId = entry.getKey(); - List scenarioIdList = entry.getValue(); - if (CollectionUtils.isNotEmpty(scenarioIdList)) { - List scenarioNameList = extApiScenarioMapper.selectNameByIdIn(scenarioIdList); - String deleteCaseName = extApiTestCaseMapper.selectNameById(refreceId); - - if (StringUtils.isNotEmpty(deleteCaseName) && CollectionUtils.isNotEmpty(scenarioNameList)) { - String nameListStr = "["; - for (String name : scenarioNameList) { - nameListStr += name + ","; - } - if (nameListStr.length() > 1) { - nameListStr = nameListStr.substring(0, nameListStr.length() - 1) + "]"; - } - String msg = deleteCaseName + StringUtils.SPACE + Translator.get("delete_check_reference_by") + ": " + nameListStr + StringUtils.SPACE; - checkMsgList.add(msg); - } + } + //测试计划引用 + List testPlanApiCases = extTestPlanApiCaseMapper.selectByRefIds(deleteIds); + Map> planList = new HashMap<>(); + if (CollectionUtils.isNotEmpty(testPlanApiCases)) { + testPlanApiCases.forEach(item -> { + String referenceId = item.getApiCaseId(); + String testPlanId = item.getTestPlanId(); + if (planList.containsKey(referenceId)) { + planList.get(referenceId).add(testPlanId); + } else { + List list = new ArrayList<>(); + list.add(testPlanId); + planList.put(referenceId, list); + } + }); + } + if (MapUtils.isNotEmpty(scenarioDic) || MapUtils.isNotEmpty(planList)) { + if (StringUtils.equals("batch", request.getType())) { + Map> map = scenarioDic.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2, () -> new HashMap<>(planList))); + result.setRefCount(map.size()); + result.setCheckMsg(new ArrayList<>(map.keySet())); + } else { + ArrayList> scenarioList = new ArrayList<>(scenarioDic.values()); + if (CollectionUtils.isNotEmpty(scenarioList)) { + result.setScenarioCount(new TreeSet(scenarioList.get(0)).size()); + } + ArrayList> testPlanList = new ArrayList<>(planList.values()); + if (CollectionUtils.isNotEmpty(testPlanList)) { + result.setPlanCount(new TreeSet(testPlanList.get(0)).size()); } } + result.setDeleteFlag(scenarioDic.size() > 0 || planList.size() > 0); } } - - result.setDeleteFlag(checkMsgList.isEmpty()); - result.setCheckMsg(checkMsgList); return result; } @@ -1287,4 +1299,5 @@ public class ApiTestCaseService { private ApiCaseBasicInfoDTO selectApiCaseBasicInfoById(String id) { return extApiTestCaseMapper.selectApiCaseBasicInfoById(id); } + } diff --git a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java index 41f4dea435..7aa408411a 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java @@ -1,5 +1,6 @@ package io.metersphere.service.ext; +import io.metersphere.api.dto.ApiProjectRequest; import io.metersphere.api.tcp.TCPPool; import io.metersphere.base.domain.Project; import io.metersphere.base.domain.ProjectApplication; @@ -8,22 +9,26 @@ import io.metersphere.base.mapper.ProjectApplicationMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.UserMapper; import io.metersphere.base.mapper.ext.BaseProjectMapper; +import io.metersphere.base.mapper.ext.ExtApiProjectMapper; import io.metersphere.commons.constants.ProjectApplicationType; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.ProjectConfig; +import io.metersphere.dto.ProjectDTO; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.i18n.Translator; import io.metersphere.request.AddProjectRequest; import io.metersphere.service.BaseProjectApplicationService; import io.metersphere.service.BaseProjectService; +import io.metersphere.service.ServiceUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.List; @Service public class ExtProjectApplicationService { @@ -41,6 +46,8 @@ public class ExtProjectApplicationService { private BaseProjectMapper baseProjectMapper; @Resource private UserMapper userMapper; + @Resource + private ExtApiProjectMapper extApiProjectMapper; public void createOrUpdateConfig(String projectId, String type, String value) { ProjectApplication conf = new ProjectApplication(); @@ -161,6 +168,7 @@ public class ExtProjectApplicationService { TCPPool.closeTcp(tcpPort); } } + public void updateCurrentUserByResourceId(String resourceId) { Project project = baseProjectMapper.selectProjectByResourceId(resourceId); if (project == null) { @@ -171,4 +179,12 @@ public class ExtProjectApplicationService { user.setLastWorkspaceId(project.getWorkspaceId()); userMapper.updateByPrimaryKeySelective(user); } + + public List getUserProject(ApiProjectRequest request) { + if (StringUtils.isNotBlank(request.getName())) { + request.setName(StringUtils.wrapIfMissing(request.getName(), "%")); + } + request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + return extApiProjectMapper.getUserProject(request); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index 01761f5286..0e823c04e6 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -5,6 +5,8 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.ApiCaseRelevanceRequest; import io.metersphere.api.dto.EnvironmentType; +import io.metersphere.api.dto.QueryReferenceRequest; +import io.metersphere.api.dto.automation.TestPlanDTO; import io.metersphere.api.dto.automation.TestPlanFailureApiDTO; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.plan.TestPlanApiCaseBatchRequest; @@ -18,10 +20,7 @@ import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; -import io.metersphere.commons.constants.ApiRunMode; -import io.metersphere.commons.constants.CommonConstants; -import io.metersphere.commons.constants.ExtendedParameter; -import io.metersphere.commons.constants.TriggerMode; +import io.metersphere.commons.constants.*; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; @@ -29,6 +28,7 @@ import io.metersphere.dto.MsExecResponseDTO; import io.metersphere.dto.RunModeConfigDTO; import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.log.vo.OperatingLogDetails; +import io.metersphere.request.OrderRequest; import io.metersphere.request.ResetOrderRequest; import io.metersphere.service.BaseProjectService; import io.metersphere.service.ServiceUtils; @@ -770,4 +770,23 @@ public class TestPlanApiCaseService { example.createCriteria().andIdIn(list); return testPlanApiCaseMapper.selectByExample(example); } + + //获取case和测试计划引用关系 + public List getReference(QueryReferenceRequest request) { + if (CollectionUtils.isEmpty(request.getOrders())) { + OrderRequest req = new OrderRequest(); + req.setName("name"); + req.setType("asc"); + request.setOrders(new ArrayList<>() {{ + this.add(req); + }}); + } + QueryReferenceRequest planRequest = new QueryReferenceRequest(); + if (StringUtils.equals(request.getScenarioType(), ReportTypeConstants.API.name())) { + planRequest.setApiId(request.getId()); + } else { + planRequest.setScenarioId(request.getId()); + } + return extTestPlanApiCaseMapper.selectTestPlanByRelevancy(planRequest); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java index 9f2ba8a203..c98238a9d1 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java @@ -21,12 +21,10 @@ import io.metersphere.api.parse.scenario.ScenarioImport; import io.metersphere.api.parse.scenario.ScenarioImportParserFactory; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; -import io.metersphere.base.mapper.ext.BaseProjectVersionMapper; -import io.metersphere.base.mapper.ext.ExtApiScenarioMapper; -import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; -import io.metersphere.base.mapper.ext.ExtScheduleMapper; +import io.metersphere.base.mapper.ext.*; import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiCaseMapper; +import io.metersphere.base.mapper.plan.ext.ExtTestPlanApiScenarioMapper; import io.metersphere.base.mapper.plan.ext.ExtTestPlanScenarioCaseMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.enums.ApiReportStatus; @@ -158,6 +156,10 @@ public class ApiScenarioService { private ExtTestPlanScenarioCaseMapper extTestPlanScenarioCaseMapper; @Resource private JMeterService jMeterService; + @Resource + private ExtApiScenarioReferenceIdMapper extApiScenarioReferenceIdMapper; + @Resource + private ExtTestPlanApiScenarioMapper extTestPlanApiScenarioMapper; private ThreadLocal currentScenarioOrder = new ThreadLocal<>(); @@ -932,7 +934,7 @@ public class ApiScenarioService { public ReferenceDTO getReference(ApiScenarioRequest request) { ReferenceDTO dto = new ReferenceDTO(); - dto.setScenarioList(extApiScenarioMapper.selectReference(request)); + //dto.setScenarioList(extApiScenarioMapper.selectReference(request)); QueryReferenceRequest planRequest = new QueryReferenceRequest(); planRequest.setScenarioId(request.getId()); planRequest.setProjectId(request.getProjectId()); @@ -1965,49 +1967,58 @@ public class ApiScenarioService { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query)); List deleteIds = request.getIds(); DeleteCheckResult result = new DeleteCheckResult(); - List checkMsgList = new ArrayList<>(); if (CollectionUtils.isNotEmpty(deleteIds)) { - List apiScenarioReferenceIdList = apiScenarioReferenceIdService.findByReferenceIdsAndRefType(deleteIds, MsTestElementConstants.REF.name()); + Map> scenarioDic = new HashMap<>(); + List apiScenarioReferenceIdList = extApiScenarioReferenceIdMapper.selectReferenceIdByIds(deleteIds); if (CollectionUtils.isNotEmpty(apiScenarioReferenceIdList)) { - Map> scenarioDic = new HashMap<>(); apiScenarioReferenceIdList.forEach(item -> { - String refreceID = item.getReferenceId(); + String referenceId = item.getReferenceId(); String scenarioId = item.getApiScenarioId(); - if (scenarioDic.containsKey(refreceID)) { - scenarioDic.get(refreceID).add(scenarioId); + if (scenarioDic.containsKey(referenceId)) { + scenarioDic.get(referenceId).add(scenarioId); } else { List list = new ArrayList<>(); list.add(scenarioId); - scenarioDic.put(refreceID, list); + scenarioDic.put(referenceId, list); } }); - - for (Map.Entry> entry : scenarioDic.entrySet()) { - String refreceId = entry.getKey(); - List scenarioIdList = entry.getValue(); - if (CollectionUtils.isNotEmpty(scenarioIdList)) { - String deleteScenarioName = extApiScenarioMapper.selectNameById(refreceId); - List scenarioNames = extApiScenarioMapper.selectNameByIdIn(scenarioIdList); - - if (StringUtils.isNotEmpty(deleteScenarioName) && CollectionUtils.isNotEmpty(scenarioNames)) { - String nameListStr = StringUtils.SPACE; - for (String name : scenarioNames) { - nameListStr += name + ","; - } - if (nameListStr.length() > 1) { - nameListStr = nameListStr.substring(0, nameListStr.length() - 1) + StringUtils.SPACE; - } - String msg = deleteScenarioName + StringUtils.SPACE + Translator.get("delete_check_reference_by") + ": " + nameListStr + StringUtils.SPACE; - checkMsgList.add(msg); - } + } + //测试计划引用 + List testPlanApiScenarios = extTestPlanApiScenarioMapper.selectByScenarioIds(deleteIds); + Map> planList = new HashMap<>(); + if (CollectionUtils.isNotEmpty(testPlanApiScenarios)) { + testPlanApiScenarios.forEach(item -> { + String referenceId = item.getApiScenarioId(); + String testPlanId = item.getTestPlanId(); + if (planList.containsKey(referenceId)) { + planList.get(referenceId).add(testPlanId); + } else { + List list = new ArrayList<>(); + list.add(testPlanId); + planList.put(referenceId, list); + } + }); + } + if (MapUtils.isNotEmpty(scenarioDic) || MapUtils.isNotEmpty(planList)) { + if (StringUtils.equals("batch", request.getType())) { + Map> map = scenarioDic.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v2, () -> new HashMap<>(planList))); + result.setRefCount(map.size()); + result.setCheckMsg(new ArrayList<>(map.keySet())); + } else { + ArrayList> scenarioList = new ArrayList<>(scenarioDic.values()); + if (CollectionUtils.isNotEmpty(scenarioList)) { + result.setScenarioCount(new TreeSet(scenarioList.get(0)).size()); + } + ArrayList> testPlanList = new ArrayList<>(planList.values()); + if (CollectionUtils.isNotEmpty(testPlanList)) { + result.setPlanCount(new TreeSet(testPlanList.get(0)).size()); } } + result.setDeleteFlag(scenarioDic.size() > 0 || planList.size() > 0); } } - - result.setDeleteFlag(checkMsgList.isEmpty()); - result.setCheckMsg(checkMsgList); return result; } diff --git a/api-test/backend/src/main/resources/i18n/messages_en_US.properties b/api-test/backend/src/main/resources/i18n/messages_en_US.properties index f325ca60f7..df000fe405 100644 --- a/api-test/backend/src/main/resources/i18n/messages_en_US.properties +++ b/api-test/backend/src/main/resources/i18n/messages_en_US.properties @@ -343,4 +343,5 @@ api_case_create_notice=Interface use case new notification update_api_case=Updated interface use case api_case_update_notice=Interface use case update notification error_xml_struct=Data is not xml -case_name_is_already_exist=Duplicate Case name \ No newline at end of file +case_name_is_already_exist=Duplicate Case name +delete_check_reference_by_plan=referenced by the test plan \ No newline at end of file diff --git a/api-test/backend/src/main/resources/i18n/messages_zh_CN.properties b/api-test/backend/src/main/resources/i18n/messages_zh_CN.properties index 0a11008735..5703cbc7c3 100644 --- a/api-test/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/api-test/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -363,3 +363,4 @@ update_api_case=更新了接口用例 api_case_update_notice=接口用例更新通知 error_xml_struct=错误的xml数据 case_name_is_already_exist=用例名称不能重复 +delete_check_reference_by_plan=被测试计划引用 diff --git a/api-test/backend/src/main/resources/i18n/messages_zh_TW.properties b/api-test/backend/src/main/resources/i18n/messages_zh_TW.properties index b22c177eff..8d28d283d1 100644 --- a/api-test/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/api-test/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -363,3 +363,4 @@ update_api_case=更新了接口用例 api_case_update_notice=接口用例更新通知 error_xml_struct=錯誤的xml數據 case_name_is_already_exist=用例名稱不能重復 +delete_check_reference_by_plan=被測試計劃引用 diff --git a/api-test/frontend/src/api/definition.js b/api-test/frontend/src/api/definition.js index 9a95d18976..b2ea40ab7c 100644 --- a/api-test/frontend/src/api/definition.js +++ b/api-test/frontend/src/api/definition.js @@ -121,8 +121,12 @@ export function jsonGenerator(params) { return post('/api/definition/generator', params); } -export function getDefinitionReference(params) { - return post('/api/definition/get-reference', params); +export function getDefinitionReference(currentPage, pageSize, params) { + return post('/api/definition/get-reference/' + currentPage + '/' + pageSize, params); +} + +export function getPlanReference(currentPage, pageSize, params) { + return post('/test/plan/api/case/get-reference/' + currentPage + '/' + pageSize, params); } export function deleteBatchByParams(params) { diff --git a/api-test/frontend/src/api/scenario.js b/api-test/frontend/src/api/scenario.js index 6ffc09f4c4..a3f29fa3c0 100644 --- a/api-test/frontend/src/api/scenario.js +++ b/api-test/frontend/src/api/scenario.js @@ -62,10 +62,6 @@ export function getApiScenarios(params) { return post('/api/automation/get-scenario-list', params); } -export function getReference(params) { - return post('/api/automation/getReference', params); -} - export function genPerformanceTestJmx(params) { return post('/api/automation/gen-jmx', params); } diff --git a/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue b/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue index 3141975e89..0a62e3b86b 100644 --- a/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue +++ b/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue @@ -262,6 +262,7 @@ :row="scope.row" @openSchedule="openSchedule(scope.row)" @openScenario="openScenario" + @showCaseRef="showScenarioRef" v-if="!trashEnable" style="display: contents"/> @@ -317,7 +318,16 @@ - + + + + + @@ -350,7 +360,7 @@ import { import {getMaintainer, getProject} from "@/api/project"; import {getProjectVersions, versionEnableByProjectId} from "@/api/xpack"; import {getCurrentProjectID, getCurrentUserId} from "metersphere-frontend/src/utils/token"; -import {downloadFile, getUUID, objToStrMap, operationConfirm, strMapToObj} from "metersphere-frontend/src/utils"; +import {downloadFile, getUUID, objToStrMap, strMapToObj} from "metersphere-frontend/src/utils"; import {hasLicense, hasPermission} from "metersphere-frontend/src/utils/permission"; import {API_SCENARIO_CONFIGS} from "metersphere-frontend/src/components/search/search-components"; import {API_SCENARIO_LIST} from "metersphere-frontend/src/utils/constants"; @@ -370,6 +380,7 @@ import {API_SCENARIO_CONFIGS_TRASH, TYPE_TO_C} from "@/business/automation/scena import MsTableSearchBar from "metersphere-frontend/src/components/MsTableSearchBar"; import MsTableAdvSearchBar from "metersphere-frontend/src/components/search/MsTableAdvSearchBar"; import ListItemDeleteConfirm from "metersphere-frontend/src/components/ListItemDeleteConfirm"; +import ScenarioDeleteConfirm from "@/business/automation/scenario/ScenarioDeleteConfirm"; import {$error} from "metersphere-frontend/src/plugins/message" import MsSearch from "metersphere-frontend/src/components/search/MsSearch"; import {buildNodePath} from "metersphere-frontend/src/model/NodeTree"; @@ -379,6 +390,8 @@ import {usePerformanceStore} from "@/store"; import {request} from "metersphere-frontend/src/plugins/request" import {parseEnvironment} from "@/business/environment/model/EnvironmentModel"; import MsApiRunMode from "@/business/automation/scenario/common/ApiRunMode"; +import ApiDeleteConfirm from "@/business/definition/components/list/ApiDeleteConfirm"; +import MsShowReference from "@/business/definition/components/reference/ShowReference"; const performanceStore = usePerformanceStore(); export default { @@ -392,6 +405,9 @@ export default { HeaderLabelOperate, MsSearch, MsApiRunMode, + ApiDeleteConfirm, + MsShowReference, + ScenarioDeleteConfirm, MsApiReportStatus: () => import("../report/ApiReportStatus"), HeaderCustom: () => import("metersphere-frontend/src/components/head/HeaderCustom"), BatchMove: () => import("@/business/commons/BatchMove"), @@ -630,6 +646,8 @@ export default { resultFilters: REPORT_STATUS, runRequest: {}, versionEnable: false, + hasRef: false, + showScenario: false, }; }, created() { @@ -1086,26 +1104,17 @@ export default { } else { let param = {}; this.buildBatchParam(param); + param.type = 'batch'; + this.showScenario = false; + this.hasRef = false; checkBeforeDelete(param).then(response => { let checkResult = response.data; let alertMsg = this.$t('load_test.delete_threadgroup_confirm') + " ?"; - if (!checkResult.deleteFlag) { - alertMsg = ""; - checkResult.checkMsg.forEach(item => { - alertMsg += item + ";"; - }); - if (alertMsg === "") { - alertMsg = this.$t('load_test.delete_threadgroup_confirm') + " ?"; - } else { - alertMsg += this.$t('api_test.is_continue') + this.$t('commons.delete') + " ?"; - } + if (checkResult.deleteFlag) { + alertMsg = this.$t('api_definition.scenario_is_referenced', [checkResult.refCount]) + ', ' + this.$t('api_test.is_continue') + " ?"; + this.showScenario = true; } - operationConfirm(this, alertMsg, () => { - removeScenarioToGcByBatch(param).then(() => { - this.$success(this.$t('commons.delete_success')); - this.search(); - }); - }); + this.$refs.apiDeleteConfirm.open(alertMsg, this.$t('permission.project_api_definition.delete_case'), param, checkResult.checkMsg); }); } }, @@ -1234,6 +1243,15 @@ export default { this.selectDataRange = dataRange; this.selectDataType = dataType; } + if (this.$route.query && this.$route.params.dataSelectRange === 'ref') { + if (this.$route.query.ids) { + if (typeof this.$route.query.ids === 'string') { + this.condition.ids = [this.$route.query.ids]; + } else { + this.condition.ids = this.$route.query.ids; + } + } + } }, changeSelectDataRangeAll() { this.$emit("changeSelectDataRangeAll"); @@ -1249,40 +1267,47 @@ export default { let param = {}; this.buildBatchParam(param); param.ids = [row.id]; + this.showScenario = false; + this.hasRef = false; checkBeforeDelete(param).then(response => { let checkResult = response.data; - let alertMsg = this.$t('load_test.delete_threadgroup_confirm'); - if (!checkResult.deleteFlag) { - alertMsg = ""; - checkResult.checkMsg.forEach(item => { - alertMsg += item; - }); - if (alertMsg === "") { - alertMsg = this.$t('load_test.delete_threadgroup_confirm'); - } else { - alertMsg += this.$t('api_test.is_continue') + this.$t('commons.delete'); - } + let alertMsg = this.$t('load_test.delete_threadgroup_confirm') + '[' + row.name + ']' + '?'; + if (checkResult.deleteFlag) { + alertMsg = '[' + row.name + '] ' + this.$t('api_definition.scenario_is') + (checkResult.scenarioCount > 0 ? this.$t('api_definition.scenario_count', [checkResult.scenarioCount]) : '') + + (checkResult.planCount > 0 && checkResult.scenarioCount > 0 ? '、 ' : '') + + (checkResult.planCount > 0 ? this.$t('api_definition.plan_count', [checkResult.planCount]) : '') + this.$t('api_test.scenario.reference') + ', ' + + this.$t('api_test.is_continue') + " ?"; + this.hasRef = true; } // getScenarioVersions(row.id).then(response => { if (hasLicense() && this.versionEnable && response.data.length > 1) { // 删除提供列表删除和全部版本删除 - this.$refs.apiDeleteConfirm.open(row, alertMsg); + this.$refs.apiDeleteConfirmVersion.open(row, alertMsg); } else { - operationConfirm(this, alertMsg, () => { - this._handleDelete(row, false); - }); + this.$refs.apiDeleteConfirm.open(alertMsg, this.$t('permission.project_api_scenario.delete'), row, null); } }); }); } }, + handleDeleteScenario(row) { + this.$refs.apiDeleteConfirm.close(); + if (row.type === 'batch') { + removeScenarioToGcByBatch(row).then(() => { + this.$success(this.$t('commons.delete_success')); + this.search(); + }); + } else { + this._handleDelete(row, false); + } + }, _handleDelete(api, deleteCurrentVersion) { // 删除指定版本 if (deleteCurrentVersion) { delByScenarioIdAndRefId(api.versionId, api.refId).then(() => { this.$success(this.$t('commons.delete_success')); - this.$refs.apiDeleteConfirm.close(); + this.$refs.apiDeleteConfirmVersion.close(); this.search(); }); } @@ -1293,7 +1318,7 @@ export default { param.ids = [api.id]; removeScenarioToGcByBatch(param).then(() => { this.$success(this.$t('commons.delete_success')); - this.$refs.apiDeleteConfirm.close(); + this.$refs.apiDeleteConfirmVersion.close(); this.search(); }); } @@ -1429,7 +1454,10 @@ export default { this.$set(data, "isStop", false); } } - } + }, + showScenarioRef(row) { + this.$refs.viewRef.open(row, 'SCENARIO'); + }, } }; diff --git a/api-test/frontend/src/business/automation/scenario/ReferenceView.vue b/api-test/frontend/src/business/automation/scenario/ReferenceView.vue deleted file mode 100644 index daf761e6e4..0000000000 --- a/api-test/frontend/src/business/automation/scenario/ReferenceView.vue +++ /dev/null @@ -1,95 +0,0 @@ - - - - - diff --git a/api-test/frontend/src/business/automation/scenario/ScenarioDeleteConfirm.vue b/api-test/frontend/src/business/automation/scenario/ScenarioDeleteConfirm.vue new file mode 100644 index 0000000000..2268c91672 --- /dev/null +++ b/api-test/frontend/src/business/automation/scenario/ScenarioDeleteConfirm.vue @@ -0,0 +1,55 @@ + + + + + diff --git a/api-test/frontend/src/business/automation/scenario/ScenarioExtendBtns.vue b/api-test/frontend/src/business/automation/scenario/ScenarioExtendBtns.vue index 00bc6ceedc..6ce0b0686a 100644 --- a/api-test/frontend/src/business/automation/scenario/ScenarioExtendBtns.vue +++ b/api-test/frontend/src/business/automation/scenario/ScenarioExtendBtns.vue @@ -15,7 +15,7 @@ - + @@ -23,7 +23,6 @@ + + diff --git a/api-test/frontend/src/business/definition/components/list/ApiList.vue b/api-test/frontend/src/business/definition/components/list/ApiList.vue index 30822b6519..7473dd499b 100644 --- a/api-test/frontend/src/business/definition/components/list/ApiList.vue +++ b/api-test/frontend/src/business/definition/components/list/ApiList.vue @@ -650,7 +650,7 @@ export default { this.condition.scenarioCoverage = null; break; case 'covered': - this.condition.apiCoverage = '"unCovered"'; + this.condition.apiCoverage = '"covered"'; this.condition.scenarioCoverage = 'covered'; break; case 'notCoveredTestCase': diff --git a/api-test/frontend/src/business/definition/components/reference/ApiExtendBtns.vue b/api-test/frontend/src/business/definition/components/reference/ApiExtendBtns.vue index 6352f9e3cd..a6d3e3ee74 100644 --- a/api-test/frontend/src/business/definition/components/reference/ApiExtendBtns.vue +++ b/api-test/frontend/src/business/definition/components/reference/ApiExtendBtns.vue @@ -9,13 +9,14 @@ {{ $t('api_test.create_performance_test') }} - + + - - diff --git a/api-test/frontend/src/business/definition/components/reference/ShowReference.vue b/api-test/frontend/src/business/definition/components/reference/ShowReference.vue new file mode 100644 index 0000000000..72d601106a --- /dev/null +++ b/api-test/frontend/src/business/definition/components/reference/ShowReference.vue @@ -0,0 +1,304 @@ + + + diff --git a/api-test/frontend/src/i18n/lang/en-US.js b/api-test/frontend/src/i18n/lang/en-US.js index f5cca6f6ad..b4f7befb1e 100644 --- a/api-test/frontend/src/i18n/lang/en-US.js +++ b/api-test/frontend/src/i18n/lang/en-US.js @@ -19,7 +19,15 @@ const message = { json_format_error: "JSON format error" }, case_name: "Case name", - case_no_permission: "No permission to edit case" + case_no_permission: "No permission to edit case", + view_case: "View case", + view_scenario: "View scenario", + case_is: "Case is", + scenario_is: "Scenario is", + scenario_count: "{0} [scenario]", + plan_count: "{0} [test plan]", + case_is_referenced: "{0} cases have reference relationships", + scenario_is_referenced: "{0} scenarios have reference relationships" }, home: { dashboard: { diff --git a/api-test/frontend/src/i18n/lang/zh-CN.js b/api-test/frontend/src/i18n/lang/zh-CN.js index 5d5b75ac2f..79b273a819 100644 --- a/api-test/frontend/src/i18n/lang/zh-CN.js +++ b/api-test/frontend/src/i18n/lang/zh-CN.js @@ -20,6 +20,14 @@ const message = { }, case_name: "用例名称", case_no_permission: "无编辑用例的权限", + view_case: "查看用例", + view_scenario: "查看场景", + case_is: "用例被", + scenario_is: "场景被", + scenario_count: "{0}个[场景]", + plan_count: "{0}个[测试计划]", + case_is_referenced: "有{0}个用例存在引用关系", + scenario_is_referenced: "有{0}个场景存在引用关系", }, home: { dashboard: { diff --git a/api-test/frontend/src/i18n/lang/zh-TW.js b/api-test/frontend/src/i18n/lang/zh-TW.js index c3b7e5fa30..0450187044 100644 --- a/api-test/frontend/src/i18n/lang/zh-TW.js +++ b/api-test/frontend/src/i18n/lang/zh-TW.js @@ -20,6 +20,14 @@ const message = { }, case_name: "用例名稱", case_no_permission: "無編輯用例的權限", + view_case: "查看用例", + view_scenario: "查看場景", + case_is: "用例被", + scenario_is: "場景被", + scenario_count: "{0}個[場景]", + plan_count: "{0}個[测试計劃]", + case_is_referenced: "有{0}個用例存在引用關係", + scenario_is_referenced: "有{0}個場景存在引用關係", }, home: { dashboard: {