From f83b8e3a7c41b2a862414c35c01ca18da945df46 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 21 Jun 2021 17:51:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=A8=E6=AF=8F=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=92=8C=E6=9B=B4=E6=96=B0=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0=E5=89=8D=E5=A2=9E=E5=8A=A0=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E6=B6=89=E5=8F=8Aurl=E7=9A=84=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在每一个新建和更新场景的函数前增加场景涉及url的统计 --- .../api/service/ApiAutomationService.java | 16 ++++++++++------ .../service/HistoricalDataUpgradeService.java | 8 ++++++++ 2 files changed, 18 insertions(+), 6 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 bd591c3e87..fd1301e3a8 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1572,6 +1572,10 @@ public class ApiAutomationService { ApiScenarioWithBLOBs apiScenarioWithBLOBs = new ApiScenarioWithBLOBs(); BeanUtils.copyBean(apiScenarioWithBLOBs, request); apiScenarioWithBLOBs.setUpdateTime(System.currentTimeMillis()); + if(apiScenarioWithBLOBs.getScenarioDefinition() != null){ + List useUrl = this.parseUrl(apiScenarioWithBLOBs); + apiScenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl)); + } apiScenarioMapper.updateByExampleSelective( apiScenarioWithBLOBs, apiScenarioExample); @@ -1600,11 +1604,15 @@ public class ApiAutomationService { private void _importCreate(List sameRequest, ApiScenarioMapper batchMapper, ApiScenarioWithBLOBs scenarioWithBLOBs, ApiTestImportRequest apiTestImportRequest) { if (CollectionUtils.isEmpty(sameRequest)) { scenarioWithBLOBs.setId(UUID.randomUUID().toString()); + List useUrl = this.parseUrl(scenarioWithBLOBs); + scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl)); batchMapper.insert(scenarioWithBLOBs); } else { //如果存在则修改 scenarioWithBLOBs.setId(sameRequest.get(0).getId()); scenarioWithBLOBs.setNum(sameRequest.get(0).getNum()); + List useUrl = this.parseUrl(scenarioWithBLOBs); + scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl)); batchMapper.updateByPrimaryKeyWithBLOBs(scenarioWithBLOBs); } } @@ -1633,6 +1641,8 @@ public class ApiAutomationService { _importCreate(sameRequest, batchMapper, scenarioWithBLOBs, apiTestImportRequest); } else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) { if (CollectionUtils.isEmpty(sameRequest)) { + List useUrl = this.parseUrl(scenarioWithBLOBs); + scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl)); batchMapper.insert(scenarioWithBLOBs); } @@ -1811,12 +1821,6 @@ public class ApiAutomationService { return 100; } - /** - * 前置工作: - * 1。将接口集合转化数据结构: map>> urlMap 用来做筛选 - * 4。自定义List coveragedIdList 已覆盖的id集合。 最终计算公式是 coveragedIdList/allApiIdList在 - * - */ Map> urlMap = new HashMap<>(); for (ApiDefinition model : allEffectiveApiList) { String url = model.getPath(); diff --git a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java index 1312783762..7f51cf6708 100644 --- a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java +++ b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java @@ -1,10 +1,12 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import io.metersphere.api.dto.EnvironmentDTO; import io.metersphere.api.dto.SaveHistoricalDataUpgrade; import io.metersphere.api.dto.automation.ScenarioStatus; +import io.metersphere.api.dto.datacount.ApiMethodUrlDTO; import io.metersphere.api.dto.definition.request.MsScenario; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.assertions.MsAssertionDuration; @@ -53,6 +55,8 @@ public class HistoricalDataUpgradeService { @Resource private ExtApiScenarioMapper extApiScenarioMapper; @Resource + private ApiAutomationService apiAutomationService; + @Resource SqlSessionFactory sqlSessionFactory; @Resource ApiTestEnvironmentService apiTestEnvironmentService; @@ -360,6 +364,8 @@ public class HistoricalDataUpgradeService { scenario.setUpdateTime(System.currentTimeMillis()); scenario.setStatus(ScenarioStatus.Underway.name()); scenario.setUserId(SessionUtils.getUserId()); + List useUrl = apiAutomationService.parseUrl(scenario); + scenario.setUseUrl(JSONArray.toJSONString(useUrl)); mapper.updateByPrimaryKeySelective(scenario); } else { scenario = new ApiScenarioWithBLOBs(); @@ -378,6 +384,8 @@ public class HistoricalDataUpgradeService { scenario.setStatus(ScenarioStatus.Underway.name()); scenario.setUserId(SessionUtils.getUserId()); scenario.setNum(num); + List useUrl = apiAutomationService.parseUrl(scenario); + scenario.setUseUrl(JSONArray.toJSONString(useUrl)); mapper.insert(scenario); } }