diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/datacount/response/ApiDataCountDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/datacount/response/ApiDataCountDTO.java index 30873c2e05..0069e09ac1 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/datacount/response/ApiDataCountDTO.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/datacount/response/ApiDataCountDTO.java @@ -1,15 +1,19 @@ package io.metersphere.api.dto.datacount.response; import io.metersphere.api.dto.datacount.ApiDataCountResult; +import io.metersphere.base.domain.ApiDefinition; import io.metersphere.commons.constants.RequestTypeConstants; import io.metersphere.commons.enums.ApiHomeFilterEnum; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.enums.ApiTestDataStatus; import lombok.Getter; import lombok.Setter; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import java.util.List; +import java.util.Map; /** * 接口数据统计返回 @@ -23,6 +27,19 @@ public class ApiDataCountDTO { private long rpcCount = 0; private long sqlCount = 0; private long createdInWeek = 0; + + //不同请求方式的覆盖数 + private long httpCovered = 0; + private long tcpCovered = 0; + private long sqlCovered = 0; + private long rpcCovered = 0; + + //不同请求方式的未覆盖 + private long httpNotCovered = 0; + private long tcpNotCovered = 0; + private long rpcNotCovered = 0; + private long sqlNotCovered = 0; + private long coveredCount = 0; private long notCoveredCount = 0; private long runningCount = 0; @@ -49,11 +66,29 @@ public class ApiDataCountDTO { //通过率 private String passRate = "0%"; - /** - * 对Protocol视角对查询结果进行统计 - * - * @param countResultList 查询参数 - */ + public void countProtocol(Map> protocalAllApiMap) { + for (Map.Entry> entry : protocalAllApiMap.entrySet()) { + switch (entry.getKey()) { + case RequestTypeConstants.DUBBO: + this.rpcCount += entry.getValue().size(); + break; + case RequestTypeConstants.HTTP: + this.httpCount += entry.getValue().size(); + break; + case RequestTypeConstants.SQL: + this.sqlCount += entry.getValue().size(); + break; + case RequestTypeConstants.TCP: + this.tcpCount += entry.getValue().size(); + break; + default: + break; + } + } + this.total = this.rpcCount + this.httpCount + this.sqlCount + this.tcpCount; + } + + public void countProtocol(List countResultList) { for (ApiDataCountResult countResult : countResultList) { @@ -77,7 +112,6 @@ public class ApiDataCountDTO { this.total = this.rpcCount + this.httpCount + this.sqlCount + this.tcpCount; } - /** * 对Status视角对查询结果进行统计 * @@ -162,4 +196,56 @@ public class ApiDataCountDTO { } } } + + /** + * 统计覆盖率相关数据 + * + * @param coverageMap 和覆盖率相关的protocol集合 + * @param isUnCovered 是否统计的是未覆盖的数据 + */ + public void countCovered(Map> coverageMap, boolean isUnCovered) { + if (MapUtils.isNotEmpty(coverageMap)) { + for (Map.Entry> entry : coverageMap.entrySet()) { + if (CollectionUtils.isNotEmpty(entry.getValue())) { + switch (entry.getKey()) { + case RequestTypeConstants.DUBBO: + if (isUnCovered) { + this.rpcNotCovered += entry.getValue().size(); + } else { + this.rpcCovered += entry.getValue().size(); + } + break; + case RequestTypeConstants.HTTP: + if (isUnCovered) { + this.httpNotCovered += entry.getValue().size(); + } else { + this.httpCovered += entry.getValue().size(); + } + break; + case RequestTypeConstants.SQL: + if (isUnCovered) { + this.sqlNotCovered += entry.getValue().size(); + } else { + this.sqlCovered += entry.getValue().size(); + } + break; + case RequestTypeConstants.TCP: + if (isUnCovered) { + this.tcpNotCovered += entry.getValue().size(); + } else { + this.tcpCovered += entry.getValue().size(); + } + break; + default: + break; + } + } + } + } + if (isUnCovered) { + this.notCoveredCount = this.rpcNotCovered + this.httpNotCovered + this.tcpNotCovered + this.sqlNotCovered; + } else { + this.coveredCount = this.rpcCovered + this.httpCovered + this.tcpCovered + this.sqlCovered; + } + } } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java index 24ec92dba3..be5e841dd1 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java @@ -1,7 +1,10 @@ package io.metersphere.base.mapper.ext; import io.metersphere.api.dto.datacount.ApiDataCountResult; -import io.metersphere.api.dto.definition.*; +import io.metersphere.api.dto.definition.ApiComputeResult; +import io.metersphere.api.dto.definition.ApiDefinitionRequest; +import io.metersphere.api.dto.definition.ApiDefinitionResult; +import io.metersphere.api.dto.definition.ApiModuleDTO; import io.metersphere.base.domain.*; import io.metersphere.dto.RelationshipGraphData; import io.metersphere.request.BaseQueryRequest; @@ -25,9 +28,7 @@ public interface ExtApiDefinitionMapper { int reduction(@Param("ids") List ids); - List countProtocolByProjectID(@Param("projectId") String projectId, @Param("versionId") String versionId); - - Long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("versionId") String versionId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); + List selectBaseInfoByProjectIDAndVersion(@Param("projectId") String projectId, @Param("versionId") String versionId); List countStateByProjectID(@Param("projectId") String projectId, @Param("versionId") String versionId); @@ -55,7 +56,7 @@ public interface ExtApiDefinitionMapper { Long getLastOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder); - long countApiByProjectIdAndHasCase(@Param("projectId") String projectId, @Param("versionId") String versionId); + List selectBaseInfoByProjectIdAndHasCase(@Param("projectId") String projectId, @Param("versionId") String versionId); List getForGraph(@Param("ids") Set ids); diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml index 4332d851eb..75a45d67f1 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml @@ -396,8 +396,8 @@ - + SELECT id,name,method,protocol,path,create_time FROM api_definition WHERE project_id = #{projectId} AND `status` != 'Trash' @@ -407,7 +407,6 @@ AND latest = 1 - GROUP BY protocol - + + + -