From f9f49e66709c0371f9e7d60bb2614d9015a5a949 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 19 Jul 2021 13:49:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=9B=86=E5=90=88=E6=8A=A5=E5=91=8A=EF=BC=8C=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E5=9C=BA=E6=99=AF=E6=9F=A5=E7=9C=8B=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=94=99=E8=AF=AF=20#1005199=20--bug=3D1005199=20--user=3D?= =?UTF-8?q?=E8=B5=B5=E5=8B=87=20=E3=80=90=E6=8E=A5=E5=8F=A3=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96=E3=80=91-=E6=89=B9=E9=87=8F=E6=89=A7...=20ht?= =?UTF-8?q?tps://www.tapd.cn/55049933/s/1025792?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 24 ++++++++++--------- .../api/service/ApiScenarioReportService.java | 24 +++++++++++++++++++ .../base/mapper/ext/ExtTaskMapper.xml | 2 +- .../automation/scenario/ApiScenarioList.vue | 18 ++++++++++---- 4 files changed, 51 insertions(+), 17 deletions(-) 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 138f014187..fdcb0b2072 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -325,7 +325,7 @@ public class ApiAutomationService { List list = apiScenarioMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(list)) { return true; - }else { + } else { return false; } } @@ -611,7 +611,7 @@ public class ApiAutomationService { } } if (http.isEnable()) { - if (StringUtils.isBlank(http.getUrl()) || (http.getIsRefEnvironment()!= null && http.getIsRefEnvironment())) { + if (StringUtils.isBlank(http.getUrl()) || (http.getIsRefEnvironment() != null && http.getIsRefEnvironment())) { env.getProjectIds().add(http.getProjectId()); env.setFullUrl(false); } @@ -643,7 +643,7 @@ public class ApiAutomationService { // 校验是否是全路径 MsHTTPSamplerProxy httpSamplerProxy = (MsHTTPSamplerProxy) tr; if (httpSamplerProxy.isEnable()) { - if (StringUtils.isBlank(httpSamplerProxy.getUrl()) || (httpSamplerProxy.getIsRefEnvironment()!= null && httpSamplerProxy.getIsRefEnvironment())) { + if (StringUtils.isBlank(httpSamplerProxy.getUrl()) || (httpSamplerProxy.getIsRefEnvironment() != null && httpSamplerProxy.getIsRefEnvironment())) { env.getProjectIds().add(httpSamplerProxy.getProjectId()); env.setFullUrl(false); } @@ -684,7 +684,7 @@ public class ApiAutomationService { http.setUrl(apiDefinition.getPath()); } if (http.isEnable()) { - if (StringUtils.isBlank(http.getUrl()) || (http.getIsRefEnvironment()!= null && http.getIsRefEnvironment())) { + if (StringUtils.isBlank(http.getUrl()) || (http.getIsRefEnvironment() != null && http.getIsRefEnvironment())) { env.setFullUrl(false); env.getProjectIds().add(http.getProjectId()); } @@ -1040,6 +1040,7 @@ public class ApiAutomationService { public void run() { List reportIds = new LinkedList<>(); for (APIScenarioReportResult key : map.keySet()) { + key.setExecuteType(ExecuteType.Marge.name()); apiScenarioReportMapper.insert(key); reportIds.add(key.getId()); try { @@ -2230,8 +2231,8 @@ public class ApiAutomationService { List apiScenarioList = extApiScenarioMapper.selectIds(ids); if (CollectionUtils.isEmpty(apiScenarioList)) { return returnList; - }else { - apiScenarioList.forEach(item ->{ + } else { + apiScenarioList.forEach(item -> { String testName = item.getName(); MsTestPlan testPlan = new MsTestPlan(); testPlan.setHashTree(new LinkedList<>()); @@ -2250,10 +2251,10 @@ public class ApiAutomationService { ServiceUtils.getSelectAllIds(batchRequest, batchRequest.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query)); List apiScenarioList = extApiScenarioMapper.selectIds(batchRequest.getIds()); - for (ApiScenarioWithBLOBs apiModel:apiScenarioList) { + for (ApiScenarioWithBLOBs apiModel : apiScenarioList) { ApiScenarioWithBLOBs newModel = apiModel; newModel.setId(UUID.randomUUID().toString()); - newModel.setName("copy_"+apiModel.getName()); + newModel.setName("copy_" + apiModel.getName()); newModel.setCreateTime(System.currentTimeMillis()); newModel.setNum(getNextNum(newModel.getProjectId())); @@ -2262,7 +2263,7 @@ public class ApiAutomationService { andProjectIdEqualTo(newModel.getProjectId()).andStatusNotEqualTo("Trash").andIdNotEqualTo(newModel.getId()); if (apiScenarioMapper.countByExample(example) > 0) { continue; - }else { + } else { boolean insertFlag = true; if (StringUtils.isNotBlank(newModel.getCustomNum())) { insertFlag = false; @@ -2278,13 +2279,14 @@ public class ApiAutomationService { boolean isCustomNumExist = true; try { isCustomNumExist = this.isCustomNumExist(newModel); - }catch (Exception e){} + } catch (Exception e) { + } insertFlag = !isCustomNumExist; } } } - if(insertFlag){ + if (insertFlag) { apiScenarioMapper.insert(newModel); } } 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 118991dc96..d4ad159ec6 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -421,6 +421,30 @@ public class ApiScenarioReportService { detail.setProjectId(report.getProjectId()); apiScenarioReportDetailMapper.insert(detail); } + // 更新场景状态 + if (StringUtils.isNotEmpty(report.getScenarioId())) { + List strings = JSON.parseObject(report.getScenarioId(), List.class); + ApiScenarioExample scenarioExample = new ApiScenarioExample(); + scenarioExample.createCriteria().andIdIn(strings); + + List scenarios = apiScenarioMapper.selectByExample(scenarioExample); + if (CollectionUtils.isNotEmpty(scenarios)) { + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + ApiScenarioMapper scenarioReportMapper = sqlSession.getMapper(ApiScenarioMapper.class); + scenarios.forEach(scenario -> { + if (testResult.getError() > 0) { + scenario.setLastResult("Fail"); + } else { + scenario.setLastResult("Success"); + } + String passRate = new DecimalFormat("0%").format((float) testResult.getSuccess() / (testResult.getSuccess() + testResult.getError())); + scenario.setPassRate(passRate); + scenario.setReportId(report.getId()); + scenarioReportMapper.updateByPrimaryKey(scenario); + }); + sqlSession.flushStatements(); + } + } // 清理其他报告保留一份合并后的报告 this.deleteByIds(reportIds); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml index 4e24d35fb0..8caeed1ea7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTaskMapper.xml @@ -6,7 +6,7 @@ SELECT tt.* FROM ( (select t.id,if(t.scenario_id like "[\"%\"]", t.name,t.scenario_name) as name ,'SCENARIO' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, t.trigger_mode as triggerMode ,t.status as executionStatus from api_scenario_report t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id - where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and t.execute_type !='Debug' and t.project_id= #{request.projectId} + where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and t.execute_type !='Debug' and t.execute_type !='Marge' and t.project_id= #{request.projectId} and t.trigger_mode = #{request.triggerMode} diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 060f412f45..c3dd231660 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -190,6 +190,11 @@ + + + + @@ -215,7 +220,8 @@ import MsTablePagination from "@/business/components/common/pagination/TablePagi import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn"; import MsTag from "../../../common/components/MsTag"; import {downloadFile, getCurrentProjectID, getUUID, objToStrMap, strMapToObj} from "@/common/js/utils"; -import MsApiReportDetail from "../report/SysnApiReportDetail"; +import SysnApiReportDetail from "../report/SysnApiReportDetail"; +import MsApiReportDetail from "../report/ApiReportDetail"; import MsTableMoreBtn from "./TableMoreBtn"; import MsScenarioExtendButtons from "@/business/components/api/automation/scenario/ScenarioExtendBtns"; import MsTestPlanList from "./testplan/TestPlanList"; @@ -259,6 +265,7 @@ export default { MsTableHeader, MsTag, MsApiReportDetail, + SysnApiReportDetail, MsScenarioExtendButtons, MsTestPlanList, MsTableOperatorButton, @@ -332,6 +339,7 @@ export default { content: {}, infoDb: false, runVisible: false, + showReportVisible: false, planVisible: false, runData: [], report: {}, @@ -469,16 +477,16 @@ export default { } this.condition.filters = {status: ["Prepare", "Underway", "Completed"]}; - if(this.trashEnable){ + if (this.trashEnable) { this.condition.filters = {status: ["Trash"]}; this.condition.moduleIds = []; this.operators = this.trashOperators; this.buttons = this.trashButtons; - }else { + } else { if (!this.isReferenceTable) { this.operators = this.unTrashOperators; this.buttons = this.unTrashButtons; - }else { + } else { this.operators = this.unTrashOperators; this.buttons = this.unTrashButtons; } @@ -812,7 +820,7 @@ export default { this.$emit('edit', rowParam); }, showReport(row) { - this.runVisible = true; + this.showReportVisible = true; this.infoDb = true; this.reportId = row.reportId; },