From 9a32e83a015ec70295f6ef51290423652d37e2af Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Tue, 5 Jan 2021 17:43:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 接口测试首页优化 --- .../api/controller/APITestController.java | 19 +- .../dto/automation/ApiScenarioRequest.java | 3 + .../dto/datacount/ExecutedCaseInfoResult.java | 5 + .../response/ExecutedCaseInfoDTO.java | 7 + .../datacount/response/TaskInfoResult.java | 2 + .../dto/definition/ApiDefinitionRequest.java | 4 + .../dto/definition/ApiTestCaseRequest.java | 2 + .../api/service/ApiAutomationService.java | 7 + .../ApiDefinitionExecResultService.java | 20 +- .../api/service/ApiDefinitionService.java | 10 + .../api/service/ApiTestCaseService.java | 7 + .../ext/ExtApiDefinitionExecResultMapper.xml | 24 +- .../mapper/ext/ExtApiDefinitionMapper.xml | 13 + .../base/mapper/ext/ExtApiScenarioMapper.xml | 13 + .../base/mapper/ext/ExtApiTestCaseMapper.xml | 6 + .../base/mapper/ext/ExtScheduleMapper.xml | 13 +- .../base/mapper/ext/ExtTestPlanMapper.xml | 2 +- .../track/service/TestPlanService.java | 4 + .../api/automation/ApiAutomation.vue | 221 +++-- .../automation/scenario/ApiScenarioList.vue | 39 +- .../api/definition/ApiDefinition.vue | 564 ++++++------ .../components/list/ApiCaseSimpleList.vue | 690 ++++++++------- .../definition/components/list/ApiList.vue | 830 ++++++++++-------- .../api/homepage/ApiTestHomePage.vue | 28 +- .../api/homepage/components/ApiInfoCard.vue | 22 +- .../components/FailureTestCaseList.vue | 31 +- .../homepage/components/RunningTaskList.vue | 11 +- .../api/homepage/components/SceneInfoCard.vue | 26 +- .../homepage/components/TestCaseInfoCard.vue | 29 +- frontend/src/i18n/en-US.js | 12 +- frontend/src/i18n/zh-CN.js | 12 +- frontend/src/i18n/zh-TW.js | 12 +- 32 files changed, 1551 insertions(+), 1137 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java index 421eec048a..9d461bb032 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -285,17 +285,17 @@ public class APITestController { long taskCountInThisWeek = scheduleService.countTaskByProjectIdInThisWeek(projectId); apiCountResult.setThisWeekAddedCount(taskCountInThisWeek); - long api_executedInThisWeekCountNumber = apiReportService.countByProjectIdAndCreateInThisWeek(projectId); - long scene_executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIdAndCreateAndByScheduleInThisWeek(projectId); - long executedInThisWeekCountNumber = api_executedInThisWeekCountNumber+scene_executedInThisWeekCountNumber; +// long api_executedInThisWeekCountNumber = apiReportService.countByProjectIdAndCreateInThisWeek(projectId); + long executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIdAndCreateAndByScheduleInThisWeek(projectId); +// long executedInThisWeekCountNumber = api_executedInThisWeekCountNumber+scene_executedInThisWeekCountNumber; apiCountResult.setThisWeekExecutedCount(executedInThisWeekCountNumber); //统计 失败 成功 以及总数 - List api_allExecuteResult = apiReportService.countByProjectIdGroupByExecuteResult(projectId); - List scene_allExecuteResult = apiScenarioReportService.countByProjectIdGroupByExecuteResult(projectId); - List allExecuteResult = new ArrayList<>(); - allExecuteResult.addAll(api_allExecuteResult); - allExecuteResult.addAll(scene_allExecuteResult); +// List api_allExecuteResult = apiReportService.countByProjectIdGroupByExecuteResult(projectId); + List allExecuteResult = apiScenarioReportService.countByProjectIdGroupByExecuteResult(projectId); +// List allExecuteResult = new ArrayList<>(); +// allExecuteResult.addAll(api_allExecuteResult); +// allExecuteResult.addAll(scene_allExecuteResult); apiCountResult.countScheduleExecute(allExecuteResult); long allCount = apiCountResult.getExecutedCount(); @@ -322,11 +322,12 @@ public class APITestController { if(dataIndex filters; private Map combine; private List ids; + private boolean isSelectThisWeedData; + private long createTime = 0; + private String executeStatus; } diff --git a/backend/src/main/java/io/metersphere/api/dto/datacount/ExecutedCaseInfoResult.java b/backend/src/main/java/io/metersphere/api/dto/datacount/ExecutedCaseInfoResult.java index 5edf645e52..e98e1be8c1 100644 --- a/backend/src/main/java/io/metersphere/api/dto/datacount/ExecutedCaseInfoResult.java +++ b/backend/src/main/java/io/metersphere/api/dto/datacount/ExecutedCaseInfoResult.java @@ -1,14 +1,18 @@ package io.metersphere.api.dto.datacount; +import io.metersphere.track.dto.TestPlanDTO; import lombok.Getter; import lombok.Setter; +import java.util.List; + /** * 已执行的案例 */ @Getter @Setter public class ExecutedCaseInfoResult { + private String testCaseID; //案例名称 private String caseName; //所属测试计划 @@ -17,4 +21,5 @@ public class ExecutedCaseInfoResult { private Long failureTimes; //案例类型 private String caseType; + private List testPlanDTOList; } diff --git a/backend/src/main/java/io/metersphere/api/dto/datacount/response/ExecutedCaseInfoDTO.java b/backend/src/main/java/io/metersphere/api/dto/datacount/response/ExecutedCaseInfoDTO.java index 0e31c47a16..e3437eedbf 100644 --- a/backend/src/main/java/io/metersphere/api/dto/datacount/response/ExecutedCaseInfoDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/datacount/response/ExecutedCaseInfoDTO.java @@ -1,8 +1,11 @@ package io.metersphere.api.dto.datacount.response; +import io.metersphere.track.dto.TestPlanDTO; import lombok.Getter; import lombok.Setter; +import java.util.List; + /** * 已执行的案例 */ @@ -19,4 +22,8 @@ public class ExecutedCaseInfoDTO { private Long failureTimes; //案例类型 private String caseType; + //案例ID + private String caseID; + //测试计划集合 + private List testPlanDTOList; } diff --git a/backend/src/main/java/io/metersphere/api/dto/datacount/response/TaskInfoResult.java b/backend/src/main/java/io/metersphere/api/dto/datacount/response/TaskInfoResult.java index ef2bb4d45a..4ec3cdd2d2 100644 --- a/backend/src/main/java/io/metersphere/api/dto/datacount/response/TaskInfoResult.java +++ b/backend/src/main/java/io/metersphere/api/dto/datacount/response/TaskInfoResult.java @@ -15,6 +15,8 @@ public class TaskInfoResult { private String taskID; //场景名称 private String scenario; + //场景ID + private String scenarioId; //规则 private String rule; //任务状态 diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java index 9c18000c7d..3073ed8300 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionRequest.java @@ -26,4 +26,8 @@ public class ApiDefinitionRequest { private List filters; private Map combine; private List ids; + private boolean isSelectThisWeedData = false; + private long createTime = 0; + private String status; + private String apiCaseCoverage; } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java index ed87f0f263..d9028e23f2 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java @@ -24,4 +24,6 @@ public class ApiTestCaseRequest { private List moduleIds; private List orders; private Map> filters; + private boolean isSelectThisWeedData; + private long createTime = 0; } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 9465a3caea..158fac6f3d 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -75,6 +75,13 @@ public class ApiAutomationService { public List list(ApiScenarioRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + if(request.isSelectThisWeedData()){ + Map weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); + Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); + if(weekFirstTime!=null){ + request.setCreateTime(weekFirstTime.getTime()); + } + } List list = extApiScenarioMapper.list(request); return list; } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index 362781a4cf..1361a4506e 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -10,7 +10,10 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.track.dto.TestPlanDTO; +import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.service.TestPlanApiCaseService; +import io.metersphere.track.service.TestPlanService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +33,8 @@ public class ApiDefinitionExecResultService { private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; @Resource private TestPlanApiCaseService testPlanApiCaseService; + @Resource + private TestPlanService testPlanService; public void saveApiResult(TestResult result, String type) { @@ -100,9 +105,22 @@ public class ApiDefinitionExecResultService { Listlist = extApiDefinitionExecResultMapper.findFaliureCaseInfoByProjectIDAndExecuteTimeAndLimitNumber(projectId, startTime.getTime()); List returnList = new ArrayList<>(limitNumber); + for(int i = 0;i 提供前台做超链接 + ExecutedCaseInfoResult item = list.get(i); + + QueryTestPlanRequest planRequest = new QueryTestPlanRequest(); + planRequest.setProjectId(projectId); + if("scenario".equals(item.getCaseType())){ + planRequest.setScenarioId(item.getTestCaseID()); + }else if("apiCase".equals(item.getCaseType())){ + planRequest.setApiId(item.getTestCaseID()); + } + List dtoList = testPlanService.selectTestPlanByRelevancy(planRequest); + item.setTestPlanDTOList(dtoList); + returnList.add(item); }else { break; } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 5aa683ab4c..944b908847 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -78,6 +78,16 @@ public class ApiDefinitionService { public List list(ApiDefinitionRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + + //判断是否查询本周数据 + if(request.isSelectThisWeedData()){ + Map weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); + Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); + if(weekFirstTime!=null){ + request.setCreateTime(weekFirstTime.getTime()); + } + } + List resList = extApiDefinitionMapper.list(request); calculateResult(resList); return resList; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 03f5b37b56..c86ad3508a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -78,6 +78,13 @@ public class ApiTestCaseService { public List listSimple(ApiTestCaseRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + if(request.isSelectThisWeedData()){ + Map weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); + Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); + if(weekFirstTime!=null){ + request.setCreateTime(weekFirstTime.getTime()); + } + } List apiTestCases = extApiTestCaseMapper.listSimple(request); if (CollectionUtils.isEmpty(apiTestCases)) { return apiTestCases; diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml index 82cdf50340..ea21de7289 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.xml @@ -34,7 +34,7 @@ SELECT COUNT(id) AS countNumber FROM `schedule` WHERE resource_id IN ( - SELECT id FROM api_test WHERE project_id = #{0,jdbcType=VARCHAR} AND status != 'Trash' - UNION SELECT id FROM api_scenario WHERE project_id = #{0,jdbcType=VARCHAR} AND status != 'Trash' ) SELECT * FROM TEST_PLAN p LEFT JOIN test_plan_project t ON t.test_plan_id=p.id - AND t.project_id = #{request.projectId} + AND (t.project_id = #{request.projectId} or p.project_id = #{request.projectId}) AND p.id IN (SELECT test_plan_id FROM test_plan_api_scenario WHERE api_scenario_id = #{request.scenarioId} ) diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 72a403bc9b..76d314a069 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -37,6 +37,7 @@ import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testplan.AddTestPlanRequest; import io.metersphere.track.request.testplancase.QueryTestPlanCaseRequest; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -698,4 +699,7 @@ public class TestPlanService { } return issues; } + public List selectTestPlanByRelevancy(QueryTestPlanRequest params){ + return extTestPlanMapper.selectTestPlanByRelevancy(params); + } } diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index 0f34f0d18c..fcc2f45bea 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -1,5 +1,5 @@