fix(接口定义): 修复接口定义回收站用例数为0的缺陷

--bug=1016199 --user=王孝刚 【接口测试】回收站-api-用例数显示为0(api下有case)
https://www.tapd.cn/55049933/s/1231791
This commit is contained in:
wxg0103 2022-08-23 19:49:03 +08:00 committed by 刘瑞斌
parent 8f2384119c
commit 85e33eb9e0
3 changed files with 56 additions and 23 deletions

View File

@ -183,7 +183,7 @@ public class ApiDefinitionService {
buildUserInfo(resList); buildUserInfo(resList);
if (StringUtils.isNotBlank(request.getProjectId())) { if (StringUtils.isNotBlank(request.getProjectId())) {
buildProjectInfo(resList, request.getProjectId()); buildProjectInfo(resList, request.getProjectId());
calculateResult(resList, request.getProjectId()); calculateResult(resList, request.getProjectId(), request);
} else { } else {
buildProjectInfoWithoutProject(resList); buildProjectInfoWithoutProject(resList);
} }
@ -2119,6 +2119,11 @@ public class ApiDefinitionService {
if (!resList.isEmpty()) { if (!resList.isEmpty()) {
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList()); List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId); List<ApiComputeResult> results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
calculateResultList(resList, results);
}
}
private void calculateResultList(List<ApiDefinitionResult> resList, List<ApiComputeResult> results) {
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity())); Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
for (ApiDefinitionResult res : resList) { for (ApiDefinitionResult res : resList) {
ApiComputeResult compRes = resultMap.get(res.getId()); ApiComputeResult compRes = resultMap.get(res.getId());
@ -2145,6 +2150,18 @@ public class ApiDefinitionService {
} }
} }
} }
public void calculateResult(List<ApiDefinitionResult> resList, String projectId, ApiDefinitionRequest request) {
if (!resList.isEmpty()) {
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
List<ApiComputeResult> results = new ArrayList<>();
if (request != null && request.getFilters().containsKey("status") && request.getFilters().get("status").get(0).equals("Trash")) {
results = extApiDefinitionMapper.selectByIdsAndStatusIsTrash(ids, projectId);
} else {
results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
}
calculateResultList(resList, results);
}
} }
/** /**

View File

@ -37,6 +37,8 @@ public interface ExtApiDefinitionMapper {
List<ApiComputeResult> selectByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId); List<ApiComputeResult> selectByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
List<ApiComputeResult> selectByIdsAndStatusIsTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
// int removeToGc(@Param("ids") List<String> ids); // int removeToGc(@Param("ids") List<String> ids);
int removeToGcByExample(ApiDefinitionExampleWithOperation example); int removeToGcByExample(ApiDefinitionExampleWithOperation example);

View File

@ -131,6 +131,20 @@
</foreach> </foreach>
</select> </select>
<select id="selectByIdsAndStatusIsTrash" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
SELECT t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal,
SUM(case when t2.status ='success' then 1 else 0 end) as success ,SUM(case when t2.status ='error' then 1 else 0
end) as error,
CONCAT(FORMAT(SUM(IF (t2.`status`='success',1,0))/COUNT(t1.id)*100,2),'%') passRate
FROM api_test_case t1
LEFT JOIN api_definition_exec_result t2 ON t1.last_result_id=t2.id
WHERE t1.project_id = #{projectId} and t1.status = 'Trash'
group by t1.api_definition_id having t1.api_definition_id in
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</select>
<sql id="combine"> <sql id="combine">
<if test='${condition}.name != null and (${name} == null or ${name} == "")'> <if test='${condition}.name != null and (${name} == null or ${name} == "")'>
and api_definition.name and api_definition.name