diff --git a/backend/src/main/java/io/metersphere/api/controller/APIReportController.java b/backend/src/main/java/io/metersphere/api/controller/APIReportController.java index 8ad8af9d20..5f41294711 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APIReportController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APIReportController.java @@ -11,7 +11,7 @@ import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.DashboardTestDTO; -import io.metersphere.service.CheckOwnerService; +import io.metersphere.service.CheckPermissionService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; @@ -27,7 +27,7 @@ public class APIReportController { @Resource private APIReportService apiReportService; @Resource - private CheckOwnerService checkOwnerService; + private CheckPermissionService checkPermissionService; @GetMapping("recent/{count}") public List recentTest(@PathVariable int count) { @@ -41,7 +41,7 @@ public class APIReportController { @GetMapping("/list/{testId}/{goPage}/{pageSize}") public Pager> listByTestId(@PathVariable String testId, @PathVariable int goPage, @PathVariable int pageSize) { - checkOwnerService.checkApiTestOwner(testId); + checkPermissionService.checkApiTestOwner(testId); Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, apiReportService.listByTestId(testId)); 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 ba511fa454..a522ce36a9 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -15,11 +15,13 @@ import io.metersphere.base.domain.ApiTest; import io.metersphere.base.domain.Schedule; import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.ScheduleGroup; -import io.metersphere.commons.utils.*; +import io.metersphere.commons.utils.CronUtils; +import io.metersphere.commons.utils.PageUtils; +import io.metersphere.commons.utils.Pager; +import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.QueryScheduleRequest; import io.metersphere.dto.ScheduleDao; -import io.metersphere.service.CheckOwnerService; - +import io.metersphere.service.CheckPermissionService; import io.metersphere.service.ScheduleService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; @@ -27,7 +29,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; - import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Date; @@ -46,7 +47,7 @@ public class APITestController { @Resource private ApiDefinitionService apiDefinitionService; @Resource - private CheckOwnerService checkownerService; + private CheckPermissionService checkownerService; @Resource private ApiTestCaseService apiTestCaseService; @Resource @@ -253,7 +254,7 @@ public class APITestController { * */ long dateCountByCreateInThisWeek = apiAutomationService.countScenarioByProjectIDAndCreatInThisWeek(projectId); apiCountResult.setThisWeekAddedCount(dateCountByCreateInThisWeek); - long executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIDAndCreateInThisWeek(projectId); + long executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIdAndCreateInThisWeek(projectId); apiCountResult.setThisWeekExecutedCount(executedInThisWeekCountNumber); long executedCountNumber = apiScenarioReportService.countByProjectID(projectId); apiCountResult.setExecutedCount(executedCountNumber); @@ -274,21 +275,27 @@ public class APITestController { } - @GetMapping("/scheduleTaskInfoCount/{workSpaceID}") - public ApiDataCountDTO scheduleTaskInfoCount(@PathVariable String workSpaceID) { + @GetMapping("/scheduleTaskInfoCount/{projectId}") + public ApiDataCountDTO scheduleTaskInfoCount(@PathVariable String projectId) { ApiDataCountDTO apiCountResult = new ApiDataCountDTO(); - long allTaskCount = scheduleService.countTaskByWorkspaceIdAndGroup(workSpaceID,ScheduleGroup.API_TEST.name()); + long allTaskCount = scheduleService.countTaskByProjectId(projectId); apiCountResult.setAllApiDataCountNumber(allTaskCount); - long taskCountInThisWeek = scheduleService.countTaskByWorkspaceIdAndGroupInThisWeek(workSpaceID,ScheduleGroup.API_TEST.name()); + long taskCountInThisWeek = scheduleService.countTaskByProjectIdInThisWeek(projectId); apiCountResult.setThisWeekAddedCount(taskCountInThisWeek); - long executedInThisWeekCountNumber = apiReportService.countByWorkspaceIdAndGroupAndCreateInThisWeek(workSpaceID,ScheduleGroup.API_TEST.name()); + long api_executedInThisWeekCountNumber = apiReportService.countByProjectIdAndCreateInThisWeek(projectId); + long scene_executedInThisWeekCountNumber = apiScenarioReportService.countByProjectIdAndCreateAndByScheduleInThisWeek(projectId); + long executedInThisWeekCountNumber = api_executedInThisWeekCountNumber+scene_executedInThisWeekCountNumber; apiCountResult.setThisWeekExecutedCount(executedInThisWeekCountNumber); //统计 失败 成功 以及总数 - List allExecuteResult = apiReportService.countByWorkspaceIdAndGroupGroupByExecuteResult(workSpaceID,ScheduleGroup.API_TEST.name()); + List api_allExecuteResult = apiReportService.countByProjectIdGroupByExecuteResult(projectId); + List scene_allExecuteResult = apiScenarioReportService.countByProjectIdGroupByExecuteResult(projectId); + List allExecuteResult = new ArrayList<>(); + allExecuteResult.addAll(api_allExecuteResult); + allExecuteResult.addAll(scene_allExecuteResult); apiCountResult.countScheduleExecute(allExecuteResult); long allCount = apiCountResult.getExecutedCount(); @@ -329,10 +336,10 @@ public class APITestController { return returnList; } - @GetMapping("/runningTask/{workspaceID}") - public List runningTask(@PathVariable String workspaceID) { + @GetMapping("/runningTask/{projectID}") + public List runningTask(@PathVariable String projectID) { - List resultList = scheduleService.findRunningTaskInfoByWorkspaceID(workspaceID); + List resultList = scheduleService.findRunningTaskInfoByProjectID(projectID); for (TaskInfoResult taskInfo : resultList) { Date nextExecutionTime = CronUtils.getNextTriggerTime(taskInfo.getRule()); diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index 70cb742f59..fd7e1e3b1b 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -31,6 +31,7 @@ public class ApiAutomationController { @PostMapping("/list/{goPage}/{pageSize}") + @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) public Pager> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index 23a7a8c2b5..2fe060e97f 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -14,6 +14,7 @@ import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.service.CheckPermissionService; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; @@ -30,6 +31,8 @@ import java.util.List; public class ApiDefinitionController { @Resource private ApiDefinitionService apiDefinitionService; + @Resource + private CheckPermissionService checkPermissionService; @PostMapping("/list/{goPage}/{pageSize}") public Pager> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { @@ -41,18 +44,21 @@ public class ApiDefinitionController { @PostMapping(value = "/create", consumes = {"multipart/form-data"}) @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR) public void create(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List bodyFiles) { + checkPermissionService.checkReadOnlyUser(); apiDefinitionService.create(request, bodyFiles); } @PostMapping(value = "/update", consumes = {"multipart/form-data"}) @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR) public void update(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List bodyFiles) { + checkPermissionService.checkReadOnlyUser(); apiDefinitionService.update(request, bodyFiles); } @GetMapping("/delete/{id}") @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR) public void delete(@PathVariable String id) { + checkPermissionService.checkReadOnlyUser(); apiDefinitionService.delete(id); } diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java index 9730e9cd86..69742559ef 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java @@ -5,7 +5,7 @@ import io.metersphere.api.dto.definition.DragModuleRequest; import io.metersphere.api.service.ApiModuleService; import io.metersphere.base.domain.ApiModule; import io.metersphere.commons.constants.RoleConstants; -import io.metersphere.service.CheckOwnerService; +import io.metersphere.service.CheckPermissionService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; @@ -21,17 +21,17 @@ public class ApiModuleController { @Resource ApiModuleService apiModuleService; @Resource - private CheckOwnerService checkOwnerService; + private CheckPermissionService checkPermissionService; @GetMapping("/list/{projectId}/{protocol}") public List getNodeByProjectId(@PathVariable String projectId,@PathVariable String protocol) { - checkOwnerService.checkProjectOwner(projectId); + checkPermissionService.checkProjectOwner(projectId); return apiModuleService.getNodeTreeByProjectId(projectId,protocol); } @GetMapping("/list/plan/{planId}/{protocol}") public List getNodeByPlanId(@PathVariable String planId, @PathVariable String protocol) { - checkOwnerService.checkTestPlanOwner(planId); + checkPermissionService.checkTestPlanOwner(planId); return apiModuleService.getNodeByPlanId(planId, protocol); } diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java b/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java index b51bc9aa4e..abcd2d86a5 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java @@ -5,14 +5,13 @@ import io.metersphere.api.dto.automation.DragApiScenarioModuleRequest; import io.metersphere.api.service.ApiScenarioModuleService; import io.metersphere.base.domain.ApiScenarioModule; import io.metersphere.commons.constants.RoleConstants; -import io.metersphere.service.CheckOwnerService; +import io.metersphere.service.CheckPermissionService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; -import java.util.List; - import javax.annotation.Resource; +import java.util.List; @RequestMapping("/api/automation/module") @RestController @@ -22,11 +21,11 @@ public class ApiScenarioModuleController { @Resource ApiScenarioModuleService apiScenarioModuleService; @Resource - private CheckOwnerService checkOwnerService; + private CheckPermissionService checkPermissionService; @GetMapping("/list/{projectId}") public List getNodeByProjectId(@PathVariable String projectId) { - checkOwnerService.checkProjectOwner(projectId); + checkPermissionService.checkProjectOwner(projectId); return apiScenarioModuleService.getNodeTreeByProjectId(projectId); } @@ -44,7 +43,7 @@ public class ApiScenarioModuleController { @GetMapping("/list/plan/{planId}") public List getNodeByPlanId(@PathVariable String planId) { - checkOwnerService.checkTestPlanOwner(planId); + checkPermissionService.checkTestPlanOwner(planId); return apiScenarioModuleService.getNodeByPlanId(planId); } diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiTestEnvironmentController.java b/backend/src/main/java/io/metersphere/api/controller/ApiTestEnvironmentController.java index ae274c383e..87d6e618ce 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiTestEnvironmentController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiTestEnvironmentController.java @@ -3,7 +3,7 @@ package io.metersphere.api.controller; import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.RoleConstants; -import io.metersphere.service.CheckOwnerService; +import io.metersphere.service.CheckPermissionService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; @@ -19,11 +19,11 @@ public class ApiTestEnvironmentController { @Resource ApiTestEnvironmentService apiTestEnvironmentService; @Resource - private CheckOwnerService checkOwnerService; + private CheckPermissionService checkPermissionService; @GetMapping("/list/{projectId}") public List list(@PathVariable String projectId) { - checkOwnerService.checkProjectOwner(projectId); + checkPermissionService.checkProjectOwner(projectId); return apiTestEnvironmentService.list(projectId); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java index 592e9ad0c9..b329cfcffa 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java @@ -15,6 +15,8 @@ public class RunDefinitionRequest { private String reportId; + private String name; + private String type; private String projectId; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 1786eca223..d1a995ea92 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -110,7 +110,9 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (useEnvironment != null) { ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); ApiTestEnvironmentWithBLOBs environment = environmentService.get(useEnvironment); - config.setConfig(JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class)); + if (environment != null && environment.getConfig() != null) { + config.setConfig(JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class)); + } } try { if (config != null && config.getConfig() != null) { @@ -119,9 +121,15 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setPort(config.getConfig().getHttpConfig().getPort()); sampler.setProtocol(config.getConfig().getHttpConfig().getProtocol()); url = config.getConfig().getHttpConfig().getProtocol() + "://" + config.getConfig().getHttpConfig().getSocket(); + // 补充如果是完整URL 则用自身URL + boolean isUrl = false; + if (StringUtils.isNotEmpty(this.getUrl()) && isURL(this.getUrl())) { + url = this.getUrl(); + isUrl = true; + } URL urlObject = new URL(url); String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); - if (StringUtils.isNotBlank(this.getPath())) { + if (StringUtils.isNotBlank(this.getPath()) && !isUrl) { envPath += this.getPath(); } if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { @@ -243,6 +251,15 @@ public class MsHTTPSamplerProxy extends MsTestElement { tree.add(headerManager); } + public boolean isURL(String str) { + //转换为小写 + try { + new URL(str); + return true; + } catch (Exception e) { + return false; + } + } private boolean isRest() { return this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).toArray().length > 0; diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java index fc0e0f7fa3..7ba26ee3d1 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java @@ -98,11 +98,14 @@ public class Body { return StringUtils.equals(type, XML); } - public boolean isWwwFROM() { - return StringUtils.equals(type, WWW_FROM); + public void initKvs() { + this.kvs = new ArrayList<>(); + this.kvs.add(new KeyValue()); } - public boolean isFromData() { - return StringUtils.equals(type, FORM_DATA); + public void initBinary() { + this.binary = new ArrayList<>(); + this.binary.add(new KeyValue()); } + } diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java index 25a9e982a1..328517e501 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/KeyValue.java @@ -15,7 +15,7 @@ public class KeyValue { private List files; private String description; private String contentType; - private boolean enable; + private boolean enable = true; private boolean encode = true; private boolean required; diff --git a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java index e455e98637..4b80284658 100644 --- a/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java @@ -20,6 +20,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -72,7 +73,7 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { protected ApiDefinitionResult buildApiDefinition(String id, String name, String path, String method) { ApiDefinitionResult apiDefinition = new ApiDefinitionResult(); apiDefinition.setName(name); - apiDefinition.setPath(path); + apiDefinition.setPath(formatPath(path)); apiDefinition.setProtocol(RequestType.HTTP); apiDefinition.setMethod(method); apiDefinition.setId(id); @@ -81,17 +82,34 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { return apiDefinition; } + private String formatPath(String url) { + try { + URL urlObject = new URL(url); + StringBuffer pathBuffer = new StringBuffer(urlObject.getPath()); + if (StringUtils.isNotEmpty(urlObject.getQuery())) { + pathBuffer.append("?").append(urlObject.getQuery()); + } + return pathBuffer.toString(); + } catch (Exception ex) { + return url; + } + } + protected MsHTTPSamplerProxy buildRequest(String name, String path, String method) { MsHTTPSamplerProxy request = new MsHTTPSamplerProxy(); request.setName(name); - request.setPath(path); + // 路径去掉域名/IP 地址,保留方法名称及参数 + request.setPath(formatPath(path)); request.setMethod(method); request.setProtocol(RequestType.HTTP); request.setId(UUID.randomUUID().toString()); request.setHeaders(new ArrayList<>()); request.setArguments(new ArrayList<>()); request.setRest(new ArrayList<>()); - request.setBody(new Body()); + Body body = new Body(); + body.initKvs(); + body.initBinary(); + request.setBody(body); return request; } diff --git a/backend/src/main/java/io/metersphere/api/service/APIReportService.java b/backend/src/main/java/io/metersphere/api/service/APIReportService.java index 25cbcbfab1..cd709a8d2b 100644 --- a/backend/src/main/java/io/metersphere/api/service/APIReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/APIReportService.java @@ -212,7 +212,7 @@ public class APIReportService { apiTestReportMapper.deleteByExample(apiTestReportExample); } - public long countByWorkspaceIdAndGroupAndCreateInThisWeek(String workspaceID, String group) { + public long countByProjectIdAndCreateInThisWeek(String projectId) { Map startAndEndDateInWeek = DateUtils.getWeedFirstTimeAndLastTime(new Date()); Date firstTime = startAndEndDateInWeek.get("firstTime"); @@ -221,11 +221,11 @@ public class APIReportService { if(firstTime==null || lastTime == null){ return 0; }else { - return extApiTestReportMapper.countByProjectIDAndCreateInThisWeek(workspaceID,group,firstTime.getTime(),lastTime.getTime()); + return extApiTestReportMapper.countByProjectIDAndCreateInThisWeek(projectId,firstTime.getTime(),lastTime.getTime()); } } - public List countByWorkspaceIdAndGroupGroupByExecuteResult(String workspaceID, String group) { - return extApiTestReportMapper.countByWorkspaceIdAndGroupGroupByExecuteResult(workspaceID,group); + public List countByProjectIdGroupByExecuteResult(String projectId) { + return extApiTestReportMapper.countByProjectIdGroupByExecuteResult(projectId); } } 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 8089c6f4d7..bfb5494e3b 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -14,7 +14,9 @@ import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiScenarioMapper; +import io.metersphere.base.mapper.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioMapper; +import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanMapper; import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper; import io.metersphere.commons.constants.*; @@ -28,6 +30,9 @@ import io.metersphere.service.ScheduleService; import io.metersphere.track.dto.TestPlanDTO; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest; +import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest; +import io.metersphere.track.service.TestPlanApiCaseService; +import io.metersphere.track.service.TestPlanScenarioCaseService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; @@ -53,8 +58,8 @@ public class ApiAutomationService { private ApiDefinitionService apiDefinitionService; @Resource private ExtApiScenarioMapper extApiScenarioMapper; -// @Resource -// private ApiTagMapper apiTagMapper; + @Resource + private TestPlanApiScenarioMapper testPlanApiScenarioMapper; @Resource private JMeterService jMeterService; @Resource @@ -150,10 +155,56 @@ public class ApiAutomationService { } public void delete(String id) { + //及连删除外键表 + this.preDelete(id); apiScenarioMapper.deleteByPrimaryKey(id); } + public void preDelete(String scenarioID){ + scheduleService.deleteByResourceId(scenarioID); + + TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); + example.createCriteria().andApiScenarioIdEqualTo(scenarioID); + List testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example); + + List idList = new ArrayList<>(testPlanApiScenarioList.size()); + for (TestPlanApiScenario api : + testPlanApiScenarioList) { + idList.add(api.getId()); + } + example = new TestPlanApiScenarioExample(); + + if(!idList.isEmpty()){ + example.createCriteria().andIdIn(idList); + testPlanApiScenarioMapper.deleteByExample(example); + } + + } + public void preDelete(List scenarioIDList){ + List testPlanApiScenarioIdList = new ArrayList<>(); + List scheduleIdList = new ArrayList<>(); + 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())){ + testPlanApiScenarioIdList.add(api.getId()); + } + } + + scheduleService.deleteByResourceId(id); + } + if(!testPlanApiScenarioIdList.isEmpty()){ + TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); + example.createCriteria().andIdIn(testPlanApiScenarioIdList); + testPlanApiScenarioMapper.deleteByExample(example); + } + + } public void deleteBatch(List ids) { + //及连删除外键表 + preDelete(ids);; ApiScenarioExample example = new ApiScenarioExample(); example.createCriteria().andIdIn(ids); apiScenarioMapper.deleteByExample(example); @@ -246,6 +297,7 @@ public class ApiAutomationService { }); scenario.setVariables(variables); } + group.setEnableCookieShare(scenario.isEnableCookieShare()); LinkedList scenarios = new LinkedList<>(); scenarios.add(scenario); group.setHashTree(scenarios); @@ -301,7 +353,7 @@ public class ApiAutomationService { QueryTestPlanRequest planRequest = new QueryTestPlanRequest(); planRequest.setScenarioId(request.getId()); planRequest.setProjectId(request.getProjectId()); - dto.setTestPlanList(extTestPlanMapper.selectReference(planRequest)); + dto.setTestPlanList(extTestPlanMapper.selectTestPlanByRelevancy(planRequest)); return dto; } @@ -312,37 +364,66 @@ public class ApiAutomationService { List list = extTestPlanMapper.selectByIds(request.getPlanIds()); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ExtTestPlanMapper mapper = sqlSession.getMapper(ExtTestPlanMapper.class); - list.forEach(item -> { - if (CollectionUtils.isNotEmpty(request.getApiIds())) { - if (CollectionUtils.isNotEmpty(request.getApiIds())) { - if (StringUtils.isEmpty(item.getApiIds())) { - item.setApiIds(JSON.toJSONString(request.getApiIds())); - } else { - // 合并api - List dbApiIDs = JSON.parseArray(item.getApiIds(), String.class); - List result = Stream.of(request.getApiIds(), dbApiIDs) - .flatMap(Collection::stream).distinct().collect(Collectors.toList()); - item.setApiIds(JSON.toJSONString(result)); - } - item.setScenarioIds(null); + ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class); + ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class); + + for (TestPlanDTO testPlan:list) { + if(request.getScenarioIds()!=null){ + for (String scenarioId : request.getScenarioIds()) { + TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); + testPlanApiScenario.setId(UUID.randomUUID().toString()); + testPlanApiScenario.setApiScenarioId(scenarioId); + testPlanApiScenario.setTestPlanId(testPlan.getId()); + testPlanApiScenario.setCreateTime(System.currentTimeMillis()); + testPlanApiScenario.setUpdateTime(System.currentTimeMillis()); + scenarioBatchMapper.insertIfNotExists(testPlanApiScenario); } } - if (CollectionUtils.isNotEmpty(request.getScenarioIds())) { - if (CollectionUtils.isNotEmpty(request.getScenarioIds())) { - if (StringUtils.isEmpty(item.getScenarioIds())) { - item.setScenarioIds(JSON.toJSONString(request.getScenarioIds())); - } else { - // 合并场景ID - List dbScenarioIDs = JSON.parseArray(item.getScenarioIds(), String.class); - List result = Stream.of(request.getScenarioIds(), dbScenarioIDs) - .flatMap(Collection::stream).distinct().collect(Collectors.toList()); - item.setScenarioIds(JSON.toJSONString(result)); - } - item.setApiIds(null); + if(request.getApiIds()!=null){ + for (String caseId : request.getApiIds()) { + TestPlanApiCase testPlanApiCase = new TestPlanApiCase(); + testPlanApiCase.setId(UUID.randomUUID().toString()); + testPlanApiCase.setApiCaseId(caseId); + testPlanApiCase.setTestPlanId(testPlan.getId()); + testPlanApiCase.setCreateTime(System.currentTimeMillis()); + testPlanApiCase.setUpdateTime(System.currentTimeMillis()); + apiCaseBatchMapper.insertIfNotExists(testPlanApiCase); } } - mapper.updatePlan(item); - }); + + } +// testPlan的ID先不存储 +// list.forEach(item -> { +// if (CollectionUtils.isNotEmpty(request.getApiIds())) { +// if (CollectionUtils.isNotEmpty(request.getApiIds())) { +// if (StringUtils.isEmpty(item.getApiIds())) { +// item.setApiIds(JSON.toJSONString(request.getApiIds())); +// } else { +// // 合并api +// List dbApiIDs = JSON.parseArray(item.getApiIds(), String.class); +// List result = Stream.of(request.getApiIds(), dbApiIDs) +// .flatMap(Collection::stream).distinct().collect(Collectors.toList()); +// item.setApiIds(JSON.toJSONString(result)); +// } +// item.setScenarioIds(null); +// } +// } +// if (CollectionUtils.isNotEmpty(request.getScenarioIds())) { +// if (CollectionUtils.isNotEmpty(request.getScenarioIds())) { +// if (StringUtils.isEmpty(item.getScenarioIds())) { +// item.setScenarioIds(JSON.toJSONString(request.getScenarioIds())); +// } else { +// // 合并场景ID +// List dbScenarioIDs = JSON.parseArray(item.getScenarioIds(), String.class); +// List result = Stream.of(request.getScenarioIds(), dbScenarioIDs) +// .flatMap(Collection::stream).distinct().collect(Collectors.toList()); +// item.setScenarioIds(JSON.toJSONString(result)); +// } +// item.setApiIds(null); +// } +// } +// mapper.updatePlan(item); +// }); sqlSession.flushStatements(); return "success"; } 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 7c00ff765c..8ec808f47c 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -29,8 +29,6 @@ public class ApiDefinitionExecResultService { public void saveApiResult(TestResult result, String type) { result.getScenarios().get(0).getRequestResults().forEach(item -> { - // 清理原始资源,每个执行 保留一条结果 - extApiDefinitionExecResultMapper.deleteByResourceId(item.getName()); ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult(); saveResult.setId(UUID.randomUUID().toString()); saveResult.setCreateTime(System.currentTimeMillis()); 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 e90df7ce74..06ed0e92da 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -392,7 +392,7 @@ public class ApiDefinitionService { QueryTestPlanRequest planRequest = new QueryTestPlanRequest(); planRequest.setApiId(request.getId()); planRequest.setProjectId(request.getProjectId()); - dto.setTestPlanList(extTestPlanMapper.selectReference(planRequest)); + dto.setTestPlanList(extTestPlanMapper.selectTestPlanByRelevancy(planRequest)); return dto; } 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 907b610bb0..0834cdb62a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -6,6 +6,7 @@ import io.metersphere.api.dto.DeleteAPIReportRequest; import io.metersphere.api.dto.QueryAPIReportRequest; import io.metersphere.api.dto.automation.APIScenarioReportResult; import io.metersphere.api.dto.automation.ExecuteType; +import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.jmeter.ScenarioResult; import io.metersphere.api.jmeter.TestResult; import io.metersphere.base.domain.*; @@ -16,10 +17,13 @@ import io.metersphere.base.mapper.TestPlanApiScenarioMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.DateUtils; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.i18n.Translator; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -28,10 +32,7 @@ import sun.security.util.Cache; import javax.annotation.Resource; import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; @Service @Transactional(rollbackFor = Exception.class) @@ -55,6 +56,13 @@ public class ApiScenarioReportService { MSException.throwException(Translator.get("api_report_is_null")); } APIScenarioReportResult report = (APIScenarioReportResult) obj; + if (CollectionUtils.isNotEmpty(result.getScenarios())) { + try { + report.setName(result.getScenarios().get(0).getName() + "-" + DateUtils.getTimeString(System.currentTimeMillis())); + } catch (Exception e) { + LogUtil.error(e.getMessage()); + } + } // report detail ApiScenarioReportDetail detail = new ApiScenarioReportDetail(); detail.setReportId(result.getTestId()); @@ -72,7 +80,9 @@ public class ApiScenarioReportService { } report.setContent(new String(detail.getContent(), StandardCharsets.UTF_8)); this.save(report, runMode); - cache.put(report.getId(), report); + if (!report.getTriggerMode().equals(ReportTriggerMode.SCHEDULE.name())) { + cache.put(report.getId(), report); + } } /** @@ -245,7 +255,7 @@ public class ApiScenarioReportService { return extApiScenarioReportMapper.countByProjectID(projectId); } - public long countByProjectIDAndCreateInThisWeek(String projectId) { + public long countByProjectIdAndCreateAndByScheduleInThisWeek(String projectId) { Map startAndEndDateInWeek = DateUtils.getWeedFirstTimeAndLastTime(new Date()); Date firstTime = startAndEndDateInWeek.get("firstTime"); @@ -254,7 +264,24 @@ public class ApiScenarioReportService { if (firstTime == null || lastTime == null) { return 0; } else { - return extApiScenarioReportMapper.countByProjectIDAndCreateInThisWeek(projectId, firstTime.getTime(), lastTime.getTime()); + return extApiScenarioReportMapper.countByProjectIdAndCreateAndByScheduleInThisWeek(projectId, firstTime.getTime(), lastTime.getTime()); } } + + public long countByProjectIdAndCreateInThisWeek(String projectId) { + Map startAndEndDateInWeek = DateUtils.getWeedFirstTimeAndLastTime(new Date()); + + Date firstTime = startAndEndDateInWeek.get("firstTime"); + Date lastTime = startAndEndDateInWeek.get("lastTime"); + + if (firstTime == null || lastTime == null) { + return 0; + } else { + return extApiScenarioReportMapper.countByProjectIdAndCreateInThisWeek(projectId, firstTime.getTime(), lastTime.getTime()); + } + } + + public List countByProjectIdGroupByExecuteResult(String projectId) { + return extApiScenarioReportMapper.countByProjectIdGroupByExecuteResult(projectId); + } } 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 7e6241ae5e..42a46d2eaa 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -13,6 +13,7 @@ import io.metersphere.base.mapper.ApiTestFileMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper; +import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.i18n.Translator; @@ -48,6 +49,8 @@ public class ApiTestCaseService { @Resource private ApiTestFileMapper apiTestFileMapper; @Resource + private ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; + @Resource private FileService fileService; @Resource private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; @@ -131,8 +134,12 @@ public class ApiTestCaseService { } public void delete(String testId) { + + extTestPlanTestCaseMapper.deleteByTestCaseID(testId); + deleteFileByTestId(testId); extApiDefinitionExecResultMapper.deleteByResourceId(testId); + apiTestCaseMapper.deleteByPrimaryKey(testId); deleteBodyFiles(testId); } @@ -253,6 +260,9 @@ public class ApiTestCaseService { } public void deleteBatch(List ids) { + for (String testId:ids) { + extTestPlanTestCaseMapper.deleteByTestCaseID(testId); + } ApiTestCaseExample example = new ApiTestCaseExample(); example.createCriteria().andIdIn(ids); apiTestCaseMapper.deleteByExample(example); 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 855d071d08..0914b1e050 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 @@ -37,7 +37,8 @@ SELECT testCase.testCaseName AS caseName,testCase.testPlanName AS testPlan ,caseErrorCountData.dataCountNumber AS failureTimes,'apiCase' AS caseType FROM ( SELECT apiCase.id AS testCaseID,apiCase.`name` AS testCaseName,group_concat(testPlan.`name`) AS testPlanName FROM api_test_case apiCase - LEFT JOIN test_plan testPlan ON testPlan.api_ids like concat('%"',apiCase.id,'"%') + LEFT JOIN test_plan_api_case testPlanCase ON testPlanCase.api_case_id = apiCase.id + LEFT JOIN test_plan testPlan ON testPlan.id = testPlanCase.test_plan_id GROUP BY apiCase.id ORDER BY apiCase.create_time DESC )testCase diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java index a4b37a10a2..425ec646de 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportMapper.java @@ -2,6 +2,7 @@ package io.metersphere.base.mapper.ext; import io.metersphere.api.dto.QueryAPIReportRequest; import io.metersphere.api.dto.automation.APIScenarioReportResult; +import io.metersphere.api.dto.datacount.ApiDataCountResult; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -14,6 +15,9 @@ public interface ExtApiScenarioReportMapper { long countByProjectID(String projectId); - long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); + long countByProjectIdAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); + long countByProjectIdAndCreateAndByScheduleInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); + + List countByProjectIdGroupByExecuteResult(String projectId); } \ No newline at end of file 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 50f7475d1b..2b48a30ab8 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 @@ -169,9 +169,28 @@ - SELECT count(id) AS countNumber FROM api_scenario_report WHERE project_id = #{projectId} AND create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp} + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.java index f2d150f0e5..a29f005c5e 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestReportMapper.java @@ -18,7 +18,7 @@ public interface ExtApiTestReportMapper { List selectDashboardTests(@Param("workspaceId") String workspaceId, @Param("startTimestamp") long startTimestamp); - List countByWorkspaceIdAndGroupGroupByExecuteResult(@Param("workspaceID") String workspaceID, @Param("group")String group); + List countByProjectIdGroupByExecuteResult(String projectId); - long countByProjectIDAndCreateInThisWeek(@Param("workspaceID") String workspaceID, @Param("group")String group, @Param("startTime") long startTime, @Param("endTime")long endTime); + long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("startTime") long startTime, @Param("endTime")long endTime); } 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 38f2523e0b..724925a6de 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 @@ -152,19 +152,24 @@ GROUP BY x - SELECT testReport.`status` AS groupField,COUNT(testReportDetail.report_id) AS countNumber FROM api_test_report_detail testReportDetail INNER JOIN `schedule` sch ON sch.resource_id = testReportDetail.test_id INNER JOIN api_test_report testReport ON testReportDetail.report_id = testReport.id - WHERE workspace_id = #{workspaceID} AND `group` = #{group} + WHERE sch.resource_id IN ( + SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR} + ) + AND `group` = #{group} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java index 9920d429ea..fc94d7b4fe 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.java @@ -10,9 +10,9 @@ import java.util.List; public interface ExtScheduleMapper { List list(@Param("request") QueryScheduleRequest request); - long countTaskByWorkspaceIdAndGroup(@Param("workspaceId") String workspaceId,@Param("group") String group); + long countTaskByProjectId(String workspaceId); - long countTaskByWorkspaceIdAndGroupAndCreateTimeRange(@Param("workspaceId")String workspaceId,@Param("group") String group, @Param("startTime") long startTime, @Param("endTime") long endTime); + long countTaskByProjectIdAndCreateTimeRange(@Param("projectId")String projectId, @Param("startTime") long startTime, @Param("endTime") long endTime); - List findRunningTaskInfoByWorkspaceID(String workspaceID); + List findRunningTaskInfoByProjectID(String workspaceID); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml index fe30863df5..77d343086c 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtScheduleMapper.xml @@ -36,26 +36,33 @@ - + SELECT COUNT(id) AS countNumber FROM `schedule` WHERE resource_id IN ( + SELECT id FROM api_test WHERE project_id = #{0,jdbcType=VARCHAR} + UNION + SELECT id FROM api_scenario WHERE project_id = #{0,jdbcType=VARCHAR} + ) - SELECT COUNT(id) AS countNumber FROM `schedule` - WHERE workspace_id = #{workspaceId} - AND `group` = #{group} + WHERE resource_id IN ( + SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR} + UNION + SELECT id FROM api_scenario WHERE project_id = #{projectId,jdbcType=VARCHAR} + ) AND create_time BETWEEN #{startTime} and #{endTime} - SELECT apiTest.`name` AS scenario,sch.id AS taskID,sch.`value` AS rule,sch.`enable` AS `taskStatus`,u.`name` AS creator,sch.update_time AS updateTime FROM api_test apiTest INNER JOIN `schedule` sch ON apiTest.id = sch.resource_id INNER JOIN `user` u ON u.id = sch.user_id - WHERE sch.`enable` = true AND sch.workspace_id = #{0,jdbcType=VARCHAR} + WHERE sch.`enable` = true AND apiTest.project_id = #{0,jdbcType=VARCHAR} UNION - SELECT apiTest.`name` AS scenario,sch.id AS taskID,sch.`value` AS rule,sch.`enable` AS `taskStatus`,u.`name` AS creator,sch.update_time AS updateTime - FROM api_scenario apiTest - INNER JOIN `schedule` sch ON apiTest.id = sch.resource_id + SELECT apiScene.`name` AS scenario,sch.id AS taskID,sch.`value` AS rule,sch.`enable` AS `taskStatus`,u.`name` AS creator,sch.update_time AS updateTime + FROM api_scenario apiScene + INNER JOIN `schedule` sch ON apiScene.id = sch.resource_id INNER JOIN `user` u ON u.id = sch.user_id - WHERE sch.`enable` = true AND sch.workspace_id = #{0,jdbcType=VARCHAR} + WHERE sch.`enable` = true AND apiScene.project_id = #{0,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java index 4cadad7073..ea1768cc89 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java @@ -21,5 +21,12 @@ public interface ExtTestPlanMapper { List selectReference(@Param("request") QueryTestPlanRequest params); + /** + * 通过关联表(test_plan_api_case/test_plan_api_scenario)查询testPlan + * @param params + * @return + */ + List selectTestPlanByRelevancy(@Param("request") QueryTestPlanRequest params); + int checkIsHave(@Param("planId") String planId, @Param("workspaceIds") Set workspaceIds); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml index eecf98dc66..e3dbb2b706 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml @@ -227,4 +227,16 @@ + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java index ad4f6e42bc..670ae1b37d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java @@ -7,6 +7,8 @@ import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.TestPlanApiCaseDTO; import io.metersphere.base.domain.TestPlanApiCase; import io.metersphere.base.domain.TestPlanApiScenario; +import io.metersphere.track.dto.TestPlanDTO; +import io.metersphere.track.request.testcase.QueryTestPlanRequest; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -15,4 +17,5 @@ public interface ExtTestPlanScenarioCaseMapper { void insertIfNotExists(@Param("request") TestPlanApiScenario request); List list(@Param("request") TestPlanScenarioRequest request); + } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java index 3911f21c76..bd23bcfbf3 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java @@ -40,4 +40,5 @@ public interface ExtTestPlanTestCaseMapper { TestPlanCaseDTO get(String testPlanTestCaseId); + void deleteByTestCaseID(String id); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml index 199b6ccb45..1a0a98a4bd 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml @@ -122,13 +122,13 @@