fix(接口定义): 修复接口定义回收站用例数为0的缺陷
--bug=1016199 --user=王孝刚 【接口测试】回收站-api-用例数显示为0(api下有case) https://www.tapd.cn/55049933/s/1231791
This commit is contained in:
parent
2764dfebe4
commit
c4bc0ce27b
|
@ -183,7 +183,7 @@ public class ApiDefinitionService {
|
|||
buildUserInfo(resList);
|
||||
if (StringUtils.isNotBlank(request.getProjectId())) {
|
||||
buildProjectInfo(resList, request.getProjectId());
|
||||
calculateResult(resList, request.getProjectId());
|
||||
calculateResult(resList, request.getProjectId(), request);
|
||||
} else {
|
||||
buildProjectInfoWithoutProject(resList);
|
||||
}
|
||||
|
@ -2119,31 +2119,48 @@ public class ApiDefinitionService {
|
|||
if (!resList.isEmpty()) {
|
||||
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
||||
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIdsAndStatusIsNotTrash(ids, projectId);
|
||||
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
|
||||
for (ApiDefinitionResult res : resList) {
|
||||
ApiComputeResult compRes = resultMap.get(res.getId());
|
||||
if (compRes != null) {
|
||||
res.setCaseType("apiCase");
|
||||
res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
|
||||
res.setCasePassingRate(compRes.getPassRate());
|
||||
// 状态优先级 未执行,未通过,通过
|
||||
if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) {
|
||||
res.setCaseStatus(Translator.get("not_execute"));
|
||||
} else if (compRes.getError() > 0) {
|
||||
res.setCaseStatus(Translator.get("execute_not_pass"));
|
||||
} else {
|
||||
res.setCaseStatus(Translator.get("execute_pass"));
|
||||
}
|
||||
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()));
|
||||
for (ApiDefinitionResult res : resList) {
|
||||
ApiComputeResult compRes = resultMap.get(res.getId());
|
||||
if (compRes != null) {
|
||||
res.setCaseType("apiCase");
|
||||
res.setCaseTotal(String.valueOf(compRes.getCaseTotal()));
|
||||
res.setCasePassingRate(compRes.getPassRate());
|
||||
// 状态优先级 未执行,未通过,通过
|
||||
if ((compRes.getError() + compRes.getSuccess()) < compRes.getCaseTotal()) {
|
||||
res.setCaseStatus(Translator.get("not_execute"));
|
||||
} else if (compRes.getError() > 0) {
|
||||
res.setCaseStatus(Translator.get("execute_not_pass"));
|
||||
} else {
|
||||
res.setCaseType("apiCase");
|
||||
res.setCaseTotal("0");
|
||||
res.setCasePassingRate("-");
|
||||
res.setCaseStatus("-");
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) {
|
||||
esbApiParamService.handleApiEsbParams(res);
|
||||
res.setCaseStatus(Translator.get("execute_pass"));
|
||||
}
|
||||
} else {
|
||||
res.setCaseType("apiCase");
|
||||
res.setCaseTotal("0");
|
||||
res.setCasePassingRate("-");
|
||||
res.setCaseStatus("-");
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) {
|
||||
esbApiParamService.handleApiEsbParams(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
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 removeToGcByExample(ApiDefinitionExampleWithOperation example);
|
||||
|
|
|
@ -131,6 +131,20 @@
|
|||
</foreach>
|
||||
</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">
|
||||
<if test='${condition}.name != null and (${name} == null or ${name} == "")'>
|
||||
and api_definition.name
|
||||
|
|
Loading…
Reference in New Issue