From cb5c5a507f26d21fbadcc7cf0e52c773962dcd82 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 11 Mar 2022 14:13:33 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E6=8A=A5=E5=91=8A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2SQL=E8=AF=AD=E5=8F=A5=E9=9C=80=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 接口测试报告查询SQL语句需优化 chore: sync --- .../APIScenarioReportController.java | 15 +- .../api/dto/QueryAPIReportRequest.java | 3 + .../api/exec/api/ApiCaseExecuteService.java | 12 +- .../api/exec/api/ApiExecuteService.java | 7 + .../scenario/ApiScenarioExecuteService.java | 13 + .../ApiDefinitionExecResultService.java | 12 + .../api/service/ApiDefinitionService.java | 8 + .../api/service/ApiScenarioReportService.java | 178 ++++++++++- .../api/service/ApiTestCaseService.java | 5 + .../ApiDefinitionScenarioRelevance.java | 11 + ...ApiDefinitionScenarioRelevanceExample.java | 270 ++++++++++++++++ .../ApiDefinitionScenarioRelevanceMapper.java | 24 ++ .../ApiDefinitionScenarioRelevanceMapper.xml | 133 ++++++++ .../ext/ExtApiDefinitionExecResultMapper.java | 3 + .../ext/ExtApiDefinitionExecResultMapper.xml | 133 ++++++++ .../ExtApiDefinitionExecResultProvider.java | 13 + .../ext/ExtApiScenarioReportMapper.java | 5 + .../mapper/ext/ExtApiScenarioReportMapper.xml | 294 ++++++++++++------ .../ext/ExtApiScenarioReportProvider.java | 17 + backend/src/main/java/io/metersphere/xpack | 2 +- .../db/migration/V110__v1.18.3_release.sql | 28 ++ ...19_release.sql => V111__v1.19_release.sql} | 0 .../src/main/resources/generatorConfig.xml | 35 +-- 23 files changed, 1090 insertions(+), 131 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevance.java create mode 100644 backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevanceExample.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.xml create mode 100644 backend/src/main/resources/db/migration/V110__v1.18.3_release.sql rename backend/src/main/resources/db/migration/{V110__v1.19_release.sql => V111__v1.19_release.sql} (100%) diff --git a/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java b/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java index c86d7b48ed..a286cfaf58 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java @@ -9,6 +9,8 @@ import io.metersphere.api.dto.automation.APIScenarioReportResult; import io.metersphere.api.dto.automation.ExecuteType; import io.metersphere.api.service.ApiScenarioReportService; import io.metersphere.base.domain.ApiScenarioReport; +import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; +import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogModule; @@ -27,6 +29,10 @@ public class APIScenarioReportController { @Resource private ApiScenarioReportService apiReportService; + @Resource + private ExtApiScenarioReportMapper extApiScenarioReportMapper; + @Resource + private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; @GetMapping("/get/{reportId}") public APIScenarioReportResult get(@PathVariable String reportId) { @@ -35,9 +41,12 @@ public class APIScenarioReportController { @PostMapping("/list/{goPage}/{pageSize}") public Pager> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) { - Page page = PageHelper.startPage(goPage, pageSize, true); - request.setLimit("LIMIT " + (goPage - 1) * pageSize + "," + pageSize * 50); - return PageUtils.setPageInfo(page, apiReportService.list(request)); + Page page = new Page(goPage, pageSize*2, true); + long scenarioCount = extApiScenarioReportMapper.selectCountByRequest(request); + long definitionCount = extApiDefinitionExecResultMapper.selectCountByRequest(request); + long totalCount = scenarioCount + definitionCount; + page.setTotal(totalCount); + return PageUtils.setPageInfo(page, apiReportService.list(goPage,pageSize*2,request)); } @PostMapping("/update") diff --git a/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java b/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java index 39c9e80f35..78ad0e7041 100644 --- a/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java @@ -22,4 +22,7 @@ public class QueryAPIReportRequest { private Map combine; private String limit; + + private Integer goPage; + private Integer pageSize; } diff --git a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java index 413cee6f5d..8b12894dd5 100644 --- a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java @@ -13,10 +13,7 @@ import io.metersphere.api.exec.scenario.ApiScenarioSerialService; import io.metersphere.api.exec.utils.ApiDefinitionExecResultUtil; import io.metersphere.api.service.*; import io.metersphere.base.domain.*; -import io.metersphere.base.mapper.ApiScenarioReportMapper; -import io.metersphere.base.mapper.ApiTestCaseMapper; -import io.metersphere.base.mapper.TestPlanApiCaseMapper; -import io.metersphere.base.mapper.TestPlanMapper; +import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; @@ -61,6 +58,8 @@ public class ApiCaseExecuteService { private ApiScenarioReportMapper apiScenarioReportMapper; @Resource ApiScenarioReportStructureService apiScenarioReportStructureService; + @Resource + private ApiDefinitionScenarioRelevanceMapper apiDefinitionScenarioRelevanceMapper; /** * 测试计划case执行 @@ -222,7 +221,10 @@ public class ApiCaseExecuteService { request.getConfig().setAmassReport(serialReportId); report.setStatus(APITestStatus.Running.name()); apiScenarioReportMapper.insert(report); - + //生成关系数据 + ApiDefinitionScenarioRelevance apiDefinitionScenarioRelevance = new ApiDefinitionScenarioRelevance(); + apiDefinitionScenarioRelevance.setReportId(report.getId()); + apiDefinitionScenarioRelevanceMapper.insert(apiDefinitionScenarioRelevance); apiScenarioReportStructureService.save(serialReportId, new ArrayList<>()); } diff --git a/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java index 6698103f0e..51f30ecc28 100644 --- a/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java @@ -20,6 +20,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.api.service.TcpApiParamService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; +import io.metersphere.base.mapper.ApiDefinitionScenarioRelevanceMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.TestPlanApiCaseMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; @@ -60,6 +61,8 @@ public class ApiExecuteService { private TcpApiParamService tcpApiParamService; @Resource private ExtApiTestCaseMapper extApiTestCaseMapper; + @Resource + private ApiDefinitionScenarioRelevanceMapper apiDefinitionScenarioRelevanceMapper; public MsExecResponseDTO jenkinsRun(RunCaseRequest request) { ApiTestCaseWithBLOBs caseWithBLOBs = null; @@ -85,6 +88,10 @@ public class ApiExecuteService { report.setType(ApiRunMode.JENKINS.name()); report.setProjectId(caseWithBLOBs.getProjectId()); apiDefinitionExecResultMapper.insert(report); + //生成关系数据 + ApiDefinitionScenarioRelevance apiDefinitionScenarioRelevance = new ApiDefinitionScenarioRelevance(); + apiDefinitionScenarioRelevance.setReportId(report.getId()); + apiDefinitionScenarioRelevanceMapper.insert(apiDefinitionScenarioRelevance); //更新接口案例的最后执行状态等信息 caseWithBLOBs.setLastResultId(report.getId()); caseWithBLOBs.setUpdateTime(System.currentTimeMillis()); diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 9841e5c3e8..f4ff29cee6 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -15,9 +15,11 @@ import io.metersphere.api.service.ApiExecutionQueueService; import io.metersphere.api.service.ApiScenarioReportService; import io.metersphere.api.service.ApiScenarioReportStructureService; import io.metersphere.api.service.TcpApiParamService; +import io.metersphere.base.domain.ApiDefinitionScenarioRelevance; import io.metersphere.base.domain.ApiScenarioExample; import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.domain.TestPlanApiScenario; +import io.metersphere.base.mapper.ApiDefinitionScenarioRelevanceMapper; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiScenarioReportMapper; import io.metersphere.base.mapper.TestPlanApiScenarioMapper; @@ -86,6 +88,9 @@ public class ApiScenarioExecuteService { private TcpApiParamService tcpApiParamService; @Resource private JMeterService jMeterService; + @Resource + private ApiDefinitionScenarioRelevanceMapper apiDefinitionScenarioRelevanceMapper; + public List run(RunScenarioRequest request) { if (LoggerUtil.getLogger().isDebugEnabled()) { @@ -159,6 +164,9 @@ public class ApiScenarioExecuteService { request.getConfig().setAmassReport(serialReportId); report.setStatus(APITestStatus.Running.name()); apiScenarioReportMapper.insert(report); + ApiDefinitionScenarioRelevance apiDefinitionScenarioRelevance = new ApiDefinitionScenarioRelevance(); + apiDefinitionScenarioRelevance.setReportId(report.getId()); + apiDefinitionScenarioRelevanceMapper.insert(apiDefinitionScenarioRelevance); responseDTOS.add(new MsExecResponseDTO(JSON.toJSONString(scenarioIds), serialReportId, request.getRunMode())); reportStructureService.save(apiScenarios, serialReportId, request.getConfig().getReportType()); @@ -361,6 +369,11 @@ public class ApiScenarioExecuteService { } } apiScenarioReportMapper.insert(report); + if(report.getExecuteType().equals(ExecuteType.Saved.name())){ + ApiDefinitionScenarioRelevance apiDefinitionScenarioRelevance = new ApiDefinitionScenarioRelevance(); + apiDefinitionScenarioRelevance.setReportId(report.getId()); + apiDefinitionScenarioRelevanceMapper.insert(apiDefinitionScenarioRelevance); + } } String runMode = StringUtils.isEmpty(request.getRunMode()) ? ApiRunMode.SCENARIO.name() : request.getRunMode(); // 调用执行方法 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 4e167b51c1..06a7e8e974 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -37,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -69,6 +70,8 @@ public class ApiDefinitionExecResultService { private ProjectMapper projectMapper; @Resource private SqlSessionFactory sqlSessionFactory; + @Resource + private ApiDefinitionScenarioRelevanceMapper apiDefinitionScenarioRelevanceMapper; public void saveApiResult(List requestResults, ResultDTO dto) { LoggerUtil.info("接收到API/CASE执行结果【 " + requestResults.size() + " 】"); @@ -350,6 +353,8 @@ public class ApiDefinitionExecResultService { public void deleteByResourceId(String resourceId) { ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample(); example.createCriteria().andResourceIdEqualTo(resourceId); + ApiDefinitionExecResult result = extApiDefinitionExecResultMapper.selectMaxResultByResourceId(resourceId); + apiDefinitionScenarioRelevanceMapper.deleteByPrimaryKey(result.getId()); apiDefinitionExecResultMapper.deleteByExample(example); } @@ -359,6 +364,13 @@ public class ApiDefinitionExecResultService { } ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample(); example.createCriteria().andResourceIdIn(ids); + List apiDefinitionExecResults = apiDefinitionExecResultMapper.selectByExample(example); + if(apiDefinitionExecResults!=null&&apiDefinitionExecResults.size()!=0){ + List reportIds = apiDefinitionExecResults.stream().map(ApiDefinitionExecResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } apiDefinitionExecResultMapper.deleteByExample(example); } 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 17b67b235e..fa0795dce4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -127,6 +127,8 @@ public class ApiDefinitionService { private ExtProjectVersionMapper extProjectVersionMapper; @Resource private ProjectApplicationService projectApplicationService; + @Resource + private ApiDefinitionScenarioRelevanceMapper apiDefinitionScenarioRelevanceMapper; private ThreadLocal currentApiOrder = new ThreadLocal<>(); private ThreadLocal currentApiCaseOrder = new ThreadLocal<>(); @@ -346,6 +348,8 @@ public class ApiDefinitionService { apiDefinitions.forEach(api -> { apiTestCaseService.deleteTestCase(api.getId()); deleteFileByTestId(api.getId()); + ApiDefinitionExecResult result = extApiDefinitionExecResultMapper.selectMaxResultByResourceId(api.getId()); + apiDefinitionScenarioRelevanceMapper.deleteByPrimaryKey(result.getId()); extApiDefinitionExecResultMapper.deleteByResourceId(api.getId()); apiDefinitionMapper.deleteByPrimaryKey(api.getId()); esbApiParamService.deleteByResourceId(api.getId()); @@ -1052,6 +1056,10 @@ public class ApiDefinitionService { result.setProjectId(request.getProjectId()); result.setTriggerMode(TriggerMode.MANUAL.name()); apiDefinitionExecResultMapper.insert(result); + //生成关系数据 + ApiDefinitionScenarioRelevance apiDefinitionScenarioRelevance = new ApiDefinitionScenarioRelevance(); + apiDefinitionScenarioRelevance.setReportId(result.getId()); + apiDefinitionScenarioRelevanceMapper.insert(apiDefinitionScenarioRelevance); } return apiExecuteService.debug(request, bodyFiles); } 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 074bfea331..343f1a9f57 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -14,9 +14,7 @@ import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.utils.DateUtils; -import io.metersphere.commons.utils.ServiceUtils; -import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.commons.utils.*; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.*; import io.metersphere.i18n.Translator; @@ -78,6 +76,9 @@ public class ApiScenarioReportService { private ApiScenarioReportStructureMapper apiScenarioReportStructureMapper; @Resource private ApiDefinitionExecResultMapper definitionExecResultMapper; + @Resource + private ApiDefinitionScenarioRelevanceMapper apiDefinitionScenarioRelevanceMapper; + public void saveResult(List requestResults, ResultDTO dto) { // 报告详情内容 @@ -132,18 +133,97 @@ public class ApiScenarioReportService { return reportResult; } - public List list(QueryAPIReportRequest request) { + public List list(int goPage,int pageSize,QueryAPIReportRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + request.setGoPage((goPage - 1) * pageSize/2); + request.setPageSize(pageSize); List list = extApiScenarioReportMapper.list(request); - List userIds = list.stream().map(APIScenarioReportResult::getUserId) + List collect = new ArrayList<>(); + Comparator comparing = null; + if(request.getOrders().size()==0){ + collect = list; + } else if(request.getOrders().size()==1){ + String name = request.getOrders().get(0).getName(); + String type = request.getOrders().get(0).getType(); + if(StringUtils.equals(name,"name")){ + comparing = Comparator.comparing(APIScenarioReportResult::getName); + if(StringUtils.equals(type,"DESC")){ + Comparator.comparing(APIScenarioReportResult::getName,Comparator.reverseOrder()); + } + collect = getApiScenarioReportResults(pageSize,list,comparing); + } + if(StringUtils.equals(name,"create_time")){ + comparing =Comparator.comparing(APIScenarioReportResult::getCreateTime); + if(StringUtils.equals(type,"DESC")){ + comparing = Comparator.comparing(APIScenarioReportResult::getCreateTime,Comparator.reverseOrder()); + } + collect = getApiScenarioReportResults(pageSize,list,comparing); + } + if(StringUtils.equals(name,"update_time")){ + if(StringUtils.equals(type,"DESC")){ + comparing = Comparator.comparing(APIScenarioReportResult::getUpdateTime,Comparator.reverseOrder()); + }else { + comparing =Comparator.comparing(APIScenarioReportResult::getUpdateTime); + } + collect = getApiScenarioReportResults(pageSize,list,comparing); + } + if(StringUtils.equals(name,"end_time")){ + comparing =Comparator.comparing(APIScenarioReportResult::getEndTime); + if(StringUtils.equals(type,"DESC")){ + comparing = Comparator.comparing(APIScenarioReportResult::getEndTime,Comparator.reverseOrder()); + } + collect = getApiScenarioReportResults(pageSize,list,comparing); + } + }else if(request.getOrders().size()>1){ + for (int i = 1; i < request.getOrders().size(); i++) { + String name1 = request.getOrders().get(i).getName(); + String type1 = request.getOrders().get(i).getType(); + if(StringUtils.equals(name1,"name")){ + if(StringUtils.equals(type1,"DESC")){ + comparing.thenComparing(APIScenarioReportResult::getName,Comparator.reverseOrder()); + }else{ + comparing.thenComparing(APIScenarioReportResult::getName); + } + } + if(StringUtils.equals(name1,"update_time")){ + if(StringUtils.equals(type1,"DESC")){ + comparing.thenComparing(APIScenarioReportResult::getUpdateTime,Comparator.reverseOrder()); + }else{ + comparing.thenComparing(APIScenarioReportResult::getUpdateTime); + } + } + if(StringUtils.equals(name1,"create_time")){ + if(StringUtils.equals(type1,"DESC")){ + comparing.thenComparing(APIScenarioReportResult::getCreateTime,Comparator.reverseOrder()); + }else{ + comparing.thenComparing(APIScenarioReportResult::getCreateTime); + } + } + if(StringUtils.equals(name1,"end_time")){ + if(StringUtils.equals(type1,"DESC")){ + comparing.thenComparing(APIScenarioReportResult::getEndTime,Comparator.reverseOrder()); + }else{ + comparing.thenComparing(APIScenarioReportResult::getEndTime); + } + } + } + collect = getApiScenarioReportResults(pageSize,list,comparing); + } + + List userIds = collect.stream().map(APIScenarioReportResult::getUserId) .collect(Collectors.toList()); Map userMap = ServiceUtils.getUserMap(userIds); - list.forEach(item -> { + collect.forEach(item -> { User user = userMap.get(item.getUserId()); if (user != null) item.setUserName(user.getName()); }); - return list; + + return collect; + } + + private List getApiScenarioReportResults(int pageSize,List list, Comparator comparing) { + return list.stream().sorted(comparing).limit(pageSize/2).collect(Collectors.toList()); } public List idList(QueryAPIReportRequest request) { @@ -183,6 +263,9 @@ public class ApiScenarioReportService { report.setTriggerMode(TriggerMode.MANUAL.name()); } apiScenarioReportMapper.insert(report); + ApiDefinitionScenarioRelevance apiDefinitionScenarioRelevance = new ApiDefinitionScenarioRelevance(); + apiDefinitionScenarioRelevance.setReportId(report.getId()); + apiDefinitionScenarioRelevanceMapper.insert(apiDefinitionScenarioRelevance); return report; } @@ -476,6 +559,13 @@ public class ApiScenarioReportService { apiScenarioReportDetailMapper.deleteByPrimaryKey(request.getId()); ApiScenarioReportResultExample example = new ApiScenarioReportResultExample(); example.createCriteria().andReportIdEqualTo(request.getId()); + List apiScenarioReportResults = apiScenarioReportResultMapper.selectByExample(example); + if(apiScenarioReportResults!=null&&apiScenarioReportResults.size()!=0){ + List reportIds = apiScenarioReportResults.stream().map(ApiScenarioReportResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } apiScenarioReportResultMapper.deleteByExample(example); ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); @@ -484,10 +574,18 @@ public class ApiScenarioReportService { ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); definitionExecResultExample.createCriteria().andIdEqualTo(request.getId()); + apiDefinitionScenarioRelevanceMapper.deleteByPrimaryKey(request.getId()); definitionExecResultMapper.deleteByExample(definitionExecResultExample); ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); execResultExample.createCriteria().andIntegratedReportIdEqualTo(request.getId()); + List apiDefinitionExecResults = definitionExecResultMapper.selectByExample(execResultExample); + if(apiDefinitionExecResults!=null&&apiDefinitionExecResults.size()!=0){ + List reportIds = apiDefinitionExecResults.stream().map(ApiDefinitionExecResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } definitionExecResultMapper.deleteByExample(execResultExample); // 补充逻辑,如果是集成报告则把零时报告全部删除 @@ -508,6 +606,13 @@ public class ApiScenarioReportService { apiScenarioReportMapper.deleteByPrimaryKey(id); ApiScenarioReportResultExample example = new ApiScenarioReportResultExample(); example.createCriteria().andReportIdEqualTo(id); + List apiScenarioReportResults = apiScenarioReportResultMapper.selectByExample(example); + if(apiScenarioReportResults!=null&&apiScenarioReportResults.size()!=0){ + List reportIds = apiScenarioReportResults.stream().map(ApiScenarioReportResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } apiScenarioReportResultMapper.deleteByExample(example); ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); @@ -517,9 +622,17 @@ public class ApiScenarioReportService { ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); definitionExecResultExample.createCriteria().andIdEqualTo(id); definitionExecResultMapper.deleteByExample(definitionExecResultExample); + apiDefinitionScenarioRelevanceMapper.deleteByPrimaryKey(id); ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); execResultExample.createCriteria().andIntegratedReportIdEqualTo(id); + List apiDefinitionExecResults = definitionExecResultMapper.selectByExample(execResultExample); + if(apiDefinitionExecResults!=null&&apiDefinitionExecResults.size()!=0){ + List ids = apiDefinitionExecResults.stream().map(ApiDefinitionExecResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(ids); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } definitionExecResultMapper.deleteByExample(execResultExample); } @@ -535,6 +648,13 @@ public class ApiScenarioReportService { ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample(); reportResultExample.createCriteria().andReportIdIn(ids); + List apiScenarioReportResults = apiScenarioReportResultMapper.selectByExample(reportResultExample); + if(apiScenarioReportResults!=null&&apiScenarioReportResults.size()!=0){ + List reportIds = apiScenarioReportResults.stream().map(ApiScenarioReportResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } apiScenarioReportResultMapper.deleteByExample(reportResultExample); ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); @@ -543,10 +663,20 @@ public class ApiScenarioReportService { ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); definitionExecResultExample.createCriteria().andIdIn(ids); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(ids); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); definitionExecResultMapper.deleteByExample(definitionExecResultExample); ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); execResultExample.createCriteria().andIntegratedReportIdIn(ids); + List apiDefinitionExecResultList = definitionExecResultMapper.selectByExample(execResultExample); + if(apiDefinitionExecResultList!=null&&apiDefinitionExecResultList.size()!=0){ + List reportIds = apiDefinitionExecResultList.stream().map(ApiDefinitionExecResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample asexample = new ApiDefinitionScenarioRelevanceExample(); + asexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(asexample); + } definitionExecResultMapper.deleteByExample(execResultExample); } } @@ -596,6 +726,13 @@ public class ApiScenarioReportService { ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample(); reportResultExample.createCriteria().andReportIdIn(handleIdList); + List apiScenarioReportResults = apiScenarioReportResultMapper.selectByExample(reportResultExample); + if(apiScenarioReportResults!=null&&apiScenarioReportResults.size()!=0){ + List reportIds = apiScenarioReportResults.stream().map(ApiScenarioReportResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } apiScenarioReportResultMapper.deleteByExample(reportResultExample); ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); @@ -604,10 +741,20 @@ public class ApiScenarioReportService { ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); definitionExecResultExample.createCriteria().andIdIn(handleIdList); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(handleIdList); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); definitionExecResultMapper.deleteByExample(definitionExecResultExample); ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); execResultExample.createCriteria().andIntegratedReportIdIn(handleIdList); + List apiDefinitionExecResults = definitionExecResultMapper.selectByExample(execResultExample); + if(apiDefinitionExecResults!=null&&apiDefinitionExecResults.size()!=0){ + List reportIds = apiDefinitionExecResults.stream().map(ApiDefinitionExecResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample asexample = new ApiDefinitionScenarioRelevanceExample(); + asexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(asexample); + } definitionExecResultMapper.deleteByExample(execResultExample); //转存剩余的数据 @@ -625,6 +772,13 @@ public class ApiScenarioReportService { ApiScenarioReportResultExample reportResultExample = new ApiScenarioReportResultExample(); reportResultExample.createCriteria().andReportIdIn(ids); + List apiScenarioReportResults = apiScenarioReportResultMapper.selectByExample(reportResultExample); + if(apiScenarioReportResults!=null&&apiScenarioReportResults.size()!=0){ + List reportIds = apiScenarioReportResults.stream().map(ApiScenarioReportResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); + } apiScenarioReportResultMapper.deleteByExample(reportResultExample); ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); @@ -633,10 +787,20 @@ public class ApiScenarioReportService { ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample(); definitionExecResultExample.createCriteria().andIdIn(ids); + ApiDefinitionScenarioRelevanceExample sexample = new ApiDefinitionScenarioRelevanceExample(); + sexample.createCriteria().andReportIdIn(ids); + apiDefinitionScenarioRelevanceMapper.deleteByExample(sexample); definitionExecResultMapper.deleteByExample(definitionExecResultExample); ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); execResultExample.createCriteria().andIntegratedReportIdIn(ids); + List apiDefinitionExecResults = definitionExecResultMapper.selectByExample(execResultExample); + if(apiDefinitionExecResults!=null&&apiDefinitionExecResults.size()!=0){ + List reportIds = apiDefinitionExecResults.stream().map(ApiDefinitionExecResult::getId).collect(Collectors.toList()); + ApiDefinitionScenarioRelevanceExample asexample = new ApiDefinitionScenarioRelevanceExample(); + asexample.createCriteria().andReportIdIn(reportIds); + apiDefinitionScenarioRelevanceMapper.deleteByExample(asexample); + } definitionExecResultMapper.deleteByExample(execResultExample); } } 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 022a6b0a44..12ed0b96b4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -102,6 +102,9 @@ public class ApiTestCaseService { private ExtProjectVersionMapper extProjectVersionMapper; @Resource private TcpApiParamService tcpApiParamService; + @Resource + private ApiDefinitionScenarioRelevanceMapper apiDefinitionScenarioRelevanceMapper; + private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; @@ -257,6 +260,8 @@ public class ApiTestCaseService { public void delete(String testId) { extTestPlanTestCaseMapper.deleteByTestCaseID(testId); deleteFileByTestId(testId); + ApiDefinitionExecResult result = extApiDefinitionExecResultMapper.selectMaxResultByResourceId(testId); + apiDefinitionScenarioRelevanceMapper.deleteByPrimaryKey(result.getId()); extApiDefinitionExecResultMapper.deleteByResourceId(testId); apiTestCaseMapper.deleteByPrimaryKey(testId); esbApiParamService.deleteByResourceId(testId); diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevance.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevance.java new file mode 100644 index 0000000000..4445a07762 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevance.java @@ -0,0 +1,11 @@ +package io.metersphere.base.domain; + +import java.io.Serializable; +import lombok.Data; + +@Data +public class ApiDefinitionScenarioRelevance implements Serializable { + private String reportId; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevanceExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevanceExample.java new file mode 100644 index 0000000000..dc3cfea1d4 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionScenarioRelevanceExample.java @@ -0,0 +1,270 @@ +package io.metersphere.base.domain; + +import java.util.ArrayList; +import java.util.List; + +public class ApiDefinitionScenarioRelevanceExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public ApiDefinitionScenarioRelevanceExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andReportIdIsNull() { + addCriterion("report_id is null"); + return (Criteria) this; + } + + public Criteria andReportIdIsNotNull() { + addCriterion("report_id is not null"); + return (Criteria) this; + } + + public Criteria andReportIdEqualTo(String value) { + addCriterion("report_id =", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotEqualTo(String value) { + addCriterion("report_id <>", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdGreaterThan(String value) { + addCriterion("report_id >", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdGreaterThanOrEqualTo(String value) { + addCriterion("report_id >=", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdLessThan(String value) { + addCriterion("report_id <", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdLessThanOrEqualTo(String value) { + addCriterion("report_id <=", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdLike(String value) { + addCriterion("report_id like", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotLike(String value) { + addCriterion("report_id not like", value, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdIn(List values) { + addCriterion("report_id in", values, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotIn(List values) { + addCriterion("report_id not in", values, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdBetween(String value1, String value2) { + addCriterion("report_id between", value1, value2, "reportId"); + return (Criteria) this; + } + + public Criteria andReportIdNotBetween(String value1, String value2) { + addCriterion("report_id not between", value1, value2, "reportId"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.java new file mode 100644 index 0000000000..0cafeb6c50 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.java @@ -0,0 +1,24 @@ +package io.metersphere.base.mapper; + +import io.metersphere.base.domain.ApiDefinitionScenarioRelevance; +import io.metersphere.base.domain.ApiDefinitionScenarioRelevanceExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface ApiDefinitionScenarioRelevanceMapper { + long countByExample(ApiDefinitionScenarioRelevanceExample example); + + int deleteByExample(ApiDefinitionScenarioRelevanceExample example); + + int deleteByPrimaryKey(String reportId); + + int insert(ApiDefinitionScenarioRelevance record); + + int insertSelective(ApiDefinitionScenarioRelevance record); + + List selectByExample(ApiDefinitionScenarioRelevanceExample example); + + int updateByExampleSelective(@Param("record") ApiDefinitionScenarioRelevance record, @Param("example") ApiDefinitionScenarioRelevanceExample example); + + int updateByExample(@Param("record") ApiDefinitionScenarioRelevance record, @Param("example") ApiDefinitionScenarioRelevanceExample example); +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.xml new file mode 100644 index 0000000000..0f640b20e9 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionScenarioRelevanceMapper.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + report_id + + + + delete from api_definition_scenario_relevance + where report_id = #{reportId,jdbcType=VARCHAR} + + + delete from api_definition_scenario_relevance + + + + + + insert into api_definition_scenario_relevance (report_id) + values (#{reportId,jdbcType=VARCHAR}) + + + insert into api_definition_scenario_relevance + + + report_id, + + + + + #{reportId,jdbcType=VARCHAR}, + + + + + + update api_definition_scenario_relevance + + + report_id = #{record.reportId,jdbcType=VARCHAR}, + + + + + + + + update api_definition_scenario_relevance + set report_id = #{record.reportId,jdbcType=VARCHAR} + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java index bb9f9f8401..d810108870 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultMapper.java @@ -1,5 +1,6 @@ package io.metersphere.base.mapper.ext; +import io.metersphere.api.dto.QueryAPIReportRequest; import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult; import io.metersphere.base.domain.ApiDefinitionExecResult; import io.metersphere.track.dto.PlanReportCaseDTO; @@ -32,6 +33,8 @@ public interface ExtApiDefinitionExecResultMapper { List selectApiResultByProjectId(String projectId); + long selectCountByRequest(@Param("request") QueryAPIReportRequest request); + List selectForPlanReport(@Param("ids") List apiReportIds); void update(@Param("ids") List ids); 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 841e60bd89..9f16c19c43 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 @@ -122,6 +122,139 @@ + + + + + + like CONCAT('%', #{${object}.value},'%') + + + not like CONCAT('%', #{${object}.value},'%') + + + in + + #{v} + + + + not in + + #{v} + + + + between #{${object}.value[0]} and #{${object}.value[1]} + + + > #{${object}.value} + + + < #{${object}.value} + + + >= #{${object}.value} + + + <= #{${object}.value} + + + = '${@io.metersphere.commons.utils.SessionUtils@getUserId()}' + + + = #{${object}.value} + + + + + + + and `name` + + + + + + and `name` + + + + + + and create_time + + + + + + and status + + + + + + and trigger_mode + + + + + + and user_id + + + + + + update api_definition_exec_result set status="STOP" where id in diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java index e37299eb46..55e5508c5a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java @@ -6,11 +6,21 @@ import java.util.List; public class ExtApiDefinitionExecResultProvider { public String insertListSql(List list) { + StringBuffer rsqlList = new StringBuffer(); + rsqlList.append(";").append("insert into api_definition_scenario_relevance ( report_id ) values "); StringBuffer sqlList = new StringBuffer(); sqlList.append("insert into api_definition_exec_result (id, `name`, resource_id, `status`, user_id, start_time, end_time," + " create_time, `type`, actuator, trigger_mode, version_id, error_code,project_id,integrated_report_id, content) values "); for (int i = 0; i < list.size(); i++) { ApiDefinitionExecResult result = list.get(i); + rsqlList.append(" (") + .append("'") + .append(result.getId()) + .append("'") + .append(")"); + if (i < list.size() - 1) { + rsqlList.append(","); + } sqlList.append(" (") .append("'") .append(result.getId()) @@ -50,6 +60,9 @@ public class ExtApiDefinitionExecResultProvider { sqlList.append(","); } } + rsqlList.append(";"); + sqlList.append(";"); + sqlList.append(rsqlList); return sqlList.toString(); } } 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 33e6b77189..2508e73806 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 @@ -3,11 +3,13 @@ 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 io.metersphere.base.domain.ApiDefinitionExecResult; import io.metersphere.base.domain.ApiScenarioReport; import io.metersphere.dto.ApiReportCountDTO; import io.metersphere.track.dto.PlanReportCaseDTO; import org.apache.ibatis.annotations.InsertProvider; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.SelectProvider; import java.util.Collection; import java.util.List; @@ -41,7 +43,10 @@ public interface ExtApiScenarioReportMapper { void update(@Param("ids") List ids); + long selectCountByRequest(@Param("request") QueryAPIReportRequest request); + @InsertProvider(type = ExtApiScenarioReportProvider.class, method = "insertListSql") void sqlInsert(List list); + } 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 5d5c1e4501..20626a72e3 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 @@ -138,20 +138,29 @@ + update api_scenario_report set status="STOP" where id in diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java index 762bbfdbef..2c2ef8b36f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java @@ -1,16 +1,27 @@ package io.metersphere.base.mapper.ext; +import io.metersphere.api.dto.QueryAPIReportRequest; import io.metersphere.api.dto.automation.APIScenarioReportResult; import java.util.List; public class ExtApiScenarioReportProvider { public String insertListSql(List list) { + StringBuffer rsqlList = new StringBuffer(); + rsqlList.append(";").append("insert into api_definition_scenario_relevance ( report_id ) values "); StringBuffer sqlList = new StringBuffer(); sqlList.append("INSERT INTO api_scenario_report (id, project_id, `name`, create_time, update_time, `status`, user_id, trigger_mode," + " execute_type, scenario_name, scenario_id, create_user, actuator, end_time, report_version, version_id, description,report_type) VALUES "); for (int i = 0; i < list.size(); i++) { APIScenarioReportResult result = list.get(i); + rsqlList.append(" (") + .append("'") + .append(result.getId()) + .append("'") + .append(")"); + if (i < list.size() - 1) { + rsqlList.append(","); + } sqlList.append(" (") .append("'") .append(result.getId()) @@ -54,6 +65,12 @@ public class ExtApiScenarioReportProvider { sqlList.append(","); } } + rsqlList.append(";"); + sqlList.append(";"); + sqlList.append(rsqlList); return sqlList.toString(); } + + + } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 7e6272ea7f..f9cd070c38 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 7e6272ea7fe3f835c3698ba06efa0168f6403f26 +Subproject commit f9cd070c384d29d3e11bdab008a79aa5d403cc12 diff --git a/backend/src/main/resources/db/migration/V110__v1.18.3_release.sql b/backend/src/main/resources/db/migration/V110__v1.18.3_release.sql new file mode 100644 index 0000000000..1e31b71ae0 --- /dev/null +++ b/backend/src/main/resources/db/migration/V110__v1.18.3_release.sql @@ -0,0 +1,28 @@ +CREATE TABLE IF NOT EXISTS `api_definition_scenario_relevance` +( + `report_id` varchar(50) NOT NULL COMMENT 'ID', + PRIMARY KEY (`report_id`), + KEY `relevance_report_id_index` (`report_id`) +) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE utf8mb4_general_ci; + +ALTER TABLE `api_scenario_report` ADD INDEX update_time_index ( `update_time` ); + +ALTER TABLE `api_definition_exec_result` ADD INDEX update_time_index ( `create_time` ); + +ALTER TABLE `api_definition_exec_result` ADD INDEX integrated_report_id_index ( `integrated_report_id` ); + + +INSERT INTO api_definition_scenario_relevance (report_id) +SELECT s_r.id +FROM api_scenario_report s_r +where s_r.execute_type = 'Saved'; + +INSERT INTO api_definition_scenario_relevance (report_id) +select a_r.id +from api_definition_exec_result a_r +where (a_r.integrated_report_id is null or a_r.integrated_report_id = 'null'); + + + + + diff --git a/backend/src/main/resources/db/migration/V110__v1.19_release.sql b/backend/src/main/resources/db/migration/V111__v1.19_release.sql similarity index 100% rename from backend/src/main/resources/db/migration/V110__v1.19_release.sql rename to backend/src/main/resources/db/migration/V111__v1.19_release.sql diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index 3bea2f7187..09597561ef 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -64,31 +64,28 @@ - + - - - - - - - - - - - - - - - -
- -
+