From b85cf231cab190efab576fa6e9caf8daad5a78f7 Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Thu, 24 Dec 2020 10:16:09 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix:=20=E9=A6=96=E9=A1=B5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF=E3=80=81?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=B8=8D=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复首页接口数据统计错误、定时任务不通知的问题 --- .../api/controller/APITestController.java | 4 +- .../api/jmeter/APIBackendListenerClient.java | 40 ++++++++++++++++--- .../api/service/ApiAutomationService.java | 34 +++++++++------- .../api/service/ApiScenarioReportService.java | 14 ++++++- .../ext/ExtApiDefinitionExecResultMapper.xml | 2 +- .../mapper/ext/ExtApiScenarioReportMapper.xml | 8 ++-- .../mapper/ext/ExtApiTestReportMapper.xml | 1 - 7 files changed, 74 insertions(+), 29 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 a522ce36a9..3006f0af17 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -302,7 +302,7 @@ public class APITestController { if(allCount!=0){ float coverageRageNumber =(float)apiCountResult.getSuccessCount()*100/allCount; DecimalFormat df = new DecimalFormat("0.0"); - apiCountResult.setCoverageRage(df.format(coverageRageNumber)+"%"); + apiCountResult.setSuccessRage(df.format(coverageRageNumber)+"%"); } return apiCountResult; @@ -354,6 +354,6 @@ public class APITestController { public void updateScheduleEnableByPrimyKey(@RequestBody ScheduleInfoRequest request) { Schedule schedule = scheduleService.getSchedule(request.getTaskID()); schedule.setEnable(request.isEnable()); - apiTestService.updateSchedule(schedule); + apiAutomationService.updateSchedule(schedule); } } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 53e57b6a1f..237de40e9f 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -1,6 +1,7 @@ package io.metersphere.api.jmeter; import io.metersphere.api.service.*; +import io.metersphere.base.domain.ApiScenarioReport; import io.metersphere.base.domain.ApiTestReport; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.ApiRunMode; @@ -20,6 +21,7 @@ import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient; import org.apache.jmeter.visualizers.backend.BackendListenerContext; +import org.python.antlr.ast.Str; import org.springframework.http.HttpMethod; import java.io.ByteArrayOutputStream; @@ -50,6 +52,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl private ApiScenarioReportService apiScenarioReportService; + public String runMode = ApiRunMode.RUN.name(); // 测试ID @@ -155,6 +158,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl testResult.getScenarios().addAll(scenarios.values()); testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getId)); ApiTestReport report = null; + String reportUrl = null; // 这部分后续优化只留 DELIMIT 和 SCENARIO 两部分 if (StringUtils.equals(this.runMode, ApiRunMode.DEBUG.name())) { report = apiReportService.get(debugReportId); @@ -173,7 +177,31 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl } else if (StringUtils.equalsAny(this.runMode, ApiRunMode.SCENARIO.name(), ApiRunMode.SCENARIO_PLAN.name())) { // 执行报告不需要存储,由用户确认后在存储 testResult.setTestId(testId); - apiScenarioReportService.complete(testResult, this.runMode); + ApiScenarioReport scenarioReport = apiScenarioReportService.complete(testResult, this.runMode); + + + report = new ApiTestReport(); + report.setStatus(scenarioReport.getStatus()); + report.setId(scenarioReport.getId()); + report.setTriggerMode(scenarioReport.getTriggerMode()); + report.setName(scenarioReport.getName()); + + + SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class); + assert systemParameterService != null; + BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report"; + + + String scenaName = scenarioReport.getName(); + if(scenaName==null){ + scenaName = ""; + }else { + scenaName = scenaName.split("-")[0]; + } + + String scenarioID = apiScenarioReportService.getApiScenarioId(scenaName,scenarioReport.getProjectId()); + testResult.setTestId(scenarioID); } else { apiTestService.changeStatus(testId, APITestStatus.Completed); report = apiReportService.getRunningReport(testResult.getTestId()); @@ -196,22 +224,24 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl } } try { - sendTask(report, testResult); + sendTask(report,reportUrl, testResult); } catch (Exception e) { LogUtil.error(e.getMessage(), e); } } - private static void sendTask(ApiTestReport report, TestResult testResult) { + private static void sendTask(ApiTestReport report,String reportUrl, TestResult testResult) { SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class); NoticeSendService noticeSendService = CommonBeanFactory.getBean(NoticeSendService.class); assert systemParameterService != null; assert noticeSendService != null; BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); - String url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId(); - + String url = reportUrl; + if(StringUtils.isEmpty(url)){ + url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId(); + } String successContext = ""; String failedContext = ""; String subject = ""; 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 bfb5494e3b..1a85a2dd6c 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -40,6 +40,7 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; +import org.python.antlr.ast.Str; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -160,7 +161,7 @@ public class ApiAutomationService { apiScenarioMapper.deleteByPrimaryKey(id); } - public void preDelete(String scenarioID){ + public void preDelete(String scenarioID) { scheduleService.deleteByResourceId(scenarioID); TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); @@ -174,37 +175,40 @@ public class ApiAutomationService { } example = new TestPlanApiScenarioExample(); - if(!idList.isEmpty()){ + if (!idList.isEmpty()) { example.createCriteria().andIdIn(idList); testPlanApiScenarioMapper.deleteByExample(example); } } - public void preDelete(List scenarioIDList){ + + public void preDelete(List scenarioIDList) { List testPlanApiScenarioIdList = new ArrayList<>(); List scheduleIdList = new ArrayList<>(); - for (String id :scenarioIDList) { + for (String id : scenarioIDList) { TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); example.createCriteria().andApiScenarioIdEqualTo(id); List testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example); - for (TestPlanApiScenario api :testPlanApiScenarioList) { - if(!testPlanApiScenarioIdList.contains(api.getId())){ + for (TestPlanApiScenario api : testPlanApiScenarioList) { + if (!testPlanApiScenarioIdList.contains(api.getId())) { testPlanApiScenarioIdList.add(api.getId()); } } scheduleService.deleteByResourceId(id); } - if(!testPlanApiScenarioIdList.isEmpty()){ + if (!testPlanApiScenarioIdList.isEmpty()) { TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); example.createCriteria().andIdIn(testPlanApiScenarioIdList); testPlanApiScenarioMapper.deleteByExample(example); } } + public void deleteBatch(List ids) { //及连删除外键表 - preDelete(ids);; + preDelete(ids); + ; ApiScenarioExample example = new ApiScenarioExample(); example.createCriteria().andIdIn(ids); apiScenarioMapper.deleteByExample(example); @@ -242,16 +246,16 @@ public class ApiAutomationService { return new ArrayList<>(); } - private void createAPIScenarioReportResult(String id, String triggerMode, String execType, String projectId,String userID) { + private void createAPIScenarioReportResult(String id, String triggerMode, String execType, String projectId, String userID) { APIScenarioReportResult report = new APIScenarioReportResult(); report.setId(id); report.setName("测试执行结果"); report.setCreateTime(System.currentTimeMillis()); report.setUpdateTime(System.currentTimeMillis()); report.setStatus(APITestStatus.Running.name()); - if(StringUtils.isNotEmpty(userID)){ + if (StringUtils.isNotEmpty(userID)) { report.setUserId(userID); - }else { + } else { report.setUserId(SessionUtils.getUserId()); } @@ -316,7 +320,7 @@ public class ApiAutomationService { jMeterService.runDefinition(request.getId(), jmeterTestPlanHashTree, request.getReportId(), runMode); createAPIScenarioReportResult(request.getId(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), - request.getExecuteType(), projectID,request.getReportUserID()); + request.getExecuteType(), projectID, request.getReportUserID()); return request.getId(); } @@ -367,8 +371,8 @@ public class ApiAutomationService { ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class); ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class); - for (TestPlanDTO testPlan:list) { - if(request.getScenarioIds()!=null){ + for (TestPlanDTO testPlan : list) { + if (request.getScenarioIds() != null) { for (String scenarioId : request.getScenarioIds()) { TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); testPlanApiScenario.setId(UUID.randomUUID().toString()); @@ -379,7 +383,7 @@ public class ApiAutomationService { scenarioBatchMapper.insertIfNotExists(testPlanApiScenario); } } - if(request.getApiIds()!=null){ + if (request.getApiIds() != null) { for (String caseId : request.getApiIds()) { TestPlanApiCase testPlanApiCase = new TestPlanApiCase(); testPlanApiCase.setId(UUID.randomUUID().toString()); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 0834cdb62a..d2f372a2b2 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -50,7 +50,18 @@ public class ApiScenarioReportService { @Resource private TestPlanApiScenarioMapper testPlanApiScenarioMapper; - public void complete(TestResult result, String runMode) { + public String getApiScenarioId(String name, String projectID) { + ApiScenarioExample example = new ApiScenarioExample(); + example.createCriteria().andNameEqualTo(name).andProjectIdEqualTo(projectID).andStatusNotEqualTo("Trash"); + List list = apiScenarioMapper.selectByExample(example); + if (list.isEmpty()) { + return null; + } else { + return list.get(0).getId(); + } + } + + public ApiScenarioReport complete(TestResult result, String runMode) { Object obj = cache.get(result.getTestId()); if (obj == null) { MSException.throwException(Translator.get("api_report_is_null")); @@ -83,6 +94,7 @@ public class ApiScenarioReportService { if (!report.getTriggerMode().equals(ReportTriggerMode.SCHEDULE.name())) { cache.put(report.getId(), report); } + return report; } /** 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 0914b1e050..254b8576b7 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 @@ -53,7 +53,7 @@ SELECT scene.`name` AS caseName,testPlan.`name` AS testPlan,count(report.id) AS failureTimes,'scenario' AS caseType FROM api_scenario_report report INNER JOIN api_scenario_report_detail reportDetail ON report.id = reportDetail.report_id - INNER JOIN api_scenario scene ON reportDetail.content like concat('%"',scene.`name`,'"%') + INNER JOIN api_scenario scene ON reportDetail.content like concat('%"', scene.`name`,'"%') LEFT JOIN test_plan_api_scenario apiScene ON apiScene.api_scenario_id = scene.id LEFT JOIN test_plan testPlan ON testPlan.id = apiScene.test_plan_id WHERE report.project_id = #{projectId} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml index 2b48a30ab8..a0b5b0c614 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.xml @@ -179,8 +179,8 @@ SELECT count(acr.report_id) AS countNumber FROM api_scenario_report_detail acr INNER JOIN api_scenario_report ar ON ar.id = acr.report_id INNER JOIN ( - SELECT acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id - ) ac on acr.content like CONCAT('%', ac.id,'%') + SELECT acitem.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id + ) ac on acr.content like CONCAT('%"', ac.`name`,'"%') WHERE acr.project_id = #{projectId} AND ar.create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} @@ -189,8 +189,8 @@ FROM api_scenario_report_detail acr INNER JOIN api_scenario_report ar ON ar.id = acr.report_id INNER JOIN ( - SELECT acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id - ) ac on acr.content like CONCAT('%', ac.id,'%') + SELECT acitem.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id + ) ac on acr.content like CONCAT('%"', ac.`name`,'"%') WHERE acr.project_id = #{projectId} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.xml index 724925a6de..536eb80268 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.xml @@ -160,7 +160,6 @@ WHERE sch.resource_id IN ( SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR} ) - AND `group` = #{group} 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 p.id IN (SELECT test_plan_id FROM test_plan_api_scenario WHERE api_scenario_id = #{request.scenarioId} ) From 4ae66e176be49767c4e54d00f0d8e31661da015f Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Thu, 24 Dec 2020 11:11:47 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20=E9=A6=96=E9=A1=B5-=E8=BF=87?= =?UTF-8?q?=E5=8E=BB=E4=B8=83=E5=A4=A9=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复首页-过去七天失败用例数量统计错误的问题 --- .../ext/ExtApiDefinitionExecResultMapper.xml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 254b8576b7..6d66b45840 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 @@ -50,12 +50,20 @@ ) caseErrorCountData ON caseErrorCountData.testCaseID =testCase.testCaseID WHERE caseErrorCountData.executeTime >= #{startTimestamp} UNION - SELECT scene.`name` AS caseName,testPlan.`name` AS testPlan,count(report.id) AS failureTimes,'scenario' AS caseType + SELECT scene.`name` AS caseName,apiScene.testPlanName AS testPlan,count(report.id) AS failureTimes,'scenario' AS caseType FROM api_scenario_report report INNER JOIN api_scenario_report_detail reportDetail ON report.id = reportDetail.report_id INNER JOIN api_scenario scene ON reportDetail.content like concat('%"', scene.`name`,'"%') - LEFT JOIN test_plan_api_scenario apiScene ON apiScene.api_scenario_id = scene.id - LEFT JOIN test_plan testPlan ON testPlan.id = apiScene.test_plan_id + LEFT JOIN + ( + SELECT + apiScene.api_scenario_id, + group_concat(testPlan.`name`) AS testPlanName + FROM + test_plan_api_scenario apiScene + INNER JOIN test_plan testPlan ON testPlan.id = apiScene.test_plan_id + GROUP BY apiScene.api_scenario_id + )apiScene ON apiScene.api_scenario_id = scene.id WHERE report.project_id = #{projectId} AND report.status = 'Error' AND report.create_time >= #{startTimestamp} GROUP BY scene.id From 42d42bb76bc92b781c79b27dc8c3ab9555bc32a7 Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Thu, 24 Dec 2020 11:19:01 +0800 Subject: [PATCH 6/9] =?UTF-8?q?fix:=20=E9=A6=96=E9=A1=B5-=E8=BF=87?= =?UTF-8?q?=E5=8E=BB=E4=B8=83=E5=A4=A9=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复首页-过去七天失败用例数量统计错误的问题 --- .../java/io/metersphere/api/controller/APITestController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3006f0af17..421eec048a 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -268,7 +268,7 @@ public class APITestController { if(allCount!=0){ float coverageRageNumber =(float)apiCountResult.getExecutionPassCount()*100/allCount; DecimalFormat df = new DecimalFormat("0.0"); - apiCountResult.setCoverageRage(df.format(coverageRageNumber)+"%"); + apiCountResult.setPassRage(df.format(coverageRageNumber)+"%"); } return apiCountResult; From 75ae7adfaef6260c0f7b8e1b12ac7bb0dd3353ed Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 24 Dec 2020 11:21:00 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20=E4=BF=9D=E5=AD=98=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=97=B6=E5=8E=BB=E6=8E=89=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E7=9A=84=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/metersphere/service/SystemParameterService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index e58e268726..1660186db3 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -212,6 +212,8 @@ public class SystemParameterService { public void saveBaseInfo(List parameters) { SystemParameterExample example = new SystemParameterExample(); parameters.forEach(param -> { + // 去掉路径最后的 / + param.setParamValue(StringUtils.removeEnd(param.getParamValue(), "/")); example.createCriteria().andParamKeyEqualTo(param.getParamKey()); if (systemParameterMapper.countByExample(example) > 0) { systemParameterMapper.updateByPrimaryKey(param); From e4dba81ad7d23636205d2766506faee93a942cb6 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 24 Dec 2020 11:37:11 +0800 Subject: [PATCH 8/9] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=8F=A3=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=85=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/ApiTestCaseController.java | 7 + .../api/service/ApiTestCaseService.java | 5 + .../base/mapper/ext/ExtApiTestCaseMapper.java | 5 + .../base/mapper/ext/ExtApiTestCaseMapper.xml | 15 ++ .../automation/scenario/EditApiScenario.vue | 31 +-- .../scenario/api/ScenarioApiRelevance.vue | 165 ++++++++++++ .../scenario/api/ScenarioRelevanceApiList.vue | 248 ++++++++++++++++++ .../api/ScenarioRelevanceCaseList.vue | 239 +++++++++++++++++ 8 files changed, 692 insertions(+), 23 deletions(-) create mode 100644 frontend/src/business/components/api/automation/scenario/api/ScenarioApiRelevance.vue create mode 100644 frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceApiList.vue create mode 100644 frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceCaseList.vue diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java index ec064953a7..015848897b 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java @@ -21,6 +21,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.List; +import java.util.Map; @RestController @RequestMapping(value = "/api/testcase") @@ -43,6 +44,12 @@ public class ApiTestCaseController { return PageUtils.setPageInfo(page, apiTestCaseService.listSimple(request)); } + @PostMapping("/get/request") + public Map listSimple(@RequestBody ApiTestCaseRequest request) { + request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + return apiTestCaseService.getRequest(request); + } + @PostMapping(value = "/create", consumes = {"multipart/form-data"}) public void create(@RequestPart("request") SaveApiTestCaseRequest request, @RequestPart(value = "files") List bodyFiles) { apiTestCaseService.create(request, bodyFiles); 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 42a46d2eaa..0ce3aa2cc0 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -332,4 +332,9 @@ public class ApiTestCaseService { example.createCriteria().andIdIn(caseIds); return apiTestCaseMapper.selectByExample(example); } + + public Map getRequest(ApiTestCaseRequest request) { + List list = extApiTestCaseMapper.getRequest(request); + return list.stream().collect(Collectors.toMap(ApiTestCaseWithBLOBs::getId, ApiTestCaseWithBLOBs::getRequest)); + } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java index 8f3f4558b6..1451d970bf 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java @@ -4,10 +4,13 @@ import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.ApiTestCaseResult; +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; +import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; +import java.util.Map; public interface ExtApiTestCaseMapper { @@ -20,4 +23,6 @@ public interface ExtApiTestCaseMapper { List countProtocolByProjectID(String projectId); long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); + + List getRequest(@Param("request") ApiTestCaseRequest request); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index a9945e7844..234bf0d40d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -290,5 +290,20 @@ AND testCase.create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} + + \ No newline at end of file diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index c9bb269508..564b195bff 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -201,11 +201,7 @@ - - - {{$t('api_test.scenario.reference')}} - {{ $t('commons.copy') }} - + @@ -260,6 +256,7 @@ import ApiImport from "../../definition/components/import/ApiImport"; import InputTag from 'vue-input-tag' import "@/common/css/material-icons.css" + import ScenarioApiRelevance from "./api/ScenarioApiRelevance"; export default { name: "EditApiScenario", @@ -268,6 +265,7 @@ currentScenario: {}, }, components: { + ScenarioApiRelevance, ApiEnvironmentConfig, MsScenarioParameters, MsApiReportDetail, @@ -279,7 +277,6 @@ MsIfController, MsApiAssertions, MsApiExtract, - MsApiDefinition, MsApiComponent, MsApiCustomize, ApiImport, @@ -323,7 +320,6 @@ debugData: {}, reportId: "", projectId: "", - visibleRef: "", enableCookieShare: false, } } @@ -518,8 +514,7 @@ } , apiListImport() { - this.visibleRef = getUUID(); - this.apiListVisible = true; + this.$refs.scenarioApiRelevance.open(); } , recursiveSorting(arr) { @@ -599,20 +594,10 @@ } } , - pushApiOrCase(referenced) { - if (this.currentRow.cases.length === 0 && this.currentRow.apis.length === 0) { - this.$warning(this.$t('api_test.automation.reference_info')); - return; - } - this.currentRow.cases.forEach(item => { - this.setApiParameter(item, "CASE", referenced); - }) - this.currentRow.apis.forEach(item => { - this.setApiParameter(item, "API", referenced); - }) - this.apiListVisible = false; - this.currentRow.cases = []; - this.currentRow.apis = []; + pushApiOrCase(data, refType, referenced) { + data.forEach(item => { + this.setApiParameter(item, refType, referenced); + }); this.sort(); this.reload(); } diff --git a/frontend/src/business/components/api/automation/scenario/api/ScenarioApiRelevance.vue b/frontend/src/business/components/api/automation/scenario/api/ScenarioApiRelevance.vue new file mode 100644 index 0000000000..185fc3df58 --- /dev/null +++ b/frontend/src/business/components/api/automation/scenario/api/ScenarioApiRelevance.vue @@ -0,0 +1,165 @@ + + + + + diff --git a/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceApiList.vue b/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceApiList.vue new file mode 100644 index 0000000000..83a0c956ca --- /dev/null +++ b/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceApiList.vue @@ -0,0 +1,248 @@ + + + + + diff --git a/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceCaseList.vue b/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceCaseList.vue new file mode 100644 index 0000000000..b4452b8964 --- /dev/null +++ b/frontend/src/business/components/api/automation/scenario/api/ScenarioRelevanceCaseList.vue @@ -0,0 +1,239 @@ + + + + + From 54247fc15cf0304de4a5d69cab9efe3df3f23e28 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 24 Dec 2020 11:40:41 +0800 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=E7=94=A8=E4=BE=8B=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/io/metersphere/xpack | 2 +- .../api/definition/components/list/ApiCaseSimpleList.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 79343a2763..9f4a9bbf46 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 79343a2763b014355f91fc21b2356a95ae437973 +Subproject commit 9f4a9bbf46fc1333dbcccea21f83e27e3ec10b1f diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index 787c5053ff..811a046091 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -273,7 +273,7 @@ } else if (this.isRelevanceModel) { return '/api/testcase/delete/' + apiCase.id; } else { - return '/api/testcase/delete/' + +apiCase.id; + return '/api/testcase/delete/' + apiCase.id; } }, // getMaintainerOptions() {